tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 1 | // Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | // Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | // Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 4 | // This library was generated by the LoxiGen Compiler. |
| 5 | // See the file LICENSE.txt which should have been included in the source distribution |
| 6 | |
| 7 | // Automatically generated by LOXI from template of_class.java |
| 8 | // Do not modify |
| 9 | |
| 10 | package org.projectfloodlight.openflow.protocol.ver13; |
| 11 | |
| 12 | import org.projectfloodlight.openflow.protocol.*; |
| 13 | import org.projectfloodlight.openflow.protocol.action.*; |
| 14 | import org.projectfloodlight.openflow.protocol.actionid.*; |
| 15 | import org.projectfloodlight.openflow.protocol.bsntlv.*; |
| 16 | import org.projectfloodlight.openflow.protocol.errormsg.*; |
| 17 | import org.projectfloodlight.openflow.protocol.meterband.*; |
| 18 | import org.projectfloodlight.openflow.protocol.instruction.*; |
| 19 | import org.projectfloodlight.openflow.protocol.instructionid.*; |
| 20 | import org.projectfloodlight.openflow.protocol.match.*; |
| 21 | import org.projectfloodlight.openflow.protocol.oxm.*; |
| 22 | import org.projectfloodlight.openflow.protocol.queueprop.*; |
| 23 | import org.projectfloodlight.openflow.types.*; |
| 24 | import org.projectfloodlight.openflow.util.*; |
| 25 | import org.projectfloodlight.openflow.exceptions.*; |
| 26 | import org.slf4j.Logger; |
| 27 | import org.slf4j.LoggerFactory; |
| 28 | import java.util.Set; |
| 29 | import com.google.common.collect.ImmutableSet; |
| 30 | import java.util.List; |
| 31 | import com.google.common.collect.ImmutableList; |
| 32 | import java.util.Collections; |
| 33 | import org.jboss.netty.buffer.ChannelBuffer; |
| 34 | import com.google.common.hash.PrimitiveSink; |
| 35 | import com.google.common.hash.Funnel; |
| 36 | |
| 37 | class OFFlowModifyVer13 implements OFFlowModify { |
| 38 | private static final Logger logger = LoggerFactory.getLogger(OFFlowModifyVer13.class); |
| 39 | // version: 1.3 |
| 40 | final static byte WIRE_VERSION = 4; |
| 41 | final static int MINIMUM_LENGTH = 56; |
| 42 | |
| 43 | private final static long DEFAULT_XID = 0x0L; |
| 44 | private final static U64 DEFAULT_COOKIE = U64.ZERO; |
| 45 | private final static U64 DEFAULT_COOKIE_MASK = U64.ZERO; |
| 46 | private final static TableId DEFAULT_TABLE_ID = TableId.ZERO; |
| 47 | private final static int DEFAULT_IDLE_TIMEOUT = 0x0; |
| 48 | private final static int DEFAULT_HARD_TIMEOUT = 0x0; |
| 49 | private final static int DEFAULT_PRIORITY = 0x0; |
| 50 | private final static OFBufferId DEFAULT_BUFFER_ID = OFBufferId.NO_BUFFER; |
| 51 | private final static OFPort DEFAULT_OUT_PORT = OFPort.ANY; |
| 52 | private final static OFGroup DEFAULT_OUT_GROUP = OFGroup.ANY; |
| 53 | private final static Set<OFFlowModFlags> DEFAULT_FLAGS = ImmutableSet.<OFFlowModFlags>of(); |
| 54 | private final static Match DEFAULT_MATCH = OFFactoryVer13.MATCH_WILDCARD_ALL; |
| 55 | private final static List<OFInstruction> DEFAULT_INSTRUCTIONS = ImmutableList.<OFInstruction>of(); |
| 56 | |
| 57 | // OF message fields |
| 58 | private final long xid; |
| 59 | private final U64 cookie; |
| 60 | private final U64 cookieMask; |
| 61 | private final TableId tableId; |
| 62 | private final int idleTimeout; |
| 63 | private final int hardTimeout; |
| 64 | private final int priority; |
| 65 | private final OFBufferId bufferId; |
| 66 | private final OFPort outPort; |
| 67 | private final OFGroup outGroup; |
| 68 | private final Set<OFFlowModFlags> flags; |
| 69 | private final Match match; |
| 70 | private final List<OFInstruction> instructions; |
| 71 | // |
| 72 | // Immutable default instance |
| 73 | final static OFFlowModifyVer13 DEFAULT = new OFFlowModifyVer13( |
| 74 | DEFAULT_XID, DEFAULT_COOKIE, DEFAULT_COOKIE_MASK, DEFAULT_TABLE_ID, DEFAULT_IDLE_TIMEOUT, DEFAULT_HARD_TIMEOUT, DEFAULT_PRIORITY, DEFAULT_BUFFER_ID, DEFAULT_OUT_PORT, DEFAULT_OUT_GROUP, DEFAULT_FLAGS, DEFAULT_MATCH, DEFAULT_INSTRUCTIONS |
| 75 | ); |
| 76 | |
| 77 | // package private constructor - used by readers, builders, and factory |
| 78 | OFFlowModifyVer13(long xid, U64 cookie, U64 cookieMask, TableId tableId, int idleTimeout, int hardTimeout, int priority, OFBufferId bufferId, OFPort outPort, OFGroup outGroup, Set<OFFlowModFlags> flags, Match match, List<OFInstruction> instructions) { |
| 79 | this.xid = xid; |
| 80 | this.cookie = cookie; |
| 81 | this.cookieMask = cookieMask; |
| 82 | this.tableId = tableId; |
| 83 | this.idleTimeout = idleTimeout; |
| 84 | this.hardTimeout = hardTimeout; |
| 85 | this.priority = priority; |
| 86 | this.bufferId = bufferId; |
| 87 | this.outPort = outPort; |
| 88 | this.outGroup = outGroup; |
| 89 | this.flags = flags; |
| 90 | this.match = match; |
| 91 | this.instructions = instructions; |
| 92 | } |
| 93 | |
| 94 | // Accessors for OF message fields |
| 95 | @Override |
| 96 | public OFVersion getVersion() { |
| 97 | return OFVersion.OF_13; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public OFType getType() { |
| 102 | return OFType.FLOW_MOD; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public long getXid() { |
| 107 | return xid; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public U64 getCookie() { |
| 112 | return cookie; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public U64 getCookieMask() { |
| 117 | return cookieMask; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public TableId getTableId() { |
| 122 | return tableId; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public OFFlowModCommand getCommand() { |
| 127 | return OFFlowModCommand.MODIFY; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public int getIdleTimeout() { |
| 132 | return idleTimeout; |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public int getHardTimeout() { |
| 137 | return hardTimeout; |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public int getPriority() { |
| 142 | return priority; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public OFBufferId getBufferId() { |
| 147 | return bufferId; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public OFPort getOutPort() { |
| 152 | return outPort; |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public OFGroup getOutGroup() { |
| 157 | return outGroup; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public Set<OFFlowModFlags> getFlags() { |
| 162 | return flags; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public Match getMatch() { |
| 167 | return match; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public List<OFInstruction> getInstructions() { |
| 172 | return instructions; |
| 173 | } |
| 174 | |
| 175 | |
| 176 | @Override |
| 177 | public List<OFAction> getActions()throws UnsupportedOperationException { |
| 178 | for (OFInstruction inst : this.instructions) { |
| 179 | if (inst instanceof OFInstructionApplyActions) { |
| 180 | OFInstructionApplyActions iap = (OFInstructionApplyActions)inst; |
| 181 | return iap.getActions(); |
| 182 | } |
| 183 | } |
| 184 | return Collections.emptyList(); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | public OFFlowModify.Builder createBuilder() { |
| 189 | return new BuilderWithParent(this); |
| 190 | } |
| 191 | |
| 192 | static class BuilderWithParent implements OFFlowModify.Builder { |
| 193 | final OFFlowModifyVer13 parentMessage; |
| 194 | |
| 195 | // OF message fields |
| 196 | private boolean xidSet; |
| 197 | private long xid; |
| 198 | private boolean cookieSet; |
| 199 | private U64 cookie; |
| 200 | private boolean cookieMaskSet; |
| 201 | private U64 cookieMask; |
| 202 | private boolean tableIdSet; |
| 203 | private TableId tableId; |
| 204 | private boolean idleTimeoutSet; |
| 205 | private int idleTimeout; |
| 206 | private boolean hardTimeoutSet; |
| 207 | private int hardTimeout; |
| 208 | private boolean prioritySet; |
| 209 | private int priority; |
| 210 | private boolean bufferIdSet; |
| 211 | private OFBufferId bufferId; |
| 212 | private boolean outPortSet; |
| 213 | private OFPort outPort; |
| 214 | private boolean outGroupSet; |
| 215 | private OFGroup outGroup; |
| 216 | private boolean flagsSet; |
| 217 | private Set<OFFlowModFlags> flags; |
| 218 | private boolean matchSet; |
| 219 | private Match match; |
| 220 | private boolean instructionsSet; |
| 221 | private List<OFInstruction> instructions; |
| 222 | |
| 223 | BuilderWithParent(OFFlowModifyVer13 parentMessage) { |
| 224 | this.parentMessage = parentMessage; |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public OFVersion getVersion() { |
| 229 | return OFVersion.OF_13; |
| 230 | } |
| 231 | |
| 232 | @Override |
| 233 | public OFType getType() { |
| 234 | return OFType.FLOW_MOD; |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public long getXid() { |
| 239 | return xid; |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public OFFlowModify.Builder setXid(long xid) { |
| 244 | this.xid = xid; |
| 245 | this.xidSet = true; |
| 246 | return this; |
| 247 | } |
| 248 | @Override |
| 249 | public U64 getCookie() { |
| 250 | return cookie; |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public OFFlowModify.Builder setCookie(U64 cookie) { |
| 255 | this.cookie = cookie; |
| 256 | this.cookieSet = true; |
| 257 | return this; |
| 258 | } |
| 259 | @Override |
| 260 | public U64 getCookieMask() { |
| 261 | return cookieMask; |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public OFFlowModify.Builder setCookieMask(U64 cookieMask) { |
| 266 | this.cookieMask = cookieMask; |
| 267 | this.cookieMaskSet = true; |
| 268 | return this; |
| 269 | } |
| 270 | @Override |
| 271 | public TableId getTableId() { |
| 272 | return tableId; |
| 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public OFFlowModify.Builder setTableId(TableId tableId) { |
| 277 | this.tableId = tableId; |
| 278 | this.tableIdSet = true; |
| 279 | return this; |
| 280 | } |
| 281 | @Override |
| 282 | public OFFlowModCommand getCommand() { |
| 283 | return OFFlowModCommand.MODIFY; |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public int getIdleTimeout() { |
| 288 | return idleTimeout; |
| 289 | } |
| 290 | |
| 291 | @Override |
| 292 | public OFFlowModify.Builder setIdleTimeout(int idleTimeout) { |
| 293 | this.idleTimeout = idleTimeout; |
| 294 | this.idleTimeoutSet = true; |
| 295 | return this; |
| 296 | } |
| 297 | @Override |
| 298 | public int getHardTimeout() { |
| 299 | return hardTimeout; |
| 300 | } |
| 301 | |
| 302 | @Override |
| 303 | public OFFlowModify.Builder setHardTimeout(int hardTimeout) { |
| 304 | this.hardTimeout = hardTimeout; |
| 305 | this.hardTimeoutSet = true; |
| 306 | return this; |
| 307 | } |
| 308 | @Override |
| 309 | public int getPriority() { |
| 310 | return priority; |
| 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public OFFlowModify.Builder setPriority(int priority) { |
| 315 | this.priority = priority; |
| 316 | this.prioritySet = true; |
| 317 | return this; |
| 318 | } |
| 319 | @Override |
| 320 | public OFBufferId getBufferId() { |
| 321 | return bufferId; |
| 322 | } |
| 323 | |
| 324 | @Override |
| 325 | public OFFlowModify.Builder setBufferId(OFBufferId bufferId) { |
| 326 | this.bufferId = bufferId; |
| 327 | this.bufferIdSet = true; |
| 328 | return this; |
| 329 | } |
| 330 | @Override |
| 331 | public OFPort getOutPort() { |
| 332 | return outPort; |
| 333 | } |
| 334 | |
| 335 | @Override |
| 336 | public OFFlowModify.Builder setOutPort(OFPort outPort) { |
| 337 | this.outPort = outPort; |
| 338 | this.outPortSet = true; |
| 339 | return this; |
| 340 | } |
| 341 | @Override |
| 342 | public OFGroup getOutGroup() { |
| 343 | return outGroup; |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public OFFlowModify.Builder setOutGroup(OFGroup outGroup) { |
| 348 | this.outGroup = outGroup; |
| 349 | this.outGroupSet = true; |
| 350 | return this; |
| 351 | } |
| 352 | @Override |
| 353 | public Set<OFFlowModFlags> getFlags() { |
| 354 | return flags; |
| 355 | } |
| 356 | |
| 357 | @Override |
| 358 | public OFFlowModify.Builder setFlags(Set<OFFlowModFlags> flags) { |
| 359 | this.flags = flags; |
| 360 | this.flagsSet = true; |
| 361 | return this; |
| 362 | } |
| 363 | @Override |
| 364 | public Match getMatch() { |
| 365 | return match; |
| 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public OFFlowModify.Builder setMatch(Match match) { |
| 370 | this.match = match; |
| 371 | this.matchSet = true; |
| 372 | return this; |
| 373 | } |
| 374 | @Override |
| 375 | public List<OFInstruction> getInstructions() { |
| 376 | return instructions; |
| 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public OFFlowModify.Builder setInstructions(List<OFInstruction> instructions) { |
| 381 | this.instructions = instructions; |
| 382 | this.instructionsSet = true; |
| 383 | return this; |
| 384 | } |
| 385 | |
| 386 | @Override |
| 387 | public List<OFAction> getActions()throws UnsupportedOperationException { |
| 388 | if (!this.instructionsSet) |
| 389 | return parentMessage.getActions(); |
| 390 | for (OFInstruction inst : this.instructions) { |
| 391 | if (inst instanceof OFInstructionApplyActions) { |
| 392 | OFInstructionApplyActions iap = (OFInstructionApplyActions)inst; |
| 393 | return iap.getActions(); |
| 394 | } |
| 395 | } |
| 396 | return Collections.emptyList(); |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public OFFlowModify.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException { |
| 401 | OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder(); |
| 402 | builder.setActions(actions); |
| 403 | this.instructions = Collections.singletonList((OFInstruction)builder.build()); |
| 404 | this.instructionsSet = true; |
| 405 | return this; |
| 406 | } |
| 407 | |
| 408 | |
| 409 | @Override |
| 410 | public OFFlowModify build() { |
| 411 | long xid = this.xidSet ? this.xid : parentMessage.xid; |
| 412 | U64 cookie = this.cookieSet ? this.cookie : parentMessage.cookie; |
| 413 | if(cookie == null) |
| 414 | throw new NullPointerException("Property cookie must not be null"); |
| 415 | U64 cookieMask = this.cookieMaskSet ? this.cookieMask : parentMessage.cookieMask; |
| 416 | if(cookieMask == null) |
| 417 | throw new NullPointerException("Property cookieMask must not be null"); |
| 418 | TableId tableId = this.tableIdSet ? this.tableId : parentMessage.tableId; |
| 419 | if(tableId == null) |
| 420 | throw new NullPointerException("Property tableId must not be null"); |
| 421 | int idleTimeout = this.idleTimeoutSet ? this.idleTimeout : parentMessage.idleTimeout; |
| 422 | int hardTimeout = this.hardTimeoutSet ? this.hardTimeout : parentMessage.hardTimeout; |
| 423 | int priority = this.prioritySet ? this.priority : parentMessage.priority; |
| 424 | OFBufferId bufferId = this.bufferIdSet ? this.bufferId : parentMessage.bufferId; |
| 425 | if(bufferId == null) |
| 426 | throw new NullPointerException("Property bufferId must not be null"); |
| 427 | OFPort outPort = this.outPortSet ? this.outPort : parentMessage.outPort; |
| 428 | if(outPort == null) |
| 429 | throw new NullPointerException("Property outPort must not be null"); |
| 430 | OFGroup outGroup = this.outGroupSet ? this.outGroup : parentMessage.outGroup; |
| 431 | if(outGroup == null) |
| 432 | throw new NullPointerException("Property outGroup must not be null"); |
| 433 | Set<OFFlowModFlags> flags = this.flagsSet ? this.flags : parentMessage.flags; |
| 434 | if(flags == null) |
| 435 | throw new NullPointerException("Property flags must not be null"); |
| 436 | Match match = this.matchSet ? this.match : parentMessage.match; |
| 437 | if(match == null) |
| 438 | throw new NullPointerException("Property match must not be null"); |
| 439 | List<OFInstruction> instructions = this.instructionsSet ? this.instructions : parentMessage.instructions; |
| 440 | if(instructions == null) |
| 441 | throw new NullPointerException("Property instructions must not be null"); |
| 442 | |
| 443 | // |
| 444 | return new OFFlowModifyVer13( |
| 445 | xid, |
| 446 | cookie, |
| 447 | cookieMask, |
| 448 | tableId, |
| 449 | idleTimeout, |
| 450 | hardTimeout, |
| 451 | priority, |
| 452 | bufferId, |
| 453 | outPort, |
| 454 | outGroup, |
| 455 | flags, |
| 456 | match, |
| 457 | instructions |
| 458 | ); |
| 459 | } |
| 460 | |
| 461 | } |
| 462 | |
| 463 | static class Builder implements OFFlowModify.Builder { |
| 464 | // OF message fields |
| 465 | private boolean xidSet; |
| 466 | private long xid; |
| 467 | private boolean cookieSet; |
| 468 | private U64 cookie; |
| 469 | private boolean cookieMaskSet; |
| 470 | private U64 cookieMask; |
| 471 | private boolean tableIdSet; |
| 472 | private TableId tableId; |
| 473 | private boolean idleTimeoutSet; |
| 474 | private int idleTimeout; |
| 475 | private boolean hardTimeoutSet; |
| 476 | private int hardTimeout; |
| 477 | private boolean prioritySet; |
| 478 | private int priority; |
| 479 | private boolean bufferIdSet; |
| 480 | private OFBufferId bufferId; |
| 481 | private boolean outPortSet; |
| 482 | private OFPort outPort; |
| 483 | private boolean outGroupSet; |
| 484 | private OFGroup outGroup; |
| 485 | private boolean flagsSet; |
| 486 | private Set<OFFlowModFlags> flags; |
| 487 | private boolean matchSet; |
| 488 | private Match match; |
| 489 | private boolean instructionsSet; |
| 490 | private List<OFInstruction> instructions; |
| 491 | |
| 492 | @Override |
| 493 | public OFVersion getVersion() { |
| 494 | return OFVersion.OF_13; |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public OFType getType() { |
| 499 | return OFType.FLOW_MOD; |
| 500 | } |
| 501 | |
| 502 | @Override |
| 503 | public long getXid() { |
| 504 | return xid; |
| 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public OFFlowModify.Builder setXid(long xid) { |
| 509 | this.xid = xid; |
| 510 | this.xidSet = true; |
| 511 | return this; |
| 512 | } |
| 513 | @Override |
| 514 | public U64 getCookie() { |
| 515 | return cookie; |
| 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public OFFlowModify.Builder setCookie(U64 cookie) { |
| 520 | this.cookie = cookie; |
| 521 | this.cookieSet = true; |
| 522 | return this; |
| 523 | } |
| 524 | @Override |
| 525 | public U64 getCookieMask() { |
| 526 | return cookieMask; |
| 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public OFFlowModify.Builder setCookieMask(U64 cookieMask) { |
| 531 | this.cookieMask = cookieMask; |
| 532 | this.cookieMaskSet = true; |
| 533 | return this; |
| 534 | } |
| 535 | @Override |
| 536 | public TableId getTableId() { |
| 537 | return tableId; |
| 538 | } |
| 539 | |
| 540 | @Override |
| 541 | public OFFlowModify.Builder setTableId(TableId tableId) { |
| 542 | this.tableId = tableId; |
| 543 | this.tableIdSet = true; |
| 544 | return this; |
| 545 | } |
| 546 | @Override |
| 547 | public OFFlowModCommand getCommand() { |
| 548 | return OFFlowModCommand.MODIFY; |
| 549 | } |
| 550 | |
| 551 | @Override |
| 552 | public int getIdleTimeout() { |
| 553 | return idleTimeout; |
| 554 | } |
| 555 | |
| 556 | @Override |
| 557 | public OFFlowModify.Builder setIdleTimeout(int idleTimeout) { |
| 558 | this.idleTimeout = idleTimeout; |
| 559 | this.idleTimeoutSet = true; |
| 560 | return this; |
| 561 | } |
| 562 | @Override |
| 563 | public int getHardTimeout() { |
| 564 | return hardTimeout; |
| 565 | } |
| 566 | |
| 567 | @Override |
| 568 | public OFFlowModify.Builder setHardTimeout(int hardTimeout) { |
| 569 | this.hardTimeout = hardTimeout; |
| 570 | this.hardTimeoutSet = true; |
| 571 | return this; |
| 572 | } |
| 573 | @Override |
| 574 | public int getPriority() { |
| 575 | return priority; |
| 576 | } |
| 577 | |
| 578 | @Override |
| 579 | public OFFlowModify.Builder setPriority(int priority) { |
| 580 | this.priority = priority; |
| 581 | this.prioritySet = true; |
| 582 | return this; |
| 583 | } |
| 584 | @Override |
| 585 | public OFBufferId getBufferId() { |
| 586 | return bufferId; |
| 587 | } |
| 588 | |
| 589 | @Override |
| 590 | public OFFlowModify.Builder setBufferId(OFBufferId bufferId) { |
| 591 | this.bufferId = bufferId; |
| 592 | this.bufferIdSet = true; |
| 593 | return this; |
| 594 | } |
| 595 | @Override |
| 596 | public OFPort getOutPort() { |
| 597 | return outPort; |
| 598 | } |
| 599 | |
| 600 | @Override |
| 601 | public OFFlowModify.Builder setOutPort(OFPort outPort) { |
| 602 | this.outPort = outPort; |
| 603 | this.outPortSet = true; |
| 604 | return this; |
| 605 | } |
| 606 | @Override |
| 607 | public OFGroup getOutGroup() { |
| 608 | return outGroup; |
| 609 | } |
| 610 | |
| 611 | @Override |
| 612 | public OFFlowModify.Builder setOutGroup(OFGroup outGroup) { |
| 613 | this.outGroup = outGroup; |
| 614 | this.outGroupSet = true; |
| 615 | return this; |
| 616 | } |
| 617 | @Override |
| 618 | public Set<OFFlowModFlags> getFlags() { |
| 619 | return flags; |
| 620 | } |
| 621 | |
| 622 | @Override |
| 623 | public OFFlowModify.Builder setFlags(Set<OFFlowModFlags> flags) { |
| 624 | this.flags = flags; |
| 625 | this.flagsSet = true; |
| 626 | return this; |
| 627 | } |
| 628 | @Override |
| 629 | public Match getMatch() { |
| 630 | return match; |
| 631 | } |
| 632 | |
| 633 | @Override |
| 634 | public OFFlowModify.Builder setMatch(Match match) { |
| 635 | this.match = match; |
| 636 | this.matchSet = true; |
| 637 | return this; |
| 638 | } |
| 639 | @Override |
| 640 | public List<OFInstruction> getInstructions() { |
| 641 | return instructions; |
| 642 | } |
| 643 | |
| 644 | @Override |
| 645 | public OFFlowModify.Builder setInstructions(List<OFInstruction> instructions) { |
| 646 | this.instructions = instructions; |
| 647 | this.instructionsSet = true; |
| 648 | return this; |
| 649 | } |
| 650 | |
| 651 | @Override |
| 652 | public List<OFAction> getActions()throws UnsupportedOperationException { |
| 653 | if (!this.instructionsSet) |
| 654 | return Collections.emptyList(); |
| 655 | for (OFInstruction inst : this.instructions) { |
| 656 | if (inst instanceof OFInstructionApplyActions) { |
| 657 | OFInstructionApplyActions iap = (OFInstructionApplyActions)inst; |
| 658 | return iap.getActions(); |
| 659 | } |
| 660 | } |
| 661 | return Collections.emptyList(); |
| 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public OFFlowModify.Builder setActions(List<OFAction> actions) throws UnsupportedOperationException { |
| 666 | OFInstructionApplyActionsVer13.Builder builder = new OFInstructionApplyActionsVer13.Builder(); |
| 667 | builder.setActions(actions); |
| 668 | this.instructions = Collections.singletonList((OFInstruction)builder.build()); |
| 669 | this.instructionsSet = true; |
| 670 | return this; |
| 671 | } |
| 672 | // |
| 673 | @Override |
| 674 | public OFFlowModify build() { |
| 675 | long xid = this.xidSet ? this.xid : DEFAULT_XID; |
| 676 | U64 cookie = this.cookieSet ? this.cookie : DEFAULT_COOKIE; |
| 677 | if(cookie == null) |
| 678 | throw new NullPointerException("Property cookie must not be null"); |
| 679 | U64 cookieMask = this.cookieMaskSet ? this.cookieMask : DEFAULT_COOKIE_MASK; |
| 680 | if(cookieMask == null) |
| 681 | throw new NullPointerException("Property cookieMask must not be null"); |
| 682 | TableId tableId = this.tableIdSet ? this.tableId : DEFAULT_TABLE_ID; |
| 683 | if(tableId == null) |
| 684 | throw new NullPointerException("Property tableId must not be null"); |
| 685 | int idleTimeout = this.idleTimeoutSet ? this.idleTimeout : DEFAULT_IDLE_TIMEOUT; |
| 686 | int hardTimeout = this.hardTimeoutSet ? this.hardTimeout : DEFAULT_HARD_TIMEOUT; |
| 687 | int priority = this.prioritySet ? this.priority : DEFAULT_PRIORITY; |
| 688 | OFBufferId bufferId = this.bufferIdSet ? this.bufferId : DEFAULT_BUFFER_ID; |
| 689 | if(bufferId == null) |
| 690 | throw new NullPointerException("Property bufferId must not be null"); |
| 691 | OFPort outPort = this.outPortSet ? this.outPort : DEFAULT_OUT_PORT; |
| 692 | if(outPort == null) |
| 693 | throw new NullPointerException("Property outPort must not be null"); |
| 694 | OFGroup outGroup = this.outGroupSet ? this.outGroup : DEFAULT_OUT_GROUP; |
| 695 | if(outGroup == null) |
| 696 | throw new NullPointerException("Property outGroup must not be null"); |
| 697 | Set<OFFlowModFlags> flags = this.flagsSet ? this.flags : DEFAULT_FLAGS; |
| 698 | if(flags == null) |
| 699 | throw new NullPointerException("Property flags must not be null"); |
| 700 | Match match = this.matchSet ? this.match : DEFAULT_MATCH; |
| 701 | if(match == null) |
| 702 | throw new NullPointerException("Property match must not be null"); |
| 703 | List<OFInstruction> instructions = this.instructionsSet ? this.instructions : DEFAULT_INSTRUCTIONS; |
| 704 | if(instructions == null) |
| 705 | throw new NullPointerException("Property instructions must not be null"); |
| 706 | |
| 707 | |
| 708 | return new OFFlowModifyVer13( |
| 709 | xid, |
| 710 | cookie, |
| 711 | cookieMask, |
| 712 | tableId, |
| 713 | idleTimeout, |
| 714 | hardTimeout, |
| 715 | priority, |
| 716 | bufferId, |
| 717 | outPort, |
| 718 | outGroup, |
| 719 | flags, |
| 720 | match, |
| 721 | instructions |
| 722 | ); |
| 723 | } |
| 724 | |
| 725 | } |
| 726 | |
| 727 | |
| 728 | final static Reader READER = new Reader(); |
| 729 | static class Reader implements OFMessageReader<OFFlowModify> { |
| 730 | @Override |
| 731 | public OFFlowModify readFrom(ChannelBuffer bb) throws OFParseError { |
| 732 | int start = bb.readerIndex(); |
| 733 | // fixed value property version == 4 |
| 734 | byte version = bb.readByte(); |
| 735 | if(version != (byte) 0x4) |
| 736 | throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got="+version); |
| 737 | // fixed value property type == 14 |
| 738 | byte type = bb.readByte(); |
| 739 | if(type != (byte) 0xe) |
| 740 | throw new OFParseError("Wrong type: Expected=OFType.FLOW_MOD(14), got="+type); |
| 741 | int length = U16.f(bb.readShort()); |
| 742 | if(length < MINIMUM_LENGTH) |
| 743 | throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length); |
| 744 | if(bb.readableBytes() + (bb.readerIndex() - start) < length) { |
| 745 | // Buffer does not have all data yet |
| 746 | bb.readerIndex(start); |
| 747 | return null; |
| 748 | } |
| 749 | if(logger.isTraceEnabled()) |
| 750 | logger.trace("readFrom - length={}", length); |
| 751 | long xid = U32.f(bb.readInt()); |
| 752 | U64 cookie = U64.ofRaw(bb.readLong()); |
| 753 | U64 cookieMask = U64.ofRaw(bb.readLong()); |
| 754 | TableId tableId = TableId.readByte(bb); |
| 755 | // fixed value property command == 1 |
| 756 | short command = bb.readByte(); |
| 757 | if(command != (short) 0x1) |
| 758 | throw new OFParseError("Wrong command: Expected=OFFlowModCommand.MODIFY(1), got="+command); |
| 759 | int idleTimeout = U16.f(bb.readShort()); |
| 760 | int hardTimeout = U16.f(bb.readShort()); |
| 761 | int priority = U16.f(bb.readShort()); |
| 762 | OFBufferId bufferId = OFBufferId.of(bb.readInt()); |
| 763 | OFPort outPort = OFPort.read4Bytes(bb); |
| 764 | OFGroup outGroup = OFGroup.read4Bytes(bb); |
| 765 | Set<OFFlowModFlags> flags = OFFlowModFlagsSerializerVer13.readFrom(bb); |
| 766 | // pad: 2 bytes |
| 767 | bb.skipBytes(2); |
| 768 | Match match = ChannelUtilsVer13.readOFMatch(bb); |
| 769 | List<OFInstruction> instructions = ChannelUtils.readList(bb, length - (bb.readerIndex() - start), OFInstructionVer13.READER); |
| 770 | |
| 771 | OFFlowModifyVer13 flowModifyVer13 = new OFFlowModifyVer13( |
| 772 | xid, |
| 773 | cookie, |
| 774 | cookieMask, |
| 775 | tableId, |
| 776 | idleTimeout, |
| 777 | hardTimeout, |
| 778 | priority, |
| 779 | bufferId, |
| 780 | outPort, |
| 781 | outGroup, |
| 782 | flags, |
| 783 | match, |
| 784 | instructions |
| 785 | ); |
| 786 | if(logger.isTraceEnabled()) |
| 787 | logger.trace("readFrom - read={}", flowModifyVer13); |
| 788 | return flowModifyVer13; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | public void putTo(PrimitiveSink sink) { |
| 793 | FUNNEL.funnel(this, sink); |
| 794 | } |
| 795 | |
| 796 | final static OFFlowModifyVer13Funnel FUNNEL = new OFFlowModifyVer13Funnel(); |
| 797 | static class OFFlowModifyVer13Funnel implements Funnel<OFFlowModifyVer13> { |
| 798 | private static final long serialVersionUID = 1L; |
| 799 | @Override |
| 800 | public void funnel(OFFlowModifyVer13 message, PrimitiveSink sink) { |
| 801 | // fixed value property version = 4 |
| 802 | sink.putByte((byte) 0x4); |
| 803 | // fixed value property type = 14 |
| 804 | sink.putByte((byte) 0xe); |
| 805 | // FIXME: skip funnel of length |
| 806 | sink.putLong(message.xid); |
| 807 | message.cookie.putTo(sink); |
| 808 | message.cookieMask.putTo(sink); |
| 809 | message.tableId.putTo(sink); |
| 810 | // fixed value property command = 1 |
| 811 | sink.putShort((short) 0x1); |
| 812 | sink.putInt(message.idleTimeout); |
| 813 | sink.putInt(message.hardTimeout); |
| 814 | sink.putInt(message.priority); |
| 815 | message.bufferId.putTo(sink); |
| 816 | message.outPort.putTo(sink); |
| 817 | message.outGroup.putTo(sink); |
| 818 | OFFlowModFlagsSerializerVer13.putTo(message.flags, sink); |
| 819 | // skip pad (2 bytes) |
| 820 | message.match.putTo(sink); |
| 821 | FunnelUtils.putList(message.instructions, sink); |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | public void writeTo(ChannelBuffer bb) { |
| 827 | WRITER.write(bb, this); |
| 828 | } |
| 829 | |
| 830 | final static Writer WRITER = new Writer(); |
| 831 | static class Writer implements OFMessageWriter<OFFlowModifyVer13> { |
| 832 | @Override |
| 833 | public void write(ChannelBuffer bb, OFFlowModifyVer13 message) { |
| 834 | int startIndex = bb.writerIndex(); |
| 835 | // fixed value property version = 4 |
| 836 | bb.writeByte((byte) 0x4); |
| 837 | // fixed value property type = 14 |
| 838 | bb.writeByte((byte) 0xe); |
| 839 | // length is length of variable message, will be updated at the end |
| 840 | int lengthIndex = bb.writerIndex(); |
| 841 | bb.writeShort(U16.t(0)); |
| 842 | |
| 843 | bb.writeInt(U32.t(message.xid)); |
| 844 | bb.writeLong(message.cookie.getValue()); |
| 845 | bb.writeLong(message.cookieMask.getValue()); |
| 846 | message.tableId.writeByte(bb); |
| 847 | // fixed value property command = 1 |
| 848 | bb.writeByte((short) 0x1); |
| 849 | bb.writeShort(U16.t(message.idleTimeout)); |
| 850 | bb.writeShort(U16.t(message.hardTimeout)); |
| 851 | bb.writeShort(U16.t(message.priority)); |
| 852 | bb.writeInt(message.bufferId.getInt()); |
| 853 | message.outPort.write4Bytes(bb); |
| 854 | message.outGroup.write4Bytes(bb); |
| 855 | OFFlowModFlagsSerializerVer13.writeTo(bb, message.flags); |
| 856 | // pad: 2 bytes |
| 857 | bb.writeZero(2); |
| 858 | message.match.writeTo(bb); |
| 859 | ChannelUtils.writeList(bb, message.instructions); |
| 860 | |
| 861 | // update length field |
| 862 | int length = bb.writerIndex() - startIndex; |
| 863 | bb.setShort(lengthIndex, length); |
| 864 | |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | @Override |
| 869 | public String toString() { |
| 870 | StringBuilder b = new StringBuilder("OFFlowModifyVer13("); |
| 871 | b.append("xid=").append(xid); |
| 872 | b.append(", "); |
| 873 | b.append("cookie=").append(cookie); |
| 874 | b.append(", "); |
| 875 | b.append("cookieMask=").append(cookieMask); |
| 876 | b.append(", "); |
| 877 | b.append("tableId=").append(tableId); |
| 878 | b.append(", "); |
| 879 | b.append("idleTimeout=").append(idleTimeout); |
| 880 | b.append(", "); |
| 881 | b.append("hardTimeout=").append(hardTimeout); |
| 882 | b.append(", "); |
| 883 | b.append("priority=").append(priority); |
| 884 | b.append(", "); |
| 885 | b.append("bufferId=").append(bufferId); |
| 886 | b.append(", "); |
| 887 | b.append("outPort=").append(outPort); |
| 888 | b.append(", "); |
| 889 | b.append("outGroup=").append(outGroup); |
| 890 | b.append(", "); |
| 891 | b.append("flags=").append(flags); |
| 892 | b.append(", "); |
| 893 | b.append("match=").append(match); |
| 894 | b.append(", "); |
| 895 | b.append("instructions=").append(instructions); |
| 896 | b.append(")"); |
| 897 | return b.toString(); |
| 898 | } |
| 899 | |
| 900 | @Override |
| 901 | public boolean equals(Object obj) { |
| 902 | if (this == obj) |
| 903 | return true; |
| 904 | if (obj == null) |
| 905 | return false; |
| 906 | if (getClass() != obj.getClass()) |
| 907 | return false; |
| 908 | OFFlowModifyVer13 other = (OFFlowModifyVer13) obj; |
| 909 | |
| 910 | if( xid != other.xid) |
| 911 | return false; |
| 912 | if (cookie == null) { |
| 913 | if (other.cookie != null) |
| 914 | return false; |
| 915 | } else if (!cookie.equals(other.cookie)) |
| 916 | return false; |
| 917 | if (cookieMask == null) { |
| 918 | if (other.cookieMask != null) |
| 919 | return false; |
| 920 | } else if (!cookieMask.equals(other.cookieMask)) |
| 921 | return false; |
| 922 | if (tableId == null) { |
| 923 | if (other.tableId != null) |
| 924 | return false; |
| 925 | } else if (!tableId.equals(other.tableId)) |
| 926 | return false; |
| 927 | if( idleTimeout != other.idleTimeout) |
| 928 | return false; |
| 929 | if( hardTimeout != other.hardTimeout) |
| 930 | return false; |
| 931 | if( priority != other.priority) |
| 932 | return false; |
| 933 | if (bufferId == null) { |
| 934 | if (other.bufferId != null) |
| 935 | return false; |
| 936 | } else if (!bufferId.equals(other.bufferId)) |
| 937 | return false; |
| 938 | if (outPort == null) { |
| 939 | if (other.outPort != null) |
| 940 | return false; |
| 941 | } else if (!outPort.equals(other.outPort)) |
| 942 | return false; |
| 943 | if (outGroup == null) { |
| 944 | if (other.outGroup != null) |
| 945 | return false; |
| 946 | } else if (!outGroup.equals(other.outGroup)) |
| 947 | return false; |
| 948 | if (flags == null) { |
| 949 | if (other.flags != null) |
| 950 | return false; |
| 951 | } else if (!flags.equals(other.flags)) |
| 952 | return false; |
| 953 | if (match == null) { |
| 954 | if (other.match != null) |
| 955 | return false; |
| 956 | } else if (!match.equals(other.match)) |
| 957 | return false; |
| 958 | if (instructions == null) { |
| 959 | if (other.instructions != null) |
| 960 | return false; |
| 961 | } else if (!instructions.equals(other.instructions)) |
| 962 | return false; |
| 963 | return true; |
| 964 | } |
| 965 | |
| 966 | @Override |
| 967 | public int hashCode() { |
| 968 | final int prime = 31; |
| 969 | int result = 1; |
| 970 | |
| 971 | result = prime * (int) (xid ^ (xid >>> 32)); |
| 972 | result = prime * result + ((cookie == null) ? 0 : cookie.hashCode()); |
| 973 | result = prime * result + ((cookieMask == null) ? 0 : cookieMask.hashCode()); |
| 974 | result = prime * result + ((tableId == null) ? 0 : tableId.hashCode()); |
| 975 | result = prime * result + idleTimeout; |
| 976 | result = prime * result + hardTimeout; |
| 977 | result = prime * result + priority; |
| 978 | result = prime * result + ((bufferId == null) ? 0 : bufferId.hashCode()); |
| 979 | result = prime * result + ((outPort == null) ? 0 : outPort.hashCode()); |
| 980 | result = prime * result + ((outGroup == null) ? 0 : outGroup.hashCode()); |
| 981 | result = prime * result + ((flags == null) ? 0 : flags.hashCode()); |
| 982 | result = prime * result + ((match == null) ? 0 : match.hashCode()); |
| 983 | result = prime * result + ((instructions == null) ? 0 : instructions.hashCode()); |
| 984 | return result; |
| 985 | } |
| 986 | |
| 987 | } |