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 | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 8 | import net.onrc.onos.intent.Intent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 9 | import net.onrc.onos.intent.IntentOperation; |
Toshio Koide | d9fa2a8 | 2014-02-19 17:35:18 -0800 | [diff] [blame^] | 10 | import net.onrc.onos.intent.IntentOperation.Operator; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 11 | import net.onrc.onos.intent.IntentOperationList; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 12 | import net.onrc.onos.intent.PathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 13 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 14 | import net.onrc.onos.intent.ShortestPathIntent; |
| 15 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 16 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
| 17 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
| 18 | |
| 19 | /** |
| 20 | * @author Toshio Koide (t-koide@onlab.us) |
| 21 | */ |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame] | 22 | public class PathCalcRuntime implements IFloodlightService { |
| 23 | private NetworkGraph graph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 24 | public PathCalcRuntime(NetworkGraph g) { |
| 25 | this.graph = g; |
| 26 | } |
| 27 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 28 | /** |
| 29 | * calculate shortest-path and constrained-shortest-path intents into low-level path intents |
| 30 | * @param intentOpList IntentOperationList having instances of ShortestPathIntent/ConstrainedShortestPathIntent |
| 31 | * @param pathIntents a set of current low-level intents |
| 32 | * @return IntentOperationList for PathIntent instances |
| 33 | */ |
| 34 | public IntentOperationList calcPathIntents(IntentOperationList intentOpList, PathIntentMap pathIntents) { |
| 35 | IntentOperationList pathIntentOpList = new IntentOperationList(); |
| 36 | HashMap<Switch, ConstrainedBFSTree> spfTrees = new HashMap<>(); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 37 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 38 | for (IntentOperation intentOp: intentOpList) { |
| 39 | switch (intentOp.operator) { |
| 40 | case ADD: |
| 41 | if (!(intentOp.intent instanceof ShortestPathIntent)) { |
| 42 | // unsupported intent type. |
| 43 | // TODO should push back the intent to caller |
| 44 | continue; |
| 45 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 46 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 47 | ShortestPathIntent spIntent = (ShortestPathIntent) intentOp.intent; |
| 48 | Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid()); |
| 49 | Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid()); |
| 50 | if (srcSwitch == null || dstSwitch == null) { |
| 51 | // incomplete intent. |
| 52 | // TODO should push back the intent to caller |
| 53 | continue; |
| 54 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 55 | |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 56 | double bandwidth = 0.0; |
| 57 | ConstrainedBFSTree tree = null; |
| 58 | if (intentOp.intent instanceof ConstrainedShortestPathIntent) { |
| 59 | bandwidth = ((ConstrainedShortestPathIntent) intentOp.intent).getBandwidth(); |
| 60 | tree = new ConstrainedBFSTree(srcSwitch, pathIntents, bandwidth); |
| 61 | } |
| 62 | else { |
| 63 | tree = spfTrees.get(srcSwitch); |
| 64 | if (tree == null) { |
| 65 | tree = new ConstrainedBFSTree(srcSwitch); |
| 66 | spfTrees.put(srcSwitch, tree); |
| 67 | } |
| 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 | PathIntent pathIntent = new PathIntent("pi" + intentOp.intent.getId(), path, bandwidth, intentOp.intent); |
| 76 | pathIntentOpList.add(new IntentOperation(IntentOperation.Operator.ADD, pathIntent)); |
| 77 | break; |
| 78 | case REMOVE: |
Toshio Koide | 0c9106d | 2014-02-19 15:26:38 -0800 | [diff] [blame] | 79 | pathIntentOpList.add(Operator.REMOVE, new Intent("pi" + intentOp.intent.getId())); |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 80 | break; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 81 | } |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 82 | } |
Toshio Koide | 27ffd41 | 2014-02-18 19:15:27 -0800 | [diff] [blame] | 83 | return pathIntentOpList; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 84 | } |
| 85 | } |