Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame^] | 3 | import java.util.HashMap; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 4 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 5 | import net.floodlightcontroller.core.module.IFloodlightService; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 6 | import net.onrc.onos.intent.ConstrainedBFSTree; |
| 7 | import net.onrc.onos.intent.ConstrainedShortestPathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 8 | import net.onrc.onos.intent.IntentOperation; |
| 9 | import net.onrc.onos.intent.IntentOperationList; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 10 | import net.onrc.onos.intent.PathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 11 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 12 | import net.onrc.onos.intent.ShortestPathIntent; |
| 13 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 14 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
| 15 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
| 16 | |
| 17 | /** |
| 18 | * @author Toshio Koide (t-koide@onlab.us) |
| 19 | */ |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 20 | public class PathCalcRuntime implements IFloodlightService { |
| 21 | private NetworkGraph graph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 22 | public PathCalcRuntime(NetworkGraph g) { |
| 23 | this.graph = g; |
| 24 | } |
| 25 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame^] | 26 | /** |
| 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 Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 35 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame^] | 36 | 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 Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 44 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame^] | 45 | 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 Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 53 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame^] | 54 | 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 Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 79 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 80 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame^] | 81 | return pathIntentOpList; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 82 | } |
| 83 | } |