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