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