blob: a5454fa40bc50088d6ac861af84a7453338e83f5 [file] [log] [blame]
Toshio Koidead17d5e2014-02-11 11:36:02 -08001package net.onrc.onos.intent;
2
Toshio Koide0c9106d2014-02-19 15:26:38 -08003import java.util.LinkedList;
4import java.util.List;
5
Toshio Koidec406e792014-02-14 16:52:42 -08006import net.onrc.onos.ofcontroller.networkgraph.Link;
Toshio Koide0c9106d2014-02-19 15:26:38 -08007import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
Toshio Koidec406e792014-02-14 16:52:42 -08008import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
Toshio Koidead17d5e2014-02-11 11:36:02 -08009import net.onrc.onos.ofcontroller.networkgraph.Path;
Toshio Koidec406e792014-02-14 16:52:42 -080010import net.onrc.onos.ofcontroller.networkgraph.Port;
Toshio Koidead17d5e2014-02-11 11:36:02 -080011
12/**
13 * @author Toshio Koide (t-koide@onlab.us)
14 */
15public class PathIntent extends Intent {
Toshio Koide0c9106d2014-02-19 15:26:38 -080016 protected List<LinkEvent> path;
Toshio Koide0e4d8d22014-02-14 10:56:10 -080017 protected double bandwidth;
Toshio Koidead17d5e2014-02-11 11:36:02 -080018 protected Intent parentIntent;
Toshio Koidec406e792014-02-14 16:52:42 -080019
20 /**
21 * Default constructor for Kryo deserialization
22 */
23 protected PathIntent() {
24 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080025
26 /**
27 *
28 * @param graph
29 * @param path
30 * @param bandwidth bandwidth which should be allocated for the path.
Toshio Koide0e4d8d22014-02-14 10:56:10 -080031 * If 0, no intent for bandwidth allocation (best effort).
32 * @param parentIntent parent intent. If null, this is root intent.
Toshio Koide13986d12014-02-11 20:25:32 -080033 * @param id
Toshio Koidead17d5e2014-02-11 11:36:02 -080034 */
Toshio Koide0e4d8d22014-02-14 10:56:10 -080035 public PathIntent(String id, Path path, double bandwidth, Intent parentIntent) {
Toshio Koide13986d12014-02-11 20:25:32 -080036 super(id);
Toshio Koide0c9106d2014-02-19 15:26:38 -080037 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 Koidec406e792014-02-14 16:52:42 -080044 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080045 this.bandwidth = bandwidth;
46 this.parentIntent = parentIntent;
47 }
48
Toshio Koidec406e792014-02-14 16:52:42 -080049 public double getBandwidth() {
Toshio Koidead17d5e2014-02-11 11:36:02 -080050 return bandwidth;
51 }
52
Toshio Koide0c9106d2014-02-19 15:26:38 -080053 public List<LinkEvent> getPathByLinkEvent() {
54 return path;
Toshio Koidec406e792014-02-14 16:52:42 -080055 }
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 Koide0c9106d2014-02-19 15:26:38 -080063 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 Koidec406e792014-02-14 16:52:42 -080068 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080069 return pathObj;
Toshio Koidead17d5e2014-02-11 11:36:02 -080070 }
71
72 public Intent getParentIntent() {
73 return parentIntent;
74 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080075}