blob: 54b35baac5f1c603a8d53efb25e6fb65dd999c42 [file] [log] [blame]
Andreas Wundsam6b877352014-10-10 21:31:47 -07001
2 private OFOxmList.Builder oxmListBuilder;
3
4 private void initBuilder() {
5 if (oxmListBuilder != null)
6 return;
7 oxmListBuilder = new OFOxmList.Builder();
8 }
9
10 private void updateOxmList() {
11 this.oxmList = this.oxmListBuilder.build();
12 this.oxmListSet = true;
13 }
14
15 private <F extends OFValueType<F>> OFOxm<F> getOxm(MatchField<F> field) {
16//:: if has_parent:
17 return this.oxmListSet ? this.oxmList.get(field) : parentMessage.oxmList.get(field);
18//:: else:
19 return this.oxmListSet ? this.oxmList.get(field) : null;
20//:: #endif
21 }
22
23 @Override
24 public <F extends OFValueType<F>> F get(MatchField<F> field)
25 throws UnsupportedOperationException {
26 OFOxm<F> value = getOxm(field);
27 if (value == null)
28 return null;
29 return value.getValue();
30 }
31
32 @Override
33 public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field)
34 throws UnsupportedOperationException {
35 OFOxm<F> value = getOxm(field);
36 if (value == null || !value.isMasked())
37 return null;
38 // TODO: If changing OXMs to extend Masked, then use it here
39 return Masked.of(value.getValue(), value.getMask());
40 }
41
42 @Override
43 public boolean supports(MatchField<?> field) {
44 return supportsField(field);
45 }
46
47 @Override
48 public boolean supportsMasked(MatchField<?> field) {
49 return supportsField(field);
50 }
51
52 @Override
53 public boolean isExact(MatchField<?> field) {
54 OFOxm<?> value = getOxm(field);
55 return (value != null && !value.isMasked());
56 }
57
58 @Override
59 public boolean isFullyWildcarded(MatchField<?> field) {
60 OFOxm<?> value = getOxm(field);
61 return (value == null);
62 }
63
64 @Override
65 public boolean isPartiallyMasked(MatchField<?> field) {
66 OFOxm<?> value = getOxm(field);
67 return (value != null && value.isMasked());
68 }
69
70 @Override
71 public <F extends OFValueType<F>> Match.Builder setExact(
72 MatchField<F> field, F value) {
73 initBuilder();
74 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.${version.constant_version}).oxms().fromValue(value, field);
75 this.oxmListBuilder.set(oxm);
76 updateOxmList();
77 return this;
78 }
79
80 @Override
81 public <F extends OFValueType<F>> Match.Builder setMasked(
82 MatchField<F> field, F value, F mask) {
83 initBuilder();
84 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.${version.constant_version}).oxms().fromValueAndMask(value, mask, field);
85 this.oxmListBuilder.set(oxm);
86 updateOxmList();
87 return this;
88 }
89
90 @Override
91 public <F extends OFValueType<F>> Match.Builder setMasked(
92 MatchField<F> field, Masked<F> valueWithMask) {
93 initBuilder();
94 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.${version.constant_version}).oxms().fromMasked(valueWithMask, field);
95 this.oxmListBuilder.set(oxm);
96 updateOxmList();
97 return this;
98 }
99
100 @Override
101 public <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) {
102 initBuilder();
103 this.oxmListBuilder.unset(field);
104 updateOxmList();
105 return this;
106 }