Committed by
Gerrit Code Review
Adding eth masking in match
Change-Id: I95e0ee66b1c6c139de7672f9bc04871fd0ead6d7
Showing
8 changed files
with
118 additions
and
9 deletions
| ... | @@ -174,11 +174,21 @@ public final class DefaultTrafficSelector implements TrafficSelector { | ... | @@ -174,11 +174,21 @@ public final class DefaultTrafficSelector implements TrafficSelector { |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | @Override | 176 | @Override |
| 177 | + public Builder matchEthDstMasked(MacAddress addr, MacAddress mask) { | ||
| 178 | + return add(Criteria.matchEthDstMasked(addr, mask)); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + @Override | ||
| 177 | public Builder matchEthSrc(MacAddress addr) { | 182 | public Builder matchEthSrc(MacAddress addr) { |
| 178 | return add(Criteria.matchEthSrc(addr)); | 183 | return add(Criteria.matchEthSrc(addr)); |
| 179 | } | 184 | } |
| 180 | 185 | ||
| 181 | @Override | 186 | @Override |
| 187 | + public Builder matchEthSrcMasked(MacAddress addr, MacAddress mask) { | ||
| 188 | + return add(Criteria.matchEthSrcMasked(addr, mask)); | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + @Override | ||
| 182 | public Builder matchEthType(short ethType) { | 192 | public Builder matchEthType(short ethType) { |
| 183 | return add(Criteria.matchEthType(ethType)); | 193 | return add(Criteria.matchEthType(ethType)); |
| 184 | } | 194 | } | ... | ... |
| ... | @@ -97,6 +97,15 @@ public interface TrafficSelector { | ... | @@ -97,6 +97,15 @@ public interface TrafficSelector { |
| 97 | Builder matchEthDst(MacAddress addr); | 97 | Builder matchEthDst(MacAddress addr); |
| 98 | 98 | ||
| 99 | /** | 99 | /** |
| 100 | + * Matches a l2 dst address with mask. | ||
| 101 | + * | ||
| 102 | + * @param addr a l2 address | ||
| 103 | + * @param mask a mask for an l2 address | ||
| 104 | + * @return a selection builder | ||
| 105 | + */ | ||
| 106 | + Builder matchEthDstMasked(MacAddress addr, MacAddress mask); | ||
| 107 | + | ||
| 108 | + /** | ||
| 100 | * Matches a l2 src address. | 109 | * Matches a l2 src address. |
| 101 | * | 110 | * |
| 102 | * @param addr a l2 address | 111 | * @param addr a l2 address |
| ... | @@ -105,6 +114,15 @@ public interface TrafficSelector { | ... | @@ -105,6 +114,15 @@ public interface TrafficSelector { |
| 105 | Builder matchEthSrc(MacAddress addr); | 114 | Builder matchEthSrc(MacAddress addr); |
| 106 | 115 | ||
| 107 | /** | 116 | /** |
| 117 | + * Matches a l2 src address with mask. | ||
| 118 | + * | ||
| 119 | + * @param addr a l2 address | ||
| 120 | + * @param mask a mask for an l2 address | ||
| 121 | + * @return a selection builder | ||
| 122 | + */ | ||
| 123 | + Builder matchEthSrcMasked(MacAddress addr, MacAddress mask); | ||
| 124 | + | ||
| 125 | + /** | ||
| 108 | * Matches the ethernet type. | 126 | * Matches the ethernet type. |
| 109 | * | 127 | * |
| 110 | * @param ethType an ethernet type | 128 | * @param ethType an ethernet type | ... | ... |
| ... | @@ -86,6 +86,17 @@ public final class Criteria { | ... | @@ -86,6 +86,17 @@ public final class Criteria { |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | /** | 88 | /** |
| 89 | + * Creates a masked match on ETH_DST field using the specified value and mask. | ||
| 90 | + * | ||
| 91 | + * @param mac MAC address value | ||
| 92 | + * @param mask MAC address masking | ||
| 93 | + * @return match criterion | ||
| 94 | + */ | ||
| 95 | + public static Criterion matchEthDstMasked(MacAddress mac, MacAddress mask) { | ||
| 96 | + return new EthCriterion(mac, mask, Type.ETH_DST_MASKED); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 89 | * Creates a match on ETH_SRC field using the specified value. This value | 100 | * Creates a match on ETH_SRC field using the specified value. This value |
| 90 | * may be a wildcard mask. | 101 | * may be a wildcard mask. |
| 91 | * | 102 | * |
| ... | @@ -97,6 +108,17 @@ public final class Criteria { | ... | @@ -97,6 +108,17 @@ public final class Criteria { |
| 97 | } | 108 | } |
| 98 | 109 | ||
| 99 | /** | 110 | /** |
| 111 | + * Creates a masked match on ETH_SRC field using the specified value and mask. | ||
| 112 | + * | ||
| 113 | + * @param mac MAC address value | ||
| 114 | + * @param mask MAC address masking | ||
| 115 | + * @return match criterion | ||
| 116 | + */ | ||
| 117 | + public static Criterion matchEthSrcMasked(MacAddress mac, MacAddress mask) { | ||
| 118 | + return new EthCriterion(mac, mask, Type.ETH_SRC_MASKED); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 100 | * Creates a match on ETH_TYPE field using the specified value. | 122 | * Creates a match on ETH_TYPE field using the specified value. |
| 101 | * | 123 | * |
| 102 | * @param ethType eth type value (16 bits unsigned integer) | 124 | * @param ethType eth type value (16 bits unsigned integer) | ... | ... |
| ... | @@ -40,9 +40,15 @@ public interface Criterion { | ... | @@ -40,9 +40,15 @@ public interface Criterion { |
| 40 | /** Ethernet destination address. */ | 40 | /** Ethernet destination address. */ |
| 41 | ETH_DST, | 41 | ETH_DST, |
| 42 | 42 | ||
| 43 | + /** Ethernet destination address with masking. */ | ||
| 44 | + ETH_DST_MASKED, | ||
| 45 | + | ||
| 43 | /** Ethernet source address. */ | 46 | /** Ethernet source address. */ |
| 44 | ETH_SRC, | 47 | ETH_SRC, |
| 45 | 48 | ||
| 49 | + /** Ethernet source address with masking. */ | ||
| 50 | + ETH_SRC_MASKED, | ||
| 51 | + | ||
| 46 | /** Ethernet frame type. */ | 52 | /** Ethernet frame type. */ |
| 47 | ETH_TYPE, | 53 | ETH_TYPE, |
| 48 | 54 | ... | ... |
| ... | @@ -24,20 +24,34 @@ import java.util.Objects; | ... | @@ -24,20 +24,34 @@ import java.util.Objects; |
| 24 | */ | 24 | */ |
| 25 | public final class EthCriterion implements Criterion { | 25 | public final class EthCriterion implements Criterion { |
| 26 | private final MacAddress mac; | 26 | private final MacAddress mac; |
| 27 | + private final MacAddress mask; | ||
| 27 | private final Type type; | 28 | private final Type type; |
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | * Constructor. | 31 | * Constructor. |
| 31 | * | 32 | * |
| 32 | * @param mac the source or destination MAC address to match | 33 | * @param mac the source or destination MAC address to match |
| 33 | - * @param type the match type. Should be either Type.ETH_DST or | 34 | + * @param mask the mask for the address |
| 34 | - * Type.ETH_SRC | 35 | + * @param type the match type. Should be either Type.ETH_DST_MASKED or |
| 36 | + * Type.ETH_SRC_MASKED | ||
| 35 | */ | 37 | */ |
| 36 | - EthCriterion(MacAddress mac, Type type) { | 38 | + EthCriterion(MacAddress mac, MacAddress mask, Type type) { |
| 37 | this.mac = mac; | 39 | this.mac = mac; |
| 40 | + this.mask = mask; | ||
| 38 | this.type = type; | 41 | this.type = type; |
| 39 | } | 42 | } |
| 40 | 43 | ||
| 44 | + /** | ||
| 45 | + * Constructor. | ||
| 46 | + * | ||
| 47 | + * @param mac the source or destination MAC address to match | ||
| 48 | + * @param type the match type. Should be either Type.ETH_DST or | ||
| 49 | + * Type.ETH_SRC | ||
| 50 | + */ | ||
| 51 | + EthCriterion(MacAddress mac, Type type) { | ||
| 52 | + this(mac, null, type); | ||
| 53 | + } | ||
| 54 | + | ||
| 41 | @Override | 55 | @Override |
| 42 | public Type type() { | 56 | public Type type() { |
| 43 | return this.type; | 57 | return this.type; |
| ... | @@ -52,14 +66,23 @@ public final class EthCriterion implements Criterion { | ... | @@ -52,14 +66,23 @@ public final class EthCriterion implements Criterion { |
| 52 | return this.mac; | 66 | return this.mac; |
| 53 | } | 67 | } |
| 54 | 68 | ||
| 69 | + /** | ||
| 70 | + * Gets the mask for the MAC address to match. | ||
| 71 | + * | ||
| 72 | + * @return the MAC address to match | ||
| 73 | + */ | ||
| 74 | + public MacAddress mask() { | ||
| 75 | + return this.mask; | ||
| 76 | + } | ||
| 77 | + | ||
| 55 | @Override | 78 | @Override |
| 56 | public String toString() { | 79 | public String toString() { |
| 57 | - return type().toString() + SEPARATOR + mac; | 80 | + return type().toString() + SEPARATOR + mac + "/" + mask; |
| 58 | } | 81 | } |
| 59 | 82 | ||
| 60 | @Override | 83 | @Override |
| 61 | public int hashCode() { | 84 | public int hashCode() { |
| 62 | - return Objects.hash(type.ordinal(), mac); | 85 | + return Objects.hash(type.ordinal(), mac, mask); |
| 63 | } | 86 | } |
| 64 | 87 | ||
| 65 | @Override | 88 | @Override |
| ... | @@ -70,6 +93,7 @@ public final class EthCriterion implements Criterion { | ... | @@ -70,6 +93,7 @@ public final class EthCriterion implements Criterion { |
| 70 | if (obj instanceof EthCriterion) { | 93 | if (obj instanceof EthCriterion) { |
| 71 | EthCriterion that = (EthCriterion) obj; | 94 | EthCriterion that = (EthCriterion) obj; |
| 72 | return Objects.equals(mac, that.mac) && | 95 | return Objects.equals(mac, that.mac) && |
| 96 | + Objects.equals(mask, that.mask) && | ||
| 73 | Objects.equals(type, that.type); | 97 | Objects.equals(type, that.type); |
| 74 | } | 98 | } |
| 75 | return false; | 99 | return false; | ... | ... |
| ... | @@ -130,6 +130,9 @@ public final class EncodeCriterionCodecHelper { | ... | @@ -130,6 +130,9 @@ public final class EncodeCriterionCodecHelper { |
| 130 | formatMap.put(Criterion.Type.ACTSET_OUTPUT, new FormatUnknown()); | 130 | formatMap.put(Criterion.Type.ACTSET_OUTPUT, new FormatUnknown()); |
| 131 | formatMap.put(Criterion.Type.PACKET_TYPE, new FormatUnknown()); | 131 | formatMap.put(Criterion.Type.PACKET_TYPE, new FormatUnknown()); |
| 132 | formatMap.put(Criterion.Type.EXTENSION, new FormatUnknown()); | 132 | formatMap.put(Criterion.Type.EXTENSION, new FormatUnknown()); |
| 133 | + formatMap.put(Criterion.Type.ETH_DST_MASKED, new FormatUnknown()); | ||
| 134 | + formatMap.put(Criterion.Type.ETH_SRC_MASKED, new FormatUnknown()); | ||
| 135 | + | ||
| 133 | } | 136 | } |
| 134 | 137 | ||
| 135 | private interface CriterionTypeFormatter { | 138 | private interface CriterionTypeFormatter { | ... | ... |
| ... | @@ -615,12 +615,26 @@ public class FlowEntryBuilder { | ... | @@ -615,12 +615,26 @@ public class FlowEntryBuilder { |
| 615 | builder.matchMetadata(metadata); | 615 | builder.matchMetadata(metadata); |
| 616 | break; | 616 | break; |
| 617 | case ETH_DST: | 617 | case ETH_DST: |
| 618 | - mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); | 618 | + if (match.isPartiallyMasked(MatchField.ETH_DST)) { |
| 619 | - builder.matchEthDst(mac); | 619 | + Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = |
| 620 | + match.getMasked(MatchField.ETH_DST); | ||
| 621 | + builder.matchEthDstMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), | ||
| 622 | + MacAddress.valueOf(maskedMac.getMask().getLong())); | ||
| 623 | + } else { | ||
| 624 | + mac = MacAddress.valueOf(match.get(MatchField.ETH_DST).getLong()); | ||
| 625 | + builder.matchEthDst(mac); | ||
| 626 | + } | ||
| 620 | break; | 627 | break; |
| 621 | case ETH_SRC: | 628 | case ETH_SRC: |
| 622 | - mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); | 629 | + if (match.isPartiallyMasked(MatchField.ETH_SRC)) { |
| 623 | - builder.matchEthSrc(mac); | 630 | + Masked<org.projectfloodlight.openflow.types.MacAddress> maskedMac = |
| 631 | + match.getMasked(MatchField.ETH_SRC); | ||
| 632 | + builder.matchEthSrcMasked(MacAddress.valueOf(maskedMac.getValue().getLong()), | ||
| 633 | + MacAddress.valueOf(maskedMac.getMask().getLong())); | ||
| 634 | + } else { | ||
| 635 | + mac = MacAddress.valueOf(match.get(MatchField.ETH_SRC).getLong()); | ||
| 636 | + builder.matchEthSrc(mac); | ||
| 637 | + } | ||
| 624 | break; | 638 | break; |
| 625 | case ETH_TYPE: | 639 | case ETH_TYPE: |
| 626 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); | 640 | int ethType = match.get(MatchField.ETH_TYPE).getValue(); | ... | ... |
| ... | @@ -219,11 +219,23 @@ public abstract class FlowModBuilder { | ... | @@ -219,11 +219,23 @@ public abstract class FlowModBuilder { |
| 219 | mBuilder.setExact(MatchField.ETH_DST, | 219 | mBuilder.setExact(MatchField.ETH_DST, |
| 220 | MacAddress.of(ethCriterion.mac().toLong())); | 220 | MacAddress.of(ethCriterion.mac().toLong())); |
| 221 | break; | 221 | break; |
| 222 | + case ETH_DST_MASKED: | ||
| 223 | + ethCriterion = (EthCriterion) c; | ||
| 224 | + mBuilder.setMasked(MatchField.ETH_DST, | ||
| 225 | + MacAddress.of(ethCriterion.mac().toLong()), | ||
| 226 | + MacAddress.of(ethCriterion.mask().toLong())); | ||
| 227 | + break; | ||
| 222 | case ETH_SRC: | 228 | case ETH_SRC: |
| 223 | ethCriterion = (EthCriterion) c; | 229 | ethCriterion = (EthCriterion) c; |
| 224 | mBuilder.setExact(MatchField.ETH_SRC, | 230 | mBuilder.setExact(MatchField.ETH_SRC, |
| 225 | MacAddress.of(ethCriterion.mac().toLong())); | 231 | MacAddress.of(ethCriterion.mac().toLong())); |
| 226 | break; | 232 | break; |
| 233 | + case ETH_SRC_MASKED: | ||
| 234 | + ethCriterion = (EthCriterion) c; | ||
| 235 | + mBuilder.setMasked(MatchField.ETH_SRC, | ||
| 236 | + MacAddress.of(ethCriterion.mac().toLong()), | ||
| 237 | + MacAddress.of(ethCriterion.mask().toLong())); | ||
| 238 | + break; | ||
| 227 | case ETH_TYPE: | 239 | case ETH_TYPE: |
| 228 | EthTypeCriterion ethType = (EthTypeCriterion) c; | 240 | EthTypeCriterion ethType = (EthTypeCriterion) c; |
| 229 | mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort())); | 241 | mBuilder.setExact(MatchField.ETH_TYPE, EthType.of(ethType.ethType().toShort())); | ... | ... |
-
Please register or login to post a comment