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