blob: b9c41ffdf14e6c2b99e7acf2ccd38c5a8b4e0e10 [file] [log] [blame]
HIGUCHI Yuta356086e2013-06-12 15:21:19 -07001package net.onrc.onos.ofcontroller.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;
6
7/**
8 * The class representing a single Flow Entry action.
9 *
10 * A set of Flow Entry actions need to be applied to each packet.
11 */
12public class FlowEntryAction {
13 /**
14 * Special action values.
15 *
16 * Those values are taken as-is from the OpenFlow-v1.0.0 specification
17 * (pp 21-22).
18 */
19 public enum ActionValues {
20 ACTION_OUTPUT ((short)0x0), // Output to switch port
21 ACTION_SET_VLAN_VID ((short)0x1), // Set the 802.1q VLAN id
22 ACTION_SET_VLAN_PCP ((short)0x2), // Set the 802.1q priority
23 ACTION_STRIP_VLAN ((short)0x3), // Strip the 802.1q header
24 ACTION_SET_DL_SRC ((short)0x4), // Ethernet source address
25 ACTION_SET_DL_DST ((short)0x5), // Ethernet destination address
26 ACTION_SET_NW_SRC ((short)0x6), // IP source address
27 ACTION_SET_NW_DST ((short)0x7), // IP destination address
28 ACTION_SET_NW_TOS ((short)0x8), // IP ToS (DSCP field, 6 bits)
29 ACTION_SET_TP_SRC ((short)0x9), // TCP/UDP source port
30 ACTION_SET_TP_DST ((short)0xa), // TCP/UDP destination port
31 ACTION_ENQUEUE ((short)0xb), // Output to queue on port
32 ACTION_VENDOR ((short)0xffff); // Vendor-specific
33
34 private final short value; // The value
35
36 /**
37 * Constructor for a given value.
38 *
39 * @param value the value to use for the initialization.
40 */
41 private ActionValues(short value) {
42 this.value = value;
43 }
44 }
45
46 /**
47 * Action structure for ACTION_OUTPUT: Output to switch port.
48 */
49 public class ActionOutput {
50 private Port port; // Output port
51 private short maxLen; // Max. length (in bytes) to send to controller
52 // if the port is set to PORT_CONTROLLER
53
54 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -070055 * Default constructor.
56 */
57 public ActionOutput() {
58 this.port = null;
59 this.maxLen = 0;
60 }
61
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -070062 /**
63 * Copy constructor.
64 *
65 * @param other the object to copy from.
66 */
67 public ActionOutput(ActionOutput other) {
68 if (other.port != null)
69 this.port = new Port(other.port);
70 this.maxLen = other.maxLen;
71 }
72
73 /**
74 * Constructor from a string.
75 *
76 * The string has the following form:
77 * [port=XXX maxLen=XXX]
78 *
79 * @param actionStr the action as a string.
80 */
81 public ActionOutput(String actionStr) {
82 this.fromString(actionStr);
83 }
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -070084
85 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -080086 * Constructor for a given output port and maximum length.
87 *
88 * @param port the output port to set.
89 * @param maxLen the maximum length (in bytes) to send to controller
90 * if the port is set to PORT_CONTROLLER.
91 */
92 public ActionOutput(Port port, short maxLen) {
93 this.port = port;
94 this.maxLen = maxLen;
95 }
96
97 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -070098 * Constructor for a given output port.
99 *
100 * @param port the output port to set.
101 */
102 public ActionOutput(Port port) {
103 this.port = port;
104 this.maxLen = 0;
105 }
106
107 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800108 * Get the output port.
109 *
110 * @return the output port.
111 */
112 @JsonProperty("port")
113 public Port port() {
114 return this.port;
115 }
116
117 /**
118 * Get the maximum length (in bytes) to send to controller if the
119 * port is set to PORT_CONTROLLER.
120 *
121 * @return the maximum length (in bytes) to send to controller if the
122 * port is set to PORT_CONTROLLER.
123 */
124 @JsonProperty("maxLen")
125 public short maxLen() {
126 return this.maxLen;
127 }
128
129 /**
130 * Convert the action to a string.
131 *
132 * The string has the following form:
133 * [port=XXX maxLen=XXX]
134 *
135 * @return the action as a string.
136 */
137 @Override
138 public String toString() {
139 String ret = "[";
140 ret += "port=" + port.toString();
141 ret += " maxLen=" + maxLen;
142 ret += "]";
143
144 return ret;
145 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700146
147 /**
148 * Convert a string to an action.
149 *
150 * The string has the following form:
151 * [port=XXX maxLen=XXX]
152 *
153 * @param actionStr the action as a string.
154 */
155 public void fromString(String actionStr) {
156 String[] parts = actionStr.split(" ");
157 String decode = null;
158
159 // Decode the "port=XXX" part
160 if (parts.length > 0)
161 decode = parts[0];
162 if (decode != null) {
163 String[] tokens = decode.split("port=");
164 if (tokens.length > 1 && tokens[1] != null) {
165 try {
166 Short valueShort = Short.valueOf(tokens[1]);
167 port = new Port(valueShort);
168 } catch (NumberFormatException e) {
169 throw new IllegalArgumentException("Invalid action string");
170 }
171 }
172 } else {
173 throw new IllegalArgumentException("Invalid action string");
174 }
175
176 // Decode the "maxLen=XXX" part
177 decode = null;
178 if (parts.length > 1)
179 decode = parts[1];
180 if (decode != null) {
181 decode = decode.replace("]", "");
182 String[] tokens = decode.split("maxLen=");
183 if (tokens.length > 1 && tokens[1] != null) {
184 try {
185 maxLen = Short.valueOf(tokens[1]);
186 } catch (NumberFormatException e) {
187 throw new IllegalArgumentException("Invalid action string");
188 }
189 }
190 } else {
191 throw new IllegalArgumentException("Invalid action string");
192 }
193 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800194 }
195
196 /**
197 * Action structure for ACTION_SET_VLAN_VID: Set the 802.1q VLAN id
198 */
199 public class ActionSetVlanId {
200 private short vlanId; // The VLAN ID to set
201
202 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700203 * Default constructor.
204 */
205 public ActionSetVlanId() {
206 this.vlanId = 0;
207 }
208
209 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700210 * Copy constructor.
211 *
212 * @param other the object to copy from.
213 */
214 public ActionSetVlanId(ActionSetVlanId other) {
215 this.vlanId = other.vlanId;
216 }
217
218 /**
219 * Constructor from a string.
220 *
221 * The string has the following form:
222 * [vlanId=XXX]
223 *
224 * @param actionStr the action as a string.
225 */
226 public ActionSetVlanId(String actionStr) {
227 this.fromString(actionStr);
228 }
229
230 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800231 * Constructor for a given VLAN ID.
232 *
233 * @param vlanId the VLAN ID to set.
234 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700235 public ActionSetVlanId(short vlanId) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800236 this.vlanId = vlanId;
237 }
238
239 /**
240 * Get the VLAN ID.
241 *
242 * @return the VLAN ID.
243 */
244 @JsonProperty("vlanId")
245 public short vlanId() {
246 return this.vlanId;
247 }
248
249 /**
250 * Convert the action to a string.
251 *
252 * The string has the following form:
253 * [vlanId=XXX]
254 *
255 * @return the action as a string.
256 */
257 @Override
258 public String toString() {
259 String ret = "[";
260 ret += "vlanId=" + this.vlanId;
261 ret += "]";
262
263 return ret;
264 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700265
266 /**
267 * Convert a string to an action.
268 *
269 * The string has the following form:
270 * [vlanId=XXX]
271 *
272 * @param actionStr the action as a string.
273 */
274 public void fromString(String actionStr) {
275 String[] parts = actionStr.split("vlanId=");
276 String decode = null;
277
278 // Decode the value
279 if (parts.length > 1)
280 decode = parts[1];
281 if (decode != null) {
282 decode = decode.replace("]", "");
283 try {
284 vlanId = Short.valueOf(decode);
285 } catch (NumberFormatException e) {
286 throw new IllegalArgumentException("Invalid action string");
287 }
288 } else {
289 throw new IllegalArgumentException("Invalid action string");
290 }
291 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800292 }
293
294 /**
295 * Action structure for ACTION_SET_VLAN_PCP: Set the 802.1q priority
296 */
297 public class ActionSetVlanPriority {
298 private byte vlanPriority; // The VLAN priority to set
299
300 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700301 * Default constructor.
302 */
303 public ActionSetVlanPriority() {
304 this.vlanPriority = 0;
305 }
306
307 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700308 * Copy constructor.
309 *
310 * @param other the object to copy from.
311 */
312 public ActionSetVlanPriority(ActionSetVlanPriority other) {
313 this.vlanPriority = other.vlanPriority;
314 }
315
316 /**
317 * Constructor from a string.
318 *
319 * The string has the following form:
320 * [vlanPriority=XXX]
321 *
322 * @param actionStr the action as a string.
323 */
324 public ActionSetVlanPriority(String actionStr) {
325 this.fromString(actionStr);
326 }
327
328 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800329 * Constructor for a given VLAN priority.
330 *
331 * @param vlanPriority the VLAN priority to set.
332 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700333 public ActionSetVlanPriority(byte vlanPriority) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800334 this.vlanPriority = vlanPriority;
335 }
336
337 /**
338 * Get the VLAN priority.
339 *
340 * @return the VLAN priority.
341 */
342 @JsonProperty("vlanPriority")
343 public byte vlanPriority() {
344 return this.vlanPriority;
345 }
346
347 /**
348 * Convert the action to a string.
349 *
350 * The string has the following form:
351 * [vlanPriority=XXX]
352 *
353 * @return the action as a string.
354 */
355 @Override
356 public String toString() {
357 String ret = "[";
358 ret += "vlanPriority=" + this.vlanPriority;
359 ret += "]";
360
361 return ret;
362 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700363
364 /**
365 * Convert a string to an action.
366 *
367 * The string has the following form:
368 * [vlanPriority=XXX]
369 *
370 * @param actionStr the action as a string.
371 */
372 public void fromString(String actionStr) {
373 String[] parts = actionStr.split("vlanPriority=");
374 String decode = null;
375
376 // Decode the value
377 if (parts.length > 1)
378 decode = parts[1];
379 if (decode != null) {
380 decode = decode.replace("]", "");
381 try {
382 vlanPriority = Byte.valueOf(decode);
383 } catch (NumberFormatException e) {
384 throw new IllegalArgumentException("Invalid action string");
385 }
386 } else {
387 throw new IllegalArgumentException("Invalid action string");
388 }
389 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800390 }
391
392 /**
393 * Action structure for ACTION_STRIP_VLAN: Strip the 802.1q header
394 */
395 public class ActionStripVlan {
396 private boolean stripVlan; // If true, strip the VLAN header
397
398 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700399 * Default constructor.
400 */
401 public ActionStripVlan() {
402 this.stripVlan = false;
403 }
404
405 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700406 * Copy constructor.
407 *
408 * @param other the object to copy from.
409 */
410 public ActionStripVlan(ActionStripVlan other) {
411 this.stripVlan = other.stripVlan;
412 }
413
414 /**
415 * Constructor from a string.
416 *
417 * The string has the following form:
418 * [stripVlan=XXX]
419 *
420 * @param actionStr the action as a string.
421 */
422 public ActionStripVlan(String actionStr) {
423 this.fromString(actionStr);
424 }
425
426 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800427 * Constructor for a given boolean flag.
428 *
429 * @param stripVlan if true, strip the VLAN header.
430 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700431 public ActionStripVlan(boolean stripVlan) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800432 this.stripVlan = stripVlan;
433 }
434
435 /**
436 * Get the boolean flag whether the VLAN header should be stripped.
437 *
438 * @return the boolean flag whether the VLAN header should be stripped.
439 */
440 @JsonProperty("stripVlan")
441 public boolean stripVlan() {
442 return this.stripVlan;
443 }
444
445 /**
446 * Convert the action to a string.
447 *
448 * The string has the following form:
449 * [stripVlan=XXX]
450 *
451 * @return the action as a string.
452 */
453 @Override
454 public String toString() {
455 String ret = "[";
456 ret += "stripVlan=" + this.stripVlan;
457 ret += "]";
458
459 return ret;
460 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700461
462 /**
463 * Convert a string to an action.
464 *
465 * The string has the following form:
466 * [stripVlan=XXX]
467 *
468 * @param actionStr the action as a string.
469 */
470 public void fromString(String actionStr) {
471 String[] parts = actionStr.split("stripVlan=");
472 String decode = null;
473
474 // Decode the value
475 if (parts.length > 1)
476 decode = parts[1];
477 if (decode != null) {
478 decode = decode.replace("]", "");
479 stripVlan = Boolean.valueOf(decode);
480 } else {
481 throw new IllegalArgumentException("Invalid action string");
482 }
483 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800484 }
485
486 /**
487 * Action structure for ACTION_SET_DL_SRC and ACTION_SET_DL_DST:
488 * Set the Ethernet source/destination address.
489 */
490 public class ActionSetEthernetAddr {
491 private MACAddress addr; // The MAC address to set
492
493 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700494 * Default constructor.
495 */
496 public ActionSetEthernetAddr() {
497 this.addr = null;
498 }
499
500 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700501 * Copy constructor.
502 *
503 * @param other the object to copy from.
504 */
505 public ActionSetEthernetAddr(ActionSetEthernetAddr other) {
506 if (other.addr != null)
507 this.addr = MACAddress.valueOf(other.addr.toLong());
508 }
509
510 /**
511 * Constructor from a string.
512 *
513 * The string has the following form:
514 * [addr=XXX]
515 *
516 * @param actionStr the action as a string.
517 */
518 public ActionSetEthernetAddr(String actionStr) {
519 this.fromString(actionStr);
520 }
521
522 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800523 * Constructor for a given MAC address.
524 *
525 * @param addr the MAC address to set.
526 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700527 public ActionSetEthernetAddr(MACAddress addr) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800528 this.addr = addr;
529 }
530
531 /**
532 * Get the MAC address.
533 *
534 * @return the MAC address.
535 */
536 @JsonProperty("addr")
537 public MACAddress addr() {
538 return this.addr;
539 }
540
541 /**
542 * Convert the action to a string.
543 *
544 * The string has the following form:
545 * [addr=XXX]
546 *
547 * @return the action as a string.
548 */
549 @Override
550 public String toString() {
551 String ret = "[";
552 ret += "addr=" + addr.toString();
553 ret += "]";
554
555 return ret;
556 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700557
558 /**
559 * Convert a string to an action.
560 *
561 * The string has the following form:
562 * [addr=XXX]
563 *
564 * @param actionStr the action as a string.
565 */
566 public void fromString(String actionStr) {
567 String[] parts = actionStr.split("addr=");
568 String decode = null;
569
570 // Decode the value
571 if (parts.length > 1)
572 decode = parts[1];
573 if (decode != null) {
574 decode = decode.replace("]", "");
575 try {
576 addr = MACAddress.valueOf(decode);
577 } catch (IllegalArgumentException e) {
578 throw new IllegalArgumentException("Invalid action string");
579 }
580 } else {
581 throw new IllegalArgumentException("Invalid action string");
582 }
583 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800584 }
585
586 /**
587 * Action structure for ACTION_SET_NW_SRC and ACTION_SET_NW_DST:
588 * Set the IPv4 source/destination address.
589 */
590 public class ActionSetIPv4Addr {
591 private IPv4 addr; // The IPv4 address to set
592
593 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700594 * Default constructor.
595 */
596 public ActionSetIPv4Addr() {
597 this.addr = null;
598 }
599
600 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700601 * Copy constructor.
602 *
603 * @param other the object to copy from.
604 */
605 public ActionSetIPv4Addr(ActionSetIPv4Addr other) {
606 if (other.addr != null)
607 this.addr = new IPv4(other.addr);
608 }
609
610 /**
611 * Constructor from a string.
612 *
613 * The string has the following form:
614 * [addr=XXX]
615 *
616 * @param actionStr the action as a string.
617 */
618 public ActionSetIPv4Addr(String actionStr) {
619 this.fromString(actionStr);
620 }
621
622 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800623 * Constructor for a given IPv4 address.
624 *
625 * @param addr the IPv4 address to set.
626 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700627 public ActionSetIPv4Addr(IPv4 addr) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800628 this.addr = addr;
629 }
630
631 /**
632 * Get the IPv4 address.
633 *
634 * @return the IPv4 address.
635 */
636 @JsonProperty("addr")
637 public IPv4 addr() {
638 return this.addr;
639 }
640
641 /**
642 * Convert the action to a string.
643 *
644 * The string has the following form:
645 * [addr=XXX]
646 *
647 * @return the action as a string.
648 */
649 @Override
650 public String toString() {
651 String ret = "[";
652 ret += "addr=" + addr.toString();
653 ret += "]";
654
655 return ret;
656 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700657
658 /**
659 * Convert a string to an action.
660 *
661 * The string has the following form:
662 * [addr=XXX]
663 *
664 * @param actionStr the action as a string.
665 */
666 public void fromString(String actionStr) {
667 String[] parts = actionStr.split("addr=");
668 String decode = null;
669
670 // Decode the value
671 if (parts.length > 1)
672 decode = parts[1];
673 if (decode != null) {
674 decode = decode.replace("]", "");
675 try {
676 addr = new IPv4(decode);
677 } catch (IllegalArgumentException e) {
678 throw new IllegalArgumentException("Invalid action string");
679 }
680 } else {
681 throw new IllegalArgumentException("Invalid action string");
682 }
683 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800684 }
685
686 /**
687 * Action structure for ACTION_SET_NW_TOS:
688 * Set the IP ToS (DSCP field, 6 bits).
689 */
690 public class ActionSetIpToS {
691 private byte ipToS; // The IP ToS to set DSCP field, 6 bits)
692
693 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700694 * Default constructor.
695 */
696 public ActionSetIpToS() {
697 this.ipToS = 0;
698 }
699
700 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700701 * Copy constructor.
702 *
703 * @param other the object to copy from.
704 */
705 public ActionSetIpToS(ActionSetIpToS other) {
706 this.ipToS = other.ipToS;
707 }
708
709 /**
710 * Constructor from a string.
711 *
712 * The string has the following form:
713 * [ipToS=XXX]
714 *
715 * @param actionStr the action as a string.
716 */
717 public ActionSetIpToS(String actionStr) {
718 this.fromString(actionStr);
719 }
720
721 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800722 * Constructor for a given IP ToS (DSCP field, 6 bits).
723 *
724 * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
725 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700726 public ActionSetIpToS(byte ipToS) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800727 this.ipToS = ipToS;
728 }
729
730 /**
731 * Get the IP ToS (DSCP field, 6 bits).
732 *
733 * @return the IP ToS (DSCP field, 6 bits).
734 */
735 @JsonProperty("ipToS")
736 public byte ipToS() {
737 return this.ipToS;
738 }
739
740 /**
741 * Convert the action to a string.
742 *
743 * The string has the following form:
744 * [ipToS=XXX]
745 *
746 * @return the action as a string.
747 */
748 @Override
749 public String toString() {
750 String ret = "[";
751 ret += "ipToS=" + ipToS;
752 ret += "]";
753
754 return ret;
755 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700756
757 /**
758 * Convert a string to an action.
759 *
760 * The string has the following form:
761 * [ipToS=XXX]
762 *
763 * @param actionStr the action as a string.
764 */
765 public void fromString(String actionStr) {
766 String[] parts = actionStr.split("ipToS=");
767 String decode = null;
768
769 // Decode the value
770 if (parts.length > 1)
771 decode = parts[1];
772 if (decode != null) {
773 decode = decode.replace("]", "");
774 try {
775 ipToS = Byte.valueOf(decode);
776 } catch (NumberFormatException e) {
777 throw new IllegalArgumentException("Invalid action string");
778 }
779 } else {
780 throw new IllegalArgumentException("Invalid action string");
781 }
782 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800783 }
784
785 /**
786 * Action structure for ACTION_SET_TP_SRC and ACTION_SET_TP_DST:
787 * Set the TCP/UDP source/destination port.
788 */
789 public class ActionSetTcpUdpPort {
790 private short port; // The TCP/UDP port to set
791
792 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700793 * Default constructor.
794 */
795 public ActionSetTcpUdpPort() {
796 this.port = 0;
797 }
798
799 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700800 * Copy constructor.
801 *
802 * @param other the object to copy from.
803 */
804 public ActionSetTcpUdpPort(ActionSetTcpUdpPort other) {
805 this.port = other.port;
806 }
807
808 /**
809 * Constructor from a string.
810 *
811 * The string has the following form:
812 * [port=XXX]
813 *
814 * @param actionStr the action as a string.
815 */
816 public ActionSetTcpUdpPort(String actionStr) {
817 this.fromString(actionStr);
818 }
819
820 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800821 * Constructor for a given TCP/UDP port.
822 *
823 * @param port the TCP/UDP port to set.
824 */
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700825 public ActionSetTcpUdpPort(short port) {
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800826 this.port = port;
827 }
828
829 /**
830 * Get the TCP/UDP port.
831 *
832 * @return the TCP/UDP port.
833 */
834 @JsonProperty("port")
835 public short port() {
836 return this.port;
837 }
838
839 /**
840 * Convert the action to a string.
841 *
842 * The string has the following form:
843 * [port=XXX]
844 *
845 * @return the action as a string.
846 */
847 @Override
848 public String toString() {
849 String ret = "[";
850 ret += "port=" + port;
851 ret += "]";
852
853 return ret;
854 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700855
856 /**
857 * Convert a string to an action.
858 *
859 * The string has the following form:
860 * [port=XXX]
861 *
862 * @param actionStr the action as a string.
863 */
864 public void fromString(String actionStr) {
865 String[] parts = actionStr.split("port=");
866 String decode = null;
867
868 // Decode the value
869 if (parts.length > 1)
870 decode = parts[1];
871 if (decode != null) {
872 decode = decode.replace("]", "");
873 try {
874 port = Short.valueOf(decode);
875 } catch (NumberFormatException e) {
876 throw new IllegalArgumentException("Invalid action string");
877 }
878 } else {
879 throw new IllegalArgumentException("Invalid action string");
880 }
881 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800882 }
883
884 /**
885 * Action structure for ACTION_ENQUEUE: Output to queue on port.
886 */
887 public class ActionEnqueue {
888 private Port port; // Port that queue belongs. Should
889 // refer to a valid physical port
890 // (i.e. < PORT_MAX) or PORT_IN_PORT
891 private int queueId; // Where to enqueue the packets
892
893 /**
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -0700894 * Default constructor.
895 */
896 public ActionEnqueue() {
897 this.port = null;
898 this.queueId = 0;
899 }
900
901 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700902 * Copy constructor.
903 *
904 * @param other the object to copy from.
905 */
906 public ActionEnqueue(ActionEnqueue other) {
907 if (other.port != null)
908 this.port = new Port(other.port);
909 this.queueId = other.queueId;
910 }
911
912 /**
913 * Constructor from a string.
914 *
915 * The string has the following form:
916 * [port=XXX queueId=XXX]
917 *
918 * @param actionStr the action as a string.
919 */
920 public ActionEnqueue(String actionStr) {
921 this.fromString(actionStr);
922 }
923
924 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -0800925 * Constructor for a given port and queue ID.
926 *
927 * @param port the port to set.
928 * @param queueId the queue ID on the port.
929 */
930 public ActionEnqueue(Port port, int queueId) {
931 this.port = port;
932 this.queueId = queueId;
933 }
934
935 /**
936 * Get the port.
937 *
938 * @return the port.
939 */
940 @JsonProperty("port")
941 public Port port() {
942 return this.port;
943 }
944
945 /**
946 * Get the queue ID.
947 *
948 * @return the queue ID.
949 */
950 @JsonProperty("queueId")
951 public int queueId() {
952 return this.queueId;
953 }
954
955 /**
956 * Convert the action to a string.
957 *
958 * The string has the following form:
959 * [port=XXX queueId=XXX]
960 *
961 * @return the action as a string.
962 */
963 @Override
964 public String toString() {
965 String ret = "[";
966 ret += "port=" + port.toString();
967 ret += " queueId=" + queueId;
968 ret += "]";
969
970 return ret;
971 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -0700972
973 /**
974 * Convert a string to an action.
975 *
976 * The string has the following form:
977 * [port=XXX queueId=XXX]
978 *
979 * @param actionStr the action as a string.
980 */
981 public void fromString(String actionStr) {
982 String[] parts = actionStr.split(" ");
983 String decode = null;
984
985 // Decode the "port=XXX" part
986 if (parts.length > 0)
987 decode = parts[0];
988 if (decode != null) {
989 String[] tokens = decode.split("port=");
990 if (tokens.length > 1 && tokens[1] != null) {
991 try {
992 Short valueShort = Short.valueOf(tokens[1]);
993 port = new Port(valueShort);
994 } catch (NumberFormatException e) {
995 throw new IllegalArgumentException("Invalid action string");
996 }
997 }
998 } else {
999 throw new IllegalArgumentException("Invalid action string");
1000 }
1001
1002 // Decode the "queueId=XXX" part
1003 decode = null;
1004 if (parts.length > 1)
1005 decode = parts[1];
1006 if (decode != null) {
1007 decode = decode.replace("]", "");
1008 String[] tokens = decode.split("queueId=");
1009 if (tokens.length > 1 && tokens[1] != null) {
1010 try {
1011 queueId = Short.valueOf(tokens[1]);
1012 } catch (NumberFormatException e) {
1013 throw new IllegalArgumentException("Invalid action string");
1014 }
1015 }
1016 } else {
1017 throw new IllegalArgumentException("Invalid action string");
1018 }
1019 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001020 }
1021
1022 private ActionValues actionType; // The action type
1023
1024 //
1025 // The actions.
1026 // NOTE: Only one action should be set.
1027 //
1028 private ActionOutput actionOutput;
1029 private ActionSetVlanId actionSetVlanId;
1030 private ActionSetVlanPriority actionSetVlanPriority;
1031 private ActionStripVlan actionStripVlan;
1032 private ActionSetEthernetAddr actionSetEthernetSrcAddr;
1033 private ActionSetEthernetAddr actionSetEthernetDstAddr;
1034 private ActionSetIPv4Addr actionSetIPv4SrcAddr;
1035 private ActionSetIPv4Addr actionSetIPv4DstAddr;
1036 private ActionSetIpToS actionSetIpToS;
1037 private ActionSetTcpUdpPort actionSetTcpUdpSrcPort;
1038 private ActionSetTcpUdpPort actionSetTcpUdpDstPort;
1039 private ActionEnqueue actionEnqueue;
1040
1041 /**
1042 * Default constructor.
1043 */
1044 public FlowEntryAction() {
1045 actionType = ActionValues.ACTION_VENDOR; // XXX: Initial value
1046 }
1047
1048 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001049 * Copy constructor.
1050 *
1051 * @param other the object to copy from.
1052 */
1053 public FlowEntryAction(FlowEntryAction other) {
1054 this.actionType = other.actionType;
1055
1056 //
1057 if (other.actionOutput != null)
1058 this.actionOutput = new ActionOutput(other.actionOutput);
1059 else
1060 this.actionOutput = null;
1061 //
1062 if (other.actionSetVlanId != null)
1063 this.actionSetVlanId = new ActionSetVlanId(other.actionSetVlanId);
1064 else
1065 this.actionSetVlanId = null;
1066 //
1067 if (other.actionSetVlanPriority != null)
1068 this.actionSetVlanPriority = new ActionSetVlanPriority(other.actionSetVlanPriority);
1069 else
1070 this.actionSetVlanPriority = null;
1071 //
1072 if (other.actionStripVlan != null)
1073 this.actionStripVlan = new ActionStripVlan(other.actionStripVlan);
1074 else
1075 this.actionStripVlan = null;
1076 //
1077 if (other.actionSetEthernetSrcAddr != null)
1078 this.actionSetEthernetSrcAddr = new ActionSetEthernetAddr(other.actionSetEthernetSrcAddr);
1079 else
1080 this.actionSetEthernetSrcAddr = null;
1081 //
1082 if (other.actionSetEthernetDstAddr != null)
1083 this.actionSetEthernetDstAddr = new ActionSetEthernetAddr(other.actionSetEthernetDstAddr);
1084 else
1085 this.actionSetEthernetDstAddr = null;
1086 //
1087 if (other.actionSetIPv4SrcAddr != null)
1088 this.actionSetIPv4SrcAddr = new ActionSetIPv4Addr(other.actionSetIPv4SrcAddr);
1089 else
1090 this.actionSetIPv4SrcAddr = null;
1091 //
1092 if (other.actionSetIPv4DstAddr != null)
1093 this.actionSetIPv4DstAddr = new ActionSetIPv4Addr(other.actionSetIPv4DstAddr);
1094 else
1095 this.actionSetIPv4DstAddr = null;
1096 //
1097 if (other.actionSetIpToS != null)
1098 this.actionSetIpToS = new ActionSetIpToS(other.actionSetIpToS);
1099 else
1100 this.actionSetIpToS = null;
1101 //
1102 if (other.actionSetTcpUdpSrcPort != null)
1103 this.actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpSrcPort);
1104 else
1105 this.actionSetTcpUdpSrcPort = null;
1106 //
1107 if (other.actionSetTcpUdpDstPort != null)
1108 this.actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(other.actionSetTcpUdpDstPort);
1109 else
1110 this.actionSetTcpUdpDstPort = null;
1111 //
1112 if (other.actionEnqueue != null)
1113 this.actionEnqueue = new ActionEnqueue(other.actionEnqueue);
1114 else
1115 this.actionEnqueue = null;
1116 }
1117
1118 /**
1119 * Constructor from a string.
1120 *
1121 * The string has the following form:
1122 * [type=XXX action=XXX]
1123 *
1124 * @param actionStr the action as a string.
1125 */
1126 public FlowEntryAction(String actionStr) {
1127 this.fromString(actionStr);
1128 }
1129
1130 /**
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001131 * Get the action type.
1132 *
1133 * @return the action type.
1134 */
1135 @JsonProperty("actionType")
1136 public ActionValues actionType() { return actionType; }
1137
1138 /**
1139 * Get the output action.
1140 *
1141 * @return the output action.
1142 */
1143 @JsonProperty("actionOutput")
1144 public ActionOutput actionOutput() { return actionOutput; }
1145
1146 /**
1147 * Set the output action on a port.
1148 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001149 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001150 */
1151 @JsonProperty("actionOutput")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001152 public void setActionOutput(ActionOutput action) {
1153 actionOutput = action;
1154 actionType = ActionValues.ACTION_OUTPUT;
1155 }
1156
1157 /**
1158 * Set the output action on a port.
1159 *
1160 * @param port the output port to set.
1161 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001162 public void setActionOutput(Port port) {
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001163 actionOutput = new ActionOutput(port);
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001164 actionType = ActionValues.ACTION_OUTPUT;
1165 }
1166
1167 /**
1168 * Set the output action to controller.
1169 *
1170 * @param maxLen the maximum length (in bytes) to send to controller.
1171 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001172 public void setActionOutputToController(short maxLen) {
1173 Port port = new Port(Port.PortValues.PORT_CONTROLLER);
1174 actionOutput = new ActionOutput(port, maxLen);
1175 actionType = ActionValues.ACTION_OUTPUT;
1176 }
1177
1178 /**
1179 * Get the action to set the VLAN ID.
1180 *
1181 * @return the action to set the VLAN ID.
1182 */
1183 @JsonProperty("actionSetVlanId")
1184 public ActionSetVlanId actionSetVlanId() { return actionSetVlanId; }
1185
1186 /**
1187 * Set the action to set the VLAN ID.
1188 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001189 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001190 */
1191 @JsonProperty("actionSetVlanId")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001192 public void setActionSetVlanId(ActionSetVlanId action) {
1193 actionSetVlanId = action;
1194 actionType = ActionValues.ACTION_SET_VLAN_VID;
1195 }
1196
1197 /**
1198 * Set the action to set the VLAN ID.
1199 *
1200 * @param vlanId the VLAN ID to set.
1201 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001202 public void setActionSetVlanId(short vlanId) {
1203 actionSetVlanId = new ActionSetVlanId(vlanId);
1204 actionType = ActionValues.ACTION_SET_VLAN_VID;
1205 }
1206
1207 /**
1208 * Get the action to set the VLAN priority.
1209 *
1210 * @return the action to set the VLAN priority.
1211 */
1212 @JsonProperty("actionSetVlanPriority")
1213 public ActionSetVlanPriority actionSetVlanPriority() {
1214 return actionSetVlanPriority;
1215 }
1216
1217 /**
1218 * Set the action to set the VLAN priority.
1219 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001220 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001221 */
1222 @JsonProperty("actionSetVlanPriority")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001223 public void setActionSetVlanPriority(ActionSetVlanPriority action) {
1224 actionSetVlanPriority = action;
1225 actionType = ActionValues.ACTION_SET_VLAN_PCP;
1226 }
1227
1228 /**
1229 * Set the action to set the VLAN priority.
1230 *
1231 * @param vlanPriority the VLAN priority to set.
1232 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001233 public void setActionSetVlanPriority(byte vlanPriority) {
1234 actionSetVlanPriority = new ActionSetVlanPriority(vlanPriority);
1235 actionType = ActionValues.ACTION_SET_VLAN_PCP;
1236 }
1237
1238 /**
1239 * Get the action to strip the VLAN header.
1240 *
1241 * @return the action to strip the VLAN header.
1242 */
1243 @JsonProperty("actionStripVlan")
1244 public ActionStripVlan actionStripVlan() {
1245 return actionStripVlan;
1246 }
1247
1248 /**
1249 * Set the action to strip the VLAN header.
1250 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001251 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001252 */
1253 @JsonProperty("actionStripVlan")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001254 public void setActionStripVlan(ActionStripVlan action) {
1255 actionStripVlan = action;
1256 actionType = ActionValues.ACTION_STRIP_VLAN;
1257 }
1258
1259 /**
1260 * Set the action to strip the VLAN header.
1261 *
1262 * @param stripVlan if true, strip the VLAN header.
1263 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001264 public void setActionStripVlan(boolean stripVlan) {
1265 actionStripVlan = new ActionStripVlan(stripVlan);
1266 actionType = ActionValues.ACTION_STRIP_VLAN;
1267 }
1268
1269 /**
1270 * Get the action to set the Ethernet source address.
1271 *
1272 * @return the action to set the Ethernet source address.
1273 */
1274 @JsonProperty("actionSetEthernetSrcAddr")
1275 public ActionSetEthernetAddr actionSetEthernetSrcAddr() {
1276 return actionSetEthernetSrcAddr;
1277 }
1278
1279 /**
1280 * Set the action to set the Ethernet source address.
1281 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001282 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001283 */
1284 @JsonProperty("actionSetEthernetSrcAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001285 public void setActionSetEthernetSrcAddr(ActionSetEthernetAddr action) {
1286 actionSetEthernetSrcAddr = action;
1287 actionType = ActionValues.ACTION_SET_DL_SRC;
1288 }
1289
1290 /**
1291 * Set the action to set the Ethernet source address.
1292 *
1293 * @param addr the MAC address to set as the Ethernet source address.
1294 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001295 public void setActionSetEthernetSrcAddr(MACAddress addr) {
1296 actionSetEthernetSrcAddr = new ActionSetEthernetAddr(addr);
1297 actionType = ActionValues.ACTION_SET_DL_SRC;
1298 }
1299
1300 /**
1301 * Get the action to set the Ethernet destination address.
1302 *
1303 * @return the action to set the Ethernet destination address.
1304 */
1305 @JsonProperty("actionSetEthernetDstAddr")
1306 public ActionSetEthernetAddr actionSetEthernetDstAddr() {
1307 return actionSetEthernetDstAddr;
1308 }
1309
1310 /**
1311 * Set the action to set the Ethernet destination address.
1312 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001313 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001314 */
1315 @JsonProperty("actionSetEthernetDstAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001316 public void setActionSetEthernetDstAddr(ActionSetEthernetAddr action) {
1317 actionSetEthernetDstAddr = action;
1318 actionType = ActionValues.ACTION_SET_DL_DST;
1319 }
1320
1321 /**
1322 * Set the action to set the Ethernet destination address.
1323 *
1324 * @param addr the MAC address to set as the Ethernet destination address.
1325 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001326 public void setActionSetEthernetDstAddr(MACAddress addr) {
1327 actionSetEthernetDstAddr = new ActionSetEthernetAddr(addr);
1328 actionType = ActionValues.ACTION_SET_DL_DST;
1329 }
1330
1331 /**
1332 * Get the action to set the IPv4 source address.
1333 *
1334 * @return the action to set the IPv4 source address.
1335 */
1336 @JsonProperty("actionSetIPv4SrcAddr")
1337 public ActionSetIPv4Addr actionSetIPv4SrcAddr() {
1338 return actionSetIPv4SrcAddr;
1339 }
1340
1341 /**
1342 * Set the action to set the IPv4 source address.
1343 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001344 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001345 */
1346 @JsonProperty("actionSetIPv4SrcAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001347 public void setActionSetIPv4SrcAddr(ActionSetIPv4Addr action) {
1348 actionSetIPv4SrcAddr = action;
1349 actionType = ActionValues.ACTION_SET_NW_SRC;
1350 }
1351
1352 /**
1353 * Set the action to set the IPv4 source address.
1354 *
1355 * @param addr the IPv4 address to set as the IPv4 source address.
1356 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001357 public void setActionSetIPv4SrcAddr(IPv4 addr) {
1358 actionSetIPv4SrcAddr = new ActionSetIPv4Addr(addr);
1359 actionType = ActionValues.ACTION_SET_NW_SRC;
1360 }
1361
1362 /**
1363 * Get the action to set the IPv4 destination address.
1364 *
1365 * @return the action to set the IPv4 destination address.
1366 */
1367 @JsonProperty("actionSetIPv4DstAddr")
1368 public ActionSetIPv4Addr actionSetIPv4DstAddr() {
1369 return actionSetIPv4DstAddr;
1370 }
1371
1372 /**
1373 * Set the action to set the IPv4 destination address.
1374 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001375 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001376 */
1377 @JsonProperty("actionSetIPv4DstAddr")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001378 public void setActionSetIPv4DstAddr(ActionSetIPv4Addr action) {
1379 actionSetIPv4DstAddr = action;
1380 actionType = ActionValues.ACTION_SET_NW_DST;
1381 }
1382
1383 /**
1384 * Set the action to set the IPv4 destination address.
1385 *
1386 * @param addr the IPv4 address to set as the IPv4 destination address.
1387 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001388 public void setActionSetIPv4DstAddr(IPv4 addr) {
1389 actionSetIPv4DstAddr = new ActionSetIPv4Addr(addr);
1390 actionType = ActionValues.ACTION_SET_NW_DST;
1391 }
1392
1393 /**
1394 * Get the action to set the IP ToS (DSCP field, 6 bits).
1395 *
1396 * @return the action to set the IP ToS (DSCP field, 6 bits).
1397 */
1398 @JsonProperty("actionSetIpToS")
1399 public ActionSetIpToS actionSetIpToS() {
1400 return actionSetIpToS;
1401 }
1402
1403 /**
1404 * Set the action to set the IP ToS (DSCP field, 6 bits).
1405 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001406 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001407 */
1408 @JsonProperty("actionSetIpToS")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001409 public void setActionSetIpToS(ActionSetIpToS action) {
1410 actionSetIpToS = action;
1411 actionType = ActionValues.ACTION_SET_NW_TOS;
1412 }
1413
1414 /**
1415 * Set the action to set the IP ToS (DSCP field, 6 bits).
1416 *
1417 * @param ipToS the IP ToS (DSCP field, 6 bits) to set.
1418 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001419 public void setActionSetIpToS(byte ipToS) {
1420 actionSetIpToS = new ActionSetIpToS(ipToS);
1421 actionType = ActionValues.ACTION_SET_NW_TOS;
1422 }
1423
1424 /**
1425 * Get the action to set the TCP/UDP source port.
1426 *
1427 * @return the action to set the TCP/UDP source port.
1428 */
1429 @JsonProperty("actionSetTcpUdpSrcPort")
1430 public ActionSetTcpUdpPort actionSetTcpUdpSrcPort() {
1431 return actionSetTcpUdpSrcPort;
1432 }
1433
1434 /**
1435 * Set the action to set the TCP/UDP source port.
1436 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001437 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001438 */
1439 @JsonProperty("actionSetTcpUdpSrcPort")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001440 public void setActionSetTcpUdpSrcPort(ActionSetTcpUdpPort action) {
1441 actionSetTcpUdpSrcPort = action;
1442 actionType = ActionValues.ACTION_SET_TP_SRC;
1443 }
1444
1445 /**
1446 * Set the action to set the TCP/UDP source port.
1447 *
1448 * @param port the TCP/UDP port to set as the TCP/UDP source port.
1449 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001450 public void setActionSetTcpUdpSrcPort(short port) {
1451 actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(port);
1452 actionType = ActionValues.ACTION_SET_TP_SRC;
1453 }
1454
1455 /**
1456 * Get the action to set the TCP/UDP destination port.
1457 *
1458 * @return the action to set the TCP/UDP destination port.
1459 */
1460 @JsonProperty("actionSetTcpUdpDstPort")
1461 public ActionSetTcpUdpPort actionSetTcpUdpDstPort() {
1462 return actionSetTcpUdpDstPort;
1463 }
1464
1465 /**
1466 * Set the action to set the TCP/UDP destination port.
1467 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001468 * @param action the action to set.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001469 */
1470 @JsonProperty("actionSetTcpUdpDstPort")
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001471 public void setActionSetTcpUdpDstPort(ActionSetTcpUdpPort action) {
1472 actionSetTcpUdpDstPort = action;
1473 actionType = ActionValues.ACTION_SET_TP_DST;
1474 }
1475
1476 /**
1477 * Set the action to set the TCP/UDP destination port.
1478 *
1479 * @param port the TCP/UDP port to set as the TCP/UDP destination port.
1480 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001481 public void setActionSetTcpUdpDstPort(short port) {
1482 actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(port);
1483 actionType = ActionValues.ACTION_SET_TP_DST;
1484 }
1485
1486 /**
1487 * Get the action to output to queue on a port.
1488 *
1489 * @return the action to output to queue on a port.
1490 */
1491 @JsonProperty("actionEnqueue")
1492 public ActionEnqueue actionEnqueue() { return actionEnqueue; }
1493
1494 /**
1495 * Set the action to output to queue on a port.
1496 *
Pavlin Radoslavovf13923a2013-03-11 19:42:17 -07001497 * @param action the action to set.
1498 */
1499 @JsonProperty("actionEnqueue")
1500 public void setActionEnqueue(ActionEnqueue action) {
1501 actionEnqueue = action;
1502 actionType = ActionValues.ACTION_ENQUEUE;
1503 }
1504
1505 /**
1506 * Set the action to output to queue on a port.
1507 *
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001508 * @param port the port to set.
1509 * @param int queueId the queue ID to set.
1510 */
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001511 public void setActionEnqueue(Port port, int queueId) {
1512 actionEnqueue = new ActionEnqueue(port, queueId);
1513 actionType = ActionValues.ACTION_ENQUEUE;
1514 }
1515
1516 /**
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001517 * Convert the action to a string.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001518 *
1519 * The string has the following form:
1520 * [type=XXX action=XXX]
1521 *
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001522 * @return the action as a string.
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001523 */
1524 @Override
1525 public String toString() {
1526 String ret = "[";
1527 ret += "type=" + actionType;
1528 switch (actionType) {
1529 case ACTION_OUTPUT:
1530 ret += " action=" + actionOutput.toString();
1531 break;
1532 case ACTION_SET_VLAN_VID:
1533 ret += " action=" + actionSetVlanId.toString();
1534 break;
1535 case ACTION_SET_VLAN_PCP:
1536 ret += " action=" + actionSetVlanPriority.toString();
1537 break;
1538 case ACTION_STRIP_VLAN:
1539 ret += " action=" + actionStripVlan.toString();
1540 break;
1541 case ACTION_SET_DL_SRC:
1542 ret += " action=" + actionSetEthernetSrcAddr.toString();
1543 break;
1544 case ACTION_SET_DL_DST:
1545 ret += " action=" + actionSetEthernetDstAddr.toString();
1546 break;
1547 case ACTION_SET_NW_SRC:
1548 ret += " action=" + actionSetIPv4SrcAddr.toString();
1549 break;
1550 case ACTION_SET_NW_DST:
1551 ret += " action=" + actionSetIPv4DstAddr.toString();
1552 break;
1553 case ACTION_SET_NW_TOS:
1554 ret += " action=" + actionSetIpToS.toString();
1555 break;
1556 case ACTION_SET_TP_SRC:
1557 ret += " action=" + actionSetTcpUdpSrcPort.toString();
1558 break;
1559 case ACTION_SET_TP_DST:
1560 ret += " action=" + actionSetTcpUdpDstPort.toString();
1561 break;
1562 case ACTION_ENQUEUE:
1563 ret += " action=" + actionEnqueue.toString();
1564 break;
1565 }
1566 ret += "]";
1567
1568 return ret;
1569 }
Pavlin Radoslavov1bc2c472013-07-17 18:11:37 -07001570
1571 /**
1572 * Convert a string to an action.
1573 *
1574 * The string has the following form:
1575 * [type=XXX action=XXX]
1576 *
1577 * @param actionStr the action as a string.
1578 */
1579 public void fromString(String actionStr) {
1580 String[] parts = actionStr.split("type=");
1581 String decode = null;
1582
1583 // Extract the string after the "type="
1584 if (parts.length > 1)
1585 decode = parts[1];
1586 if (decode == null)
1587 throw new IllegalArgumentException("Invalid action string");
1588
1589 // Remove the trailing ']'
1590 if ((decode.length() > 0) && (decode.charAt(decode.length() - 1) == ']')) {
1591 decode = decode.substring(0, decode.length() - 1);
1592 } else {
1593 throw new IllegalArgumentException("Invalid action string");
1594 }
1595
1596 // Extract the type value and the action value
1597 parts = decode.split(" action=");
1598
1599 // Decode the "type=XXX" payload
1600 if (parts.length > 0)
1601 decode = parts[0];
1602 if (decode != null) {
1603 try {
1604 actionType = Enum.valueOf(ActionValues.class, decode);
1605 } catch (IllegalArgumentException e) {
1606 throw new IllegalArgumentException("Invalid action string");
1607 }
1608 } else {
1609 throw new IllegalArgumentException("Invalid action string");
1610 }
1611
1612 // Decode the "action=XXX" payload
1613 decode = null;
1614 if (parts.length > 1)
1615 decode = parts[1];
1616 if (decode == null)
1617 throw new IllegalArgumentException("Invalid action string");
1618 //
1619 try {
1620 switch (actionType) {
1621 case ACTION_OUTPUT:
1622 actionOutput = new ActionOutput(decode);
1623 break;
1624 case ACTION_SET_VLAN_VID:
1625 actionSetVlanId = new ActionSetVlanId(decode);
1626 break;
1627 case ACTION_SET_VLAN_PCP:
1628 actionSetVlanPriority = new ActionSetVlanPriority(decode);
1629 break;
1630 case ACTION_STRIP_VLAN:
1631 actionStripVlan = new ActionStripVlan(decode);
1632 break;
1633 case ACTION_SET_DL_SRC:
1634 actionSetEthernetSrcAddr = new ActionSetEthernetAddr(decode);
1635 break;
1636 case ACTION_SET_DL_DST:
1637 actionSetEthernetDstAddr = new ActionSetEthernetAddr(decode);
1638 break;
1639 case ACTION_SET_NW_SRC:
1640 actionSetIPv4SrcAddr = new ActionSetIPv4Addr(decode);
1641 break;
1642 case ACTION_SET_NW_DST:
1643 actionSetIPv4DstAddr = new ActionSetIPv4Addr(decode);
1644 break;
1645 case ACTION_SET_NW_TOS:
1646 actionSetIpToS = new ActionSetIpToS(decode);
1647 break;
1648 case ACTION_SET_TP_SRC:
1649 actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(decode);
1650 break;
1651 case ACTION_SET_TP_DST:
1652 actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(decode);
1653 break;
1654 case ACTION_ENQUEUE:
1655 actionEnqueue = new ActionEnqueue(decode);
1656 break;
1657 }
1658 } catch (IllegalArgumentException e) {
1659 throw new IllegalArgumentException("Invalid action string");
1660 }
1661 }
Pavlin Radoslavovede97582013-03-08 18:57:28 -08001662}