blob: 4ef4cf0e828ff1686bd0461f4127c877fe937544 [file] [log] [blame]
Toshio Koidead17d5e2014-02-11 11:36:02 -08001package net.onrc.onos.intent;
2
Toshio Koidec406e792014-02-14 16:52:42 -08003import net.onrc.onos.ofcontroller.networkgraph.Link;
4import net.onrc.onos.ofcontroller.networkgraph.NetworkGraph;
Toshio Koidead17d5e2014-02-11 11:36:02 -08005import net.onrc.onos.ofcontroller.networkgraph.Path;
Toshio Koidec406e792014-02-14 16:52:42 -08006import net.onrc.onos.ofcontroller.networkgraph.Port;
7import net.onrc.onos.ofcontroller.networkgraph.Switch;
Toshio Koidead17d5e2014-02-11 11:36:02 -08008
9/**
10 * @author Toshio Koide (t-koide@onlab.us)
11 */
12public class PathIntent extends Intent {
Toshio Koidec406e792014-02-14 16:52:42 -080013 protected long pathData[];
Toshio Koide0e4d8d22014-02-14 10:56:10 -080014 protected double bandwidth;
Toshio Koidead17d5e2014-02-11 11:36:02 -080015 protected Intent parentIntent;
Toshio Koidec406e792014-02-14 16:52:42 -080016
17 /**
18 * Default constructor for Kryo deserialization
19 */
20 protected PathIntent() {
21 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080022
23 /**
24 *
25 * @param graph
26 * @param path
27 * @param bandwidth bandwidth which should be allocated for the path.
Toshio Koide0e4d8d22014-02-14 10:56:10 -080028 * If 0, no intent for bandwidth allocation (best effort).
29 * @param parentIntent parent intent. If null, this is root intent.
Toshio Koide13986d12014-02-11 20:25:32 -080030 * @param id
Toshio Koidead17d5e2014-02-11 11:36:02 -080031 */
Toshio Koide0e4d8d22014-02-14 10:56:10 -080032 public PathIntent(String id, Path path, double bandwidth, Intent parentIntent) {
Toshio Koide13986d12014-02-11 20:25:32 -080033 super(id);
Toshio Koidec406e792014-02-14 16:52:42 -080034 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 Koidead17d5e2014-02-11 11:36:02 -080042 this.bandwidth = bandwidth;
43 this.parentIntent = parentIntent;
44 }
45
Toshio Koidec406e792014-02-14 16:52:42 -080046 public double getBandwidth() {
Toshio Koidead17d5e2014-02-11 11:36:02 -080047 return bandwidth;
48 }
49
Toshio Koidec406e792014-02-14 16:52:42 -080050 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 Koidead17d5e2014-02-11 11:36:02 -080072 return path;
73 }
74
75 public Intent getParentIntent() {
76 return parentIntent;
77 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080078}