blob: 32fe7469be63b12d2ce1d11f44ad64fde03daccb [file] [log] [blame]
Toshio Koidec87810e2014-02-11 13:03:21 -08001package net.onrc.onos.intent.runtime;
2
Toshio Koide27ffd412014-02-18 19:15:27 -08003import java.util.HashMap;
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;
Toshio Koide4f308732014-02-18 15:19:48 -08008import net.onrc.onos.intent.IntentOperation;
9import net.onrc.onos.intent.IntentOperationList;
Toshio Koidec87810e2014-02-11 13:03:21 -080010import net.onrc.onos.intent.PathIntent;
Toshio Koide4f308732014-02-18 15:19:48 -080011import net.onrc.onos.intent.PathIntentMap;
Toshio Koidec87810e2014-02-11 13:03:21 -080012import net.onrc.onos.intent.ShortestPathIntent;
13import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
14import net.onrc.onos.ofcontroller.networkgraph.Path;
15import net.onrc.onos.ofcontroller.networkgraph.Switch;
16
17/**
18 * @author Toshio Koide (t-koide@onlab.us)
19 */
Toshio Koide4f308732014-02-18 15:19:48 -080020public class PathCalcRuntime implements IFloodlightService {
21 private NetworkGraph graph;
Toshio Koidec87810e2014-02-11 13:03:21 -080022 public PathCalcRuntime(NetworkGraph g) {
23 this.graph = g;
24 }
25
Toshio Koide27ffd412014-02-18 19:15:27 -080026 /**
27 * calculate shortest-path and constrained-shortest-path intents into low-level path intents
28 * @param intentOpList IntentOperationList having instances of ShortestPathIntent/ConstrainedShortestPathIntent
29 * @param pathIntents a set of current low-level intents
30 * @return IntentOperationList for PathIntent instances
31 */
32 public IntentOperationList calcPathIntents(IntentOperationList intentOpList, PathIntentMap pathIntents) {
33 IntentOperationList pathIntentOpList = new IntentOperationList();
34 HashMap<Switch, ConstrainedBFSTree> spfTrees = new HashMap<>();
Toshio Koidec87810e2014-02-11 13:03:21 -080035
Toshio Koide27ffd412014-02-18 19:15:27 -080036 for (IntentOperation intentOp: intentOpList) {
37 switch (intentOp.operator) {
38 case ADD:
39 if (!(intentOp.intent instanceof ShortestPathIntent)) {
40 // unsupported intent type.
41 // TODO should push back the intent to caller
42 continue;
43 }
Toshio Koidec87810e2014-02-11 13:03:21 -080044
Toshio Koide27ffd412014-02-18 19:15:27 -080045 ShortestPathIntent spIntent = (ShortestPathIntent) intentOp.intent;
46 Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid());
47 Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid());
48 if (srcSwitch == null || dstSwitch == null) {
49 // incomplete intent.
50 // TODO should push back the intent to caller
51 continue;
52 }
Toshio Koidec87810e2014-02-11 13:03:21 -080053
Toshio Koide27ffd412014-02-18 19:15:27 -080054 double bandwidth = 0.0;
55 ConstrainedBFSTree tree = null;
56 if (intentOp.intent instanceof ConstrainedShortestPathIntent) {
57 bandwidth = ((ConstrainedShortestPathIntent) intentOp.intent).getBandwidth();
58 tree = new ConstrainedBFSTree(srcSwitch, pathIntents, bandwidth);
59 }
60 else {
61 tree = spfTrees.get(srcSwitch);
62 if (tree == null) {
63 tree = new ConstrainedBFSTree(srcSwitch);
64 spfTrees.put(srcSwitch, tree);
65 }
66 }
67 Path path = tree.getPath(dstSwitch);
68 if (path == null) {
69 // path not found.
70 // TODO should push back the intent to caller
71 continue;
72 }
73 PathIntent pathIntent = new PathIntent("pi" + intentOp.intent.getId(), path, bandwidth, intentOp.intent);
74 pathIntentOpList.add(new IntentOperation(IntentOperation.Operator.ADD, pathIntent));
75 break;
76 case REMOVE:
77 pathIntentOpList.add(intentOp);
78 break;
Toshio Koidec87810e2014-02-11 13:03:21 -080079 }
Toshio Koidec87810e2014-02-11 13:03:21 -080080 }
Toshio Koide27ffd412014-02-18 19:15:27 -080081 return pathIntentOpList;
Toshio Koidec87810e2014-02-11 13:03:21 -080082 }
83}