blob: 02a969c310ab71330e92e0ddbe036089d941bf0e [file] [log] [blame]
Jonathan Hart23701d12014-04-03 10:45:48 -07001package net.onrc.onos.core.util;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08002
Pavlin Radoslavovede97582013-03-08 18:57:28 -08003import net.floodlightcontroller.util.MACAddress;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08004
5import org.codehaus.jackson.annotate.JsonProperty;
Jonathan Hart862ea922014-07-09 14:41:04 -07006import org.openflow.protocol.OFPort;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08007
8/**
9 * The class representing a single Flow Entry action.
Ray Milkey269ffb92014-04-03 14:43:30 -070010 * <p/>
Pavlin Radoslavovd5b21db2013-07-29 17:09:53 -070011 * A Flow Entry action that needs to be applied to each packet.
12 * Note that it contains only a single action. Multiple actions are
13 * listed in a list inside @ref FlowEntryActions.
Pavlin Radoslavovede97582013-03-08 18:57:28 -080014 */
15public class FlowEntryAction {
16 /**
17 * Special action values.
Ray Milkey269ffb92014-04-03 14:43:30 -070018 * <p/>
Pavlin Radoslavovede97582013-03-08 18:57:28 -080019 * Those values are taken as-is from the OpenFlow-v1.0.0 specification
20 * (pp 21-22).
21 */
22 public enum ActionValues {
Ray Milkey269ffb92014-04-03 14:43:30 -070023 ACTION_OUTPUT((short) 0x0), // Output to switch port
24 ACTION_SET_VLAN_VID((short) 0x1), // Set the 802.1q VLAN id
25 ACTION_SET_VLAN_PCP((short) 0x2), // Set the 802.1q priority
26 ACTION_STRIP_VLAN((short) 0x3), // Strip the 802.1q header
27 ACTION_SET_DL_SRC((short) 0x4), // Ethernet source address
28 ACTION_SET_DL_DST((short) 0x5), // Ethernet destination address
29 ACTION_SET_NW_SRC((short) 0x6), // IP source address
30 ACTION_SET_NW_DST((short) 0x7), // IP destination address
31 ACTION_SET_NW_TOS((short) 0x8), // IP ToS (DSCP field, 6 bits)
32 ACTION_SET_TP_SRC((short) 0x9), // TCP/UDP source port
33 ACTION_SET_TP_DST((short) 0xa), // TCP/UDP destination port
34 ACTION_ENQUEUE((short) 0xb), // Output to queue on port
35 ACTION_VENDOR((short) 0xffff); // Vendor-specific
Pavlin Radoslavovede97582013-03-08 18:57:28 -080036
Ray Milkey269ffb92014-04-03 14:43:30 -070037 private final short value; // The value
Pavlin Radoslavovede97582013-03-08 18:57:28 -080038
Ray Milkey269ffb92014-04-03 14:43:30 -070039 /**
40 * Constructor for a given value.
41 *
42 * @param value the value to use for the initialization.
43 */
44 private ActionValues(short value) {
45 this.value = value;
46 }
Pavlin Radoslavov020e96c2013-12-11 12:48:04 -080047
Ray Milkey269ffb92014-04-03 14:43:30 -070048 /**
49 * Get the value.
50 *
51 * @return the value.
52 */
53 public short getValue() {
54 return value;
55 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -080056 }
57
58 /**
59 * Action structure for ACTION_OUTPUT: Output to switch port.
60 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -070061 public static class ActionOutput {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070062 private PortNumber port; // Output port
Ray Milkey269ffb92014-04-03 14:43:30 -070063 private short maxLen; // Max. length (in bytes) to send to controller
64 // if the port is set to PORT_CONTROLLER
Pavlin Radoslavovede97582013-03-08 18:57:28 -080065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 /**
67 * Default constructor.
68 */
69 public ActionOutput() {
70 this.port = null;
71 this.maxLen = 0;
72 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -070073
Ray Milkey269ffb92014-04-03 14:43:30 -070074 /**
75 * Copy constructor.
76 *
77 * @param other the object to copy from.
78 */
79 public ActionOutput(ActionOutput other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -070080 if (other.port != null) {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -070081 this.port = new PortNumber(other.port);
Ray Milkeyb29e6262014-04-09 16:02:14 -070082 }
Ray Milkey269ffb92014-04-03 14:43:30 -070083 this.maxLen = other.maxLen;
84 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070085
Ray Milkey269ffb92014-04-03 14:43:30 -070086 /**
87 * Constructor from a string.
88 * <p/>
89 * The string has the following form:
90 * [port=XXX maxLen=XXX]
91 *
92 * @param actionStr the action as a string.
93 */
94 public ActionOutput(String actionStr) {
95 this.fromString(actionStr);
96 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -070097
Ray Milkey269ffb92014-04-03 14:43:30 -070098 /**
99 * Constructor for a given output port and maximum length.
100 *
101 * @param port the output port to set.
102 * @param maxLen the maximum length (in bytes) to send to controller
103 * if the port is set to PORT_CONTROLLER.
104 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700105 public ActionOutput(PortNumber port, short maxLen) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700106 this.port = port;
107 this.maxLen = maxLen;
108 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800109
Ray Milkey269ffb92014-04-03 14:43:30 -0700110 /**
111 * Constructor for a given output port.
112 *
113 * @param port the output port to set.
114 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700115 public ActionOutput(PortNumber port) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700116 this.port = port;
117 this.maxLen = 0;
118 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700119
Ray Milkey269ffb92014-04-03 14:43:30 -0700120 /**
121 * Get the output port.
122 *
123 * @return the output port.
124 */
125 @JsonProperty("port")
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700126 public PortNumber port() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700127 return this.port;
128 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800129
Ray Milkey269ffb92014-04-03 14:43:30 -0700130 /**
131 * Get the maximum length (in bytes) to send to controller if the
132 * port is set to PORT_CONTROLLER.
133 *
134 * @return the maximum length (in bytes) to send to controller if the
135 * port is set to PORT_CONTROLLER.
136 */
137 @JsonProperty("maxLen")
138 public short maxLen() {
139 return this.maxLen;
140 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800141
Ray Milkey269ffb92014-04-03 14:43:30 -0700142 /**
143 * Convert the action to a string.
144 * <p/>
145 * The string has the following form:
146 * [port=XXX maxLen=XXX]
147 *
148 * @return the action as a string.
149 */
150 @Override
151 public String toString() {
152 String ret = "[";
153 ret += "port=" + port.toString();
154 ret += " maxLen=" + maxLen;
155 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800156
Ray Milkey269ffb92014-04-03 14:43:30 -0700157 return ret;
158 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700159
Ray Milkey269ffb92014-04-03 14:43:30 -0700160 /**
161 * Convert a string to an action.
162 * <p/>
163 * The string has the following form:
164 * [port=XXX maxLen=XXX]
165 *
166 * @param actionStr the action as a string.
167 */
168 public void fromString(String actionStr) {
169 String[] parts = actionStr.split(" ");
170 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700171
Ray Milkey269ffb92014-04-03 14:43:30 -0700172 // Decode the "port=XXX" part
Ray Milkeyb29e6262014-04-09 16:02:14 -0700173 if (parts.length > 0) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700174 decode = parts[0];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700175 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700176 if (decode != null) {
177 String[] tokens = decode.split("port=");
178 if (tokens.length > 1 && tokens[1] != null) {
179 try {
180 Short valueShort = Short.valueOf(tokens[1]);
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700181 port = new PortNumber(valueShort);
Ray Milkey269ffb92014-04-03 14:43:30 -0700182 } catch (NumberFormatException e) {
183 throw new IllegalArgumentException("Invalid action string");
184 }
185 }
186 } else {
187 throw new IllegalArgumentException("Invalid action string");
188 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700189
Ray Milkey269ffb92014-04-03 14:43:30 -0700190 // Decode the "maxLen=XXX" part
191 decode = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700192 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700193 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700194 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700195 if (decode != null) {
196 decode = decode.replace("]", "");
197 String[] tokens = decode.split("maxLen=");
198 if (tokens.length > 1 && tokens[1] != null) {
199 try {
200 maxLen = Short.valueOf(tokens[1]);
201 } catch (NumberFormatException e) {
202 throw new IllegalArgumentException("Invalid action string");
203 }
204 }
205 } else {
206 throw new IllegalArgumentException("Invalid action string");
207 }
208 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800209 }
210
211 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700212 * Action structure for ACTION_SET_VLAN_VID: Set the 802.1q VLAN id.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800213 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700214 public static class ActionSetVlanId {
Ray Milkey269ffb92014-04-03 14:43:30 -0700215 private short vlanId; // The VLAN ID to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800216
Ray Milkey269ffb92014-04-03 14:43:30 -0700217 /**
218 * Default constructor.
219 */
220 public ActionSetVlanId() {
221 this.vlanId = 0;
222 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700223
Ray Milkey269ffb92014-04-03 14:43:30 -0700224 /**
225 * Copy constructor.
226 *
227 * @param other the object to copy from.
228 */
229 public ActionSetVlanId(ActionSetVlanId other) {
230 this.vlanId = other.vlanId;
231 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700232
Ray Milkey269ffb92014-04-03 14:43:30 -0700233 /**
234 * Constructor from a string.
235 * <p/>
236 * The string has the following form:
237 * [vlanId=XXX]
238 *
239 * @param actionStr the action as a string.
240 */
241 public ActionSetVlanId(String actionStr) {
242 this.fromString(actionStr);
243 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700244
Ray Milkey269ffb92014-04-03 14:43:30 -0700245 /**
246 * Constructor for a given VLAN ID.
247 *
248 * @param vlanId the VLAN ID to set.
249 */
250 public ActionSetVlanId(short vlanId) {
251 this.vlanId = vlanId;
252 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800253
Ray Milkey269ffb92014-04-03 14:43:30 -0700254 /**
255 * Get the VLAN ID.
256 *
257 * @return the VLAN ID.
258 */
259 @JsonProperty("vlanId")
260 public short vlanId() {
261 return this.vlanId;
262 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800263
Ray Milkey269ffb92014-04-03 14:43:30 -0700264 /**
265 * Convert the action to a string.
266 * <p/>
267 * The string has the following form:
268 * [vlanId=XXX]
269 *
270 * @return the action as a string.
271 */
272 @Override
273 public String toString() {
274 String ret = "[";
275 ret += "vlanId=" + this.vlanId;
276 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800277
Ray Milkey269ffb92014-04-03 14:43:30 -0700278 return ret;
279 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700280
Ray Milkey269ffb92014-04-03 14:43:30 -0700281 /**
282 * Convert a string to an action.
283 * <p/>
284 * The string has the following form:
285 * [vlanId=XXX]
286 *
287 * @param actionStr the action as a string.
288 */
289 public void fromString(String actionStr) {
290 String[] parts = actionStr.split("vlanId=");
291 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700292
Ray Milkey269ffb92014-04-03 14:43:30 -0700293 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700294 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700295 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700296 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700297 if (decode != null) {
298 decode = decode.replace("]", "");
299 try {
300 vlanId = Short.valueOf(decode);
301 } catch (NumberFormatException e) {
302 throw new IllegalArgumentException("Invalid action string");
303 }
304 } else {
305 throw new IllegalArgumentException("Invalid action string");
306 }
307 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800308 }
309
310 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700311 * Action structure for ACTION_SET_VLAN_PCP: Set the 802.1q priority.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800312 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700313 public static class ActionSetVlanPriority {
Ray Milkey269ffb92014-04-03 14:43:30 -0700314 private byte vlanPriority; // The VLAN priority to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800315
Ray Milkey269ffb92014-04-03 14:43:30 -0700316 /**
317 * Default constructor.
318 */
319 public ActionSetVlanPriority() {
320 this.vlanPriority = 0;
321 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700322
Ray Milkey269ffb92014-04-03 14:43:30 -0700323 /**
324 * Copy constructor.
325 *
326 * @param other the object to copy from.
327 */
328 public ActionSetVlanPriority(ActionSetVlanPriority other) {
329 this.vlanPriority = other.vlanPriority;
330 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700331
Ray Milkey269ffb92014-04-03 14:43:30 -0700332 /**
333 * Constructor from a string.
334 * <p/>
335 * The string has the following form:
336 * [vlanPriority=XXX]
337 *
338 * @param actionStr the action as a string.
339 */
340 public ActionSetVlanPriority(String actionStr) {
341 this.fromString(actionStr);
342 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700343
Ray Milkey269ffb92014-04-03 14:43:30 -0700344 /**
345 * Constructor for a given VLAN priority.
346 *
347 * @param vlanPriority the VLAN priority to set.
348 */
349 public ActionSetVlanPriority(byte vlanPriority) {
350 this.vlanPriority = vlanPriority;
351 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800352
Ray Milkey269ffb92014-04-03 14:43:30 -0700353 /**
354 * Get the VLAN priority.
355 *
356 * @return the VLAN priority.
357 */
358 @JsonProperty("vlanPriority")
359 public byte vlanPriority() {
360 return this.vlanPriority;
361 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800362
Ray Milkey269ffb92014-04-03 14:43:30 -0700363 /**
364 * Convert the action to a string.
365 * <p/>
366 * The string has the following form:
367 * [vlanPriority=XXX]
368 *
369 * @return the action as a string.
370 */
371 @Override
372 public String toString() {
373 String ret = "[";
374 ret += "vlanPriority=" + this.vlanPriority;
375 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800376
Ray Milkey269ffb92014-04-03 14:43:30 -0700377 return ret;
378 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700379
Ray Milkey269ffb92014-04-03 14:43:30 -0700380 /**
381 * Convert a string to an action.
382 * <p/>
383 * The string has the following form:
384 * [vlanPriority=XXX]
385 *
386 * @param actionStr the action as a string.
387 */
388 public void fromString(String actionStr) {
389 String[] parts = actionStr.split("vlanPriority=");
390 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700391
Ray Milkey269ffb92014-04-03 14:43:30 -0700392 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700393 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700394 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700395 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700396 if (decode != null) {
397 decode = decode.replace("]", "");
398 try {
399 vlanPriority = Byte.valueOf(decode);
400 } catch (NumberFormatException e) {
401 throw new IllegalArgumentException("Invalid action string");
402 }
403 } else {
404 throw new IllegalArgumentException("Invalid action string");
405 }
406 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800407 }
408
409 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700410 * Action structure for ACTION_STRIP_VLAN: Strip the 802.1q header.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800411 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700412 public static class ActionStripVlan {
Ray Milkey269ffb92014-04-03 14:43:30 -0700413 private boolean stripVlan; // If true, strip the VLAN header
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800414
Ray Milkey269ffb92014-04-03 14:43:30 -0700415 /**
416 * Default constructor.
417 */
418 public ActionStripVlan() {
419 this.stripVlan = false;
420 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700421
Ray Milkey269ffb92014-04-03 14:43:30 -0700422 /**
423 * Copy constructor.
424 *
425 * @param other the object to copy from.
426 */
427 public ActionStripVlan(ActionStripVlan other) {
428 this.stripVlan = other.stripVlan;
429 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700430
Ray Milkey269ffb92014-04-03 14:43:30 -0700431 /**
432 * Constructor from a string.
433 * <p/>
434 * The string has the following form:
435 * [stripVlan=XXX]
436 *
437 * @param actionStr the action as a string.
438 */
439 public ActionStripVlan(String actionStr) {
440 this.fromString(actionStr);
441 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700442
Ray Milkey269ffb92014-04-03 14:43:30 -0700443 /**
444 * Constructor for a given boolean flag.
445 *
446 * @param stripVlan if true, strip the VLAN header.
447 */
448 public ActionStripVlan(boolean stripVlan) {
449 this.stripVlan = stripVlan;
450 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800451
Ray Milkey269ffb92014-04-03 14:43:30 -0700452 /**
453 * Get the boolean flag whether the VLAN header should be stripped.
454 *
455 * @return the boolean flag whether the VLAN header should be stripped.
456 */
457 @JsonProperty("stripVlan")
458 public boolean stripVlan() {
459 return this.stripVlan;
460 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800461
Ray Milkey269ffb92014-04-03 14:43:30 -0700462 /**
463 * Convert the action to a string.
464 * <p/>
465 * The string has the following form:
466 * [stripVlan=XXX]
467 *
468 * @return the action as a string.
469 */
470 @Override
471 public String toString() {
472 String ret = "[";
473 ret += "stripVlan=" + this.stripVlan;
474 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800475
Ray Milkey269ffb92014-04-03 14:43:30 -0700476 return ret;
477 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700478
Ray Milkey269ffb92014-04-03 14:43:30 -0700479 /**
480 * Convert a string to an action.
481 * <p/>
482 * The string has the following form:
483 * [stripVlan=XXX]
484 *
485 * @param actionStr the action as a string.
486 */
487 public void fromString(String actionStr) {
488 String[] parts = actionStr.split("stripVlan=");
489 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700490
Ray Milkey269ffb92014-04-03 14:43:30 -0700491 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700492 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700493 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700494 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700495 if (decode != null) {
496 decode = decode.replace("]", "");
497 stripVlan = Boolean.valueOf(decode);
498 } else {
499 throw new IllegalArgumentException("Invalid action string");
500 }
501 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800502 }
503
504 /**
505 * Action structure for ACTION_SET_DL_SRC and ACTION_SET_DL_DST:
506 * Set the Ethernet source/destination address.
507 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700508 public static class ActionSetEthernetAddr {
Ray Milkey269ffb92014-04-03 14:43:30 -0700509 private MACAddress addr; // The MAC address to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800510
Ray Milkey269ffb92014-04-03 14:43:30 -0700511 /**
512 * Default constructor.
513 */
514 public ActionSetEthernetAddr() {
515 this.addr = null;
516 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700517
Ray Milkey269ffb92014-04-03 14:43:30 -0700518 /**
519 * Copy constructor.
520 *
521 * @param other the object to copy from.
522 */
523 public ActionSetEthernetAddr(ActionSetEthernetAddr other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700524 if (other.addr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700525 this.addr = MACAddress.valueOf(other.addr.toLong());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700526 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700527 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700528
Ray Milkey269ffb92014-04-03 14:43:30 -0700529 /**
530 * Constructor from a string.
531 * <p/>
532 * The string has the following form:
533 * [addr=XXX]
534 *
535 * @param actionStr the action as a string.
536 */
537 public ActionSetEthernetAddr(String actionStr) {
538 this.fromString(actionStr);
539 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700540
Ray Milkey269ffb92014-04-03 14:43:30 -0700541 /**
542 * Constructor for a given MAC address.
543 *
544 * @param addr the MAC address to set.
545 */
546 public ActionSetEthernetAddr(MACAddress addr) {
547 this.addr = addr;
548 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800549
Ray Milkey269ffb92014-04-03 14:43:30 -0700550 /**
551 * Get the MAC address.
552 *
553 * @return the MAC address.
554 */
555 @JsonProperty("addr")
556 public MACAddress addr() {
557 return this.addr;
558 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800559
Ray Milkey269ffb92014-04-03 14:43:30 -0700560 /**
561 * Convert the action to a string.
562 * <p/>
563 * The string has the following form:
564 * [addr=XXX]
565 *
566 * @return the action as a string.
567 */
568 @Override
569 public String toString() {
570 String ret = "[";
571 ret += "addr=" + addr.toString();
572 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800573
Ray Milkey269ffb92014-04-03 14:43:30 -0700574 return ret;
575 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700576
Ray Milkey269ffb92014-04-03 14:43:30 -0700577 /**
578 * Convert a string to an action.
579 * <p/>
580 * The string has the following form:
581 * [addr=XXX]
582 *
583 * @param actionStr the action as a string.
584 */
585 public void fromString(String actionStr) {
586 String[] parts = actionStr.split("addr=");
587 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700588
Ray Milkey269ffb92014-04-03 14:43:30 -0700589 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700590 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700591 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700592 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700593 if (decode != null) {
594 decode = decode.replace("]", "");
595 try {
596 addr = MACAddress.valueOf(decode);
597 } catch (IllegalArgumentException e) {
598 throw new IllegalArgumentException("Invalid action string");
599 }
600 } else {
601 throw new IllegalArgumentException("Invalid action string");
602 }
603 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800604 }
605
606 /**
607 * Action structure for ACTION_SET_NW_SRC and ACTION_SET_NW_DST:
608 * Set the IPv4 source/destination address.
609 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700610 public static class ActionSetIPv4Addr {
Ray Milkey269ffb92014-04-03 14:43:30 -0700611 private IPv4 addr; // The IPv4 address to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800612
Ray Milkey269ffb92014-04-03 14:43:30 -0700613 /**
614 * Default constructor.
615 */
616 public ActionSetIPv4Addr() {
617 this.addr = null;
618 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700619
Ray Milkey269ffb92014-04-03 14:43:30 -0700620 /**
621 * Copy constructor.
622 *
623 * @param other the object to copy from.
624 */
625 public ActionSetIPv4Addr(ActionSetIPv4Addr other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700626 if (other.addr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700627 this.addr = new IPv4(other.addr);
Ray Milkeyb29e6262014-04-09 16:02:14 -0700628 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700629 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700630
Ray Milkey269ffb92014-04-03 14:43:30 -0700631 /**
632 * Constructor from a string.
633 * <p/>
634 * The string has the following form:
635 * [addr=XXX]
636 *
637 * @param actionStr the action as a string.
638 */
639 public ActionSetIPv4Addr(String actionStr) {
640 this.fromString(actionStr);
641 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700642
Ray Milkey269ffb92014-04-03 14:43:30 -0700643 /**
644 * Constructor for a given IPv4 address.
645 *
646 * @param addr the IPv4 address to set.
647 */
648 public ActionSetIPv4Addr(IPv4 addr) {
649 this.addr = addr;
650 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800651
Ray Milkey269ffb92014-04-03 14:43:30 -0700652 /**
653 * Get the IPv4 address.
654 *
655 * @return the IPv4 address.
656 */
657 @JsonProperty("addr")
658 public IPv4 addr() {
659 return this.addr;
660 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800661
Ray Milkey269ffb92014-04-03 14:43:30 -0700662 /**
663 * Convert the action to a string.
664 * <p/>
665 * The string has the following form:
666 * [addr=XXX]
667 *
668 * @return the action as a string.
669 */
670 @Override
671 public String toString() {
672 String ret = "[";
673 ret += "addr=" + addr.toString();
674 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800675
Ray Milkey269ffb92014-04-03 14:43:30 -0700676 return ret;
677 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700678
Ray Milkey269ffb92014-04-03 14:43:30 -0700679 /**
680 * Convert a string to an action.
681 * <p/>
682 * The string has the following form:
683 * [addr=XXX]
684 *
685 * @param actionStr the action as a string.
686 */
687 public void fromString(String actionStr) {
688 String[] parts = actionStr.split("addr=");
689 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700690
Ray Milkey269ffb92014-04-03 14:43:30 -0700691 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700692 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700693 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700694 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700695 if (decode != null) {
696 decode = decode.replace("]", "");
697 try {
698 addr = new IPv4(decode);
699 } catch (IllegalArgumentException e) {
700 throw new IllegalArgumentException("Invalid action string");
701 }
702 } else {
703 throw new IllegalArgumentException("Invalid action string");
704 }
705 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800706 }
707
708 /**
709 * Action structure for ACTION_SET_NW_TOS:
710 * Set the IP ToS (DSCP field, 6 bits).
711 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700712 public static class ActionSetIpToS {
Ray Milkey269ffb92014-04-03 14:43:30 -0700713 private byte ipToS; // The IP ToS to set DSCP field, 6 bits)
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800714
Ray Milkey269ffb92014-04-03 14:43:30 -0700715 /**
716 * Default constructor.
717 */
718 public ActionSetIpToS() {
719 this.ipToS = 0;
720 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700721
Ray Milkey269ffb92014-04-03 14:43:30 -0700722 /**
723 * Copy constructor.
724 *
725 * @param other the object to copy from.
726 */
727 public ActionSetIpToS(ActionSetIpToS other) {
728 this.ipToS = other.ipToS;
729 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700730
Ray Milkey269ffb92014-04-03 14:43:30 -0700731 /**
732 * Constructor from a string.
733 * <p/>
734 * The string has the following form:
735 * [ipToS=XXX]
736 *
737 * @param actionStr the action as a string.
738 */
739 public ActionSetIpToS(String actionStr) {
740 this.fromString(actionStr);
741 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700742
Ray Milkey269ffb92014-04-03 14:43:30 -0700743 /**
744 * Constructor for a given IP ToS (DSCP field, 6 bits).
745 *
746 * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
747 */
748 public ActionSetIpToS(byte ipToS) {
749 this.ipToS = ipToS;
750 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800751
Ray Milkey269ffb92014-04-03 14:43:30 -0700752 /**
753 * Get the IP ToS (DSCP field, 6 bits).
754 *
755 * @return the IP ToS (DSCP field, 6 bits).
756 */
757 @JsonProperty("ipToS")
758 public byte ipToS() {
759 return this.ipToS;
760 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800761
Ray Milkey269ffb92014-04-03 14:43:30 -0700762 /**
763 * Convert the action to a string.
764 * <p/>
765 * The string has the following form:
766 * [ipToS=XXX]
767 *
768 * @return the action as a string.
769 */
770 @Override
771 public String toString() {
772 String ret = "[";
773 ret += "ipToS=" + ipToS;
774 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800775
Ray Milkey269ffb92014-04-03 14:43:30 -0700776 return ret;
777 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700778
Ray Milkey269ffb92014-04-03 14:43:30 -0700779 /**
780 * Convert a string to an action.
781 * <p/>
782 * The string has the following form:
783 * [ipToS=XXX]
784 *
785 * @param actionStr the action as a string.
786 */
787 public void fromString(String actionStr) {
788 String[] parts = actionStr.split("ipToS=");
789 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700790
Ray Milkey269ffb92014-04-03 14:43:30 -0700791 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700792 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700793 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700794 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700795 if (decode != null) {
796 decode = decode.replace("]", "");
797 try {
798 ipToS = Byte.valueOf(decode);
799 } catch (NumberFormatException e) {
800 throw new IllegalArgumentException("Invalid action string");
801 }
802 } else {
803 throw new IllegalArgumentException("Invalid action string");
804 }
805 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800806 }
807
808 /**
809 * Action structure for ACTION_SET_TP_SRC and ACTION_SET_TP_DST:
810 * Set the TCP/UDP source/destination port.
811 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700812 public static class ActionSetTcpUdpPort {
Ray Milkey269ffb92014-04-03 14:43:30 -0700813 private short port; // The TCP/UDP port to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800814
Ray Milkey269ffb92014-04-03 14:43:30 -0700815 /**
816 * Default constructor.
817 */
818 public ActionSetTcpUdpPort() {
819 this.port = 0;
820 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700821
Ray Milkey269ffb92014-04-03 14:43:30 -0700822 /**
823 * Copy constructor.
824 *
825 * @param other the object to copy from.
826 */
827 public ActionSetTcpUdpPort(ActionSetTcpUdpPort other) {
828 this.port = other.port;
829 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700830
Ray Milkey269ffb92014-04-03 14:43:30 -0700831 /**
832 * Constructor from a string.
833 * <p/>
834 * The string has the following form:
835 * [port=XXX]
836 *
837 * @param actionStr the action as a string.
838 */
839 public ActionSetTcpUdpPort(String actionStr) {
840 this.fromString(actionStr);
841 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700842
Ray Milkey269ffb92014-04-03 14:43:30 -0700843 /**
844 * Constructor for a given TCP/UDP port.
845 *
846 * @param port the TCP/UDP port to set.
847 */
848 public ActionSetTcpUdpPort(short port) {
849 this.port = port;
850 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800851
Ray Milkey269ffb92014-04-03 14:43:30 -0700852 /**
853 * Get the TCP/UDP port.
854 *
855 * @return the TCP/UDP port.
856 */
857 @JsonProperty("port")
858 public short port() {
859 return this.port;
860 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800861
Ray Milkey269ffb92014-04-03 14:43:30 -0700862 /**
863 * Convert the action to a string.
864 * <p/>
865 * The string has the following form:
866 * [port=XXX]
867 *
868 * @return the action as a string.
869 */
870 @Override
871 public String toString() {
872 String ret = "[";
873 ret += "port=" + port;
874 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800875
Ray Milkey269ffb92014-04-03 14:43:30 -0700876 return ret;
877 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700878
Ray Milkey269ffb92014-04-03 14:43:30 -0700879 /**
880 * Convert a string to an action.
881 * <p/>
882 * The string has the following form:
883 * [port=XXX]
884 *
885 * @param actionStr the action as a string.
886 */
887 public void fromString(String actionStr) {
888 String[] parts = actionStr.split("port=");
889 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700890
Ray Milkey269ffb92014-04-03 14:43:30 -0700891 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700892 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700893 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700894 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700895 if (decode != null) {
896 decode = decode.replace("]", "");
897 try {
898 port = Short.valueOf(decode);
899 } catch (NumberFormatException e) {
900 throw new IllegalArgumentException("Invalid action string");
901 }
902 } else {
903 throw new IllegalArgumentException("Invalid action string");
904 }
905 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800906 }
907
908 /**
909 * Action structure for ACTION_ENQUEUE: Output to queue on port.
910 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700911 public static class ActionEnqueue {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700912 private PortNumber port; // Port that queue belongs. Should
Ray Milkey269ffb92014-04-03 14:43:30 -0700913 // refer to a valid physical port
914 // (i.e. < PORT_MAX) or PORT_IN_PORT
915 private int queueId; // Where to enqueue the packets
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800916
Ray Milkey269ffb92014-04-03 14:43:30 -0700917 /**
918 * Default constructor.
919 */
920 public ActionEnqueue() {
921 this.port = null;
922 this.queueId = 0;
923 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700924
Ray Milkey269ffb92014-04-03 14:43:30 -0700925 /**
926 * Copy constructor.
927 *
928 * @param other the object to copy from.
929 */
930 public ActionEnqueue(ActionEnqueue other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700931 if (other.port != null) {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700932 this.port = new PortNumber(other.port);
Ray Milkeyb29e6262014-04-09 16:02:14 -0700933 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700934 this.queueId = other.queueId;
935 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700936
Ray Milkey269ffb92014-04-03 14:43:30 -0700937 /**
938 * Constructor from a string.
939 * <p/>
940 * The string has the following form:
941 * [port=XXX queueId=XXX]
942 *
943 * @param actionStr the action as a string.
944 */
945 public ActionEnqueue(String actionStr) {
946 this.fromString(actionStr);
947 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700948
Ray Milkey269ffb92014-04-03 14:43:30 -0700949 /**
950 * Constructor for a given port and queue ID.
951 *
952 * @param port the port to set.
953 * @param queueId the queue ID on the port.
954 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700955 public ActionEnqueue(PortNumber port, int queueId) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700956 this.port = port;
957 this.queueId = queueId;
958 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800959
Ray Milkey269ffb92014-04-03 14:43:30 -0700960 /**
961 * Get the port.
962 *
963 * @return the port.
964 */
965 @JsonProperty("port")
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700966 public PortNumber port() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700967 return this.port;
968 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800969
Ray Milkey269ffb92014-04-03 14:43:30 -0700970 /**
971 * Get the queue ID.
972 *
973 * @return the queue ID.
974 */
975 @JsonProperty("queueId")
976 public int queueId() {
977 return this.queueId;
978 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800979
Ray Milkey269ffb92014-04-03 14:43:30 -0700980 /**
981 * Convert the action to a string.
982 * <p/>
983 * The string has the following form:
984 * [port=XXX queueId=XXX]
985 *
986 * @return the action as a string.
987 */
988 @Override
989 public String toString() {
990 String ret = "[";
991 ret += "port=" + port.toString();
992 ret += " queueId=" + queueId;
993 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800994
Ray Milkey269ffb92014-04-03 14:43:30 -0700995 return ret;
996 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700997
Ray Milkey269ffb92014-04-03 14:43:30 -0700998 /**
999 * Convert a string to an action.
1000 * <p/>
1001 * The string has the following form:
1002 * [port=XXX queueId=XXX]
1003 *
1004 * @param actionStr the action as a string.
1005 */
1006 public void fromString(String actionStr) {
1007 String[] parts = actionStr.split(" ");
1008 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001009
Ray Milkey269ffb92014-04-03 14:43:30 -07001010 // Decode the "port=XXX" part
Ray Milkeyb29e6262014-04-09 16:02:14 -07001011 if (parts.length > 0) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001012 decode = parts[0];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001013 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001014 if (decode != null) {
1015 String[] tokens = decode.split("port=");
1016 if (tokens.length > 1 && tokens[1] != null) {
1017 try {
1018 Short valueShort = Short.valueOf(tokens[1]);
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07001019 port = new PortNumber(valueShort);
Ray Milkey269ffb92014-04-03 14:43:30 -07001020 } catch (NumberFormatException e) {
1021 throw new IllegalArgumentException("Invalid action string");
1022 }
1023 }
1024 } else {
1025 throw new IllegalArgumentException("Invalid action string");
1026 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001027
Ray Milkey269ffb92014-04-03 14:43:30 -07001028 // Decode the "queueId=XXX" part
1029 decode = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001030 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001031 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001032 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001033 if (decode != null) {
1034 decode = decode.replace("]", "");
1035 String[] tokens = decode.split("queueId=");
1036 if (tokens.length > 1 && tokens[1] != null) {
1037 try {
1038 queueId = Short.valueOf(tokens[1]);
1039 } catch (NumberFormatException e) {
1040 throw new IllegalArgumentException("Invalid action string");
1041 }
1042 }
1043 } else {
1044 throw new IllegalArgumentException("Invalid action string");
1045 }
1046 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001047 }
1048
Ray Milkey269ffb92014-04-03 14:43:30 -07001049 private ActionValues actionType; // The action type
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001050
1051 //
1052 // The actions.
1053 // NOTE: Only one action should be set.
1054 //
1055 private ActionOutput actionOutput;
1056 private ActionSetVlanId actionSetVlanId;
1057 private ActionSetVlanPriority actionSetVlanPriority;
1058 private ActionStripVlan actionStripVlan;
1059 private ActionSetEthernetAddr actionSetEthernetSrcAddr;
1060 private ActionSetEthernetAddr actionSetEthernetDstAddr;
1061 private ActionSetIPv4Addr actionSetIPv4SrcAddr;
1062 private ActionSetIPv4Addr actionSetIPv4DstAddr;
1063 private ActionSetIpToS actionSetIpToS;
1064 private ActionSetTcpUdpPort actionSetTcpUdpSrcPort;
1065 private ActionSetTcpUdpPort actionSetTcpUdpDstPort;
1066 private ActionEnqueue actionEnqueue;
1067
1068 /**
1069 * Default constructor.
1070 */
1071 public FlowEntryAction() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001072 actionType = ActionValues.ACTION_VENDOR; // XXX: Initial value
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001073 }
1074
1075 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001076 * Copy constructor.
1077 *
1078 * @param other the object to copy from.
1079 */
1080 public FlowEntryAction(FlowEntryAction other) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001081 this.actionType = other.actionType;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001082
Ray Milkey269ffb92014-04-03 14:43:30 -07001083 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001084 if (other.actionOutput != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001085 this.actionOutput = new ActionOutput(other.actionOutput);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001086 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001087 this.actionOutput = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001088 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001089 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001090 if (other.actionSetVlanId != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001091 this.actionSetVlanId = new ActionSetVlanId(other.actionSetVlanId);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001092 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001093 this.actionSetVlanId = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001094 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001095 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001096 if (other.actionSetVlanPriority != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001097 this.actionSetVlanPriority = new ActionSetVlanPriority(other.actionSetVlanPriority);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001098 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001099 this.actionSetVlanPriority = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001100 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001101 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001102 if (other.actionStripVlan != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001103 this.actionStripVlan = new ActionStripVlan(other.actionStripVlan);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001104 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001105 this.actionStripVlan = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001106 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001107 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001108 if (other.actionSetEthernetSrcAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001109 this.actionSetEthernetSrcAddr = new ActionSetEthernetAddr(other.actionSetEthernetSrcAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001110 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001111 this.actionSetEthernetSrcAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001112 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001113 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001114 if (other.actionSetEthernetDstAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001115 this.actionSetEthernetDstAddr = new ActionSetEthernetAddr(other.actionSetEthernetDstAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001116 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001117 this.actionSetEthernetDstAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001118 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001119 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001120 if (other.actionSetIPv4SrcAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001121 this.actionSetIPv4SrcAddr = new ActionSetIPv4Addr(other.actionSetIPv4SrcAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001122 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001123 this.actionSetIPv4SrcAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001124 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001125 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001126 if (other.actionSetIPv4DstAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001127 this.actionSetIPv4DstAddr = new ActionSetIPv4Addr(other.actionSetIPv4DstAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001128 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001129 this.actionSetIPv4DstAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001130 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001131 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001132 if (other.actionSetIpToS != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001133 this.actionSetIpToS = new ActionSetIpToS(other.actionSetIpToS);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001134 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001135 this.actionSetIpToS = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001136 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001137 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001138 if (other.actionSetTcpUdpSrcPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001139 this.actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpSrcPort);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001140 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001141 this.actionSetTcpUdpSrcPort = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001142 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001143 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001144 if (other.actionSetTcpUdpDstPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001145 this.actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpDstPort);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001146 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001147 this.actionSetTcpUdpDstPort = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001148 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001149 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001150 if (other.actionEnqueue != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001151 this.actionEnqueue = new ActionEnqueue(other.actionEnqueue);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001152 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001153 this.actionEnqueue = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001154 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001155 }
1156
1157 /**
1158 * Constructor from a string.
Ray Milkey269ffb92014-04-03 14:43:30 -07001159 * <p/>
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001160 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -07001161 * [type=XXX action=XXX]
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001162 *
1163 * @param actionStr the action as a string.
1164 */
1165 public FlowEntryAction(String actionStr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001166 this.fromString(actionStr);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001167 }
1168
1169 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001170 * Get the action type.
1171 *
1172 * @return the action type.
1173 */
1174 @JsonProperty("actionType")
Ray Milkey269ffb92014-04-03 14:43:30 -07001175 public ActionValues actionType() {
1176 return actionType;
1177 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001178
1179 /**
1180 * Get the output action.
1181 *
1182 * @return the output action.
1183 */
1184 @JsonProperty("actionOutput")
Ray Milkey269ffb92014-04-03 14:43:30 -07001185 public ActionOutput actionOutput() {
1186 return actionOutput;
1187 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001188
1189 /**
1190 * Set the output action on a port.
1191 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001192 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001193 */
1194 @JsonProperty("actionOutput")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001195 public void setActionOutput(ActionOutput action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001196 actionOutput = action;
1197 actionType = ActionValues.ACTION_OUTPUT;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001198 }
1199
1200 /**
1201 * Set the output action on a port.
1202 *
1203 * @param port the output port to set.
1204 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07001205 public void setActionOutput(PortNumber port) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001206 actionOutput = new ActionOutput(port);
1207 actionType = ActionValues.ACTION_OUTPUT;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001208 }
1209
1210 /**
1211 * Set the output action to controller.
1212 *
1213 * @param maxLen the maximum length (in bytes) to send to controller.
1214 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001215 public void setActionOutputToController(short maxLen) {
Jonathan Hart862ea922014-07-09 14:41:04 -07001216 PortNumber port = new PortNumber(OFPort.OFPP_CONTROLLER.getValue());
Ray Milkey269ffb92014-04-03 14:43:30 -07001217 actionOutput = new ActionOutput(port, maxLen);
1218 actionType = ActionValues.ACTION_OUTPUT;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001219 }
1220
1221 /**
1222 * Get the action to set the VLAN ID.
1223 *
1224 * @return the action to set the VLAN ID.
1225 */
1226 @JsonProperty("actionSetVlanId")
Ray Milkey269ffb92014-04-03 14:43:30 -07001227 public ActionSetVlanId actionSetVlanId() {
1228 return actionSetVlanId;
1229 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001230
1231 /**
1232 * Set the action to set the VLAN ID.
1233 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001234 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001235 */
1236 @JsonProperty("actionSetVlanId")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001237 public void setActionSetVlanId(ActionSetVlanId action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001238 actionSetVlanId = action;
1239 actionType = ActionValues.ACTION_SET_VLAN_VID;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001240 }
1241
1242 /**
1243 * Set the action to set the VLAN ID.
1244 *
1245 * @param vlanId the VLAN ID to set.
1246 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001247 public void setActionSetVlanId(short vlanId) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001248 actionSetVlanId = new ActionSetVlanId(vlanId);
1249 actionType = ActionValues.ACTION_SET_VLAN_VID;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001250 }
1251
1252 /**
1253 * Get the action to set the VLAN priority.
1254 *
1255 * @return the action to set the VLAN priority.
1256 */
1257 @JsonProperty("actionSetVlanPriority")
1258 public ActionSetVlanPriority actionSetVlanPriority() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001259 return actionSetVlanPriority;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001260 }
1261
1262 /**
1263 * Set the action to set the VLAN priority.
1264 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001265 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001266 */
1267 @JsonProperty("actionSetVlanPriority")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001268 public void setActionSetVlanPriority(ActionSetVlanPriority action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001269 actionSetVlanPriority = action;
1270 actionType = ActionValues.ACTION_SET_VLAN_PCP;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001271 }
1272
1273 /**
1274 * Set the action to set the VLAN priority.
1275 *
1276 * @param vlanPriority the VLAN priority to set.
1277 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001278 public void setActionSetVlanPriority(byte vlanPriority) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001279 actionSetVlanPriority = new ActionSetVlanPriority(vlanPriority);
1280 actionType = ActionValues.ACTION_SET_VLAN_PCP;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001281 }
1282
1283 /**
1284 * Get the action to strip the VLAN header.
1285 *
1286 * @return the action to strip the VLAN header.
1287 */
1288 @JsonProperty("actionStripVlan")
1289 public ActionStripVlan actionStripVlan() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001290 return actionStripVlan;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001291 }
1292
1293 /**
1294 * Set the action to strip the VLAN header.
1295 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001296 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001297 */
1298 @JsonProperty("actionStripVlan")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001299 public void setActionStripVlan(ActionStripVlan action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001300 actionStripVlan = action;
1301 actionType = ActionValues.ACTION_STRIP_VLAN;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001302 }
1303
1304 /**
1305 * Set the action to strip the VLAN header.
1306 *
1307 * @param stripVlan if true, strip the VLAN header.
1308 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001309 public void setActionStripVlan(boolean stripVlan) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001310 actionStripVlan = new ActionStripVlan(stripVlan);
1311 actionType = ActionValues.ACTION_STRIP_VLAN;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001312 }
1313
1314 /**
1315 * Get the action to set the Ethernet source address.
1316 *
1317 * @return the action to set the Ethernet source address.
1318 */
1319 @JsonProperty("actionSetEthernetSrcAddr")
1320 public ActionSetEthernetAddr actionSetEthernetSrcAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001321 return actionSetEthernetSrcAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001322 }
1323
1324 /**
1325 * Set the action to set the Ethernet source address.
1326 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001327 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001328 */
1329 @JsonProperty("actionSetEthernetSrcAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001330 public void setActionSetEthernetSrcAddr(ActionSetEthernetAddr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001331 actionSetEthernetSrcAddr = action;
1332 actionType = ActionValues.ACTION_SET_DL_SRC;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001333 }
1334
1335 /**
1336 * Set the action to set the Ethernet source address.
1337 *
1338 * @param addr the MAC address to set as the Ethernet source address.
1339 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001340 public void setActionSetEthernetSrcAddr(MACAddress addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001341 actionSetEthernetSrcAddr = new ActionSetEthernetAddr(addr);
1342 actionType = ActionValues.ACTION_SET_DL_SRC;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001343 }
1344
1345 /**
1346 * Get the action to set the Ethernet destination address.
1347 *
1348 * @return the action to set the Ethernet destination address.
1349 */
1350 @JsonProperty("actionSetEthernetDstAddr")
1351 public ActionSetEthernetAddr actionSetEthernetDstAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001352 return actionSetEthernetDstAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001353 }
1354
1355 /**
1356 * Set the action to set the Ethernet destination address.
1357 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001358 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001359 */
1360 @JsonProperty("actionSetEthernetDstAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001361 public void setActionSetEthernetDstAddr(ActionSetEthernetAddr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001362 actionSetEthernetDstAddr = action;
1363 actionType = ActionValues.ACTION_SET_DL_DST;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001364 }
1365
1366 /**
1367 * Set the action to set the Ethernet destination address.
1368 *
1369 * @param addr the MAC address to set as the Ethernet destination address.
1370 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001371 public void setActionSetEthernetDstAddr(MACAddress addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001372 actionSetEthernetDstAddr = new ActionSetEthernetAddr(addr);
1373 actionType = ActionValues.ACTION_SET_DL_DST;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001374 }
1375
1376 /**
1377 * Get the action to set the IPv4 source address.
1378 *
1379 * @return the action to set the IPv4 source address.
1380 */
1381 @JsonProperty("actionSetIPv4SrcAddr")
1382 public ActionSetIPv4Addr actionSetIPv4SrcAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001383 return actionSetIPv4SrcAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001384 }
1385
1386 /**
1387 * Set the action to set the IPv4 source address.
1388 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001389 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001390 */
1391 @JsonProperty("actionSetIPv4SrcAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001392 public void setActionSetIPv4SrcAddr(ActionSetIPv4Addr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001393 actionSetIPv4SrcAddr = action;
1394 actionType = ActionValues.ACTION_SET_NW_SRC;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001395 }
1396
1397 /**
1398 * Set the action to set the IPv4 source address.
1399 *
1400 * @param addr the IPv4 address to set as the IPv4 source address.
1401 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001402 public void setActionSetIPv4SrcAddr(IPv4 addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001403 actionSetIPv4SrcAddr = new ActionSetIPv4Addr(addr);
1404 actionType = ActionValues.ACTION_SET_NW_SRC;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001405 }
1406
1407 /**
1408 * Get the action to set the IPv4 destination address.
1409 *
1410 * @return the action to set the IPv4 destination address.
1411 */
1412 @JsonProperty("actionSetIPv4DstAddr")
1413 public ActionSetIPv4Addr actionSetIPv4DstAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001414 return actionSetIPv4DstAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001415 }
1416
1417 /**
1418 * Set the action to set the IPv4 destination address.
1419 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001420 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001421 */
1422 @JsonProperty("actionSetIPv4DstAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001423 public void setActionSetIPv4DstAddr(ActionSetIPv4Addr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001424 actionSetIPv4DstAddr = action;
1425 actionType = ActionValues.ACTION_SET_NW_DST;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001426 }
1427
1428 /**
1429 * Set the action to set the IPv4 destination address.
1430 *
1431 * @param addr the IPv4 address to set as the IPv4 destination address.
1432 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001433 public void setActionSetIPv4DstAddr(IPv4 addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001434 actionSetIPv4DstAddr = new ActionSetIPv4Addr(addr);
1435 actionType = ActionValues.ACTION_SET_NW_DST;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001436 }
1437
1438 /**
1439 * Get the action to set the IP ToS (DSCP field, 6 bits).
1440 *
1441 * @return the action to set the IP ToS (DSCP field, 6 bits).
1442 */
1443 @JsonProperty("actionSetIpToS")
1444 public ActionSetIpToS actionSetIpToS() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001445 return actionSetIpToS;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001446 }
1447
1448 /**
1449 * Set the action to set the IP ToS (DSCP field, 6 bits).
1450 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001451 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001452 */
1453 @JsonProperty("actionSetIpToS")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001454 public void setActionSetIpToS(ActionSetIpToS action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001455 actionSetIpToS = action;
1456 actionType = ActionValues.ACTION_SET_NW_TOS;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001457 }
1458
1459 /**
1460 * Set the action to set the IP ToS (DSCP field, 6 bits).
1461 *
1462 * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
1463 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001464 public void setActionSetIpToS(byte ipToS) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001465 actionSetIpToS = new ActionSetIpToS(ipToS);
1466 actionType = ActionValues.ACTION_SET_NW_TOS;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001467 }
1468
1469 /**
1470 * Get the action to set the TCP/UDP source port.
1471 *
1472 * @return the action to set the TCP/UDP source port.
1473 */
1474 @JsonProperty("actionSetTcpUdpSrcPort")
1475 public ActionSetTcpUdpPort actionSetTcpUdpSrcPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001476 return actionSetTcpUdpSrcPort;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001477 }
1478
1479 /**
1480 * Set the action to set the TCP/UDP source port.
1481 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001482 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001483 */
1484 @JsonProperty("actionSetTcpUdpSrcPort")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001485 public void setActionSetTcpUdpSrcPort(ActionSetTcpUdpPort action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001486 actionSetTcpUdpSrcPort = action;
1487 actionType = ActionValues.ACTION_SET_TP_SRC;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001488 }
1489
1490 /**
1491 * Set the action to set the TCP/UDP source port.
1492 *
1493 * @param port the TCP/UDP port to set as the TCP/UDP source port.
1494 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001495 public void setActionSetTcpUdpSrcPort(short port) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001496 actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(port);
1497 actionType = ActionValues.ACTION_SET_TP_SRC;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001498 }
1499
1500 /**
1501 * Get the action to set the TCP/UDP destination port.
1502 *
1503 * @return the action to set the TCP/UDP destination port.
1504 */
1505 @JsonProperty("actionSetTcpUdpDstPort")
1506 public ActionSetTcpUdpPort actionSetTcpUdpDstPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001507 return actionSetTcpUdpDstPort;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001508 }
1509
1510 /**
1511 * Set the action to set the TCP/UDP destination port.
1512 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001513 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001514 */
1515 @JsonProperty("actionSetTcpUdpDstPort")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001516 public void setActionSetTcpUdpDstPort(ActionSetTcpUdpPort action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001517 actionSetTcpUdpDstPort = action;
1518 actionType = ActionValues.ACTION_SET_TP_DST;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001519 }
1520
1521 /**
1522 * Set the action to set the TCP/UDP destination port.
1523 *
1524 * @param port the TCP/UDP port to set as the TCP/UDP destination port.
1525 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001526 public void setActionSetTcpUdpDstPort(short port) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001527 actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(port);
1528 actionType = ActionValues.ACTION_SET_TP_DST;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001529 }
1530
1531 /**
1532 * Get the action to output to queue on a port.
1533 *
1534 * @return the action to output to queue on a port.
1535 */
1536 @JsonProperty("actionEnqueue")
Ray Milkey269ffb92014-04-03 14:43:30 -07001537 public ActionEnqueue actionEnqueue() {
1538 return actionEnqueue;
1539 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001540
1541 /**
1542 * Set the action to output to queue on a port.
1543 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001544 * @param action the action to set.
1545 */
1546 @JsonProperty("actionEnqueue")
1547 public void setActionEnqueue(ActionEnqueue action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001548 actionEnqueue = action;
1549 actionType = ActionValues.ACTION_ENQUEUE;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001550 }
1551
1552 /**
1553 * Set the action to output to queue on a port.
1554 *
Ray Milkey269ffb92014-04-03 14:43:30 -07001555 * @param port the port to set.
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -07001556 * @param queueId the queue ID to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001557 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07001558 public void setActionEnqueue(PortNumber port, int queueId) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001559 actionEnqueue = new ActionEnqueue(port, queueId);
1560 actionType = ActionValues.ACTION_ENQUEUE;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001561 }
1562
1563 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001564 * Convert the action to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -07001565 * <p/>
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001566 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -07001567 * [type=XXX action=XXX]
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001568 *
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001569 * @return the action as a string.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001570 */
1571 @Override
1572 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001573 String ret = "[";
1574 ret += "type=" + actionType;
1575 switch (actionType) {
1576 case ACTION_OUTPUT:
1577 ret += " action=" + actionOutput.toString();
1578 break;
1579 case ACTION_SET_VLAN_VID:
1580 ret += " action=" + actionSetVlanId.toString();
1581 break;
1582 case ACTION_SET_VLAN_PCP:
1583 ret += " action=" + actionSetVlanPriority.toString();
1584 break;
1585 case ACTION_STRIP_VLAN:
1586 ret += " action=" + actionStripVlan.toString();
1587 break;
1588 case ACTION_SET_DL_SRC:
1589 ret += " action=" + actionSetEthernetSrcAddr.toString();
1590 break;
1591 case ACTION_SET_DL_DST:
1592 ret += " action=" + actionSetEthernetDstAddr.toString();
1593 break;
1594 case ACTION_SET_NW_SRC:
1595 ret += " action=" + actionSetIPv4SrcAddr.toString();
1596 break;
1597 case ACTION_SET_NW_DST:
1598 ret += " action=" + actionSetIPv4DstAddr.toString();
1599 break;
1600 case ACTION_SET_NW_TOS:
1601 ret += " action=" + actionSetIpToS.toString();
1602 break;
1603 case ACTION_SET_TP_SRC:
1604 ret += " action=" + actionSetTcpUdpSrcPort.toString();
1605 break;
1606 case ACTION_SET_TP_DST:
1607 ret += " action=" + actionSetTcpUdpDstPort.toString();
1608 break;
1609 case ACTION_ENQUEUE:
1610 ret += " action=" + actionEnqueue.toString();
1611 break;
1612 case ACTION_VENDOR:
1613 ret += " action=VENDOR";
1614 break;
Ray Milkey0b122ed2014-04-14 10:06:03 -07001615 default:
1616 ret += " action=unknown";
1617 break;
Ray Milkey269ffb92014-04-03 14:43:30 -07001618 }
1619 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001620
Ray Milkey269ffb92014-04-03 14:43:30 -07001621 return ret;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001622 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001623
1624 /**
1625 * Convert a string to an action.
Ray Milkey269ffb92014-04-03 14:43:30 -07001626 * <p/>
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001627 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -07001628 * [type=XXX action=XXX]
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001629 *
1630 * @param actionStr the action as a string.
1631 */
1632 public void fromString(String actionStr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001633 String[] parts = actionStr.split("type=");
1634 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001635
Ray Milkey269ffb92014-04-03 14:43:30 -07001636 // Extract the string after the "type="
Ray Milkeyb29e6262014-04-09 16:02:14 -07001637 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001638 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001639 }
1640 if (decode == null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001641 throw new IllegalArgumentException("Invalid action string");
Ray Milkeyb29e6262014-04-09 16:02:14 -07001642 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001643
Ray Milkey269ffb92014-04-03 14:43:30 -07001644 // Remove the trailing ']'
1645 if ((decode.length() > 0) && (decode.charAt(decode.length() - 1) == ']')) {
1646 decode = decode.substring(0, decode.length() - 1);
1647 } else {
1648 throw new IllegalArgumentException("Invalid action string");
1649 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001650
Ray Milkey269ffb92014-04-03 14:43:30 -07001651 // Extract the type value and the action value
1652 parts = decode.split(" action=");
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001653
Ray Milkey269ffb92014-04-03 14:43:30 -07001654 // Decode the "type=XXX" payload
Ray Milkeyb29e6262014-04-09 16:02:14 -07001655 if (parts.length > 0) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001656 decode = parts[0];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001657 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001658 if (decode != null) {
1659 try {
1660 actionType = Enum.valueOf(ActionValues.class, decode);
1661 } catch (IllegalArgumentException e) {
1662 throw new IllegalArgumentException("Invalid action string");
1663 }
1664 } else {
1665 throw new IllegalArgumentException("Invalid action string");
1666 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001667
Ray Milkey269ffb92014-04-03 14:43:30 -07001668 // Decode the "action=XXX" payload
1669 decode = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001670 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001671 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001672 }
1673 if (decode == null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001674 throw new IllegalArgumentException("Invalid action string");
Ray Milkeyb29e6262014-04-09 16:02:14 -07001675 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001676 //
1677 try {
1678 switch (actionType) {
1679 case ACTION_OUTPUT:
1680 actionOutput = new ActionOutput(decode);
1681 break;
1682 case ACTION_SET_VLAN_VID:
1683 actionSetVlanId = new ActionSetVlanId(decode);
1684 break;
1685 case ACTION_SET_VLAN_PCP:
1686 actionSetVlanPriority = new ActionSetVlanPriority(decode);
1687 break;
1688 case ACTION_STRIP_VLAN:
1689 actionStripVlan = new ActionStripVlan(decode);
1690 break;
1691 case ACTION_SET_DL_SRC:
1692 actionSetEthernetSrcAddr = new ActionSetEthernetAddr(decode);
1693 break;
1694 case ACTION_SET_DL_DST:
1695 actionSetEthernetDstAddr = new ActionSetEthernetAddr(decode);
1696 break;
1697 case ACTION_SET_NW_SRC:
1698 actionSetIPv4SrcAddr = new ActionSetIPv4Addr(decode);
1699 break;
1700 case ACTION_SET_NW_DST:
1701 actionSetIPv4DstAddr = new ActionSetIPv4Addr(decode);
1702 break;
1703 case ACTION_SET_NW_TOS:
1704 actionSetIpToS = new ActionSetIpToS(decode);
1705 break;
1706 case ACTION_SET_TP_SRC:
1707 actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(decode);
1708 break;
1709 case ACTION_SET_TP_DST:
1710 actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(decode);
1711 break;
1712 case ACTION_ENQUEUE:
1713 actionEnqueue = new ActionEnqueue(decode);
1714 break;
1715 case ACTION_VENDOR:
1716 // TODO: Handle it as appropriate
1717 break;
Ray Milkey0b122ed2014-04-14 10:06:03 -07001718 default:
1719 throw new IllegalArgumentException("Invalid action string");
Ray Milkey269ffb92014-04-03 14:43:30 -07001720 }
1721 } catch (IllegalArgumentException e) {
Ray Milkey0b122ed2014-04-14 10:06:03 -07001722 throw new IllegalArgumentException("Invalid action type", e);
Ray Milkey269ffb92014-04-03 14:43:30 -07001723 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001724 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001725}