blob: 4ca8864c91cf9e29e984d1a82b617a5242c353ab [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.List;
29import java.util.Iterator;
30import com.google.common.collect.AbstractIterator;
31import java.util.Set;
32import org.jboss.netty.buffer.ChannelBuffer;
33import com.google.common.hash.PrimitiveSink;
34import com.google.common.hash.Funnel;
35
36class OFMatchV3Ver13 implements OFMatchV3 {
37 private static final Logger logger = LoggerFactory.getLogger(OFMatchV3Ver13.class);
38 // version: 1.3
39 final static byte WIRE_VERSION = 4;
40 final static int MINIMUM_LENGTH = 4;
41
42 private final static OFOxmList DEFAULT_OXM_LIST = OFOxmList.EMPTY;
43
44 // OF message fields
45 private final OFOxmList oxmList;
46//
47 // Immutable default instance
48 final static OFMatchV3Ver13 DEFAULT = new OFMatchV3Ver13(
49 DEFAULT_OXM_LIST
50 );
51
52 // package private constructor - used by readers, builders, and factory
53 OFMatchV3Ver13(OFOxmList oxmList) {
54 this.oxmList = oxmList;
55 }
56
57 // Accessors for OF message fields
58 @Override
59 public int getType() {
60 return 0x1;
61 }
62
63 @Override
64 public OFOxmList getOxmList() {
65 return oxmList;
66 }
67
68 @Override
69 public OFVersion getVersion() {
70 return OFVersion.OF_13;
71 }
72
73
74 @Override
75 public <F extends OFValueType<F>> F get(MatchField<F> field)
76 throws UnsupportedOperationException {
77 if (!supports(field))
78 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
79
80 OFOxm<F> oxm = this.oxmList.get(field);
81
82 if (oxm == null || !field.arePrerequisitesOK(this))
83 return null;
84
85 return oxm.getValue();
86 }
87
88 @Override
89 public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
90 throws UnsupportedOperationException {
91 if (!supportsMasked(field))
92 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support masked matching on field " + field.getName());
93
94 OFOxm<F> oxm = this.oxmList.get(field);
95
96 if (oxm == null || !field.arePrerequisitesOK(this))
97 return null;
98
99 if (oxm.getMask() == null)
100 return null;
101
102 // TODO: Make OfOxm extend Masked and just return the OXM?
103 return Masked.of(oxm.getValue(), oxm.getMask());
104 }
105
106 private static boolean supportsField(MatchField<?> field) {
107 switch (field.id) {
108 case ARP_OP:
109 case ARP_SHA:
110 case ARP_SPA:
111 case ARP_THA:
112 case ARP_TPA:
113 case BSN_EGR_PORT_GROUP_ID:
114 case BSN_GLOBAL_VRF_ALLOWED:
115 case BSN_IN_PORTS_128:
116 case BSN_L3_DST_CLASS_ID:
117 case BSN_L3_INTERFACE_CLASS_ID:
118 case BSN_L3_SRC_CLASS_ID:
119 case BSN_LAG_ID:
120 case BSN_TCP_FLAGS:
121 case BSN_UDF0:
122 case BSN_UDF1:
123 case BSN_UDF2:
124 case BSN_UDF3:
125 case BSN_UDF4:
126 case BSN_UDF5:
127 case BSN_UDF6:
128 case BSN_UDF7:
129 case BSN_VLAN_XLATE_PORT_GROUP_ID:
130 case BSN_VRF:
131 case ETH_DST:
132 case ETH_SRC:
133 case ETH_TYPE:
134 case ICMPV4_CODE:
135 case ICMPV4_TYPE:
136 case ICMPV6_CODE:
137 case ICMPV6_TYPE:
138 case IN_PHY_PORT:
139 case IN_PORT:
140 case IPV4_DST:
141 case IPV4_SRC:
142 case IPV6_DST:
143 case IPV6_FLABEL:
144 case IPV6_ND_SLL:
145 case IPV6_ND_TARGET:
146 case IPV6_ND_TLL:
147 case IPV6_SRC:
148 case IP_DSCP:
149 case IP_ECN:
150 case IP_PROTO:
151 case METADATA:
152 case MPLS_LABEL:
153 case MPLS_TC:
154 case SCTP_DST:
155 case SCTP_SRC:
156 case TCP_DST:
157 case TCP_SRC:
158 case TUNNEL_ID:
159 case UDP_DST:
160 case UDP_SRC:
161 case VLAN_PCP:
162 case VLAN_VID:
163 return true;
164 default:
165 return false;
166 }
167 }
168
169 @Override
170 public boolean supports(MatchField<?> field) {
171 return supportsField(field);
172 }
173
174 @Override
175 public boolean supportsMasked(MatchField<?> field) {
176 return supportsField(field);
177 }
178
179 @Override
180 public boolean isExact(MatchField<?> field) {
181 if (!supports(field))
182 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
183
184 OFOxm<?> oxm = this.oxmList.get(field);
185
186 return oxm != null && !oxm.isMasked();
187 }
188
189 @Override
190 public boolean isFullyWildcarded(MatchField<?> field) {
191 if (!supports(field))
192 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
193
194 OFOxm<?> oxm = this.oxmList.get(field);
195
196 return oxm == null;
197 }
198
199 @Override
200 public boolean isPartiallyMasked(MatchField<?> field) {
201 if (!supports(field))
202 throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName());
203
204 OFOxm<?> oxm = this.oxmList.get(field);
205
206 return oxm != null && oxm.isMasked();
207 }
208
209 private class MatchFieldIterator extends AbstractIterator<MatchField<?>> {
210 private Iterator<OFOxm<?>> oxmIterator;
211
212 MatchFieldIterator() {
213 oxmIterator = oxmList.iterator();
214 }
215
216 @Override
217 protected MatchField<?> computeNext() {
218 while(oxmIterator.hasNext()) {
219 OFOxm<?> oxm = oxmIterator.next();
220 if(oxm.getMatchField().arePrerequisitesOK(OFMatchV3Ver13.this))
221 return oxm.getMatchField();
222 }
223 endOfData();
224 return null;
225 }
226 }
227
228 @Override
229 public Iterable<MatchField<?>> getMatchFields() {
230 return new Iterable<MatchField<?>>() {
231 public Iterator<MatchField<?>> iterator() {
232 return new MatchFieldIterator();
233 }
234 };
235 }
236
237 public OFMatchV3.Builder createBuilder() {
238 return new BuilderWithParent(this);
239 }
240
241 static class BuilderWithParent implements OFMatchV3.Builder {
242 final OFMatchV3Ver13 parentMessage;
243
244 // OF message fields
245 private boolean oxmListSet;
246 private OFOxmList oxmList;
247
248 BuilderWithParent(OFMatchV3Ver13 parentMessage) {
249 this.parentMessage = parentMessage;
250 }
251
252 @Override
253 public int getType() {
254 return 0x1;
255 }
256
257 @Override
258 public OFOxmList getOxmList() {
259 return oxmList;
260 }
261
262 @Override
263 public OFMatchV3.Builder setOxmList(OFOxmList oxmList) {
264 this.oxmList = oxmList;
265 this.oxmListSet = true;
266 return this;
267 }
268 @Override
269 public OFVersion getVersion() {
270 return OFVersion.OF_13;
271 }
272
273
274
275 @Override
276 public OFMatchV3 build() {
277 OFOxmList oxmList = this.oxmListSet ? this.oxmList : parentMessage.oxmList;
278 if(oxmList == null)
279 throw new NullPointerException("Property oxmList must not be null");
280
281 //
282 return new OFMatchV3Ver13(
283 oxmList
284 );
285 }
286
287 private OFOxmList.Builder oxmListBuilder;
288
289 private void initBuilder() {
290 if (oxmListBuilder != null)
291 return;
292 oxmListBuilder = new OFOxmList.Builder();
293 }
294
295 private void updateOxmList() {
296 this.oxmList = this.oxmListBuilder.build();
297 this.oxmListSet = true;
298 }
299
300 private <F extends OFValueType<F>> OFOxm<F> getOxm(MatchField<F> field) {
301 return this.oxmListSet ? this.oxmList.get(field) : parentMessage.oxmList.get(field);
302 }
303
304 @Override
305 public <F extends OFValueType<F>> F get(MatchField<F> field)
306 throws UnsupportedOperationException {
307 OFOxm<F> value = getOxm(field);
308 if (value == null)
309 return null;
310 return value.getValue();
311 }
312
313 @Override
314 public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
315 throws UnsupportedOperationException {
316 OFOxm<F> value = getOxm(field);
317 if (value == null || !value.isMasked())
318 return null;
319 // TODO: If changing OXMs to extend Masked, then use it here
320 return Masked.of(value.getValue(), value.getMask());
321 }
322
323 @Override
324 public boolean supports(MatchField<?> field) {
325 return supportsField(field);
326 }
327
328 @Override
329 public boolean supportsMasked(MatchField<?> field) {
330 return supportsField(field);
331 }
332
333 @Override
334 public boolean isExact(MatchField<?> field) {
335 OFOxm<?> value = getOxm(field);
336 return (value != null && !value.isMasked());
337 }
338
339 @Override
340 public boolean isFullyWildcarded(MatchField<?> field) {
341 OFOxm<?> value = getOxm(field);
342 return (value == null);
343 }
344
345 @Override
346 public boolean isPartiallyMasked(MatchField<?> field) {
347 OFOxm<?> value = getOxm(field);
348 return (value != null && value.isMasked());
349 }
350
351 @Override
352 public <F extends OFValueType<F>> Match.Builder setExact(
353 MatchField<F> field, F value) {
354 initBuilder();
355 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValue(value, field);
356 this.oxmListBuilder.set(oxm);
357 updateOxmList();
358 return this;
359 }
360
361 @Override
362 public <F extends OFValueType<F>> Match.Builder setMasked(
363 MatchField<F> field, F value, F mask) {
364 initBuilder();
365 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValueAndMask(value, mask, field);
366 this.oxmListBuilder.set(oxm);
367 updateOxmList();
368 return this;
369 }
370
371 @Override
372 public <F extends OFValueType<F>> Match.Builder setMasked(
373 MatchField<F> field, Masked<F> valueWithMask) {
374 initBuilder();
375 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromMasked(valueWithMask, field);
376 this.oxmListBuilder.set(oxm);
377 updateOxmList();
378 return this;
379 }
380
381 @Override
382 public <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) {
383 initBuilder();
384 this.oxmListBuilder.unset(field);
385 updateOxmList();
386 return this;
387 }
388
389
390 }
391
392 static class Builder implements OFMatchV3.Builder {
393 // OF message fields
394 private boolean oxmListSet;
395 private OFOxmList oxmList;
396
397 @Override
398 public int getType() {
399 return 0x1;
400 }
401
402 @Override
403 public OFOxmList getOxmList() {
404 return oxmList;
405 }
406
407 @Override
408 public OFMatchV3.Builder setOxmList(OFOxmList oxmList) {
409 this.oxmList = oxmList;
410 this.oxmListSet = true;
411 return this;
412 }
413 @Override
414 public OFVersion getVersion() {
415 return OFVersion.OF_13;
416 }
417
418//
419 @Override
420 public OFMatchV3 build() {
421 OFOxmList oxmList = this.oxmListSet ? this.oxmList : DEFAULT_OXM_LIST;
422 if(oxmList == null)
423 throw new NullPointerException("Property oxmList must not be null");
424
425
426 return new OFMatchV3Ver13(
427 oxmList
428 );
429 }
430
431 private OFOxmList.Builder oxmListBuilder;
432
433 private void initBuilder() {
434 if (oxmListBuilder != null)
435 return;
436 oxmListBuilder = new OFOxmList.Builder();
437 }
438
439 private void updateOxmList() {
440 this.oxmList = this.oxmListBuilder.build();
441 this.oxmListSet = true;
442 }
443
444 private <F extends OFValueType<F>> OFOxm<F> getOxm(MatchField<F> field) {
445 return this.oxmListSet ? this.oxmList.get(field) : null;
446 }
447
448 @Override
449 public <F extends OFValueType<F>> F get(MatchField<F> field)
450 throws UnsupportedOperationException {
451 OFOxm<F> value = getOxm(field);
452 if (value == null)
453 return null;
454 return value.getValue();
455 }
456
457 @Override
458 public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
459 throws UnsupportedOperationException {
460 OFOxm<F> value = getOxm(field);
461 if (value == null || !value.isMasked())
462 return null;
463 // TODO: If changing OXMs to extend Masked, then use it here
464 return Masked.of(value.getValue(), value.getMask());
465 }
466
467 @Override
468 public boolean supports(MatchField<?> field) {
469 return supportsField(field);
470 }
471
472 @Override
473 public boolean supportsMasked(MatchField<?> field) {
474 return supportsField(field);
475 }
476
477 @Override
478 public boolean isExact(MatchField<?> field) {
479 OFOxm<?> value = getOxm(field);
480 return (value != null && !value.isMasked());
481 }
482
483 @Override
484 public boolean isFullyWildcarded(MatchField<?> field) {
485 OFOxm<?> value = getOxm(field);
486 return (value == null);
487 }
488
489 @Override
490 public boolean isPartiallyMasked(MatchField<?> field) {
491 OFOxm<?> value = getOxm(field);
492 return (value != null && value.isMasked());
493 }
494
495 @Override
496 public <F extends OFValueType<F>> Match.Builder setExact(
497 MatchField<F> field, F value) {
498 initBuilder();
499 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValue(value, field);
500 this.oxmListBuilder.set(oxm);
501 updateOxmList();
502 return this;
503 }
504
505 @Override
506 public <F extends OFValueType<F>> Match.Builder setMasked(
507 MatchField<F> field, F value, F mask) {
508 initBuilder();
509 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValueAndMask(value, mask, field);
510 this.oxmListBuilder.set(oxm);
511 updateOxmList();
512 return this;
513 }
514
515 @Override
516 public <F extends OFValueType<F>> Match.Builder setMasked(
517 MatchField<F> field, Masked<F> valueWithMask) {
518 initBuilder();
519 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromMasked(valueWithMask, field);
520 this.oxmListBuilder.set(oxm);
521 updateOxmList();
522 return this;
523 }
524
525 @Override
526 public <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) {
527 initBuilder();
528 this.oxmListBuilder.unset(field);
529 updateOxmList();
530 return this;
531 }
532
533
534 }
535
536
537 final static Reader READER = new Reader();
538 static class Reader implements OFMessageReader<OFMatchV3> {
539 @Override
540 public OFMatchV3 readFrom(ChannelBuffer bb) throws OFParseError {
541 int start = bb.readerIndex();
542 // fixed value property type == 0x1
543 short type = bb.readShort();
544 if(type != (short) 0x1)
545 throw new OFParseError("Wrong type: Expected=0x1(0x1), got="+type);
546 int length = U16.f(bb.readShort());
547 if(length < MINIMUM_LENGTH)
548 throw new OFParseError("Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
549 if(bb.readableBytes() + (bb.readerIndex() - start) < length) {
550 // Buffer does not have all data yet
551 bb.readerIndex(start);
552 return null;
553 }
554 if(logger.isTraceEnabled())
555 logger.trace("readFrom - length={}", length);
556 OFOxmList oxmList = OFOxmList.readFrom(bb, length - (bb.readerIndex() - start), OFOxmVer13.READER);
557 // align message to 8 bytes (length does not contain alignment)
558 bb.skipBytes(((length + 7)/8 * 8 ) - length );
559
560 OFMatchV3Ver13 matchV3Ver13 = new OFMatchV3Ver13(
561 oxmList
562 );
563 if(logger.isTraceEnabled())
564 logger.trace("readFrom - read={}", matchV3Ver13);
565 return matchV3Ver13;
566 }
567 }
568
569 public void putTo(PrimitiveSink sink) {
570 FUNNEL.funnel(this, sink);
571 }
572
573 final static OFMatchV3Ver13Funnel FUNNEL = new OFMatchV3Ver13Funnel();
574 static class OFMatchV3Ver13Funnel implements Funnel<OFMatchV3Ver13> {
575 private static final long serialVersionUID = 1L;
576 @Override
577 public void funnel(OFMatchV3Ver13 message, PrimitiveSink sink) {
578 // fixed value property type = 0x1
579 sink.putShort((short) 0x1);
580 // FIXME: skip funnel of length
581 message.oxmList.putTo(sink);
582 }
583 }
584
585
586 public void writeTo(ChannelBuffer bb) {
587 WRITER.write(bb, this);
588 }
589
590 final static Writer WRITER = new Writer();
591 static class Writer implements OFMessageWriter<OFMatchV3Ver13> {
592 @Override
593 public void write(ChannelBuffer bb, OFMatchV3Ver13 message) {
594 int startIndex = bb.writerIndex();
595 // fixed value property type = 0x1
596 bb.writeShort((short) 0x1);
597 // length is length of variable message, will be updated at the end
598 int lengthIndex = bb.writerIndex();
599 bb.writeShort(U16.t(0));
600
601 message.oxmList.writeTo(bb);
602
603 // update length field
604 int length = bb.writerIndex() - startIndex;
605 int alignedLength = ((length + 7)/8 * 8);
606 bb.setShort(lengthIndex, length);
607 // align message to 8 bytes
608 bb.writeZero(alignedLength - length);
609
610 }
611 }
612
613 @Override
614 public String toString() {
615 StringBuilder b = new StringBuilder("OFMatchV3Ver13(");
616 boolean first = true;
617 for(MatchField<?> field : getMatchFields()) {
618 if(first)
619 first = false;
620 else
621 b.append(", ");
622 String name = field.getName();
623 b.append(name).append('=').append(this.get(field));
624 if(isPartiallyMasked(field)) {
625 b.append('/').append(this.getMasked(field).getMask());
626 }
627 }
628 b.append(")");
629 return b.toString();
630 }
631
632 @Override
633 public boolean equals(Object obj) {
634 if (this == obj)
635 return true;
636 if (obj == null)
637 return false;
638 if (getClass() != obj.getClass())
639 return false;
640 OFMatchV3Ver13 other = (OFMatchV3Ver13) obj;
641
642 if (oxmList == null) {
643 if (other.oxmList != null)
644 return false;
645 } else if (!oxmList.equals(other.oxmList))
646 return false;
647 return true;
648 }
649
650 @Override
651 public int hashCode() {
652 final int prime = 31;
653 int result = 1;
654
655 result = prime * result + ((oxmList == null) ? 0 : oxmList.hashCode());
656 return result;
657 }
658
659}