- if (this.intersetcs(other)) {
- for (MatchType type : MatchType.values()) {
- if (this.isAny(type) && other.isAny(type)) {
- continue;
- }
- if (this.isAny(type)) {
- intersection.setField(other.getField(type).clone());
- continue;
- } else if (other.isAny(type)) {
- intersection.setField(this.getField(type).clone());
- continue;
- }
- // Either they are equal or it is about IP address
- switch (type) {
- // When it is about IP address, take the wider prefix address between the twos
- case NW_SRC:
- case NW_DST:
- MatchField thisField = this.getField(type);
- MatchField otherField = other.getField(type);
- InetAddress thisAddress = (InetAddress) thisField.getValue();
- InetAddress otherAddress = (InetAddress) otherField.getValue();
- InetAddress thisMask = (InetAddress) thisField.getMask();
- InetAddress otherMask = (InetAddress) otherField.getMask();
-
- int thisMaskLen = (thisMask == null) ? ((thisAddress instanceof Inet4Address) ? 32 : 128)
- : NetUtils.getSubnetMaskLength(thisMask);
- int otherMaskLen = (otherMask == null) ? ((otherAddress instanceof Inet4Address) ? 32 : 128)
- : NetUtils.getSubnetMaskLength(otherMask);
- if (otherMaskLen < thisMaskLen) {
- intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen), otherMask));
- } else {
- intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(thisAddress, thisMaskLen), thisMask));
- }
- break;
- default:
- // this and other match field are equal for this type, pick this match field
- intersection.setField(this.getField(type).clone());
+ for (MatchType type : MatchType.values()) {
+ if (this.isAny(type) && other.isAny(type)) {
+ continue;
+ }
+ if (this.isAny(type)) {
+ intersection.setField(other.getField(type).clone());
+ continue;
+ } else if (other.isAny(type)) {
+ intersection.setField(this.getField(type).clone());
+ continue;
+ }
+ // Either they are equal or it is about IP address
+ switch (type) {
+ // When it is about IP address, take the wider prefix address
+ // between the twos
+ case NW_SRC:
+ case NW_DST:
+ MatchField thisField = this.getField(type);
+ MatchField otherField = other.getField(type);
+ InetAddress thisAddress = (InetAddress) thisField.getValue();
+ InetAddress otherAddress = (InetAddress) otherField.getValue();
+ InetAddress thisMask = (InetAddress) thisField.getMask();
+ InetAddress otherMask = (InetAddress) otherField.getMask();
+
+ int thisMaskLen = (thisMask == null) ? ((thisAddress instanceof Inet4Address) ? 32 : 128) : NetUtils
+ .getSubnetMaskLength(thisMask);
+ int otherMaskLen = (otherMask == null) ? ((otherAddress instanceof Inet4Address) ? 32 : 128) : NetUtils
+ .getSubnetMaskLength(otherMask);
+ if (otherMaskLen < thisMaskLen) {
+ intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen),
+ otherMask));
+ } else {
+ intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(thisAddress, thisMaskLen),
+ thisMask));