blob: b496100186f6b04ce3353e5880ba92fec1672293 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001// 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
10package org.projectfloodlight.openflow.protocol.ver13;
11
12import org.projectfloodlight.openflow.protocol.*;
13import org.projectfloodlight.openflow.protocol.action.*;
14import org.projectfloodlight.openflow.protocol.actionid.*;
15import org.projectfloodlight.openflow.protocol.bsntlv.*;
16import org.projectfloodlight.openflow.protocol.errormsg.*;
17import org.projectfloodlight.openflow.protocol.meterband.*;
18import org.projectfloodlight.openflow.protocol.instruction.*;
19import org.projectfloodlight.openflow.protocol.instructionid.*;
20import org.projectfloodlight.openflow.protocol.match.*;
21import org.projectfloodlight.openflow.protocol.oxm.*;
22import org.projectfloodlight.openflow.protocol.queueprop.*;
23import org.projectfloodlight.openflow.types.*;
24import org.projectfloodlight.openflow.util.*;
25import org.projectfloodlight.openflow.exceptions.*;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28import java.util.Set;
29import org.jboss.netty.buffer.ChannelBuffer;
30import com.google.common.hash.PrimitiveSink;
31import com.google.common.hash.Funnel;
32import java.util.Arrays;
33
34class OFPacketInVer13 implements OFPacketIn {
35 private static final Logger logger = LoggerFactory.getLogger(OFPacketInVer13.class);
36 // version: 1.3
37 final static byte WIRE_VERSION = 4;
38 final static int MINIMUM_LENGTH = 30;
39
40 private final static long DEFAULT_XID = 0x0L;
41 private final static OFBufferId DEFAULT_BUFFER_ID = OFBufferId.NO_BUFFER;
42 private final static int DEFAULT_TOTAL_LEN = 0x0;
43 private final static TableId DEFAULT_TABLE_ID = TableId.ALL;
44 private final static U64 DEFAULT_COOKIE = U64.ZERO;
45 private final static Match DEFAULT_MATCH = OFFactoryVer13.MATCH_WILDCARD_ALL;
46 private final static byte[] DEFAULT_DATA = new byte[0];
47
48 // OF message fields
49 private final long xid;
50 private final OFBufferId bufferId;
51 private final int totalLen;
52 private final OFPacketInReason reason;
53 private final TableId tableId;
54 private final U64 cookie;
55 private final Match match;
56 private final byte[] data;
57//
58
59 // package private constructor - used by readers, builders, and factory
60 OFPacketInVer13(long xid, OFBufferId bufferId, int totalLen, OFPacketInReason reason, TableId tableId, U64 cookie, Match match, byte[] data) {
61 this.xid = xid;
62 this.bufferId = bufferId;
63 this.totalLen = totalLen;
64 this.reason = reason;
65 this.tableId = tableId;
66 this.cookie = cookie;
67 this.match = match;
68 this.data = data;
69 }
70
71 // Accessors for OF message fields
72 @Override
73 public OFVersion getVersion() {
74 return OFVersion.OF_13;
75 }
76
77 @Override
78 public OFType getType() {
79 return OFType.PACKET_IN;
80 }
81
82 @Override
83 public long getXid() {
84 return xid;
85 }
86
87 @Override
88 public OFBufferId getBufferId() {
89 return bufferId;
90 }
91
92 @Override
93 public int getTotalLen() {
94 return totalLen;
95 }
96
97 @Override
98 public OFPacketInReason getReason() {
99 return reason;
100 }
101
102 @Override
103 public TableId getTableId() {
104 return tableId;
105 }
106
107 @Override
108 public Match getMatch() {
109 return match;
110 }
111
112 @Override
113 public byte[] getData() {
114 return data;
115 }
116
117 @Override
118 public OFPort getInPort()throws UnsupportedOperationException {
119 throw new UnsupportedOperationException("Property inPort not supported in version 1.3");
120 }
121
122 @Override
123 public OFPort getInPhyPort()throws UnsupportedOperationException {
124 throw new UnsupportedOperationException("Property inPhyPort not supported in version 1.3");
125 }
126
127 @Override
128 public U64 getCookie() {
129 return cookie;
130 }
131
132
133
134 public OFPacketIn.Builder createBuilder() {
135 return new BuilderWithParent(this);
136 }
137
138 static class BuilderWithParent implements OFPacketIn.Builder {
139 final OFPacketInVer13 parentMessage;
140
141 // OF message fields
142 private boolean xidSet;
143 private long xid;
144 private boolean bufferIdSet;
145 private OFBufferId bufferId;
146 private boolean totalLenSet;
147 private int totalLen;
148 private boolean reasonSet;
149 private OFPacketInReason reason;
150 private boolean tableIdSet;
151 private TableId tableId;
152 private boolean cookieSet;
153 private U64 cookie;
154 private boolean matchSet;
155 private Match match;
156 private boolean dataSet;
157 private byte[] data;
158
159 BuilderWithParent(OFPacketInVer13 parentMessage) {
160 this.parentMessage = parentMessage;
161 }
162
163 @Override
164 public OFVersion getVersion() {
165 return OFVersion.OF_13;
166 }
167
168 @Override
169 public OFType getType() {
170 return OFType.PACKET_IN;
171 }
172
173 @Override
174 public long getXid() {
175 return xid;
176 }
177
178 @Override
179 public OFPacketIn.Builder setXid(long xid) {
180 this.xid = xid;
181 this.xidSet = true;
182 return this;
183 }
184 @Override
185 public OFBufferId getBufferId() {
186 return bufferId;
187 }
188
189 @Override
190 public OFPacketIn.Builder setBufferId(OFBufferId bufferId) {
191 this.bufferId = bufferId;
192 this.bufferIdSet = true;
193 return this;
194 }
195 @Override
196 public int getTotalLen() {
197 return totalLen;
198 }
199
200 @Override
201 public OFPacketIn.Builder setTotalLen(int totalLen) {
202 this.totalLen = totalLen;
203 this.totalLenSet = true;
204 return this;
205 }
206 @Override
207 public OFPacketInReason getReason() {
208 return reason;
209 }
210
211 @Override
212 public OFPacketIn.Builder setReason(OFPacketInReason reason) {
213 this.reason = reason;
214 this.reasonSet = true;
215 return this;
216 }
217 @Override
218 public TableId getTableId() {
219 return tableId;
220 }
221
222 @Override
223 public OFPacketIn.Builder setTableId(TableId tableId) {
224 this.tableId = tableId;
225 this.tableIdSet = true;
226 return this;
227 }
228 @Override
229 public Match getMatch() {
230 return match;
231 }
232
233 @Override
234 public OFPacketIn.Builder setMatch(Match match) {
235 this.match = match;
236 this.matchSet = true;
237 return this;
238 }
239 @Override
240 public byte[] getData() {
241 return data;
242 }
243
244 @Override
245 public OFPacketIn.Builder setData(byte[] data) {
246 this.data = data;
247 this.dataSet = true;
248 return this;
249 }
250 @Override
251 public OFPort getInPort()throws UnsupportedOperationException {
252 throw new UnsupportedOperationException("Property inPort not supported in version 1.3");
253 }
254
255 @Override
256 public OFPacketIn.Builder setInPort(OFPort inPort) throws UnsupportedOperationException {
257 throw new UnsupportedOperationException("Property inPort not supported in version 1.3");
258 }
259 @Override
260 public OFPort getInPhyPort()throws UnsupportedOperationException {
261 throw new UnsupportedOperationException("Property inPhyPort not supported in version 1.3");
262 }
263
264 @Override
265 public OFPacketIn.Builder setInPhyPort(OFPort inPhyPort) throws UnsupportedOperationException {
266 throw new UnsupportedOperationException("Property inPhyPort not supported in version 1.3");
267 }
268 @Override
269 public U64 getCookie() {
270 return cookie;
271 }
272
273 @Override
274 public OFPacketIn.Builder setCookie(U64 cookie) {
275 this.cookie = cookie;
276 this.cookieSet = true;
277 return this;
278 }
279
280
281 @Override
282 public OFPacketIn build() {
283 long xid = this.xidSet ? this.xid : parentMessage.xid;
284 OFBufferId bufferId = this.bufferIdSet ? this.bufferId : parentMessage.bufferId;
285 if(bufferId == null)
286 throw new NullPointerException("Property bufferId must not be null");
287 int totalLen = this.totalLenSet ? this.totalLen : parentMessage.totalLen;
288 OFPacketInReason reason = this.reasonSet ? this.reason : parentMessage.reason;
289 if(reason == null)
290 throw new NullPointerException("Property reason must not be null");
291 TableId tableId = this.tableIdSet ? this.tableId : parentMessage.tableId;
292 if(tableId == null)
293 throw new NullPointerException("Property tableId must not be null");
294 U64 cookie = this.cookieSet ? this.cookie : parentMessage.cookie;
295 if(cookie == null)
296 throw new NullPointerException("Property cookie must not be null");
297 Match match = this.matchSet ? this.match : parentMessage.match;
298 if(match == null)
299 throw new NullPointerException("Property match must not be null");
300 byte[] data = this.dataSet ? this.data : parentMessage.data;
301 if(data == null)
302 throw new NullPointerException("Property data must not be null");
303
304 //
305 return new OFPacketInVer13(
306 xid,
307 bufferId,
308 totalLen,
309 reason,
310 tableId,
311 cookie,
312 match,
313 data
314 );
315 }
316
317 }
318
319 static class Builder implements OFPacketIn.Builder {
320 // OF message fields
321 private boolean xidSet;
322 private long xid;
323 private boolean bufferIdSet;
324 private OFBufferId bufferId;
325 private boolean totalLenSet;
326 private int totalLen;
327 private boolean reasonSet;
328 private OFPacketInReason reason;
329 private boolean tableIdSet;
330 private TableId tableId;
331 private boolean cookieSet;
332 private U64 cookie;
333 private boolean matchSet;
334 private Match match;
335 private boolean dataSet;
336 private byte[] data;
337
338 @Override
339 public OFVersion getVersion() {
340 return OFVersion.OF_13;
341 }
342
343 @Override
344 public OFType getType() {
345 return OFType.PACKET_IN;
346 }
347
348 @Override
349 public long getXid() {
350 return xid;
351 }
352
353 @Override
354 public OFPacketIn.Builder setXid(long xid) {
355 this.xid = xid;
356 this.xidSet = true;
357 return this;
358 }
359 @Override
360 public OFBufferId getBufferId() {
361 return bufferId;
362 }
363
364 @Override
365 public OFPacketIn.Builder setBufferId(OFBufferId bufferId) {
366 this.bufferId = bufferId;
367 this.bufferIdSet = true;
368 return this;
369 }
370 @Override
371 public int getTotalLen() {
372 return totalLen;
373 }
374
375 @Override
376 public OFPacketIn.Builder setTotalLen(int totalLen) {
377 this.totalLen = totalLen;
378 this.totalLenSet = true;
379 return this;
380 }
381 @Override
382 public OFPacketInReason getReason() {
383 return reason;
384 }
385
386 @Override
387 public OFPacketIn.Builder setReason(OFPacketInReason reason) {
388 this.reason = reason;
389 this.reasonSet = true;
390 return this;
391 }
392 @Override
393 public TableId getTableId() {
394 return tableId;
395 }
396
397 @Override
398 public OFPacketIn.Builder setTableId(TableId tableId) {
399 this.tableId = tableId;
400 this.tableIdSet = true;
401 return this;
402 }
403 @Override
404 public Match getMatch() {
405 return match;
406 }
407
408 @Override
409 public OFPacketIn.Builder setMatch(Match match) {
410 this.match = match;
411 this.matchSet = true;
412 return this;
413 }
414 @Override
415 public byte[] getData() {
416 return data;
417 }
418
419 @Override
420 public OFPacketIn.Builder setData(byte[] data) {
421 this.data = data;
422 this.dataSet = true;
423 return this;
424 }
425 @Override
426 public OFPort getInPort()throws UnsupportedOperationException {
427 throw new UnsupportedOperationException("Property inPort not supported in version 1.3");
428 }
429
430 @Override
431 public OFPacketIn.Builder setInPort(OFPort inPort) throws UnsupportedOperationException {
432 throw new UnsupportedOperationException("Property inPort not supported in version 1.3");
433 }
434 @Override
435 public OFPort getInPhyPort()throws UnsupportedOperationException {
436 throw new UnsupportedOperationException("Property inPhyPort not supported in version 1.3");
437 }
438
439 @Override
440 public OFPacketIn.Builder setInPhyPort(OFPort inPhyPort) throws UnsupportedOperationException {
441 throw new UnsupportedOperationException("Property inPhyPort not supported in version 1.3");
442 }
443 @Override
444 public U64 getCookie() {
445 return cookie;
446 }
447
448 @Override
449 public OFPacketIn.Builder setCookie(U64 cookie) {
450 this.cookie = cookie;
451 this.cookieSet = true;
452 return this;
453 }
454//
455 @Override
456 public OFPacketIn build() {
457 long xid = this.xidSet ? this.xid : DEFAULT_XID;
458 OFBufferId bufferId = this.bufferIdSet ? this.bufferId : DEFAULT_BUFFER_ID;
459 if(bufferId == null)
460 throw new NullPointerException("Property bufferId must not be null");
461 int totalLen = this.totalLenSet ? this.totalLen : DEFAULT_TOTAL_LEN;
462 if(!this.reasonSet)
463 throw new IllegalStateException("Property reason doesn't have default value -- must be set");
464 if(reason == null)
465 throw new NullPointerException("Property reason must not be null");
466 TableId tableId = this.tableIdSet ? this.tableId : DEFAULT_TABLE_ID;
467 if(tableId == null)
468 throw new NullPointerException("Property tableId must not be null");
469 U64 cookie = this.cookieSet ? this.cookie : DEFAULT_COOKIE;
470 if(cookie == null)
471 throw new NullPointerException("Property cookie must not be null");
472 Match match = this.matchSet ? this.match : DEFAULT_MATCH;
473 if(match == null)
474 throw new NullPointerException("Property match must not be null");
475 byte[] data = this.dataSet ? this.data : DEFAULT_DATA;
476 if(data == null)
477 throw new NullPointerException("Property data must not be null");
478
479
480 return new OFPacketInVer13(
481 xid,
482 bufferId,
483 totalLen,
484 reason,
485 tableId,
486 cookie,
487 match,
488 data
489 );
490 }
491
492 }
493
494
495 final static Reader READER = new Reader();
496 static class Reader implements OFMessageReader<OFPacketIn> {
497 @Override
498 public OFPacketIn readFrom(ChannelBuffer bb) throws OFParseError {
499 int start = bb.readerIndex();
500 // fixed value property version == 4
501 byte version = bb.readByte();
502 if(version != (byte) 0x4)
503 throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got="+version);
504 // fixed value property type == 10
505 byte type = bb.readByte();
506 if(type != (byte) 0xa)
507 throw new OFParseError("Wrong type: Expected=OFType.PACKET_IN(10), got="+type);
508 int length = U16.f(bb.readShort());
509 if(length < MINIMUM_LENGTH)
510 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
511 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
512 // Buffer does not have all data yet
513 bb.readerIndex(start);
514 return null;
515 }
516 if(logger.isTraceEnabled())
517 logger.trace("readFrom - length={}", length);
518 long xid = U32.f(bb.readInt());
519 OFBufferId bufferId = OFBufferId.of(bb.readInt());
520 int totalLen = U16.f(bb.readShort());
521 OFPacketInReason reason = OFPacketInReasonSerializerVer13.readFrom(bb);
522 TableId tableId = TableId.readByte(bb);
523 U64 cookie = U64.ofRaw(bb.readLong());
524 Match match = ChannelUtilsVer13.readOFMatch(bb);
525 // pad: 2 bytes
526 bb.skipBytes(2);
527 byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));
528
529 OFPacketInVer13 packetInVer13 = new OFPacketInVer13(
530 xid,
531 bufferId,
532 totalLen,
533 reason,
534 tableId,
535 cookie,
536 match,
537 data
538 );
539 if(logger.isTraceEnabled())
540 logger.trace("readFrom - read={}", packetInVer13);
541 return packetInVer13;
542 }
543 }
544
545 public void putTo(PrimitiveSink sink) {
546 FUNNEL.funnel(this, sink);
547 }
548
549 final static OFPacketInVer13Funnel FUNNEL = new OFPacketInVer13Funnel();
550 static class OFPacketInVer13Funnel implements Funnel<OFPacketInVer13> {
551 private static final long serialVersionUID = 1L;
552 @Override
553 public void funnel(OFPacketInVer13 message, PrimitiveSink sink) {
554 // fixed value property version = 4
555 sink.putByte((byte) 0x4);
556 // fixed value property type = 10
557 sink.putByte((byte) 0xa);
558 // FIXME: skip funnel of length
559 sink.putLong(message.xid);
560 message.bufferId.putTo(sink);
561 sink.putInt(message.totalLen);
562 OFPacketInReasonSerializerVer13.putTo(message.reason, sink);
563 message.tableId.putTo(sink);
564 message.cookie.putTo(sink);
565 message.match.putTo(sink);
566 // skip pad (2 bytes)
567 sink.putBytes(message.data);
568 }
569 }
570
571
572 public void writeTo(ChannelBuffer bb) {
573 WRITER.write(bb, this);
574 }
575
576 final static Writer WRITER = new Writer();
577 static class Writer implements OFMessageWriter<OFPacketInVer13> {
578 @Override
579 public void write(ChannelBuffer bb, OFPacketInVer13 message) {
580 int startIndex = bb.writerIndex();
581 // fixed value property version = 4
582 bb.writeByte((byte) 0x4);
583 // fixed value property type = 10
584 bb.writeByte((byte) 0xa);
585 // length is length of variable message, will be updated at the end
586 int lengthIndex = bb.writerIndex();
587 bb.writeShort(U16.t(0));
588
589 bb.writeInt(U32.t(message.xid));
590 bb.writeInt(message.bufferId.getInt());
591 bb.writeShort(U16.t(message.totalLen));
592 OFPacketInReasonSerializerVer13.writeTo(bb, message.reason);
593 message.tableId.writeByte(bb);
594 bb.writeLong(message.cookie.getValue());
595 message.match.writeTo(bb);
596 // pad: 2 bytes
597 bb.writeZero(2);
598 bb.writeBytes(message.data);
599
600 // update length field
601 int length = bb.writerIndex() - startIndex;
602 bb.setShort(lengthIndex, length);
603
604 }
605 }
606
607 @Override
608 public String toString() {
609 StringBuilder b = new StringBuilder("OFPacketInVer13(");
610 b.append("xid=").append(xid);
611 b.append(", ");
612 b.append("bufferId=").append(bufferId);
613 b.append(", ");
614 b.append("totalLen=").append(totalLen);
615 b.append(", ");
616 b.append("reason=").append(reason);
617 b.append(", ");
618 b.append("tableId=").append(tableId);
619 b.append(", ");
620 b.append("cookie=").append(cookie);
621 b.append(", ");
622 b.append("match=").append(match);
623 b.append(", ");
624 b.append("data=").append(Arrays.toString(data));
625 b.append(")");
626 return b.toString();
627 }
628
629 @Override
630 public boolean equals(Object obj) {
631 if (this == obj)
632 return true;
633 if (obj == null)
634 return false;
635 if (getClass() != obj.getClass())
636 return false;
637 OFPacketInVer13 other = (OFPacketInVer13) obj;
638
639 if( xid != other.xid)
640 return false;
641 if (bufferId == null) {
642 if (other.bufferId != null)
643 return false;
644 } else if (!bufferId.equals(other.bufferId))
645 return false;
646 if( totalLen != other.totalLen)
647 return false;
648 if (reason == null) {
649 if (other.reason != null)
650 return false;
651 } else if (!reason.equals(other.reason))
652 return false;
653 if (tableId == null) {
654 if (other.tableId != null)
655 return false;
656 } else if (!tableId.equals(other.tableId))
657 return false;
658 if (cookie == null) {
659 if (other.cookie != null)
660 return false;
661 } else if (!cookie.equals(other.cookie))
662 return false;
663 if (match == null) {
664 if (other.match != null)
665 return false;
666 } else if (!match.equals(other.match))
667 return false;
668 if (!Arrays.equals(data, other.data))
669 return false;
670 return true;
671 }
672
673 @Override
674 public int hashCode() {
675 final int prime = 31;
676 int result = 1;
677
678 result = prime * (int) (xid ^ (xid >>> 32));
679 result = prime * result + ((bufferId == null) ? 0 : bufferId.hashCode());
680 result = prime * result + totalLen;
681 result = prime * result + ((reason == null) ? 0 : reason.hashCode());
682 result = prime * result + ((tableId == null) ? 0 : tableId.hashCode());
683 result = prime * result + ((cookie == null) ? 0 : cookie.hashCode());
684 result = prime * result + ((match == null) ? 0 : match.hashCode());
685 result = prime * result + Arrays.hashCode(data);
686 return result;
687 }
688
689}