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