Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent.runtime; |
| 2 | |
| 3 | import java.util.Collection; |
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; |
| 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; |
| 10 | import net.onrc.onos.intent.IntentOperationList; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 11 | import net.onrc.onos.intent.PathIntent; |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame^] | 12 | import net.onrc.onos.intent.PathIntentMap; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 13 | import net.onrc.onos.intent.ShortestPathIntent; |
| 14 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 15 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
| 16 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
| 17 | |
| 18 | /** |
| 19 | * @author Toshio Koide (t-koide@onlab.us) |
| 20 | */ |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame^] | 21 | public class PathCalcRuntime implements IFloodlightService { |
| 22 | private NetworkGraph graph; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 23 | public PathCalcRuntime(NetworkGraph g) { |
| 24 | this.graph = g; |
| 25 | } |
| 26 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame^] | 27 | public PathIntentMap calcPathIntents(Collection<Intent> highLevelIntents, PathIntentMap pathIntents) { |
| 28 | IntentOperationList intentOpList = new IntentOperationList(); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 29 | |
Toshio Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame^] | 30 | for (Intent intent: highLevelIntents) { |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 31 | 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 Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 38 | Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid()); |
| 39 | Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 40 | if (srcSwitch == null || dstSwitch == null) { |
| 41 | // incomplete intent. |
| 42 | // TODO should push back the intent to caller |
| 43 | continue; |
| 44 | } |
| 45 | |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 46 | double bandwidth = 0.0; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 47 | 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 Koide | 4f30873 | 2014-02-18 15:19:48 -0800 | [diff] [blame^] | 61 | |
| 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 Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 65 | } |
| 66 | return pathIntents; |
| 67 | } |
| 68 | } |