blob: 3e09f8c634d7d11a5d0bf4774e3aa15716f48cb1 [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>();
22 PathIntents outputIntents = new PathIntents();
23
24 public PathCalcRuntime(NetworkGraph g) {
25 this.graph = g;
26 }
27
28 public Collection<Intent> getInputIntents() {
29 return inputIntents;
30 }
31
32 public PathIntents getOutputIntents() {
33 return outputIntents;
34 }
35
36 public void addInputIntents(Collection<Intent> inputIntents) {
37 this.inputIntents.addAll(inputIntents);
38 this.outputIntents = calcPathIntents(inputIntents);
39 }
40
41 protected PathIntents calcPathIntents(Collection<Intent> originalIntents) {
42 PathIntents pathIntents = new PathIntents();
43
44 for (Intent intent: originalIntents) {
45 if (!(intent instanceof ShortestPathIntent)) {
46 // unsupported intent type.
47 // TODO should push back the intent to caller
48 continue;
49 }
50
51 ShortestPathIntent spIntent = (ShortestPathIntent) intent;
52 Switch srcSwitch = spIntent.getSourcePort().getSwitch();
53 Switch dstSwitch = spIntent.getDestinationPort().getSwitch();
54 if (srcSwitch == null || dstSwitch == null) {
55 // incomplete intent.
56 // TODO should push back the intent to caller
57 continue;
58 }
59
60 Double bandwidth = null;
61 ConstrainedBFSTree tree = null;
62 if (intent instanceof ConstrainedShortestPathIntent) {
63 bandwidth = ((ConstrainedShortestPathIntent) intent).getBandwidth();
64 tree = new ConstrainedBFSTree(srcSwitch, pathIntents, bandwidth);
65 }
66 else {
67 tree = new ConstrainedBFSTree(srcSwitch);
68 }
69 Path path = tree.getPath(dstSwitch);
70 if (path == null) {
71 // path not found.
72 // TODO should push back the intent to caller
73 continue;
74 }
75
76 pathIntents.addIntent(new PathIntent(path, bandwidth, intent));
77 }
78 return pathIntents;
79 }
80}