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