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; |
| 4 | import java.util.HashSet; |
| 5 | |
| 6 | import net.onrc.onos.intent.ConstrainedBFSTree; |
| 7 | import net.onrc.onos.intent.ConstrainedShortestPathIntent; |
| 8 | import net.onrc.onos.intent.Intent; |
| 9 | import net.onrc.onos.intent.PathIntent; |
| 10 | import net.onrc.onos.intent.PathIntents; |
| 11 | import net.onrc.onos.intent.ShortestPathIntent; |
| 12 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
| 13 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
| 14 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
| 15 | |
| 16 | /** |
| 17 | * @author Toshio Koide (t-koide@onlab.us) |
| 18 | */ |
| 19 | public class PathCalcRuntime { |
| 20 | NetworkGraph graph; |
| 21 | HashSet<Intent> inputIntents = new HashSet<Intent>(); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 22 | PathIntents outputIntents = null; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 23 | |
| 24 | public PathCalcRuntime(NetworkGraph g) { |
| 25 | this.graph = g; |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 26 | outputIntents = new PathIntents(g); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | public Collection<Intent> getInputIntents() { |
| 30 | return inputIntents; |
| 31 | } |
| 32 | |
| 33 | public PathIntents getOutputIntents() { |
| 34 | return outputIntents; |
| 35 | } |
| 36 | |
| 37 | public void addInputIntents(Collection<Intent> inputIntents) { |
| 38 | this.inputIntents.addAll(inputIntents); |
| 39 | this.outputIntents = calcPathIntents(inputIntents); |
| 40 | } |
| 41 | |
| 42 | protected PathIntents calcPathIntents(Collection<Intent> originalIntents) { |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 43 | PathIntents pathIntents = new PathIntents(graph); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 44 | |
| 45 | for (Intent intent: originalIntents) { |
| 46 | if (!(intent instanceof ShortestPathIntent)) { |
| 47 | // unsupported intent type. |
| 48 | // TODO should push back the intent to caller |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | ShortestPathIntent spIntent = (ShortestPathIntent) intent; |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 53 | Switch srcSwitch = graph.getSwitch(spIntent.getSrcSwitchDpid()); |
| 54 | Switch dstSwitch = graph.getSwitch(spIntent.getDstSwitchDpid()); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 55 | if (srcSwitch == null || dstSwitch == null) { |
| 56 | // incomplete intent. |
| 57 | // TODO should push back the intent to caller |
| 58 | continue; |
| 59 | } |
| 60 | |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 61 | double bandwidth = 0.0; |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 62 | ConstrainedBFSTree tree = null; |
| 63 | if (intent instanceof ConstrainedShortestPathIntent) { |
| 64 | bandwidth = ((ConstrainedShortestPathIntent) intent).getBandwidth(); |
| 65 | tree = new ConstrainedBFSTree(srcSwitch, pathIntents, bandwidth); |
| 66 | } |
| 67 | else { |
| 68 | tree = new ConstrainedBFSTree(srcSwitch); |
| 69 | } |
| 70 | Path path = tree.getPath(dstSwitch); |
| 71 | if (path == null) { |
| 72 | // path not found. |
| 73 | // TODO should push back the intent to caller |
| 74 | continue; |
| 75 | } |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 76 | |
Toshio Koide | 13986d1 | 2014-02-11 20:25:32 -0800 | [diff] [blame] | 77 | pathIntents.addIntent(new PathIntent("pi" + intent.getId(), path, bandwidth, intent)); |
Toshio Koide | c87810e | 2014-02-11 13:03:21 -0800 | [diff] [blame] | 78 | } |
| 79 | return pathIntents; |
| 80 | } |
| 81 | } |