Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 3 | import net.onrc.onos.ofcontroller.networkgraph.Link; |
| 4 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 5 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 6 | import net.onrc.onos.ofcontroller.networkgraph.Port; |
| 7 | import net.onrc.onos.ofcontroller.networkgraph.Switch; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * @author Toshio Koide (t-koide@onlab.us) |
| 11 | */ |
| 12 | public class PathIntent extends Intent { |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 13 | protected long pathData[]; |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 14 | protected double bandwidth; |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 15 | protected Intent parentIntent; |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Default constructor for Kryo deserialization |
| 19 | */ |
| 20 | protected PathIntent() { |
| 21 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * |
| 25 | * @param graph |
| 26 | * @param path |
| 27 | * @param bandwidth bandwidth which should be allocated for the path. |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 28 | * If 0, no intent for bandwidth allocation (best effort). |
| 29 | * @param parentIntent parent intent. If null, this is root intent. |
Toshio Koide | 13986d1 | 2014-02-11 20:25:32 -0800 | [diff] [blame] | 30 | * @param id |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 31 | */ |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 32 | public PathIntent(String id, Path path, double bandwidth, Intent parentIntent) { |
Toshio Koide | 13986d1 | 2014-02-11 20:25:32 -0800 | [diff] [blame] | 33 | super(id); |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 34 | pathData = new long[path.size() * 4]; |
| 35 | for (int i=0; i<path.size(); i++) { |
| 36 | Link link = path.get(i); |
| 37 | this.pathData[i*4] = link.getSourceSwitch().getDpid(); |
| 38 | this.pathData[i*4+1] = link.getSourcePort().getNumber(); |
| 39 | this.pathData[i*4+2] = link.getDestinationSwitch().getDpid(); |
| 40 | this.pathData[i*4+3] = link.getDestinationPort().getNumber(); |
| 41 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 42 | this.bandwidth = bandwidth; |
| 43 | this.parentIntent = parentIntent; |
| 44 | } |
| 45 | |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 46 | public double getBandwidth() { |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 47 | return bandwidth; |
| 48 | } |
| 49 | |
Toshio Koide | c406e79 | 2014-02-14 16:52:42 -0800 | [diff] [blame] | 50 | public long[] getPathData() { |
| 51 | return pathData; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get Path object. |
| 56 | * @param graph |
| 57 | * @return path object. If there is no path in the specified graph, returns null. |
| 58 | */ |
| 59 | public Path getPath(NetworkGraph graph) { |
| 60 | Path path = new Path(); |
| 61 | Switch srcSwitch; |
| 62 | Port srcPort; |
| 63 | Link link; |
| 64 | for (int i=0; i<pathData.length; i+=4) { |
| 65 | if ((srcSwitch = graph.getSwitch(pathData[i])) == null) return null; |
| 66 | if ((srcPort = srcSwitch.getPort(pathData[i+1])) == null) return null; |
| 67 | if ((link = srcPort.getOutgoingLink()) == null) return null; |
| 68 | if (link.getDestinationSwitch().getDpid() != pathData[i+2]) return null; |
| 69 | if (link.getDestinationPort().getNumber() != pathData[i+3]) return null; |
| 70 | path.add(link); |
| 71 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 72 | return path; |
| 73 | } |
| 74 | |
| 75 | public Intent getParentIntent() { |
| 76 | return parentIntent; |
| 77 | } |
Toshio Koide | ad17d5e | 2014-02-11 11:36:02 -0800 | [diff] [blame] | 78 | } |