blob: 1361baae52f107b92c8e5461a062f220cc0d9b6e [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Toshio Koidead17d5e2014-02-11 11:36:02 -08002
3import net.floodlightcontroller.util.MACAddress;
Ray Milkey7d7f0a02014-06-18 12:52:13 -07004import net.onrc.onos.core.intent.runtime.web.serializers.ShortestPathIntentSerializer;
Jonathan Hart23701d12014-04-03 10:45:48 -07005import net.onrc.onos.core.util.Dpid;
Ray Milkey2fa6ca42014-06-13 15:38:20 -07006import org.codehaus.jackson.map.annotate.JsonSerialize;
Toshio Koidead17d5e2014-02-11 11:36:02 -08007
8/**
Brian O'Connora581b9d2014-06-15 23:32:36 -07009 * The ShortestPathIntent is a simple, "high-level" intent that
10 * provides shortest path connectivity between two end points in
11 * the network.
Toshio Koidead17d5e2014-02-11 11:36:02 -080012 */
Ray Milkey2fa6ca42014-06-13 15:38:20 -070013@JsonSerialize(using = ShortestPathIntentSerializer.class)
Toshio Koidead17d5e2014-02-11 11:36:02 -080014public class ShortestPathIntent extends Intent {
Komal Shah399a2922014-05-28 01:57:40 -070015 public static final long EMPTYMACADDRESS = 0;
16 public static final int EMPTYIPADDRESS = 0;
Ray Milkey269ffb92014-04-03 14:43:30 -070017 protected long srcSwitchDpid;
18 protected long srcPortNumber;
19 protected long srcMacAddress;
20 protected long dstSwitchDpid;
21 protected long dstPortNumber;
22 protected long dstMacAddress;
Komal Shah399a2922014-05-28 01:57:40 -070023 protected int srcIpAddress;
24 protected int dstIpAddress;
Ray Milkey269ffb92014-04-03 14:43:30 -070025 protected String pathIntentId = null;
TeruU30c0c932014-05-15 16:47:41 -070026 protected int idleTimeout;
27 protected int hardTimeout;
28 protected int firstSwitchIdleTimeout;
Jonathan Hart4dc8d872014-05-30 14:23:25 -070029 protected int firstSwitchHardTimeout;
Toshio Koidead17d5e2014-02-11 11:36:02 -080030
Ray Milkey269ffb92014-04-03 14:43:30 -070031 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -070032 * Default constructor for Kryo deserialization.
Ray Milkey269ffb92014-04-03 14:43:30 -070033 */
34 protected ShortestPathIntent() {
35 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080036
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -070037 /**
38 * Constructor for ShortestPathIntent.
39 *
40 * @param id Intent ID
41 * @param srcSwitch Source Switch DPID
42 * @param srcPort Source Port
43 * @param srcMac Source Host MAC Address
44 * @param dstSwitch Destination Switch DPID
45 * @param dstPort Destination Port
46 * @param dstMac Destination Host MAC Address
47 */
Ray Milkey269ffb92014-04-03 14:43:30 -070048 public ShortestPathIntent(String id,
Brian O'Connora581b9d2014-06-15 23:32:36 -070049 long srcSwitch, long srcPort, long srcMac,
50 long dstSwitch, long dstPort, long dstMac) {
Komal Shah399a2922014-05-28 01:57:40 -070051 this(id, srcSwitch, srcPort, srcMac, EMPTYIPADDRESS, dstSwitch, dstPort, dstMac, EMPTYIPADDRESS);
52 }
53
Brian O'Connora581b9d2014-06-15 23:32:36 -070054 /**
55 * Constructor.
56 *
57 * @param id Intent ID
58 * @param srcSwitch Source Switch DPID
59 * @param srcPort Source Port
60 * @param srcMac Source Host MAC Address
61 * @param srcIp Source IP Address
62 * @param dstSwitch Destination Switch DPID
63 * @param dstPort Destination Port
64 * @param dstMac Destination Host MAC Address
65 * @param dstIp Destination IP Address
66 */
Komal Shah399a2922014-05-28 01:57:40 -070067 public ShortestPathIntent(String id,
Brian O'Connora581b9d2014-06-15 23:32:36 -070068 long srcSwitch, long srcPort, long srcMac, int srcIp,
Ray Milkey5bf7f6f2014-08-15 10:20:40 -070069 long dstSwitch, long dstPort, long dstMac, int dstIp) {
Ray Milkey269ffb92014-04-03 14:43:30 -070070 super(id);
Komal Shah399a2922014-05-28 01:57:40 -070071 this.srcSwitchDpid = srcSwitch;
72 this.srcPortNumber = srcPort;
73 this.srcMacAddress = srcMac;
74 this.dstSwitchDpid = dstSwitch;
75 this.dstPortNumber = dstPort;
76 this.dstMacAddress = dstMac;
77 this.srcIpAddress = srcIp;
78 this.dstIpAddress = dstIp;
Ray Milkey269ffb92014-04-03 14:43:30 -070079 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080080
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -070081 /**
82 * Gets the source Switch DPID.
83 *
84 * @return Source Switch DPID
85 */
Ray Milkey269ffb92014-04-03 14:43:30 -070086 public long getSrcSwitchDpid() {
87 return srcSwitchDpid;
88 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080089
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -070090 /**
91 * Gets the source Port.
92 *
93 * @return Source Port
94 */
Ray Milkey269ffb92014-04-03 14:43:30 -070095 public long getSrcPortNumber() {
96 return srcPortNumber;
97 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080098
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -070099 /**
100 * Gets the source Host MAC Address.
101 *
102 * @return Source Host MAC Address
103 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700104 public long getSrcMac() {
105 return srcMacAddress;
106 }
Toshio Koidead17d5e2014-02-11 11:36:02 -0800107
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700108 /**
109 * Gets the destination Switch DPID.
110 *
111 * @return Destination Switch DPID
112 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700113 public long getDstSwitchDpid() {
114 return dstSwitchDpid;
115 }
Toshio Koide0e4d8d22014-02-14 10:56:10 -0800116
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700117 /**
118 * Gets the destination Port.
119 *
120 * @return Destination Port
121 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700122 public long getDstPortNumber() {
123 return dstPortNumber;
124 }
Toshio Koide0e4d8d22014-02-14 10:56:10 -0800125
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700126 /**
127 * Gets the destination Host MAC Address.
128 *
129 * @return Destination Host MAC Address
130 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700131 public long getDstMac() {
132 return dstMacAddress;
133 }
Toshio Koidead17d5e2014-02-11 11:36:02 -0800134
Brian O'Connora581b9d2014-06-15 23:32:36 -0700135 /**
136 * Get the source IP address.
137 *
138 * @return source IP address
139 */
140 public int getSrcIp() {
141 return srcIpAddress;
142 }
143
144 /**
145 * Get the destination IP address.
146 *
147 * @return destination IP address
148 */
149 public int getDstIp() {
150 return dstIpAddress;
151 }
152
153 /**
154 * Set the low-level PathIntent ID.
155 *
156 * @param pathIntent new PathIntent
157 */
158 public void setPathIntentId(PathIntent pathIntent) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700159 pathIntentId = pathIntent.getId();
160 }
Toshio Koidea10c0372014-02-20 17:28:10 -0800161
Brian O'Connora581b9d2014-06-15 23:32:36 -0700162 /**
163 * Get the low-level PathIntent ID.
164 *
165 * @return the ID of the low-level PathIntent
166 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700167 public String getPathIntentId() {
168 return pathIntentId;
169 }
Toshio Koidea10c0372014-02-20 17:28:10 -0800170
Ray Milkeyff735142014-05-22 19:06:02 -0700171 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700172 public int getIdleTimeout() {
173 return idleTimeout;
174 }
175
Ray Milkeyff735142014-05-22 19:06:02 -0700176 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700177 public int getHardTimeout() {
178 return hardTimeout;
179 }
180
Ray Milkeyff735142014-05-22 19:06:02 -0700181 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700182 public void setIdleTimeout(int idleTimeout) {
183 this.idleTimeout = idleTimeout;
184 }
185
Ray Milkeyff735142014-05-22 19:06:02 -0700186 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700187 public void setHardTimeout(int hardTimeout) {
188 this.hardTimeout = hardTimeout;
189 }
190
Ray Milkeyff735142014-05-22 19:06:02 -0700191 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700192 public int getFirstSwitchIdleTimeout() {
193 return firstSwitchIdleTimeout;
194 }
195
Ray Milkeyff735142014-05-22 19:06:02 -0700196 // TODO - this is intended to be refactored and removed
Jonathan Hart33e1f302014-05-30 14:37:09 -0700197 public int getFirstSwitchHardTimeout() {
Jonathan Hart4dc8d872014-05-30 14:23:25 -0700198 return firstSwitchHardTimeout;
TeruU30c0c932014-05-15 16:47:41 -0700199 }
200
Ray Milkeyff735142014-05-22 19:06:02 -0700201 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700202 public void setFirstSwitchIdleTimeout(int firstSwitchIdleTimeout) {
203 this.firstSwitchIdleTimeout = firstSwitchIdleTimeout;
204 }
205
Ray Milkeyff735142014-05-22 19:06:02 -0700206 // TODO - this is intended to be refactored and removed
Jonathan Hart33e1f302014-05-30 14:37:09 -0700207 public void setFirstSwitchHardTimeout(int firstSwitchHardTimeout) {
208 this.firstSwitchHardTimeout = firstSwitchHardTimeout;
TeruU30c0c932014-05-15 16:47:41 -0700209 }
210
Brian O'Connora581b9d2014-06-15 23:32:36 -0700211 /**
212 * Generates a hash code using the Intent ID.
213 *
214 * @return hashcode
215 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700216 @Override
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700217 public int hashCode() {
Brian O'Connora581b9d2014-06-15 23:32:36 -0700218 return super.hashCode();
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700219 }
220
Brian O'Connora581b9d2014-06-15 23:32:36 -0700221 /**
222 * Compares two intent object by type (class) and Intent ID.
223 *
224 * @param obj other Intent
225 * @return true if equal, false otherwise
226 */
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700227 @Override
228 public boolean equals(Object obj) {
Brian O'Connora581b9d2014-06-15 23:32:36 -0700229 return super.equals(obj);
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700230 }
231
Brian O'Connora581b9d2014-06-15 23:32:36 -0700232 /**
233 * Returns a String representation of this Intent.
234 *
235 * @return comma separated list of Intent parameters
236 */
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700237 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700238 public String toString() {
Jonathan Hartc00f5c22014-06-10 15:14:40 -0700239 return String.format("id:%s, state:%s, srcDpid:%s, srcPort:%d, " +
240 "srcMac:%s, srcIP:%s, dstDpid:%s, dstPort:%d, dstMac:%s, dstIP:%s",
Ray Milkey269ffb92014-04-03 14:43:30 -0700241 getId(), getState(),
Jonathan Hartc00f5c22014-06-10 15:14:40 -0700242 new Dpid(srcSwitchDpid), srcPortNumber,
243 MACAddress.valueOf(srcMacAddress), Integer.toString(srcIpAddress),
244 new Dpid(dstSwitchDpid), dstPortNumber,
245 MACAddress.valueOf(dstMacAddress), Integer.toString(dstIpAddress));
Komal Shah399a2922014-05-28 01:57:40 -0700246 }
247
Toshio Koidead17d5e2014-02-11 11:36:02 -0800248}