blob: d22d516f970bc371c81635c3cfadf0ab41f0f24d [file] [log] [blame]
Toshio Koidec87810e2014-02-11 13:03:21 -08001package net.onrc.onos.intent.runtime;
2
3import java.util.Collection;
Toshio Koidec87810e2014-02-11 13:03:21 -08004
Toshio Koide4f308732014-02-18 15:19:48 -08005import net.floodlightcontroller.core.module.IFloodlightService;
Toshio Koidec87810e2014-02-11 13:03:21 -08006import net.onrc.onos.intent.ConstrainedBFSTree;
7import net.onrc.onos.intent.ConstrainedShortestPathIntent;
8import net.onrc.onos.intent.Intent;
Toshio Koide4f308732014-02-18 15:19:48 -08009import net.onrc.onos.intent.IntentOperation;
10import net.onrc.onos.intent.IntentOperationList;
Toshio Koidec87810e2014-02-11 13:03:21 -080011import net.onrc.onos.intent.PathIntent;
Toshio Koide4f308732014-02-18 15:19:48 -080012import net.onrc.onos.intent.PathIntentMap;
Toshio Koidec87810e2014-02-11 13:03:21 -080013import net.onrc.onos.intent.ShortestPathIntent;
14import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
15import net.onrc.onos.ofcontroller.networkgraph.Path;
16import net.onrc.onos.ofcontroller.networkgraph.Switch;
17
18/**
19 * @author Toshio Koide (t-koide@onlab.us)
20 */
Toshio Koide4f308732014-02-18 15:19:48 -080021public class PathCalcRuntime implements IFloodlightService {
22 private NetworkGraph graph;
Toshio Koidec87810e2014-02-11 13:03:21 -080023 public PathCalcRuntime(NetworkGraph g) {
24 this.graph = g;
25 }
26
Toshio Koide4f308732014-02-18 15:19:48 -080027 public PathIntentMap calcPathIntents(Collection<Intent> highLevelIntents, PathIntentMap pathIntents) {
28 IntentOperationList intentOpList = new IntentOperationList();
Toshio Koidec87810e2014-02-11 13:03:21 -080029
Toshio Koide4f308732014-02-18 15:19:48 -080030 for (Intent intent: highLevelIntents) {
Toshio Koidec87810e2014-02-11 13:03:21 -080031 if (!(intent instanceof ShortestPathIntent)) {
32 // unsupported intent type.
33 // TODO should push back the intent to caller
34 continue;
35 }
36
37 ShortestPathIntent spIntent = (ShortestPathIntent) intent;
Toshio Koide0e4d8d22014-02-14 10:56:10 -080038 Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid());
39 Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid());
Toshio Koidec87810e2014-02-11 13:03:21 -080040 if (srcSwitch == null || dstSwitch == null) {
41 // incomplete intent.
42 // TODO should push back the intent to caller
43 continue;
44 }
45
Toshio Koide0e4d8d22014-02-14 10:56:10 -080046 double bandwidth = 0.0;
Toshio Koidec87810e2014-02-11 13:03:21 -080047 ConstrainedBFSTree tree = null;
48 if (intent instanceof ConstrainedShortestPathIntent) {
49 bandwidth = ((ConstrainedShortestPathIntent) intent).getBandwidth();
50 tree = new ConstrainedBFSTree(srcSwitch, pathIntents, bandwidth);
51 }
52 else {
53 tree = new ConstrainedBFSTree(srcSwitch);
54 }
55 Path path = tree.getPath(dstSwitch);
56 if (path == null) {
57 // path not found.
58 // TODO should push back the intent to caller
59 continue;
60 }
Toshio Koide4f308732014-02-18 15:19:48 -080061
62 PathIntent pathIntent = new PathIntent("pi" + intent.getId(), path, bandwidth, intent);
63 pathIntents.addIntent(pathIntent);
64 intentOpList.add(new IntentOperation(IntentOperation.Operator.ADD, pathIntent));
Toshio Koidec87810e2014-02-11 13:03:21 -080065 }
66 return pathIntents;
67 }
68}