blob: 0a171b3904d460a337b48366449a58f0f0b7ecfa [file] [log] [blame]
Toshio Koidec87810e2014-02-11 13:03:21 -08001package net.onrc.onos.intent.runtime;
2
3import java.util.Collection;
4import java.util.HashSet;
5
6import net.onrc.onos.intent.ConstrainedBFSTree;
7import net.onrc.onos.intent.ConstrainedShortestPathIntent;
8import net.onrc.onos.intent.Intent;
9import net.onrc.onos.intent.PathIntent;
10import net.onrc.onos.intent.PathIntents;
11import net.onrc.onos.intent.ShortestPathIntent;
12import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
13import net.onrc.onos.ofcontroller.networkgraph.Path;
14import net.onrc.onos.ofcontroller.networkgraph.Switch;
15
16/**
17 * @author Toshio Koide (t-koide@onlab.us)
18 */
19public class PathCalcRuntime {
20 NetworkGraph graph;
21 HashSet<Intent> inputIntents = new HashSet<Intent>();
Toshio Koidec406e792014-02-14 16:52:42 -080022 PathIntents outputIntents = null;
Toshio Koidec87810e2014-02-11 13:03:21 -080023
24 public PathCalcRuntime(NetworkGraph g) {
25 this.graph = g;
Toshio Koidec406e792014-02-14 16:52:42 -080026 outputIntents = new PathIntents(g);
Toshio Koidec87810e2014-02-11 13:03:21 -080027 }
28
29 public Collection<Intent> getInputIntents() {
30 return inputIntents;
31 }
32
33 public PathIntents getOutputIntents() {
34 return outputIntents;
35 }
36
37 public void addInputIntents(Collection<Intent> inputIntents) {
38 this.inputIntents.addAll(inputIntents);
39 this.outputIntents = calcPathIntents(inputIntents);
40 }
41
42 protected PathIntents calcPathIntents(Collection<Intent> originalIntents) {
Toshio Koidec406e792014-02-14 16:52:42 -080043 PathIntents pathIntents = new PathIntents(graph);
Toshio Koidec87810e2014-02-11 13:03:21 -080044
45 for (Intent intent: originalIntents) {
46 if (!(intent instanceof ShortestPathIntent)) {
47 // unsupported intent type.
48 // TODO should push back the intent to caller
49 continue;
50 }
51
52 ShortestPathIntent spIntent = (ShortestPathIntent) intent;
Toshio Koide0e4d8d22014-02-14 10:56:10 -080053 Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid());
54 Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid());
Toshio Koidec87810e2014-02-11 13:03:21 -080055 if (srcSwitch == null || dstSwitch == null) {
56 // incomplete intent.
57 // TODO should push back the intent to caller
58 continue;
59 }
60
Toshio Koide0e4d8d22014-02-14 10:56:10 -080061 double bandwidth = 0.0;
Toshio Koidec87810e2014-02-11 13:03:21 -080062 ConstrainedBFSTree tree = null;
63 if (intent instanceof ConstrainedShortestPathIntent) {
64 bandwidth = ((ConstrainedShortestPathIntent) intent).getBandwidth();
65 tree = new ConstrainedBFSTree(srcSwitch, pathIntents, bandwidth);
66 }
67 else {
68 tree = new ConstrainedBFSTree(srcSwitch);
69 }
70 Path path = tree.getPath(dstSwitch);
71 if (path == null) {
72 // path not found.
73 // TODO should push back the intent to caller
74 continue;
75 }
Toshio Koide0e4d8d22014-02-14 10:56:10 -080076
Toshio Koide13986d12014-02-11 20:25:32 -080077 pathIntents.addIntent(new PathIntent("pi" + intent.getId(), path, bandwidth, intent));
Toshio Koidec87810e2014-02-11 13:03:21 -080078 }
79 return pathIntents;
80 }
81}