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