Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 1 | |
| 2 | @Override |
| 3 | public <F extends OFValueType<F>> F get(MatchField<F> field) |
| 4 | throws UnsupportedOperationException { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 5 | if (!supports(field)) |
| 6 | throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName()); |
| 7 | |
| 8 | OFOxm<F> oxm = this.oxmList.get(field); |
| 9 | |
| 10 | if (oxm == null || !field.arePrerequisitesOK(this)) |
| 11 | return null; |
| 12 | |
| 13 | return oxm.getValue(); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | @Override |
| 17 | public <F extends OFValueType<F>> Masked<F> getMasked(MatchField<F> field) |
| 18 | throws UnsupportedOperationException { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 19 | if (!supportsMasked(field)) |
| 20 | throw new UnsupportedOperationException("OFMatchV3Ver13 does not support masked matching on field " + field.getName()); |
| 21 | |
| 22 | OFOxm<F> oxm = this.oxmList.get(field); |
| 23 | |
| 24 | if (oxm == null || !field.arePrerequisitesOK(this)) |
| 25 | return null; |
| 26 | |
| 27 | if (oxm.getMask() == null) |
| 28 | return null; |
| 29 | |
| 30 | // TODO: Make OfOxm extend Masked and just return the OXM? |
| 31 | return Masked.of(oxm.getValue(), oxm.getMask()); |
| 32 | } |
| 33 | |
| 34 | private static boolean supportsField(MatchField<?> field) { |
| 35 | switch (field.id) { |
| 36 | case IN_PORT: |
| 37 | case IN_PHY_PORT: |
| 38 | case METADATA: |
| 39 | case ETH_DST: |
| 40 | case ETH_SRC: |
| 41 | case ETH_TYPE: |
| 42 | case VLAN_VID: |
| 43 | case VLAN_PCP: |
| 44 | case IP_DSCP: |
| 45 | case IP_ECN: |
| 46 | case IP_PROTO: |
| 47 | case IPV4_SRC: |
| 48 | case IPV4_DST: |
| 49 | case TCP_SRC: |
| 50 | case TCP_DST: |
| 51 | case UDP_SRC: |
| 52 | case UDP_DST: |
| 53 | case SCTP_SRC: |
| 54 | case SCTP_DST: |
| 55 | case ICMPV4_TYPE: |
| 56 | case ICMPV4_CODE: |
| 57 | case ARP_OP: |
| 58 | case ARP_SPA: |
| 59 | case ARP_TPA: |
| 60 | case ARP_SHA: |
| 61 | case ARP_THA: |
| 62 | case IPV6_SRC: |
| 63 | case IPV6_DST: |
| 64 | case IPV6_FLABEL: |
Andreas Wundsam | 2fdf99d | 2013-10-27 06:15:47 -0700 | [diff] [blame] | 65 | case BSN_IN_PORTS_128: |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 66 | return true; |
| 67 | default: |
| 68 | return false; |
| 69 | } |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public boolean supports(MatchField<?> field) { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 74 | return supportsField(field); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean supportsMasked(MatchField<?> field) { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 79 | return supportsField(field); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean isExact(MatchField<?> field) { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 84 | if (!supports(field)) |
| 85 | throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName()); |
| 86 | |
| 87 | OFOxm<?> oxm = this.oxmList.get(field); |
| 88 | |
| 89 | return oxm != null && !oxm.isMasked(); |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public boolean isFullyWildcarded(MatchField<?> field) { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 94 | if (!supports(field)) |
| 95 | throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName()); |
| 96 | |
| 97 | OFOxm<?> oxm = this.oxmList.get(field); |
| 98 | |
| 99 | return oxm == null; |
Andreas Wundsam | bc679f7 | 2013-08-01 22:13:09 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean isPartiallyMasked(MatchField<?> field) { |
Yotam Harchol | 98af775 | 2013-08-22 14:59:38 -0700 | [diff] [blame] | 104 | if (!supports(field)) |
| 105 | throw new UnsupportedOperationException("OFMatchV3Ver13 does not support matching on field " + field.getName()); |
| 106 | |
| 107 | OFOxm<?> oxm = this.oxmList.get(field); |
| 108 | |
| 109 | return oxm != null && oxm.isMasked(); |
Andreas Wundsam | 2fdf99d | 2013-10-27 06:15:47 -0700 | [diff] [blame] | 110 | } |
Rob Vaterlaus | 934b4ad | 2013-11-12 10:08:59 -0800 | [diff] [blame] | 111 | |
| 112 | private class MatchFieldIterator extends UnmodifiableIterator<MatchField<?>> { |
| 113 | private Iterator<OFOxm<?>> oxmIterator; |
| 114 | |
| 115 | MatchFieldIterator() { |
| 116 | oxmIterator = oxmList.iterator(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public boolean hasNext() { |
| 121 | return oxmIterator.hasNext(); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public MatchField<?> next() { |
| 126 | OFOxm<?> next = oxmIterator.next(); |
| 127 | return next.getMatchField(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public Iterable<MatchField<?>> getMatchFields() { |
| 133 | return new Iterable<MatchField<?>>() { |
| 134 | public Iterator<MatchField<?>> iterator() { |
| 135 | return new MatchFieldIterator(); |
| 136 | } |
| 137 | }; |
| 138 | } |