blob: 48f8b705fc73012f655ff83173a5cea3ab03a21b [file] [log] [blame]
Andreas Wundsambc679f72013-08-01 22:13:09 -07001
Yotam Harchol98af7752013-08-22 14:59:38 -07002 private OFOxmList.Builder oxmListBuilder;
3
4 private synchronized void initBuilder() {
5 if (oxmListBuilder != null)
6 return;
7 oxmListBuilder = new OFOxmList.Builder();
8 }
9
10 private synchronized 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
Andreas Wundsambc679f72013-08-01 22:13:09 -070021 }
22
23 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070024 public synchronized <F extends OFValueType<F>> F get(MatchField<F> field)
Andreas Wundsambc679f72013-08-01 22:13:09 -070025 throws UnsupportedOperationException {
Yotam Harchol98af7752013-08-22 14:59:38 -070026 OFOxm<F> value = getOxm(field);
27 if (value == null)
28 return null;
29 return value.getValue();
30 }
31
32 @Override
33 public synchronized <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());
Andreas Wundsambc679f72013-08-01 22:13:09 -070040 }
41
42 @Override
43 public boolean supports(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070044 return supportsField(field);
Andreas Wundsambc679f72013-08-01 22:13:09 -070045 }
46
47 @Override
48 public boolean supportsMasked(MatchField<?> field) {
Yotam Harchol98af7752013-08-22 14:59:38 -070049 return supportsField(field);
Andreas Wundsambc679f72013-08-01 22:13:09 -070050 }
51
52 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070053 public synchronized boolean isExact(MatchField<?> field) {
54 OFOxm<?> value = getOxm(field);
55 return (value != null && !value.isMasked());
Andreas Wundsambc679f72013-08-01 22:13:09 -070056 }
57
58 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070059 public synchronized boolean isFullyWildcarded(MatchField<?> field) {
60 OFOxm<?> value = getOxm(field);
61 return (value == null);
Andreas Wundsambc679f72013-08-01 22:13:09 -070062 }
63
64 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070065 public synchronized boolean isPartiallyMasked(MatchField<?> field) {
66 OFOxm<?> value = getOxm(field);
67 return (value != null && value.isMasked());
Andreas Wundsambc679f72013-08-01 22:13:09 -070068 }
69
70 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070071 public synchronized <F extends OFValueType<F>> Match.Builder setExact(
Andreas Wundsambc679f72013-08-01 22:13:09 -070072 MatchField<F> field, F value) {
Yotam Harchol98af7752013-08-22 14:59:38 -070073 initBuilder();
74 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValue(value, field);
75 this.oxmListBuilder.set(oxm);
76 updateOxmList();
77 return this;
Andreas Wundsambc679f72013-08-01 22:13:09 -070078 }
79
80 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070081 public synchronized <F extends OFValueType<F>> Match.Builder setMasked(
Andreas Wundsambc679f72013-08-01 22:13:09 -070082 MatchField<F> field, F value, F mask) {
Yotam Harchol98af7752013-08-22 14:59:38 -070083 initBuilder();
84 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromValueAndMask(value, mask, field);
85 this.oxmListBuilder.set(oxm);
86 updateOxmList();
87 return this;
Andreas Wundsambc679f72013-08-01 22:13:09 -070088 }
89
90 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -070091 public synchronized <F extends OFValueType<F>> Match.Builder setMasked(
Andreas Wundsambc679f72013-08-01 22:13:09 -070092 MatchField<F> field, Masked<F> valueWithMask) {
Yotam Harchol98af7752013-08-22 14:59:38 -070093 initBuilder();
94 OFOxm<F> oxm = OFFactories.getFactory(OFVersion.OF_13).oxms().fromMasked(valueWithMask, field);
95 this.oxmListBuilder.set(oxm);
96 updateOxmList();
97 return this;
Andreas Wundsambc679f72013-08-01 22:13:09 -070098 }
99
100 @Override
Yotam Harchol98af7752013-08-22 14:59:38 -0700101 public synchronized <F extends OFValueType<F>> Match.Builder wildcard(MatchField<F> field) {
102 initBuilder();
103 this.oxmListBuilder.unset(field);
104 updateOxmList();
105 return this;
Andreas Wundsambc679f72013-08-01 22:13:09 -0700106 }
107