Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 1 | |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 2 | 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 Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 24 | public synchronized <F extends OFValueType<F>> F get(MatchField<F> field) |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 25 | throws UnsupportedOperationException { |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 26 | 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 Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public boolean supports(MatchField<?> field) { |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 44 | return supportsField(field); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public boolean supportsMasked(MatchField<?> field) { |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 49 | return supportsField(field); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 53 | public synchronized boolean isExact(MatchField<?> field) { |
| 54 | OFOxm<?> value = getOxm(field); |
| 55 | return (value != null && !value.isMasked()); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 59 | public synchronized boolean isFullyWildcarded(MatchField<?> field) { |
| 60 | OFOxm<?> value = getOxm(field); |
| 61 | return (value == null); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 65 | public synchronized boolean isPartiallyMasked(MatchField<?> field) { |
| 66 | OFOxm<?> value = getOxm(field); |
| 67 | return (value != null && value.isMasked()); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 71 | public synchronized <F extends OFValueType<F>> Match.Builder setExact( |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 72 | MatchField<F> field, F value) { |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 73 | 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 Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 81 | public synchronized <F extends OFValueType<F>> Match.Builder setMasked( |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 82 | MatchField<F> field, F value, F mask) { |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 83 | 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 Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 91 | public synchronized <F extends OFValueType<F>> Match.Builder setMasked( |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 92 | MatchField<F> field, Masked<F> valueWithMask) { |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 93 | 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 Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
Yotam Harchol | bd1d728 | 2013-08-22 20:10:31 -0700 | [diff] [blame] | 101 | 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 Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 106 | } |