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