blob: 2e2ca8cdb07a30f4f16b8c9f9e03b121077ca469 [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 // CHECKSTYLE:OFF suppress the warning about too many parameters
68 public ShortestPathIntent(String id,
Brian O'Connora581b9d2014-06-15 23:32:36 -070069 long srcSwitch, long srcPort, long srcMac, int srcIp,
70 long dstSwitch, long dstPort, long dstMac, int dstIp ) {
71 // CHECKSTYLE:ON
Ray Milkey269ffb92014-04-03 14:43:30 -070072 super(id);
Komal Shah399a2922014-05-28 01:57:40 -070073 this.srcSwitchDpid = srcSwitch;
74 this.srcPortNumber = srcPort;
75 this.srcMacAddress = srcMac;
76 this.dstSwitchDpid = dstSwitch;
77 this.dstPortNumber = dstPort;
78 this.dstMacAddress = dstMac;
79 this.srcIpAddress = srcIp;
80 this.dstIpAddress = dstIp;
Ray Milkey269ffb92014-04-03 14:43:30 -070081 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080082
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -070083 /**
84 * Gets the source Switch DPID.
85 *
86 * @return Source Switch DPID
87 */
Ray Milkey269ffb92014-04-03 14:43:30 -070088 public long getSrcSwitchDpid() {
89 return srcSwitchDpid;
90 }
Toshio Koidead17d5e2014-02-11 11:36:02 -080091
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -070092 /**
93 * Gets the source Port.
94 *
95 * @return Source Port
96 */
Ray Milkey269ffb92014-04-03 14:43:30 -070097 public long getSrcPortNumber() {
98 return srcPortNumber;
99 }
Toshio Koidead17d5e2014-02-11 11:36:02 -0800100
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700101 /**
102 * Gets the source Host MAC Address.
103 *
104 * @return Source Host MAC Address
105 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700106 public long getSrcMac() {
107 return srcMacAddress;
108 }
Toshio Koidead17d5e2014-02-11 11:36:02 -0800109
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700110 /**
111 * Gets the destination Switch DPID.
112 *
113 * @return Destination Switch DPID
114 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700115 public long getDstSwitchDpid() {
116 return dstSwitchDpid;
117 }
Toshio Koide0e4d8d22014-02-14 10:56:10 -0800118
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700119 /**
120 * Gets the destination Port.
121 *
122 * @return Destination Port
123 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700124 public long getDstPortNumber() {
125 return dstPortNumber;
126 }
Toshio Koide0e4d8d22014-02-14 10:56:10 -0800127
Yuta HIGUCHIce4a06b2014-04-25 19:37:57 -0700128 /**
129 * Gets the destination Host MAC Address.
130 *
131 * @return Destination Host MAC Address
132 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700133 public long getDstMac() {
134 return dstMacAddress;
135 }
Toshio Koidead17d5e2014-02-11 11:36:02 -0800136
Brian O'Connora581b9d2014-06-15 23:32:36 -0700137 /**
138 * Get the source IP address.
139 *
140 * @return source IP address
141 */
142 public int getSrcIp() {
143 return srcIpAddress;
144 }
145
146 /**
147 * Get the destination IP address.
148 *
149 * @return destination IP address
150 */
151 public int getDstIp() {
152 return dstIpAddress;
153 }
154
155 /**
156 * Set the low-level PathIntent ID.
157 *
158 * @param pathIntent new PathIntent
159 */
160 public void setPathIntentId(PathIntent pathIntent) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700161 pathIntentId = pathIntent.getId();
162 }
Toshio Koidea10c0372014-02-20 17:28:10 -0800163
Brian O'Connora581b9d2014-06-15 23:32:36 -0700164 /**
165 * Get the low-level PathIntent ID.
166 *
167 * @return the ID of the low-level PathIntent
168 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700169 public String getPathIntentId() {
170 return pathIntentId;
171 }
Toshio Koidea10c0372014-02-20 17:28:10 -0800172
Ray Milkeyff735142014-05-22 19:06:02 -0700173 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700174 public int getIdleTimeout() {
175 return idleTimeout;
176 }
177
Ray Milkeyff735142014-05-22 19:06:02 -0700178 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700179 public int getHardTimeout() {
180 return hardTimeout;
181 }
182
Ray Milkeyff735142014-05-22 19:06:02 -0700183 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700184 public void setIdleTimeout(int idleTimeout) {
185 this.idleTimeout = idleTimeout;
186 }
187
Ray Milkeyff735142014-05-22 19:06:02 -0700188 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700189 public void setHardTimeout(int hardTimeout) {
190 this.hardTimeout = hardTimeout;
191 }
192
Ray Milkeyff735142014-05-22 19:06:02 -0700193 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700194 public int getFirstSwitchIdleTimeout() {
195 return firstSwitchIdleTimeout;
196 }
197
Ray Milkeyff735142014-05-22 19:06:02 -0700198 // TODO - this is intended to be refactored and removed
Jonathan Hart33e1f302014-05-30 14:37:09 -0700199 public int getFirstSwitchHardTimeout() {
Jonathan Hart4dc8d872014-05-30 14:23:25 -0700200 return firstSwitchHardTimeout;
TeruU30c0c932014-05-15 16:47:41 -0700201 }
202
Ray Milkeyff735142014-05-22 19:06:02 -0700203 // TODO - this is intended to be refactored and removed
TeruU30c0c932014-05-15 16:47:41 -0700204 public void setFirstSwitchIdleTimeout(int firstSwitchIdleTimeout) {
205 this.firstSwitchIdleTimeout = firstSwitchIdleTimeout;
206 }
207
Ray Milkeyff735142014-05-22 19:06:02 -0700208 // TODO - this is intended to be refactored and removed
Jonathan Hart33e1f302014-05-30 14:37:09 -0700209 public void setFirstSwitchHardTimeout(int firstSwitchHardTimeout) {
210 this.firstSwitchHardTimeout = firstSwitchHardTimeout;
TeruU30c0c932014-05-15 16:47:41 -0700211 }
212
Brian O'Connora581b9d2014-06-15 23:32:36 -0700213 /**
214 * Generates a hash code using the Intent ID.
215 *
216 * @return hashcode
217 */
Ray Milkey269ffb92014-04-03 14:43:30 -0700218 @Override
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700219 public int hashCode() {
Brian O'Connora581b9d2014-06-15 23:32:36 -0700220 return super.hashCode();
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700221 }
222
Brian O'Connora581b9d2014-06-15 23:32:36 -0700223 /**
224 * Compares two intent object by type (class) and Intent ID.
225 *
226 * @param obj other Intent
227 * @return true if equal, false otherwise
228 */
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700229 @Override
230 public boolean equals(Object obj) {
Brian O'Connora581b9d2014-06-15 23:32:36 -0700231 return super.equals(obj);
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700232 }
233
Brian O'Connora581b9d2014-06-15 23:32:36 -0700234 /**
235 * Returns a String representation of this Intent.
236 *
237 * @return comma separated list of Intent parameters
238 */
Pavlin Radoslavov7fb16412014-04-11 18:45:19 -0700239 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -0700240 public String toString() {
Jonathan Hartc00f5c22014-06-10 15:14:40 -0700241 return String.format("id:%s, state:%s, srcDpid:%s, srcPort:%d, " +
242 "srcMac:%s, srcIP:%s, dstDpid:%s, dstPort:%d, dstMac:%s, dstIP:%s",
Ray Milkey269ffb92014-04-03 14:43:30 -0700243 getId(), getState(),
Jonathan Hartc00f5c22014-06-10 15:14:40 -0700244 new Dpid(srcSwitchDpid), srcPortNumber,
245 MACAddress.valueOf(srcMacAddress), Integer.toString(srcIpAddress),
246 new Dpid(dstSwitchDpid), dstPortNumber,
247 MACAddress.valueOf(dstMacAddress), Integer.toString(dstIpAddress));
Komal Shah399a2922014-05-28 01:57:40 -0700248 }
249
Toshio Koidead17d5e2014-02-11 11:36:02 -0800250}