Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
| 3 | import net.floodlightcontroller.util.IPv4; |
| 4 | import net.floodlightcontroller.util.MACAddress; |
| 5 | import net.floodlightcontroller.util.Port; |
| 6 | |
| 7 | import org.codehaus.jackson.annotate.JsonProperty; |
| 8 | |
| 9 | /** |
| 10 | * The class representing a single Flow Entry action. |
| 11 | * |
| 12 | * A set of Flow Entry actions need to be applied to each packet. |
| 13 | */ |
| 14 | public class FlowEntryAction { |
| 15 | /** |
| 16 | * Special action values. |
| 17 | * |
| 18 | * Those values are taken as-is from the OpenFlow-v1.0.0 specification |
| 19 | * (pp 21-22). |
| 20 | */ |
| 21 | public enum ActionValues { |
| 22 | ACTION_OUTPUT ((short)0x0), // Output to switch port |
| 23 | ACTION_SET_VLAN_VID ((short)0x1), // Set the 802.1q VLAN id |
| 24 | ACTION_SET_VLAN_PCP ((short)0x2), // Set the 802.1q priority |
| 25 | ACTION_STRIP_VLAN ((short)0x3), // Strip the 802.1q header |
| 26 | ACTION_SET_DL_SRC ((short)0x4), // Ethernet source address |
| 27 | ACTION_SET_DL_DST ((short)0x5), // Ethernet destination address |
| 28 | ACTION_SET_NW_SRC ((short)0x6), // IP source address |
| 29 | ACTION_SET_NW_DST ((short)0x7), // IP destination address |
| 30 | ACTION_SET_NW_TOS ((short)0x8), // IP ToS (DSCP field, 6 bits) |
| 31 | ACTION_SET_TP_SRC ((short)0x9), // TCP/UDP source port |
| 32 | ACTION_SET_TP_DST ((short)0xa), // TCP/UDP destination port |
| 33 | ACTION_ENQUEUE ((short)0xb), // Output to queue on port |
| 34 | ACTION_VENDOR ((short)0xffff); // Vendor-specific |
| 35 | |
| 36 | private final short value; // The value |
| 37 | |
| 38 | /** |
| 39 | * Constructor for a given value. |
| 40 | * |
| 41 | * @param value the value to use for the initialization. |
| 42 | */ |
| 43 | private ActionValues(short value) { |
| 44 | this.value = value; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Action structure for ACTION_OUTPUT: Output to switch port. |
| 50 | */ |
| 51 | public class ActionOutput { |
| 52 | private Port port; // Output port |
| 53 | private short maxLen; // Max. length (in bytes) to send to controller |
| 54 | // if the port is set to PORT_CONTROLLER |
| 55 | |
| 56 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 57 | * Default constructor. |
| 58 | */ |
| 59 | public ActionOutput() { |
| 60 | this.port = null; |
| 61 | this.maxLen = 0; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 66 | * Constructor for a given output port and maximum length. |
| 67 | * |
| 68 | * @param port the output port to set. |
| 69 | * @param maxLen the maximum length (in bytes) to send to controller |
| 70 | * if the port is set to PORT_CONTROLLER. |
| 71 | */ |
| 72 | public ActionOutput(Port port, short maxLen) { |
| 73 | this.port = port; |
| 74 | this.maxLen = maxLen; |
| 75 | } |
| 76 | |
| 77 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 78 | * Constructor for a given output port. |
| 79 | * |
| 80 | * @param port the output port to set. |
| 81 | */ |
| 82 | public ActionOutput(Port port) { |
| 83 | this.port = port; |
| 84 | this.maxLen = 0; |
| 85 | } |
| 86 | |
| 87 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 88 | * Get the output port. |
| 89 | * |
| 90 | * @return the output port. |
| 91 | */ |
| 92 | @JsonProperty("port") |
| 93 | public Port port() { |
| 94 | return this.port; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Get the maximum length (in bytes) to send to controller if the |
| 99 | * port is set to PORT_CONTROLLER. |
| 100 | * |
| 101 | * @return the maximum length (in bytes) to send to controller if the |
| 102 | * port is set to PORT_CONTROLLER. |
| 103 | */ |
| 104 | @JsonProperty("maxLen") |
| 105 | public short maxLen() { |
| 106 | return this.maxLen; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Convert the action to a string. |
| 111 | * |
| 112 | * The string has the following form: |
| 113 | * [port=XXX maxLen=XXX] |
| 114 | * |
| 115 | * @return the action as a string. |
| 116 | */ |
| 117 | @Override |
| 118 | public String toString() { |
| 119 | String ret = "["; |
| 120 | ret += "port=" + port.toString(); |
| 121 | ret += " maxLen=" + maxLen; |
| 122 | ret += "]"; |
| 123 | |
| 124 | return ret; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Action structure for ACTION_SET_VLAN_VID: Set the 802.1q VLAN id |
| 130 | */ |
| 131 | public class ActionSetVlanId { |
| 132 | private short vlanId; // The VLAN ID to set |
| 133 | |
| 134 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 135 | * Default constructor. |
| 136 | */ |
| 137 | public ActionSetVlanId() { |
| 138 | this.vlanId = 0; |
| 139 | } |
| 140 | |
| 141 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 142 | * Constructor for a given VLAN ID. |
| 143 | * |
| 144 | * @param vlanId the VLAN ID to set. |
| 145 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 146 | public ActionSetVlanId(short vlanId) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 147 | this.vlanId = vlanId; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Get the VLAN ID. |
| 152 | * |
| 153 | * @return the VLAN ID. |
| 154 | */ |
| 155 | @JsonProperty("vlanId") |
| 156 | public short vlanId() { |
| 157 | return this.vlanId; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Convert the action to a string. |
| 162 | * |
| 163 | * The string has the following form: |
| 164 | * [vlanId=XXX] |
| 165 | * |
| 166 | * @return the action as a string. |
| 167 | */ |
| 168 | @Override |
| 169 | public String toString() { |
| 170 | String ret = "["; |
| 171 | ret += "vlanId=" + this.vlanId; |
| 172 | ret += "]"; |
| 173 | |
| 174 | return ret; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Action structure for ACTION_SET_VLAN_PCP: Set the 802.1q priority |
| 180 | */ |
| 181 | public class ActionSetVlanPriority { |
| 182 | private byte vlanPriority; // The VLAN priority to set |
| 183 | |
| 184 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 185 | * Default constructor. |
| 186 | */ |
| 187 | public ActionSetVlanPriority() { |
| 188 | this.vlanPriority = 0; |
| 189 | } |
| 190 | |
| 191 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 192 | * Constructor for a given VLAN priority. |
| 193 | * |
| 194 | * @param vlanPriority the VLAN priority to set. |
| 195 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 196 | public ActionSetVlanPriority(byte vlanPriority) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 197 | this.vlanPriority = vlanPriority; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Get the VLAN priority. |
| 202 | * |
| 203 | * @return the VLAN priority. |
| 204 | */ |
| 205 | @JsonProperty("vlanPriority") |
| 206 | public byte vlanPriority() { |
| 207 | return this.vlanPriority; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Convert the action to a string. |
| 212 | * |
| 213 | * The string has the following form: |
| 214 | * [vlanPriority=XXX] |
| 215 | * |
| 216 | * @return the action as a string. |
| 217 | */ |
| 218 | @Override |
| 219 | public String toString() { |
| 220 | String ret = "["; |
| 221 | ret += "vlanPriority=" + this.vlanPriority; |
| 222 | ret += "]"; |
| 223 | |
| 224 | return ret; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Action structure for ACTION_STRIP_VLAN: Strip the 802.1q header |
| 230 | */ |
| 231 | public class ActionStripVlan { |
| 232 | private boolean stripVlan; // If true, strip the VLAN header |
| 233 | |
| 234 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 235 | * Default constructor. |
| 236 | */ |
| 237 | public ActionStripVlan() { |
| 238 | this.stripVlan = false; |
| 239 | } |
| 240 | |
| 241 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 242 | * Constructor for a given boolean flag. |
| 243 | * |
| 244 | * @param stripVlan if true, strip the VLAN header. |
| 245 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 246 | public ActionStripVlan(boolean stripVlan) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 247 | this.stripVlan = stripVlan; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Get the boolean flag whether the VLAN header should be stripped. |
| 252 | * |
| 253 | * @return the boolean flag whether the VLAN header should be stripped. |
| 254 | */ |
| 255 | @JsonProperty("stripVlan") |
| 256 | public boolean stripVlan() { |
| 257 | return this.stripVlan; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Convert the action to a string. |
| 262 | * |
| 263 | * The string has the following form: |
| 264 | * [stripVlan=XXX] |
| 265 | * |
| 266 | * @return the action as a string. |
| 267 | */ |
| 268 | @Override |
| 269 | public String toString() { |
| 270 | String ret = "["; |
| 271 | ret += "stripVlan=" + this.stripVlan; |
| 272 | ret += "]"; |
| 273 | |
| 274 | return ret; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Action structure for ACTION_SET_DL_SRC and ACTION_SET_DL_DST: |
| 280 | * Set the Ethernet source/destination address. |
| 281 | */ |
| 282 | public class ActionSetEthernetAddr { |
| 283 | private MACAddress addr; // The MAC address to set |
| 284 | |
| 285 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 286 | * Default constructor. |
| 287 | */ |
| 288 | public ActionSetEthernetAddr() { |
| 289 | this.addr = null; |
| 290 | } |
| 291 | |
| 292 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 293 | * Constructor for a given MAC address. |
| 294 | * |
| 295 | * @param addr the MAC address to set. |
| 296 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 297 | public ActionSetEthernetAddr(MACAddress addr) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 298 | this.addr = addr; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Get the MAC address. |
| 303 | * |
| 304 | * @return the MAC address. |
| 305 | */ |
| 306 | @JsonProperty("addr") |
| 307 | public MACAddress addr() { |
| 308 | return this.addr; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Convert the action to a string. |
| 313 | * |
| 314 | * The string has the following form: |
| 315 | * [addr=XXX] |
| 316 | * |
| 317 | * @return the action as a string. |
| 318 | */ |
| 319 | @Override |
| 320 | public String toString() { |
| 321 | String ret = "["; |
| 322 | ret += "addr=" + addr.toString(); |
| 323 | ret += "]"; |
| 324 | |
| 325 | return ret; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Action structure for ACTION_SET_NW_SRC and ACTION_SET_NW_DST: |
| 331 | * Set the IPv4 source/destination address. |
| 332 | */ |
| 333 | public class ActionSetIPv4Addr { |
| 334 | private IPv4 addr; // The IPv4 address to set |
| 335 | |
| 336 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 337 | * Default constructor. |
| 338 | */ |
| 339 | public ActionSetIPv4Addr() { |
| 340 | this.addr = null; |
| 341 | } |
| 342 | |
| 343 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 344 | * Constructor for a given IPv4 address. |
| 345 | * |
| 346 | * @param addr the IPv4 address to set. |
| 347 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 348 | public ActionSetIPv4Addr(IPv4 addr) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 349 | this.addr = addr; |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Get the IPv4 address. |
| 354 | * |
| 355 | * @return the IPv4 address. |
| 356 | */ |
| 357 | @JsonProperty("addr") |
| 358 | public IPv4 addr() { |
| 359 | return this.addr; |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Convert the action to a string. |
| 364 | * |
| 365 | * The string has the following form: |
| 366 | * [addr=XXX] |
| 367 | * |
| 368 | * @return the action as a string. |
| 369 | */ |
| 370 | @Override |
| 371 | public String toString() { |
| 372 | String ret = "["; |
| 373 | ret += "addr=" + addr.toString(); |
| 374 | ret += "]"; |
| 375 | |
| 376 | return ret; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /** |
| 381 | * Action structure for ACTION_SET_NW_TOS: |
| 382 | * Set the IP ToS (DSCP field, 6 bits). |
| 383 | */ |
| 384 | public class ActionSetIpToS { |
| 385 | private byte ipToS; // The IP ToS to set DSCP field, 6 bits) |
| 386 | |
| 387 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 388 | * Default constructor. |
| 389 | */ |
| 390 | public ActionSetIpToS() { |
| 391 | this.ipToS = 0; |
| 392 | } |
| 393 | |
| 394 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 395 | * Constructor for a given IP ToS (DSCP field, 6 bits). |
| 396 | * |
| 397 | * @param ipToS the IP ToS (DSCP field, 6 bits) to set. |
| 398 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 399 | public ActionSetIpToS(byte ipToS) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 400 | this.ipToS = ipToS; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Get the IP ToS (DSCP field, 6 bits). |
| 405 | * |
| 406 | * @return the IP ToS (DSCP field, 6 bits). |
| 407 | */ |
| 408 | @JsonProperty("ipToS") |
| 409 | public byte ipToS() { |
| 410 | return this.ipToS; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | * Convert the action to a string. |
| 415 | * |
| 416 | * The string has the following form: |
| 417 | * [ipToS=XXX] |
| 418 | * |
| 419 | * @return the action as a string. |
| 420 | */ |
| 421 | @Override |
| 422 | public String toString() { |
| 423 | String ret = "["; |
| 424 | ret += "ipToS=" + ipToS; |
| 425 | ret += "]"; |
| 426 | |
| 427 | return ret; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * Action structure for ACTION_SET_TP_SRC and ACTION_SET_TP_DST: |
| 433 | * Set the TCP/UDP source/destination port. |
| 434 | */ |
| 435 | public class ActionSetTcpUdpPort { |
| 436 | private short port; // The TCP/UDP port to set |
| 437 | |
| 438 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 439 | * Default constructor. |
| 440 | */ |
| 441 | public ActionSetTcpUdpPort() { |
| 442 | this.port = 0; |
| 443 | } |
| 444 | |
| 445 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 446 | * Constructor for a given TCP/UDP port. |
| 447 | * |
| 448 | * @param port the TCP/UDP port to set. |
| 449 | */ |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 450 | public ActionSetTcpUdpPort(short port) { |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 451 | this.port = port; |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Get the TCP/UDP port. |
| 456 | * |
| 457 | * @return the TCP/UDP port. |
| 458 | */ |
| 459 | @JsonProperty("port") |
| 460 | public short port() { |
| 461 | return this.port; |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * Convert the action to a string. |
| 466 | * |
| 467 | * The string has the following form: |
| 468 | * [port=XXX] |
| 469 | * |
| 470 | * @return the action as a string. |
| 471 | */ |
| 472 | @Override |
| 473 | public String toString() { |
| 474 | String ret = "["; |
| 475 | ret += "port=" + port; |
| 476 | ret += "]"; |
| 477 | |
| 478 | return ret; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Action structure for ACTION_ENQUEUE: Output to queue on port. |
| 484 | */ |
| 485 | public class ActionEnqueue { |
| 486 | private Port port; // Port that queue belongs. Should |
| 487 | // refer to a valid physical port |
| 488 | // (i.e. < PORT_MAX) or PORT_IN_PORT |
| 489 | private int queueId; // Where to enqueue the packets |
| 490 | |
| 491 | /** |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 492 | * Default constructor. |
| 493 | */ |
| 494 | public ActionEnqueue() { |
| 495 | this.port = null; |
| 496 | this.queueId = 0; |
| 497 | } |
| 498 | |
| 499 | /** |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 500 | * Constructor for a given port and queue ID. |
| 501 | * |
| 502 | * @param port the port to set. |
| 503 | * @param queueId the queue ID on the port. |
| 504 | */ |
| 505 | public ActionEnqueue(Port port, int queueId) { |
| 506 | this.port = port; |
| 507 | this.queueId = queueId; |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Get the port. |
| 512 | * |
| 513 | * @return the port. |
| 514 | */ |
| 515 | @JsonProperty("port") |
| 516 | public Port port() { |
| 517 | return this.port; |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Get the queue ID. |
| 522 | * |
| 523 | * @return the queue ID. |
| 524 | */ |
| 525 | @JsonProperty("queueId") |
| 526 | public int queueId() { |
| 527 | return this.queueId; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Convert the action to a string. |
| 532 | * |
| 533 | * The string has the following form: |
| 534 | * [port=XXX queueId=XXX] |
| 535 | * |
| 536 | * @return the action as a string. |
| 537 | */ |
| 538 | @Override |
| 539 | public String toString() { |
| 540 | String ret = "["; |
| 541 | ret += "port=" + port.toString(); |
| 542 | ret += " queueId=" + queueId; |
| 543 | ret += "]"; |
| 544 | |
| 545 | return ret; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | private ActionValues actionType; // The action type |
| 550 | |
| 551 | // |
| 552 | // The actions. |
| 553 | // NOTE: Only one action should be set. |
| 554 | // |
| 555 | private ActionOutput actionOutput; |
| 556 | private ActionSetVlanId actionSetVlanId; |
| 557 | private ActionSetVlanPriority actionSetVlanPriority; |
| 558 | private ActionStripVlan actionStripVlan; |
| 559 | private ActionSetEthernetAddr actionSetEthernetSrcAddr; |
| 560 | private ActionSetEthernetAddr actionSetEthernetDstAddr; |
| 561 | private ActionSetIPv4Addr actionSetIPv4SrcAddr; |
| 562 | private ActionSetIPv4Addr actionSetIPv4DstAddr; |
| 563 | private ActionSetIpToS actionSetIpToS; |
| 564 | private ActionSetTcpUdpPort actionSetTcpUdpSrcPort; |
| 565 | private ActionSetTcpUdpPort actionSetTcpUdpDstPort; |
| 566 | private ActionEnqueue actionEnqueue; |
| 567 | |
| 568 | /** |
| 569 | * Default constructor. |
| 570 | */ |
| 571 | public FlowEntryAction() { |
| 572 | actionType = ActionValues.ACTION_VENDOR; // XXX: Initial value |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * Get the action type. |
| 577 | * |
| 578 | * @return the action type. |
| 579 | */ |
| 580 | @JsonProperty("actionType") |
| 581 | public ActionValues actionType() { return actionType; } |
| 582 | |
| 583 | /** |
| 584 | * Get the output action. |
| 585 | * |
| 586 | * @return the output action. |
| 587 | */ |
| 588 | @JsonProperty("actionOutput") |
| 589 | public ActionOutput actionOutput() { return actionOutput; } |
| 590 | |
| 591 | /** |
| 592 | * Set the output action on a port. |
| 593 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 594 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 595 | */ |
| 596 | @JsonProperty("actionOutput") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 597 | public void setActionOutput(ActionOutput action) { |
| 598 | actionOutput = action; |
| 599 | actionType = ActionValues.ACTION_OUTPUT; |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Set the output action on a port. |
| 604 | * |
| 605 | * @param port the output port to set. |
| 606 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 607 | public void setActionOutput(Port port) { |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 608 | actionOutput = new ActionOutput(port); |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 609 | actionType = ActionValues.ACTION_OUTPUT; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * Set the output action to controller. |
| 614 | * |
| 615 | * @param maxLen the maximum length (in bytes) to send to controller. |
| 616 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 617 | public void setActionOutputToController(short maxLen) { |
| 618 | Port port = new Port(Port.PortValues.PORT_CONTROLLER); |
| 619 | actionOutput = new ActionOutput(port, maxLen); |
| 620 | actionType = ActionValues.ACTION_OUTPUT; |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Get the action to set the VLAN ID. |
| 625 | * |
| 626 | * @return the action to set the VLAN ID. |
| 627 | */ |
| 628 | @JsonProperty("actionSetVlanId") |
| 629 | public ActionSetVlanId actionSetVlanId() { return actionSetVlanId; } |
| 630 | |
| 631 | /** |
| 632 | * Set the action to set the VLAN ID. |
| 633 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 634 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 635 | */ |
| 636 | @JsonProperty("actionSetVlanId") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 637 | public void setActionSetVlanId(ActionSetVlanId action) { |
| 638 | actionSetVlanId = action; |
| 639 | actionType = ActionValues.ACTION_SET_VLAN_VID; |
| 640 | } |
| 641 | |
| 642 | /** |
| 643 | * Set the action to set the VLAN ID. |
| 644 | * |
| 645 | * @param vlanId the VLAN ID to set. |
| 646 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 647 | public void setActionSetVlanId(short vlanId) { |
| 648 | actionSetVlanId = new ActionSetVlanId(vlanId); |
| 649 | actionType = ActionValues.ACTION_SET_VLAN_VID; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Get the action to set the VLAN priority. |
| 654 | * |
| 655 | * @return the action to set the VLAN priority. |
| 656 | */ |
| 657 | @JsonProperty("actionSetVlanPriority") |
| 658 | public ActionSetVlanPriority actionSetVlanPriority() { |
| 659 | return actionSetVlanPriority; |
| 660 | } |
| 661 | |
| 662 | /** |
| 663 | * Set the action to set the VLAN priority. |
| 664 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 665 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 666 | */ |
| 667 | @JsonProperty("actionSetVlanPriority") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 668 | public void setActionSetVlanPriority(ActionSetVlanPriority action) { |
| 669 | actionSetVlanPriority = action; |
| 670 | actionType = ActionValues.ACTION_SET_VLAN_PCP; |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Set the action to set the VLAN priority. |
| 675 | * |
| 676 | * @param vlanPriority the VLAN priority to set. |
| 677 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 678 | public void setActionSetVlanPriority(byte vlanPriority) { |
| 679 | actionSetVlanPriority = new ActionSetVlanPriority(vlanPriority); |
| 680 | actionType = ActionValues.ACTION_SET_VLAN_PCP; |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * Get the action to strip the VLAN header. |
| 685 | * |
| 686 | * @return the action to strip the VLAN header. |
| 687 | */ |
| 688 | @JsonProperty("actionStripVlan") |
| 689 | public ActionStripVlan actionStripVlan() { |
| 690 | return actionStripVlan; |
| 691 | } |
| 692 | |
| 693 | /** |
| 694 | * Set the action to strip the VLAN header. |
| 695 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 696 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 697 | */ |
| 698 | @JsonProperty("actionStripVlan") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 699 | public void setActionStripVlan(ActionStripVlan action) { |
| 700 | actionStripVlan = action; |
| 701 | actionType = ActionValues.ACTION_STRIP_VLAN; |
| 702 | } |
| 703 | |
| 704 | /** |
| 705 | * Set the action to strip the VLAN header. |
| 706 | * |
| 707 | * @param stripVlan if true, strip the VLAN header. |
| 708 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 709 | public void setActionStripVlan(boolean stripVlan) { |
| 710 | actionStripVlan = new ActionStripVlan(stripVlan); |
| 711 | actionType = ActionValues.ACTION_STRIP_VLAN; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Get the action to set the Ethernet source address. |
| 716 | * |
| 717 | * @return the action to set the Ethernet source address. |
| 718 | */ |
| 719 | @JsonProperty("actionSetEthernetSrcAddr") |
| 720 | public ActionSetEthernetAddr actionSetEthernetSrcAddr() { |
| 721 | return actionSetEthernetSrcAddr; |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Set the action to set the Ethernet source address. |
| 726 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 727 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 728 | */ |
| 729 | @JsonProperty("actionSetEthernetSrcAddr") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 730 | public void setActionSetEthernetSrcAddr(ActionSetEthernetAddr action) { |
| 731 | actionSetEthernetSrcAddr = action; |
| 732 | actionType = ActionValues.ACTION_SET_DL_SRC; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Set the action to set the Ethernet source address. |
| 737 | * |
| 738 | * @param addr the MAC address to set as the Ethernet source address. |
| 739 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 740 | public void setActionSetEthernetSrcAddr(MACAddress addr) { |
| 741 | actionSetEthernetSrcAddr = new ActionSetEthernetAddr(addr); |
| 742 | actionType = ActionValues.ACTION_SET_DL_SRC; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Get the action to set the Ethernet destination address. |
| 747 | * |
| 748 | * @return the action to set the Ethernet destination address. |
| 749 | */ |
| 750 | @JsonProperty("actionSetEthernetDstAddr") |
| 751 | public ActionSetEthernetAddr actionSetEthernetDstAddr() { |
| 752 | return actionSetEthernetDstAddr; |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * Set the action to set the Ethernet destination address. |
| 757 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 758 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 759 | */ |
| 760 | @JsonProperty("actionSetEthernetDstAddr") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 761 | public void setActionSetEthernetDstAddr(ActionSetEthernetAddr action) { |
| 762 | actionSetEthernetDstAddr = action; |
| 763 | actionType = ActionValues.ACTION_SET_DL_DST; |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Set the action to set the Ethernet destination address. |
| 768 | * |
| 769 | * @param addr the MAC address to set as the Ethernet destination address. |
| 770 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 771 | public void setActionSetEthernetDstAddr(MACAddress addr) { |
| 772 | actionSetEthernetDstAddr = new ActionSetEthernetAddr(addr); |
| 773 | actionType = ActionValues.ACTION_SET_DL_DST; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Get the action to set the IPv4 source address. |
| 778 | * |
| 779 | * @return the action to set the IPv4 source address. |
| 780 | */ |
| 781 | @JsonProperty("actionSetIPv4SrcAddr") |
| 782 | public ActionSetIPv4Addr actionSetIPv4SrcAddr() { |
| 783 | return actionSetIPv4SrcAddr; |
| 784 | } |
| 785 | |
| 786 | /** |
| 787 | * Set the action to set the IPv4 source address. |
| 788 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 789 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 790 | */ |
| 791 | @JsonProperty("actionSetIPv4SrcAddr") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 792 | public void setActionSetIPv4SrcAddr(ActionSetIPv4Addr action) { |
| 793 | actionSetIPv4SrcAddr = action; |
| 794 | actionType = ActionValues.ACTION_SET_NW_SRC; |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Set the action to set the IPv4 source address. |
| 799 | * |
| 800 | * @param addr the IPv4 address to set as the IPv4 source address. |
| 801 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 802 | public void setActionSetIPv4SrcAddr(IPv4 addr) { |
| 803 | actionSetIPv4SrcAddr = new ActionSetIPv4Addr(addr); |
| 804 | actionType = ActionValues.ACTION_SET_NW_SRC; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Get the action to set the IPv4 destination address. |
| 809 | * |
| 810 | * @return the action to set the IPv4 destination address. |
| 811 | */ |
| 812 | @JsonProperty("actionSetIPv4DstAddr") |
| 813 | public ActionSetIPv4Addr actionSetIPv4DstAddr() { |
| 814 | return actionSetIPv4DstAddr; |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Set the action to set the IPv4 destination address. |
| 819 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 820 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 821 | */ |
| 822 | @JsonProperty("actionSetIPv4DstAddr") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 823 | public void setActionSetIPv4DstAddr(ActionSetIPv4Addr action) { |
| 824 | actionSetIPv4DstAddr = action; |
| 825 | actionType = ActionValues.ACTION_SET_NW_DST; |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * Set the action to set the IPv4 destination address. |
| 830 | * |
| 831 | * @param addr the IPv4 address to set as the IPv4 destination address. |
| 832 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 833 | public void setActionSetIPv4DstAddr(IPv4 addr) { |
| 834 | actionSetIPv4DstAddr = new ActionSetIPv4Addr(addr); |
| 835 | actionType = ActionValues.ACTION_SET_NW_DST; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Get the action to set the IP ToS (DSCP field, 6 bits). |
| 840 | * |
| 841 | * @return the action to set the IP ToS (DSCP field, 6 bits). |
| 842 | */ |
| 843 | @JsonProperty("actionSetIpToS") |
| 844 | public ActionSetIpToS actionSetIpToS() { |
| 845 | return actionSetIpToS; |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * Set the action to set the IP ToS (DSCP field, 6 bits). |
| 850 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 851 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 852 | */ |
| 853 | @JsonProperty("actionSetIpToS") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 854 | public void setActionSetIpToS(ActionSetIpToS action) { |
| 855 | actionSetIpToS = action; |
| 856 | actionType = ActionValues.ACTION_SET_NW_TOS; |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * Set the action to set the IP ToS (DSCP field, 6 bits). |
| 861 | * |
| 862 | * @param ipToS the IP ToS (DSCP field, 6 bits) to set. |
| 863 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 864 | public void setActionSetIpToS(byte ipToS) { |
| 865 | actionSetIpToS = new ActionSetIpToS(ipToS); |
| 866 | actionType = ActionValues.ACTION_SET_NW_TOS; |
| 867 | } |
| 868 | |
| 869 | /** |
| 870 | * Get the action to set the TCP/UDP source port. |
| 871 | * |
| 872 | * @return the action to set the TCP/UDP source port. |
| 873 | */ |
| 874 | @JsonProperty("actionSetTcpUdpSrcPort") |
| 875 | public ActionSetTcpUdpPort actionSetTcpUdpSrcPort() { |
| 876 | return actionSetTcpUdpSrcPort; |
| 877 | } |
| 878 | |
| 879 | /** |
| 880 | * Set the action to set the TCP/UDP source port. |
| 881 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 882 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 883 | */ |
| 884 | @JsonProperty("actionSetTcpUdpSrcPort") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 885 | public void setActionSetTcpUdpSrcPort(ActionSetTcpUdpPort action) { |
| 886 | actionSetTcpUdpSrcPort = action; |
| 887 | actionType = ActionValues.ACTION_SET_TP_SRC; |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * Set the action to set the TCP/UDP source port. |
| 892 | * |
| 893 | * @param port the TCP/UDP port to set as the TCP/UDP source port. |
| 894 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 895 | public void setActionSetTcpUdpSrcPort(short port) { |
| 896 | actionSetTcpUdpSrcPort = new ActionSetTcpUdpPort(port); |
| 897 | actionType = ActionValues.ACTION_SET_TP_SRC; |
| 898 | } |
| 899 | |
| 900 | /** |
| 901 | * Get the action to set the TCP/UDP destination port. |
| 902 | * |
| 903 | * @return the action to set the TCP/UDP destination port. |
| 904 | */ |
| 905 | @JsonProperty("actionSetTcpUdpDstPort") |
| 906 | public ActionSetTcpUdpPort actionSetTcpUdpDstPort() { |
| 907 | return actionSetTcpUdpDstPort; |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Set the action to set the TCP/UDP destination port. |
| 912 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 913 | * @param action the action to set. |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 914 | */ |
| 915 | @JsonProperty("actionSetTcpUdpDstPort") |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 916 | public void setActionSetTcpUdpDstPort(ActionSetTcpUdpPort action) { |
| 917 | actionSetTcpUdpDstPort = action; |
| 918 | actionType = ActionValues.ACTION_SET_TP_DST; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Set the action to set the TCP/UDP destination port. |
| 923 | * |
| 924 | * @param port the TCP/UDP port to set as the TCP/UDP destination port. |
| 925 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 926 | public void setActionSetTcpUdpDstPort(short port) { |
| 927 | actionSetTcpUdpDstPort = new ActionSetTcpUdpPort(port); |
| 928 | actionType = ActionValues.ACTION_SET_TP_DST; |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * Get the action to output to queue on a port. |
| 933 | * |
| 934 | * @return the action to output to queue on a port. |
| 935 | */ |
| 936 | @JsonProperty("actionEnqueue") |
| 937 | public ActionEnqueue actionEnqueue() { return actionEnqueue; } |
| 938 | |
| 939 | /** |
| 940 | * Set the action to output to queue on a port. |
| 941 | * |
Pavlin Radoslavov | f13923a | 2013-03-11 19:42:17 -0700 | [diff] [blame] | 942 | * @param action the action to set. |
| 943 | */ |
| 944 | @JsonProperty("actionEnqueue") |
| 945 | public void setActionEnqueue(ActionEnqueue action) { |
| 946 | actionEnqueue = action; |
| 947 | actionType = ActionValues.ACTION_ENQUEUE; |
| 948 | } |
| 949 | |
| 950 | /** |
| 951 | * Set the action to output to queue on a port. |
| 952 | * |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 953 | * @param port the port to set. |
| 954 | * @param int queueId the queue ID to set. |
| 955 | */ |
Pavlin Radoslavov | ede9758 | 2013-03-08 18:57:28 -0800 | [diff] [blame] | 956 | public void setActionEnqueue(Port port, int queueId) { |
| 957 | actionEnqueue = new ActionEnqueue(port, queueId); |
| 958 | actionType = ActionValues.ACTION_ENQUEUE; |
| 959 | } |
| 960 | |
| 961 | /** |
| 962 | * Convert the set of actions to a string. |
| 963 | * |
| 964 | * The string has the following form: |
| 965 | * [type=XXX action=XXX] |
| 966 | * |
| 967 | * @return the set of actions as a string. |
| 968 | */ |
| 969 | @Override |
| 970 | public String toString() { |
| 971 | String ret = "["; |
| 972 | ret += "type=" + actionType; |
| 973 | switch (actionType) { |
| 974 | case ACTION_OUTPUT: |
| 975 | ret += " action=" + actionOutput.toString(); |
| 976 | break; |
| 977 | case ACTION_SET_VLAN_VID: |
| 978 | ret += " action=" + actionSetVlanId.toString(); |
| 979 | break; |
| 980 | case ACTION_SET_VLAN_PCP: |
| 981 | ret += " action=" + actionSetVlanPriority.toString(); |
| 982 | break; |
| 983 | case ACTION_STRIP_VLAN: |
| 984 | ret += " action=" + actionStripVlan.toString(); |
| 985 | break; |
| 986 | case ACTION_SET_DL_SRC: |
| 987 | ret += " action=" + actionSetEthernetSrcAddr.toString(); |
| 988 | break; |
| 989 | case ACTION_SET_DL_DST: |
| 990 | ret += " action=" + actionSetEthernetDstAddr.toString(); |
| 991 | break; |
| 992 | case ACTION_SET_NW_SRC: |
| 993 | ret += " action=" + actionSetIPv4SrcAddr.toString(); |
| 994 | break; |
| 995 | case ACTION_SET_NW_DST: |
| 996 | ret += " action=" + actionSetIPv4DstAddr.toString(); |
| 997 | break; |
| 998 | case ACTION_SET_NW_TOS: |
| 999 | ret += " action=" + actionSetIpToS.toString(); |
| 1000 | break; |
| 1001 | case ACTION_SET_TP_SRC: |
| 1002 | ret += " action=" + actionSetTcpUdpSrcPort.toString(); |
| 1003 | break; |
| 1004 | case ACTION_SET_TP_DST: |
| 1005 | ret += " action=" + actionSetTcpUdpDstPort.toString(); |
| 1006 | break; |
| 1007 | case ACTION_ENQUEUE: |
| 1008 | ret += " action=" + actionEnqueue.toString(); |
| 1009 | break; |
| 1010 | } |
| 1011 | ret += "]"; |
| 1012 | |
| 1013 | return ret; |
| 1014 | } |
| 1015 | } |