blob: d5ad674bd945078804fa6f65454da7e109150126 [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 {
Yuta HIGUCHI9da3a6e2014-06-10 22:11:58 -0700180 port = new PortNumber(tokens[1]);
Ray Milkey269ffb92014-04-03 14:43:30 -0700181 } catch (NumberFormatException e) {
182 throw new IllegalArgumentException("Invalid action string");
183 }
184 }
185 } else {
186 throw new IllegalArgumentException("Invalid action string");
187 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700188
Ray Milkey269ffb92014-04-03 14:43:30 -0700189 // Decode the "maxLen=XXX" part
190 decode = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700191 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700192 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700193 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700194 if (decode != null) {
195 decode = decode.replace("]", "");
196 String[] tokens = decode.split("maxLen=");
197 if (tokens.length > 1 && tokens[1] != null) {
198 try {
199 maxLen = Short.valueOf(tokens[1]);
200 } catch (NumberFormatException e) {
201 throw new IllegalArgumentException("Invalid action string");
202 }
203 }
204 } else {
205 throw new IllegalArgumentException("Invalid action string");
206 }
207 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800208 }
209
210 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700211 * Action structure for ACTION_SET_VLAN_VID: Set the 802.1q VLAN id.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800212 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700213 public static class ActionSetVlanId {
Ray Milkey269ffb92014-04-03 14:43:30 -0700214 private short vlanId; // The VLAN ID to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800215
Ray Milkey269ffb92014-04-03 14:43:30 -0700216 /**
217 * Default constructor.
218 */
219 public ActionSetVlanId() {
220 this.vlanId = 0;
221 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700222
Ray Milkey269ffb92014-04-03 14:43:30 -0700223 /**
224 * Copy constructor.
225 *
226 * @param other the object to copy from.
227 */
228 public ActionSetVlanId(ActionSetVlanId other) {
229 this.vlanId = other.vlanId;
230 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700231
Ray Milkey269ffb92014-04-03 14:43:30 -0700232 /**
233 * Constructor from a string.
234 * <p/>
235 * The string has the following form:
236 * [vlanId=XXX]
237 *
238 * @param actionStr the action as a string.
239 */
240 public ActionSetVlanId(String actionStr) {
241 this.fromString(actionStr);
242 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700243
Ray Milkey269ffb92014-04-03 14:43:30 -0700244 /**
245 * Constructor for a given VLAN ID.
246 *
247 * @param vlanId the VLAN ID to set.
248 */
249 public ActionSetVlanId(short vlanId) {
250 this.vlanId = vlanId;
251 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800252
Ray Milkey269ffb92014-04-03 14:43:30 -0700253 /**
254 * Get the VLAN ID.
255 *
256 * @return the VLAN ID.
257 */
258 @JsonProperty("vlanId")
259 public short vlanId() {
260 return this.vlanId;
261 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800262
Ray Milkey269ffb92014-04-03 14:43:30 -0700263 /**
264 * Convert the action to a string.
265 * <p/>
266 * The string has the following form:
267 * [vlanId=XXX]
268 *
269 * @return the action as a string.
270 */
271 @Override
272 public String toString() {
273 String ret = "[";
274 ret += "vlanId=" + this.vlanId;
275 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800276
Ray Milkey269ffb92014-04-03 14:43:30 -0700277 return ret;
278 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700279
Ray Milkey269ffb92014-04-03 14:43:30 -0700280 /**
281 * Convert a string to an action.
282 * <p/>
283 * The string has the following form:
284 * [vlanId=XXX]
285 *
286 * @param actionStr the action as a string.
287 */
288 public void fromString(String actionStr) {
289 String[] parts = actionStr.split("vlanId=");
290 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700291
Ray Milkey269ffb92014-04-03 14:43:30 -0700292 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700293 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700294 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700295 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700296 if (decode != null) {
297 decode = decode.replace("]", "");
298 try {
299 vlanId = Short.valueOf(decode);
300 } catch (NumberFormatException e) {
301 throw new IllegalArgumentException("Invalid action string");
302 }
303 } else {
304 throw new IllegalArgumentException("Invalid action string");
305 }
306 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800307 }
308
309 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700310 * Action structure for ACTION_SET_VLAN_PCP: Set the 802.1q priority.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800311 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700312 public static class ActionSetVlanPriority {
Ray Milkey269ffb92014-04-03 14:43:30 -0700313 private byte vlanPriority; // The VLAN priority to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800314
Ray Milkey269ffb92014-04-03 14:43:30 -0700315 /**
316 * Default constructor.
317 */
318 public ActionSetVlanPriority() {
319 this.vlanPriority = 0;
320 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700321
Ray Milkey269ffb92014-04-03 14:43:30 -0700322 /**
323 * Copy constructor.
324 *
325 * @param other the object to copy from.
326 */
327 public ActionSetVlanPriority(ActionSetVlanPriority other) {
328 this.vlanPriority = other.vlanPriority;
329 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700330
Ray Milkey269ffb92014-04-03 14:43:30 -0700331 /**
332 * Constructor from a string.
333 * <p/>
334 * The string has the following form:
335 * [vlanPriority=XXX]
336 *
337 * @param actionStr the action as a string.
338 */
339 public ActionSetVlanPriority(String actionStr) {
340 this.fromString(actionStr);
341 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700342
Ray Milkey269ffb92014-04-03 14:43:30 -0700343 /**
344 * Constructor for a given VLAN priority.
345 *
346 * @param vlanPriority the VLAN priority to set.
347 */
348 public ActionSetVlanPriority(byte vlanPriority) {
349 this.vlanPriority = vlanPriority;
350 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800351
Ray Milkey269ffb92014-04-03 14:43:30 -0700352 /**
353 * Get the VLAN priority.
354 *
355 * @return the VLAN priority.
356 */
357 @JsonProperty("vlanPriority")
358 public byte vlanPriority() {
359 return this.vlanPriority;
360 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800361
Ray Milkey269ffb92014-04-03 14:43:30 -0700362 /**
363 * Convert the action to a string.
364 * <p/>
365 * The string has the following form:
366 * [vlanPriority=XXX]
367 *
368 * @return the action as a string.
369 */
370 @Override
371 public String toString() {
372 String ret = "[";
373 ret += "vlanPriority=" + this.vlanPriority;
374 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800375
Ray Milkey269ffb92014-04-03 14:43:30 -0700376 return ret;
377 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700378
Ray Milkey269ffb92014-04-03 14:43:30 -0700379 /**
380 * Convert a string to an action.
381 * <p/>
382 * The string has the following form:
383 * [vlanPriority=XXX]
384 *
385 * @param actionStr the action as a string.
386 */
387 public void fromString(String actionStr) {
388 String[] parts = actionStr.split("vlanPriority=");
389 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700390
Ray Milkey269ffb92014-04-03 14:43:30 -0700391 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700392 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700393 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700394 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700395 if (decode != null) {
396 decode = decode.replace("]", "");
397 try {
398 vlanPriority = Byte.valueOf(decode);
399 } catch (NumberFormatException e) {
400 throw new IllegalArgumentException("Invalid action string");
401 }
402 } else {
403 throw new IllegalArgumentException("Invalid action string");
404 }
405 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800406 }
407
408 /**
Ray Milkeyb41100a2014-04-10 10:42:15 -0700409 * Action structure for ACTION_STRIP_VLAN: Strip the 802.1q header.
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800410 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700411 public static class ActionStripVlan {
Ray Milkey269ffb92014-04-03 14:43:30 -0700412 private boolean stripVlan; // If true, strip the VLAN header
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800413
Ray Milkey269ffb92014-04-03 14:43:30 -0700414 /**
415 * Default constructor.
416 */
417 public ActionStripVlan() {
418 this.stripVlan = false;
419 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700420
Ray Milkey269ffb92014-04-03 14:43:30 -0700421 /**
422 * Copy constructor.
423 *
424 * @param other the object to copy from.
425 */
426 public ActionStripVlan(ActionStripVlan other) {
427 this.stripVlan = other.stripVlan;
428 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700429
Ray Milkey269ffb92014-04-03 14:43:30 -0700430 /**
431 * Constructor from a string.
432 * <p/>
433 * The string has the following form:
434 * [stripVlan=XXX]
435 *
436 * @param actionStr the action as a string.
437 */
438 public ActionStripVlan(String actionStr) {
439 this.fromString(actionStr);
440 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700441
Ray Milkey269ffb92014-04-03 14:43:30 -0700442 /**
443 * Constructor for a given boolean flag.
444 *
445 * @param stripVlan if true, strip the VLAN header.
446 */
447 public ActionStripVlan(boolean stripVlan) {
448 this.stripVlan = stripVlan;
449 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800450
Ray Milkey269ffb92014-04-03 14:43:30 -0700451 /**
452 * Get the boolean flag whether the VLAN header should be stripped.
453 *
454 * @return the boolean flag whether the VLAN header should be stripped.
455 */
456 @JsonProperty("stripVlan")
457 public boolean stripVlan() {
458 return this.stripVlan;
459 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800460
Ray Milkey269ffb92014-04-03 14:43:30 -0700461 /**
462 * Convert the action to a string.
463 * <p/>
464 * The string has the following form:
465 * [stripVlan=XXX]
466 *
467 * @return the action as a string.
468 */
469 @Override
470 public String toString() {
471 String ret = "[";
472 ret += "stripVlan=" + this.stripVlan;
473 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800474
Ray Milkey269ffb92014-04-03 14:43:30 -0700475 return ret;
476 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700477
Ray Milkey269ffb92014-04-03 14:43:30 -0700478 /**
479 * Convert a string to an action.
480 * <p/>
481 * The string has the following form:
482 * [stripVlan=XXX]
483 *
484 * @param actionStr the action as a string.
485 */
486 public void fromString(String actionStr) {
487 String[] parts = actionStr.split("stripVlan=");
488 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700489
Ray Milkey269ffb92014-04-03 14:43:30 -0700490 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700491 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700492 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700493 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700494 if (decode != null) {
495 decode = decode.replace("]", "");
496 stripVlan = Boolean.valueOf(decode);
497 } else {
498 throw new IllegalArgumentException("Invalid action string");
499 }
500 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800501 }
502
503 /**
504 * Action structure for ACTION_SET_DL_SRC and ACTION_SET_DL_DST:
505 * Set the Ethernet source/destination address.
506 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700507 public static class ActionSetEthernetAddr {
Ray Milkey269ffb92014-04-03 14:43:30 -0700508 private MACAddress addr; // The MAC address to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800509
Ray Milkey269ffb92014-04-03 14:43:30 -0700510 /**
511 * Default constructor.
512 */
513 public ActionSetEthernetAddr() {
514 this.addr = null;
515 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700516
Ray Milkey269ffb92014-04-03 14:43:30 -0700517 /**
518 * Copy constructor.
519 *
520 * @param other the object to copy from.
521 */
522 public ActionSetEthernetAddr(ActionSetEthernetAddr other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700523 if (other.addr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700524 this.addr = MACAddress.valueOf(other.addr.toLong());
Ray Milkeyb29e6262014-04-09 16:02:14 -0700525 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700526 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700527
Ray Milkey269ffb92014-04-03 14:43:30 -0700528 /**
529 * Constructor from a string.
530 * <p/>
531 * The string has the following form:
532 * [addr=XXX]
533 *
534 * @param actionStr the action as a string.
535 */
536 public ActionSetEthernetAddr(String actionStr) {
537 this.fromString(actionStr);
538 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700539
Ray Milkey269ffb92014-04-03 14:43:30 -0700540 /**
541 * Constructor for a given MAC address.
542 *
543 * @param addr the MAC address to set.
544 */
545 public ActionSetEthernetAddr(MACAddress addr) {
546 this.addr = addr;
547 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800548
Ray Milkey269ffb92014-04-03 14:43:30 -0700549 /**
550 * Get the MAC address.
551 *
552 * @return the MAC address.
553 */
554 @JsonProperty("addr")
555 public MACAddress addr() {
556 return this.addr;
557 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800558
Ray Milkey269ffb92014-04-03 14:43:30 -0700559 /**
560 * Convert the action to a string.
561 * <p/>
562 * The string has the following form:
563 * [addr=XXX]
564 *
565 * @return the action as a string.
566 */
567 @Override
568 public String toString() {
569 String ret = "[";
570 ret += "addr=" + addr.toString();
571 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800572
Ray Milkey269ffb92014-04-03 14:43:30 -0700573 return ret;
574 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700575
Ray Milkey269ffb92014-04-03 14:43:30 -0700576 /**
577 * Convert a string to an action.
578 * <p/>
579 * The string has the following form:
580 * [addr=XXX]
581 *
582 * @param actionStr the action as a string.
583 */
584 public void fromString(String actionStr) {
585 String[] parts = actionStr.split("addr=");
586 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700587
Ray Milkey269ffb92014-04-03 14:43:30 -0700588 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700589 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700590 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700591 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700592 if (decode != null) {
593 decode = decode.replace("]", "");
594 try {
595 addr = MACAddress.valueOf(decode);
596 } catch (IllegalArgumentException e) {
597 throw new IllegalArgumentException("Invalid action string");
598 }
599 } else {
600 throw new IllegalArgumentException("Invalid action string");
601 }
602 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800603 }
604
605 /**
606 * Action structure for ACTION_SET_NW_SRC and ACTION_SET_NW_DST:
607 * Set the IPv4 source/destination address.
608 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700609 public static class ActionSetIPv4Addr {
Ray Milkey269ffb92014-04-03 14:43:30 -0700610 private IPv4 addr; // The IPv4 address to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800611
Ray Milkey269ffb92014-04-03 14:43:30 -0700612 /**
613 * Default constructor.
614 */
615 public ActionSetIPv4Addr() {
616 this.addr = null;
617 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700618
Ray Milkey269ffb92014-04-03 14:43:30 -0700619 /**
620 * Copy constructor.
621 *
622 * @param other the object to copy from.
623 */
624 public ActionSetIPv4Addr(ActionSetIPv4Addr other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700625 if (other.addr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700626 this.addr = new IPv4(other.addr);
Ray Milkeyb29e6262014-04-09 16:02:14 -0700627 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700628 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700629
Ray Milkey269ffb92014-04-03 14:43:30 -0700630 /**
631 * Constructor from a string.
632 * <p/>
633 * The string has the following form:
634 * [addr=XXX]
635 *
636 * @param actionStr the action as a string.
637 */
638 public ActionSetIPv4Addr(String actionStr) {
639 this.fromString(actionStr);
640 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700641
Ray Milkey269ffb92014-04-03 14:43:30 -0700642 /**
643 * Constructor for a given IPv4 address.
644 *
645 * @param addr the IPv4 address to set.
646 */
647 public ActionSetIPv4Addr(IPv4 addr) {
648 this.addr = addr;
649 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800650
Ray Milkey269ffb92014-04-03 14:43:30 -0700651 /**
652 * Get the IPv4 address.
653 *
654 * @return the IPv4 address.
655 */
656 @JsonProperty("addr")
657 public IPv4 addr() {
658 return this.addr;
659 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800660
Ray Milkey269ffb92014-04-03 14:43:30 -0700661 /**
662 * Convert the action to a string.
663 * <p/>
664 * The string has the following form:
665 * [addr=XXX]
666 *
667 * @return the action as a string.
668 */
669 @Override
670 public String toString() {
671 String ret = "[";
672 ret += "addr=" + addr.toString();
673 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800674
Ray Milkey269ffb92014-04-03 14:43:30 -0700675 return ret;
676 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700677
Ray Milkey269ffb92014-04-03 14:43:30 -0700678 /**
679 * Convert a string to an action.
680 * <p/>
681 * The string has the following form:
682 * [addr=XXX]
683 *
684 * @param actionStr the action as a string.
685 */
686 public void fromString(String actionStr) {
687 String[] parts = actionStr.split("addr=");
688 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700689
Ray Milkey269ffb92014-04-03 14:43:30 -0700690 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700691 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700692 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700693 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700694 if (decode != null) {
695 decode = decode.replace("]", "");
696 try {
697 addr = new IPv4(decode);
698 } catch (IllegalArgumentException e) {
699 throw new IllegalArgumentException("Invalid action string");
700 }
701 } else {
702 throw new IllegalArgumentException("Invalid action string");
703 }
704 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800705 }
706
707 /**
708 * Action structure for ACTION_SET_NW_TOS:
709 * Set the IP ToS (DSCP field, 6 bits).
710 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700711 public static class ActionSetIpToS {
Ray Milkey269ffb92014-04-03 14:43:30 -0700712 private byte ipToS; // The IP ToS to set DSCP field, 6 bits)
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800713
Ray Milkey269ffb92014-04-03 14:43:30 -0700714 /**
715 * Default constructor.
716 */
717 public ActionSetIpToS() {
718 this.ipToS = 0;
719 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700720
Ray Milkey269ffb92014-04-03 14:43:30 -0700721 /**
722 * Copy constructor.
723 *
724 * @param other the object to copy from.
725 */
726 public ActionSetIpToS(ActionSetIpToS other) {
727 this.ipToS = other.ipToS;
728 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700729
Ray Milkey269ffb92014-04-03 14:43:30 -0700730 /**
731 * Constructor from a string.
732 * <p/>
733 * The string has the following form:
734 * [ipToS=XXX]
735 *
736 * @param actionStr the action as a string.
737 */
738 public ActionSetIpToS(String actionStr) {
739 this.fromString(actionStr);
740 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700741
Ray Milkey269ffb92014-04-03 14:43:30 -0700742 /**
743 * Constructor for a given IP ToS (DSCP field, 6 bits).
744 *
745 * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
746 */
747 public ActionSetIpToS(byte ipToS) {
748 this.ipToS = ipToS;
749 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800750
Ray Milkey269ffb92014-04-03 14:43:30 -0700751 /**
752 * Get the IP ToS (DSCP field, 6 bits).
753 *
754 * @return the IP ToS (DSCP field, 6 bits).
755 */
756 @JsonProperty("ipToS")
757 public byte ipToS() {
758 return this.ipToS;
759 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800760
Ray Milkey269ffb92014-04-03 14:43:30 -0700761 /**
762 * Convert the action to a string.
763 * <p/>
764 * The string has the following form:
765 * [ipToS=XXX]
766 *
767 * @return the action as a string.
768 */
769 @Override
770 public String toString() {
771 String ret = "[";
772 ret += "ipToS=" + ipToS;
773 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800774
Ray Milkey269ffb92014-04-03 14:43:30 -0700775 return ret;
776 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700777
Ray Milkey269ffb92014-04-03 14:43:30 -0700778 /**
779 * Convert a string to an action.
780 * <p/>
781 * The string has the following form:
782 * [ipToS=XXX]
783 *
784 * @param actionStr the action as a string.
785 */
786 public void fromString(String actionStr) {
787 String[] parts = actionStr.split("ipToS=");
788 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700789
Ray Milkey269ffb92014-04-03 14:43:30 -0700790 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700791 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700792 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700793 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700794 if (decode != null) {
795 decode = decode.replace("]", "");
796 try {
797 ipToS = Byte.valueOf(decode);
798 } catch (NumberFormatException e) {
799 throw new IllegalArgumentException("Invalid action string");
800 }
801 } else {
802 throw new IllegalArgumentException("Invalid action string");
803 }
804 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800805 }
806
807 /**
808 * Action structure for ACTION_SET_TP_SRC and ACTION_SET_TP_DST:
809 * Set the TCP/UDP source/destination port.
810 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700811 public static class ActionSetTcpUdpPort {
Ray Milkey269ffb92014-04-03 14:43:30 -0700812 private short port; // The TCP/UDP port to set
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800813
Ray Milkey269ffb92014-04-03 14:43:30 -0700814 /**
815 * Default constructor.
816 */
817 public ActionSetTcpUdpPort() {
818 this.port = 0;
819 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700820
Ray Milkey269ffb92014-04-03 14:43:30 -0700821 /**
822 * Copy constructor.
823 *
824 * @param other the object to copy from.
825 */
826 public ActionSetTcpUdpPort(ActionSetTcpUdpPort other) {
827 this.port = other.port;
828 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700829
Ray Milkey269ffb92014-04-03 14:43:30 -0700830 /**
831 * Constructor from a string.
832 * <p/>
833 * The string has the following form:
834 * [port=XXX]
835 *
836 * @param actionStr the action as a string.
837 */
838 public ActionSetTcpUdpPort(String actionStr) {
839 this.fromString(actionStr);
840 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700841
Ray Milkey269ffb92014-04-03 14:43:30 -0700842 /**
843 * Constructor for a given TCP/UDP port.
844 *
845 * @param port the TCP/UDP port to set.
846 */
847 public ActionSetTcpUdpPort(short port) {
848 this.port = port;
849 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800850
Ray Milkey269ffb92014-04-03 14:43:30 -0700851 /**
852 * Get the TCP/UDP port.
853 *
854 * @return the TCP/UDP port.
855 */
856 @JsonProperty("port")
857 public short port() {
858 return this.port;
859 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800860
Ray Milkey269ffb92014-04-03 14:43:30 -0700861 /**
862 * Convert the action to a string.
863 * <p/>
864 * The string has the following form:
865 * [port=XXX]
866 *
867 * @return the action as a string.
868 */
869 @Override
870 public String toString() {
871 String ret = "[";
872 ret += "port=" + port;
873 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800874
Ray Milkey269ffb92014-04-03 14:43:30 -0700875 return ret;
876 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700877
Ray Milkey269ffb92014-04-03 14:43:30 -0700878 /**
879 * Convert a string to an action.
880 * <p/>
881 * The string has the following form:
882 * [port=XXX]
883 *
884 * @param actionStr the action as a string.
885 */
886 public void fromString(String actionStr) {
887 String[] parts = actionStr.split("port=");
888 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700889
Ray Milkey269ffb92014-04-03 14:43:30 -0700890 // Decode the value
Ray Milkeyb29e6262014-04-09 16:02:14 -0700891 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700892 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -0700893 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700894 if (decode != null) {
895 decode = decode.replace("]", "");
896 try {
897 port = Short.valueOf(decode);
898 } catch (NumberFormatException e) {
899 throw new IllegalArgumentException("Invalid action string");
900 }
901 } else {
902 throw new IllegalArgumentException("Invalid action string");
903 }
904 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800905 }
906
907 /**
908 * Action structure for ACTION_ENQUEUE: Output to queue on port.
909 */
Yuta HIGUCHI382827f2013-10-14 16:06:43 -0700910 public static class ActionEnqueue {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700911 private PortNumber port; // Port that queue belongs. Should
Ray Milkey269ffb92014-04-03 14:43:30 -0700912 // refer to a valid physical port
913 // (i.e. < PORT_MAX) or PORT_IN_PORT
914 private int queueId; // Where to enqueue the packets
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800915
Ray Milkey269ffb92014-04-03 14:43:30 -0700916 /**
917 * Default constructor.
918 */
919 public ActionEnqueue() {
920 this.port = null;
921 this.queueId = 0;
922 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700923
Ray Milkey269ffb92014-04-03 14:43:30 -0700924 /**
925 * Copy constructor.
926 *
927 * @param other the object to copy from.
928 */
929 public ActionEnqueue(ActionEnqueue other) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700930 if (other.port != null) {
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700931 this.port = new PortNumber(other.port);
Ray Milkeyb29e6262014-04-09 16:02:14 -0700932 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700933 this.queueId = other.queueId;
934 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700935
Ray Milkey269ffb92014-04-03 14:43:30 -0700936 /**
937 * Constructor from a string.
938 * <p/>
939 * The string has the following form:
940 * [port=XXX queueId=XXX]
941 *
942 * @param actionStr the action as a string.
943 */
944 public ActionEnqueue(String actionStr) {
945 this.fromString(actionStr);
946 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700947
Ray Milkey269ffb92014-04-03 14:43:30 -0700948 /**
949 * Constructor for a given port and queue ID.
950 *
951 * @param port the port to set.
952 * @param queueId the queue ID on the port.
953 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700954 public ActionEnqueue(PortNumber port, int queueId) {
Ray Milkey269ffb92014-04-03 14:43:30 -0700955 this.port = port;
956 this.queueId = queueId;
957 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800958
Ray Milkey269ffb92014-04-03 14:43:30 -0700959 /**
960 * Get the port.
961 *
962 * @return the port.
963 */
964 @JsonProperty("port")
Yuta HIGUCHIfb564502014-06-16 21:29:00 -0700965 public PortNumber port() {
Ray Milkey269ffb92014-04-03 14:43:30 -0700966 return this.port;
967 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800968
Ray Milkey269ffb92014-04-03 14:43:30 -0700969 /**
970 * Get the queue ID.
971 *
972 * @return the queue ID.
973 */
974 @JsonProperty("queueId")
975 public int queueId() {
976 return this.queueId;
977 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800978
Ray Milkey269ffb92014-04-03 14:43:30 -0700979 /**
980 * Convert the action to a string.
981 * <p/>
982 * The string has the following form:
983 * [port=XXX queueId=XXX]
984 *
985 * @return the action as a string.
986 */
987 @Override
988 public String toString() {
989 String ret = "[";
990 ret += "port=" + port.toString();
991 ret += " queueId=" + queueId;
992 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800993
Ray Milkey269ffb92014-04-03 14:43:30 -0700994 return ret;
995 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700996
Ray Milkey269ffb92014-04-03 14:43:30 -0700997 /**
998 * Convert a string to an action.
999 * <p/>
1000 * The string has the following form:
1001 * [port=XXX queueId=XXX]
1002 *
1003 * @param actionStr the action as a string.
1004 */
1005 public void fromString(String actionStr) {
1006 String[] parts = actionStr.split(" ");
1007 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001008
Ray Milkey269ffb92014-04-03 14:43:30 -07001009 // Decode the "port=XXX" part
Ray Milkeyb29e6262014-04-09 16:02:14 -07001010 if (parts.length > 0) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001011 decode = parts[0];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001012 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001013 if (decode != null) {
1014 String[] tokens = decode.split("port=");
1015 if (tokens.length > 1 && tokens[1] != null) {
1016 try {
1017 Short valueShort = Short.valueOf(tokens[1]);
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07001018 port = new PortNumber(valueShort);
Ray Milkey269ffb92014-04-03 14:43:30 -07001019 } catch (NumberFormatException e) {
1020 throw new IllegalArgumentException("Invalid action string");
1021 }
1022 }
1023 } else {
1024 throw new IllegalArgumentException("Invalid action string");
1025 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001026
Ray Milkey269ffb92014-04-03 14:43:30 -07001027 // Decode the "queueId=XXX" part
1028 decode = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001029 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001030 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001031 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001032 if (decode != null) {
1033 decode = decode.replace("]", "");
1034 String[] tokens = decode.split("queueId=");
1035 if (tokens.length > 1 && tokens[1] != null) {
1036 try {
1037 queueId = Short.valueOf(tokens[1]);
1038 } catch (NumberFormatException e) {
1039 throw new IllegalArgumentException("Invalid action string");
1040 }
1041 }
1042 } else {
1043 throw new IllegalArgumentException("Invalid action string");
1044 }
1045 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001046 }
1047
Ray Milkey269ffb92014-04-03 14:43:30 -07001048 private ActionValues actionType; // The action type
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001049
1050 //
1051 // The actions.
1052 // NOTE: Only one action should be set.
1053 //
1054 private ActionOutput actionOutput;
1055 private ActionSetVlanId actionSetVlanId;
1056 private ActionSetVlanPriority actionSetVlanPriority;
1057 private ActionStripVlan actionStripVlan;
1058 private ActionSetEthernetAddr actionSetEthernetSrcAddr;
1059 private ActionSetEthernetAddr actionSetEthernetDstAddr;
1060 private ActionSetIPv4Addr actionSetIPv4SrcAddr;
1061 private ActionSetIPv4Addr actionSetIPv4DstAddr;
1062 private ActionSetIpToS actionSetIpToS;
1063 private ActionSetTcpUdpPort actionSetTcpUdpSrcPort;
1064 private ActionSetTcpUdpPort actionSetTcpUdpDstPort;
1065 private ActionEnqueue actionEnqueue;
1066
1067 /**
1068 * Default constructor.
1069 */
1070 public FlowEntryAction() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001071 actionType = ActionValues.ACTION_VENDOR; // XXX: Initial value
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001072 }
1073
1074 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001075 * Copy constructor.
1076 *
1077 * @param other the object to copy from.
1078 */
1079 public FlowEntryAction(FlowEntryAction other) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001080 this.actionType = other.actionType;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001081
Ray Milkey269ffb92014-04-03 14:43:30 -07001082 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001083 if (other.actionOutput != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001084 this.actionOutput = new ActionOutput(other.actionOutput);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001085 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001086 this.actionOutput = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001087 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001088 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001089 if (other.actionSetVlanId != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001090 this.actionSetVlanId = new ActionSetVlanId(other.actionSetVlanId);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001091 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001092 this.actionSetVlanId = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001093 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001094 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001095 if (other.actionSetVlanPriority != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001096 this.actionSetVlanPriority = new ActionSetVlanPriority(other.actionSetVlanPriority);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001097 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001098 this.actionSetVlanPriority = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001099 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001100 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001101 if (other.actionStripVlan != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001102 this.actionStripVlan = new ActionStripVlan(other.actionStripVlan);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001103 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001104 this.actionStripVlan = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001105 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001106 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001107 if (other.actionSetEthernetSrcAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001108 this.actionSetEthernetSrcAddr = new ActionSetEthernetAddr(other.actionSetEthernetSrcAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001109 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001110 this.actionSetEthernetSrcAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001111 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001112 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001113 if (other.actionSetEthernetDstAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001114 this.actionSetEthernetDstAddr = new ActionSetEthernetAddr(other.actionSetEthernetDstAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001115 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001116 this.actionSetEthernetDstAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001117 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001118 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001119 if (other.actionSetIPv4SrcAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001120 this.actionSetIPv4SrcAddr = new ActionSetIPv4Addr(other.actionSetIPv4SrcAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001121 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001122 this.actionSetIPv4SrcAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001123 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001124 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001125 if (other.actionSetIPv4DstAddr != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001126 this.actionSetIPv4DstAddr = new ActionSetIPv4Addr(other.actionSetIPv4DstAddr);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001127 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001128 this.actionSetIPv4DstAddr = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001129 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001130 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001131 if (other.actionSetIpToS != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001132 this.actionSetIpToS = new ActionSetIpToS(other.actionSetIpToS);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001133 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001134 this.actionSetIpToS = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001135 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001136 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001137 if (other.actionSetTcpUdpSrcPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001138 this.actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpSrcPort);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001139 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001140 this.actionSetTcpUdpSrcPort = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001141 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001142 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001143 if (other.actionSetTcpUdpDstPort != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001144 this.actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpDstPort);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001145 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001146 this.actionSetTcpUdpDstPort = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001147 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001148 //
Ray Milkeyb29e6262014-04-09 16:02:14 -07001149 if (other.actionEnqueue != null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001150 this.actionEnqueue = new ActionEnqueue(other.actionEnqueue);
Ray Milkeyb29e6262014-04-09 16:02:14 -07001151 } else {
Ray Milkey269ffb92014-04-03 14:43:30 -07001152 this.actionEnqueue = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001153 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001154 }
1155
1156 /**
1157 * Constructor from a string.
Ray Milkey269ffb92014-04-03 14:43:30 -07001158 * <p/>
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001159 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -07001160 * [type=XXX action=XXX]
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001161 *
1162 * @param actionStr the action as a string.
1163 */
1164 public FlowEntryAction(String actionStr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001165 this.fromString(actionStr);
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001166 }
1167
1168 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001169 * Get the action type.
1170 *
1171 * @return the action type.
1172 */
1173 @JsonProperty("actionType")
Ray Milkey269ffb92014-04-03 14:43:30 -07001174 public ActionValues actionType() {
1175 return actionType;
1176 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001177
1178 /**
1179 * Get the output action.
1180 *
1181 * @return the output action.
1182 */
1183 @JsonProperty("actionOutput")
Ray Milkey269ffb92014-04-03 14:43:30 -07001184 public ActionOutput actionOutput() {
1185 return actionOutput;
1186 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001187
1188 /**
1189 * Set the output action on a port.
1190 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001191 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001192 */
1193 @JsonProperty("actionOutput")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001194 public void setActionOutput(ActionOutput action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001195 actionOutput = action;
1196 actionType = ActionValues.ACTION_OUTPUT;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001197 }
1198
1199 /**
1200 * Set the output action on a port.
1201 *
1202 * @param port the output port to set.
1203 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07001204 public void setActionOutput(PortNumber port) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001205 actionOutput = new ActionOutput(port);
1206 actionType = ActionValues.ACTION_OUTPUT;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001207 }
1208
1209 /**
1210 * Set the output action to controller.
1211 *
1212 * @param maxLen the maximum length (in bytes) to send to controller.
1213 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001214 public void setActionOutputToController(short maxLen) {
Jonathan Hart862ea922014-07-09 14:41:04 -07001215 PortNumber port = new PortNumber(OFPort.OFPP_CONTROLLER.getValue());
Ray Milkey269ffb92014-04-03 14:43:30 -07001216 actionOutput = new ActionOutput(port, maxLen);
1217 actionType = ActionValues.ACTION_OUTPUT;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001218 }
1219
1220 /**
1221 * Get the action to set the VLAN ID.
1222 *
1223 * @return the action to set the VLAN ID.
1224 */
1225 @JsonProperty("actionSetVlanId")
Ray Milkey269ffb92014-04-03 14:43:30 -07001226 public ActionSetVlanId actionSetVlanId() {
1227 return actionSetVlanId;
1228 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001229
1230 /**
1231 * Set the action to set the VLAN ID.
1232 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001233 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001234 */
1235 @JsonProperty("actionSetVlanId")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001236 public void setActionSetVlanId(ActionSetVlanId action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001237 actionSetVlanId = action;
1238 actionType = ActionValues.ACTION_SET_VLAN_VID;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001239 }
1240
1241 /**
1242 * Set the action to set the VLAN ID.
1243 *
1244 * @param vlanId the VLAN ID to set.
1245 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001246 public void setActionSetVlanId(short vlanId) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001247 actionSetVlanId = new ActionSetVlanId(vlanId);
1248 actionType = ActionValues.ACTION_SET_VLAN_VID;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001249 }
1250
1251 /**
1252 * Get the action to set the VLAN priority.
1253 *
1254 * @return the action to set the VLAN priority.
1255 */
1256 @JsonProperty("actionSetVlanPriority")
1257 public ActionSetVlanPriority actionSetVlanPriority() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001258 return actionSetVlanPriority;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001259 }
1260
1261 /**
1262 * Set the action to set the VLAN priority.
1263 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001264 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001265 */
1266 @JsonProperty("actionSetVlanPriority")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001267 public void setActionSetVlanPriority(ActionSetVlanPriority action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001268 actionSetVlanPriority = action;
1269 actionType = ActionValues.ACTION_SET_VLAN_PCP;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001270 }
1271
1272 /**
1273 * Set the action to set the VLAN priority.
1274 *
1275 * @param vlanPriority the VLAN priority to set.
1276 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001277 public void setActionSetVlanPriority(byte vlanPriority) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001278 actionSetVlanPriority = new ActionSetVlanPriority(vlanPriority);
1279 actionType = ActionValues.ACTION_SET_VLAN_PCP;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001280 }
1281
1282 /**
1283 * Get the action to strip the VLAN header.
1284 *
1285 * @return the action to strip the VLAN header.
1286 */
1287 @JsonProperty("actionStripVlan")
1288 public ActionStripVlan actionStripVlan() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001289 return actionStripVlan;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001290 }
1291
1292 /**
1293 * Set the action to strip the VLAN header.
1294 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001295 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001296 */
1297 @JsonProperty("actionStripVlan")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001298 public void setActionStripVlan(ActionStripVlan action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001299 actionStripVlan = action;
1300 actionType = ActionValues.ACTION_STRIP_VLAN;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001301 }
1302
1303 /**
1304 * Set the action to strip the VLAN header.
1305 *
1306 * @param stripVlan if true, strip the VLAN header.
1307 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001308 public void setActionStripVlan(boolean stripVlan) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001309 actionStripVlan = new ActionStripVlan(stripVlan);
1310 actionType = ActionValues.ACTION_STRIP_VLAN;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001311 }
1312
1313 /**
1314 * Get the action to set the Ethernet source address.
1315 *
1316 * @return the action to set the Ethernet source address.
1317 */
1318 @JsonProperty("actionSetEthernetSrcAddr")
1319 public ActionSetEthernetAddr actionSetEthernetSrcAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001320 return actionSetEthernetSrcAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001321 }
1322
1323 /**
1324 * Set the action to set the Ethernet source address.
1325 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001326 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001327 */
1328 @JsonProperty("actionSetEthernetSrcAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001329 public void setActionSetEthernetSrcAddr(ActionSetEthernetAddr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001330 actionSetEthernetSrcAddr = action;
1331 actionType = ActionValues.ACTION_SET_DL_SRC;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001332 }
1333
1334 /**
1335 * Set the action to set the Ethernet source address.
1336 *
1337 * @param addr the MAC address to set as the Ethernet source address.
1338 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001339 public void setActionSetEthernetSrcAddr(MACAddress addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001340 actionSetEthernetSrcAddr = new ActionSetEthernetAddr(addr);
1341 actionType = ActionValues.ACTION_SET_DL_SRC;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001342 }
1343
1344 /**
1345 * Get the action to set the Ethernet destination address.
1346 *
1347 * @return the action to set the Ethernet destination address.
1348 */
1349 @JsonProperty("actionSetEthernetDstAddr")
1350 public ActionSetEthernetAddr actionSetEthernetDstAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001351 return actionSetEthernetDstAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001352 }
1353
1354 /**
1355 * Set the action to set the Ethernet destination address.
1356 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001357 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001358 */
1359 @JsonProperty("actionSetEthernetDstAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001360 public void setActionSetEthernetDstAddr(ActionSetEthernetAddr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001361 actionSetEthernetDstAddr = action;
1362 actionType = ActionValues.ACTION_SET_DL_DST;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001363 }
1364
1365 /**
1366 * Set the action to set the Ethernet destination address.
1367 *
1368 * @param addr the MAC address to set as the Ethernet destination address.
1369 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001370 public void setActionSetEthernetDstAddr(MACAddress addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001371 actionSetEthernetDstAddr = new ActionSetEthernetAddr(addr);
1372 actionType = ActionValues.ACTION_SET_DL_DST;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001373 }
1374
1375 /**
1376 * Get the action to set the IPv4 source address.
1377 *
1378 * @return the action to set the IPv4 source address.
1379 */
1380 @JsonProperty("actionSetIPv4SrcAddr")
1381 public ActionSetIPv4Addr actionSetIPv4SrcAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001382 return actionSetIPv4SrcAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001383 }
1384
1385 /**
1386 * Set the action to set the IPv4 source address.
1387 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001388 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001389 */
1390 @JsonProperty("actionSetIPv4SrcAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001391 public void setActionSetIPv4SrcAddr(ActionSetIPv4Addr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001392 actionSetIPv4SrcAddr = action;
1393 actionType = ActionValues.ACTION_SET_NW_SRC;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001394 }
1395
1396 /**
1397 * Set the action to set the IPv4 source address.
1398 *
1399 * @param addr the IPv4 address to set as the IPv4 source address.
1400 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001401 public void setActionSetIPv4SrcAddr(IPv4 addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001402 actionSetIPv4SrcAddr = new ActionSetIPv4Addr(addr);
1403 actionType = ActionValues.ACTION_SET_NW_SRC;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001404 }
1405
1406 /**
1407 * Get the action to set the IPv4 destination address.
1408 *
1409 * @return the action to set the IPv4 destination address.
1410 */
1411 @JsonProperty("actionSetIPv4DstAddr")
1412 public ActionSetIPv4Addr actionSetIPv4DstAddr() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001413 return actionSetIPv4DstAddr;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001414 }
1415
1416 /**
1417 * Set the action to set the IPv4 destination address.
1418 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001419 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001420 */
1421 @JsonProperty("actionSetIPv4DstAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001422 public void setActionSetIPv4DstAddr(ActionSetIPv4Addr action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001423 actionSetIPv4DstAddr = action;
1424 actionType = ActionValues.ACTION_SET_NW_DST;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001425 }
1426
1427 /**
1428 * Set the action to set the IPv4 destination address.
1429 *
1430 * @param addr the IPv4 address to set as the IPv4 destination address.
1431 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001432 public void setActionSetIPv4DstAddr(IPv4 addr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001433 actionSetIPv4DstAddr = new ActionSetIPv4Addr(addr);
1434 actionType = ActionValues.ACTION_SET_NW_DST;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001435 }
1436
1437 /**
1438 * Get the action to set the IP ToS (DSCP field, 6 bits).
1439 *
1440 * @return the action to set the IP ToS (DSCP field, 6 bits).
1441 */
1442 @JsonProperty("actionSetIpToS")
1443 public ActionSetIpToS actionSetIpToS() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001444 return actionSetIpToS;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001445 }
1446
1447 /**
1448 * Set the action to set the IP ToS (DSCP field, 6 bits).
1449 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001450 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001451 */
1452 @JsonProperty("actionSetIpToS")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001453 public void setActionSetIpToS(ActionSetIpToS action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001454 actionSetIpToS = action;
1455 actionType = ActionValues.ACTION_SET_NW_TOS;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001456 }
1457
1458 /**
1459 * Set the action to set the IP ToS (DSCP field, 6 bits).
1460 *
1461 * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
1462 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001463 public void setActionSetIpToS(byte ipToS) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001464 actionSetIpToS = new ActionSetIpToS(ipToS);
1465 actionType = ActionValues.ACTION_SET_NW_TOS;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001466 }
1467
1468 /**
1469 * Get the action to set the TCP/UDP source port.
1470 *
1471 * @return the action to set the TCP/UDP source port.
1472 */
1473 @JsonProperty("actionSetTcpUdpSrcPort")
1474 public ActionSetTcpUdpPort actionSetTcpUdpSrcPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001475 return actionSetTcpUdpSrcPort;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001476 }
1477
1478 /**
1479 * Set the action to set the TCP/UDP source port.
1480 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001481 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001482 */
1483 @JsonProperty("actionSetTcpUdpSrcPort")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001484 public void setActionSetTcpUdpSrcPort(ActionSetTcpUdpPort action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001485 actionSetTcpUdpSrcPort = action;
1486 actionType = ActionValues.ACTION_SET_TP_SRC;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001487 }
1488
1489 /**
1490 * Set the action to set the TCP/UDP source port.
1491 *
1492 * @param port the TCP/UDP port to set as the TCP/UDP source port.
1493 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001494 public void setActionSetTcpUdpSrcPort(short port) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001495 actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(port);
1496 actionType = ActionValues.ACTION_SET_TP_SRC;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001497 }
1498
1499 /**
1500 * Get the action to set the TCP/UDP destination port.
1501 *
1502 * @return the action to set the TCP/UDP destination port.
1503 */
1504 @JsonProperty("actionSetTcpUdpDstPort")
1505 public ActionSetTcpUdpPort actionSetTcpUdpDstPort() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001506 return actionSetTcpUdpDstPort;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001507 }
1508
1509 /**
1510 * Set the action to set the TCP/UDP destination port.
1511 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001512 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001513 */
1514 @JsonProperty("actionSetTcpUdpDstPort")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001515 public void setActionSetTcpUdpDstPort(ActionSetTcpUdpPort action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001516 actionSetTcpUdpDstPort = action;
1517 actionType = ActionValues.ACTION_SET_TP_DST;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001518 }
1519
1520 /**
1521 * Set the action to set the TCP/UDP destination port.
1522 *
1523 * @param port the TCP/UDP port to set as the TCP/UDP destination port.
1524 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001525 public void setActionSetTcpUdpDstPort(short port) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001526 actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(port);
1527 actionType = ActionValues.ACTION_SET_TP_DST;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001528 }
1529
1530 /**
1531 * Get the action to output to queue on a port.
1532 *
1533 * @return the action to output to queue on a port.
1534 */
1535 @JsonProperty("actionEnqueue")
Ray Milkey269ffb92014-04-03 14:43:30 -07001536 public ActionEnqueue actionEnqueue() {
1537 return actionEnqueue;
1538 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001539
1540 /**
1541 * Set the action to output to queue on a port.
1542 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001543 * @param action the action to set.
1544 */
1545 @JsonProperty("actionEnqueue")
1546 public void setActionEnqueue(ActionEnqueue action) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001547 actionEnqueue = action;
1548 actionType = ActionValues.ACTION_ENQUEUE;
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001549 }
1550
1551 /**
1552 * Set the action to output to queue on a port.
1553 *
Ray Milkey269ffb92014-04-03 14:43:30 -07001554 * @param port the port to set.
HIGUCHI Yutaeb567aa2013-10-08 19:27:35 -07001555 * @param queueId the queue ID to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001556 */
Yuta HIGUCHIfb564502014-06-16 21:29:00 -07001557 public void setActionEnqueue(PortNumber port, int queueId) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001558 actionEnqueue = new ActionEnqueue(port, queueId);
1559 actionType = ActionValues.ACTION_ENQUEUE;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001560 }
1561
1562 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001563 * Convert the action to a string.
Ray Milkey269ffb92014-04-03 14:43:30 -07001564 * <p/>
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001565 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -07001566 * [type=XXX action=XXX]
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001567 *
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001568 * @return the action as a string.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001569 */
1570 @Override
1571 public String toString() {
Ray Milkey269ffb92014-04-03 14:43:30 -07001572 String ret = "[";
1573 ret += "type=" + actionType;
1574 switch (actionType) {
1575 case ACTION_OUTPUT:
1576 ret += " action=" + actionOutput.toString();
1577 break;
1578 case ACTION_SET_VLAN_VID:
1579 ret += " action=" + actionSetVlanId.toString();
1580 break;
1581 case ACTION_SET_VLAN_PCP:
1582 ret += " action=" + actionSetVlanPriority.toString();
1583 break;
1584 case ACTION_STRIP_VLAN:
1585 ret += " action=" + actionStripVlan.toString();
1586 break;
1587 case ACTION_SET_DL_SRC:
1588 ret += " action=" + actionSetEthernetSrcAddr.toString();
1589 break;
1590 case ACTION_SET_DL_DST:
1591 ret += " action=" + actionSetEthernetDstAddr.toString();
1592 break;
1593 case ACTION_SET_NW_SRC:
1594 ret += " action=" + actionSetIPv4SrcAddr.toString();
1595 break;
1596 case ACTION_SET_NW_DST:
1597 ret += " action=" + actionSetIPv4DstAddr.toString();
1598 break;
1599 case ACTION_SET_NW_TOS:
1600 ret += " action=" + actionSetIpToS.toString();
1601 break;
1602 case ACTION_SET_TP_SRC:
1603 ret += " action=" + actionSetTcpUdpSrcPort.toString();
1604 break;
1605 case ACTION_SET_TP_DST:
1606 ret += " action=" + actionSetTcpUdpDstPort.toString();
1607 break;
1608 case ACTION_ENQUEUE:
1609 ret += " action=" + actionEnqueue.toString();
1610 break;
1611 case ACTION_VENDOR:
1612 ret += " action=VENDOR";
1613 break;
Ray Milkey0b122ed2014-04-14 10:06:03 -07001614 default:
1615 ret += " action=unknown";
1616 break;
Ray Milkey269ffb92014-04-03 14:43:30 -07001617 }
1618 ret += "]";
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001619
Ray Milkey269ffb92014-04-03 14:43:30 -07001620 return ret;
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001621 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001622
1623 /**
1624 * Convert a string to an action.
Ray Milkey269ffb92014-04-03 14:43:30 -07001625 * <p/>
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001626 * The string has the following form:
Ray Milkey269ffb92014-04-03 14:43:30 -07001627 * [type=XXX action=XXX]
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001628 *
1629 * @param actionStr the action as a string.
1630 */
1631 public void fromString(String actionStr) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001632 String[] parts = actionStr.split("type=");
1633 String decode = null;
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001634
Ray Milkey269ffb92014-04-03 14:43:30 -07001635 // Extract the string after the "type="
Ray Milkeyb29e6262014-04-09 16:02:14 -07001636 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001637 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001638 }
1639 if (decode == null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001640 throw new IllegalArgumentException("Invalid action string");
Ray Milkeyb29e6262014-04-09 16:02:14 -07001641 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001642
Ray Milkey269ffb92014-04-03 14:43:30 -07001643 // Remove the trailing ']'
1644 if ((decode.length() > 0) && (decode.charAt(decode.length() - 1) == ']')) {
1645 decode = decode.substring(0, decode.length() - 1);
1646 } else {
1647 throw new IllegalArgumentException("Invalid action string");
1648 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001649
Ray Milkey269ffb92014-04-03 14:43:30 -07001650 // Extract the type value and the action value
1651 parts = decode.split(" action=");
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001652
Ray Milkey269ffb92014-04-03 14:43:30 -07001653 // Decode the "type=XXX" payload
Ray Milkeyb29e6262014-04-09 16:02:14 -07001654 if (parts.length > 0) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001655 decode = parts[0];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001656 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001657 if (decode != null) {
1658 try {
1659 actionType = Enum.valueOf(ActionValues.class, decode);
1660 } catch (IllegalArgumentException e) {
1661 throw new IllegalArgumentException("Invalid action string");
1662 }
1663 } else {
1664 throw new IllegalArgumentException("Invalid action string");
1665 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001666
Ray Milkey269ffb92014-04-03 14:43:30 -07001667 // Decode the "action=XXX" payload
1668 decode = null;
Ray Milkeyb29e6262014-04-09 16:02:14 -07001669 if (parts.length > 1) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001670 decode = parts[1];
Ray Milkeyb29e6262014-04-09 16:02:14 -07001671 }
1672 if (decode == null) {
Ray Milkey269ffb92014-04-03 14:43:30 -07001673 throw new IllegalArgumentException("Invalid action string");
Ray Milkeyb29e6262014-04-09 16:02:14 -07001674 }
Ray Milkey269ffb92014-04-03 14:43:30 -07001675 //
1676 try {
1677 switch (actionType) {
1678 case ACTION_OUTPUT:
1679 actionOutput = new ActionOutput(decode);
1680 break;
1681 case ACTION_SET_VLAN_VID:
1682 actionSetVlanId = new ActionSetVlanId(decode);
1683 break;
1684 case ACTION_SET_VLAN_PCP:
1685 actionSetVlanPriority = new ActionSetVlanPriority(decode);
1686 break;
1687 case ACTION_STRIP_VLAN:
1688 actionStripVlan = new ActionStripVlan(decode);
1689 break;
1690 case ACTION_SET_DL_SRC:
1691 actionSetEthernetSrcAddr = new ActionSetEthernetAddr(decode);
1692 break;
1693 case ACTION_SET_DL_DST:
1694 actionSetEthernetDstAddr = new ActionSetEthernetAddr(decode);
1695 break;
1696 case ACTION_SET_NW_SRC:
1697 actionSetIPv4SrcAddr = new ActionSetIPv4Addr(decode);
1698 break;
1699 case ACTION_SET_NW_DST:
1700 actionSetIPv4DstAddr = new ActionSetIPv4Addr(decode);
1701 break;
1702 case ACTION_SET_NW_TOS:
1703 actionSetIpToS = new ActionSetIpToS(decode);
1704 break;
1705 case ACTION_SET_TP_SRC:
1706 actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(decode);
1707 break;
1708 case ACTION_SET_TP_DST:
1709 actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(decode);
1710 break;
1711 case ACTION_ENQUEUE:
1712 actionEnqueue = new ActionEnqueue(decode);
1713 break;
1714 case ACTION_VENDOR:
1715 // TODO: Handle it as appropriate
1716 break;
Ray Milkey0b122ed2014-04-14 10:06:03 -07001717 default:
1718 throw new IllegalArgumentException("Invalid action string");
Ray Milkey269ffb92014-04-03 14:43:30 -07001719 }
1720 } catch (IllegalArgumentException e) {
Ray Milkey0b122ed2014-04-14 10:06:03 -07001721 throw new IllegalArgumentException("Invalid action type", e);
Ray Milkey269ffb92014-04-03 14:43:30 -07001722 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001723 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001724}