/** * Returns the prefix size in bits of the specified subnet mask. Example: * For the subnet mask 255.255.255.128 it returns 25 while for 255.0.0.0 it * returns 8. If the passed subnetMask object is null, 0 is returned * * @param subnetMask * the subnet mask as InetAddress * @return the prefix length as number of bits */ public static int getSubnetMaskLength(InetAddress subnetMask) { return subnetMask == null ? 0 : NetUtils.getSubnetMaskLength(subnetMask.getAddress()); }
public boolean equalMasks(Object a, Object b) { if (a == b) { return true; } switch (this) { case NW_SRC: case NW_DST: /* * For network address mask, network node may return full mask for * flows the controller generated with a null mask object */ if (a == null || b == null) { InetAddress mask = (a == null) ? (InetAddress) b : (InetAddress) a; int maxLength = (mask instanceof Inet4Address) ? 32 : 128; return (NetUtils.getSubnetMaskLength(mask) == maxLength); } default: if (a == null) { return false; } return a.equals(b); } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof NwSrc)) { return false; } NwSrc other = (NwSrc) obj; // Equality to be checked against prefix addresses int thisMaskLen = (this.mask == null) ? ((this.address instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(this.mask); int otherMaskLen = (other.mask == null) ? ((other.address instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(other.mask); return NetUtils.getSubnetPrefix(address, thisMaskLen).equals( NetUtils.getSubnetPrefix(other.address, otherMaskLen)); } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof NwDst)) { return false; } NwDst other = (NwDst) obj; // Equality to be checked against prefix addresses int thisMaskLen = (this.mask == null) ? ((this.address instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(this.mask); int otherMaskLen = (other.mask == null) ? ((other.address instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(other.mask); return NetUtils.getSubnetPrefix(address, thisMaskLen).equals( NetUtils.getSubnetPrefix(other.address, otherMaskLen)); } }
this.dstIPv6SubnetMaskbits = (short)NetUtils.getSubnetMaskLength(mbytes); this.nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; this.match_len += 36;
public void setNetworkDestination(InetAddress address, InetAddress mask) { if (address instanceof Inet6Address) { this.nwDst = (Inet6Address) address; if (mask == null) { this.nwDstState = MatchFieldState.MATCH_FIELD_ONLY; this.match_len += (address instanceof Inet6Address) ? 20 : 8; } else { this.dstIPv6SubnetMaskbits = (short)NetUtils.getSubnetMaskLength(mask); this.nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; this.match_len += (address instanceof Inet6Address) ? 36 : 12; } } else { this.setNetworkDestination(NetUtils.byteArray4ToInt(address.getAddress())); this.wildcards ^= (((1 << 6) - 1) << 14); if (mask == null) { this.nwDstState = MatchFieldState.MATCH_FIELD_ONLY; this.match_len += 8; } else { this.nwDstState = MatchFieldState.MATCH_FIELD_WITH_MASK; this.match_len += 12; this.wildcards |= ((32 - NetUtils.getSubnetMaskLength(mask)) << 14); } } }
this.srcIPv6SubnetMaskbits = (short)NetUtils.getSubnetMaskLength(mbytes); this.nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; this.match_len += 36;
public void setNetworkSource(InetAddress address, InetAddress mask) { if (address instanceof Inet6Address) { this.nwSrc = (Inet6Address) address; if (mask == null) { this.nwSrcState = MatchFieldState.MATCH_FIELD_ONLY; this.match_len += (address instanceof Inet6Address) ? 20 : 8; } else { this.srcIPv6SubnetMaskbits = (short)NetUtils.getSubnetMaskLength(mask); this.nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; this.match_len += (address instanceof Inet6Address) ? 36 : 12; } } else { super.setNetworkSource(NetUtils.byteArray4ToInt(address.getAddress())); this.wildcards ^= (((1 << 6) - 1) << 8); if (mask == null) { this.nwSrcState = MatchFieldState.MATCH_FIELD_ONLY; this.match_len += 8; } else { this.nwSrcState = MatchFieldState.MATCH_FIELD_WITH_MASK; this.match_len += 12; this.wildcards |= ((32 - NetUtils.getSubnetMaskLength(mask)) << 8); } } }
public boolean equals(Object value1, Object value2, Object mask1, Object mask2) { switch (this) { case NW_SRC: case NW_DST: // Equality to be checked against prefix addresses InetAddress thisIP = (InetAddress) value1; int thisMaskLen = (mask1 == null) ? ((thisIP instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) mask1); InetAddress otherIP = (InetAddress) value2; int otherMaskLen = (mask2 == null) ? ((otherIP instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) mask2); return NetUtils.getSubnetPrefix(thisIP, thisMaskLen) .equals(NetUtils.getSubnetPrefix(otherIP, otherMaskLen)); default: return (this.equalValues(value1, value2) && this.equalMasks(mask1, mask2)); } }
public int hashCode(Object v, Object m) { final int prime = 31; int result = 1; result = prime * result + this.calculateConsistentHashCode(); switch (this) { case DL_SRC: case DL_DST: result = prime * result + ((v == null)? 0 : NetUtils.byteArray4ToInt((byte[])v)); result = prime * result + ((m == null)? 0 : NetUtils.byteArray4ToInt((byte[])m)); break; case NW_SRC: case NW_DST: // Hash code has to take into account only prefix address InetAddress ip = (InetAddress) v; int maskLen = (m == null) ? ((ip instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) m); InetAddress prefix = NetUtils.getSubnetPrefix(ip, maskLen); result = prime * result + ((v == null)? 0 : prefix.hashCode()); break; default: result = prime * result + ((v == null)? 0 : v.hashCode()); result = prime * result + ((m == null)? 0 : m.hashCode()); } return result; } public boolean equalValues(Object a, Object b) {
.getSubnetMaskLength(testMask); int filterMaskLen = (filterMask == null) ? ((testAddress instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(filterMask);
.getSubnetMaskLength(thisMask); int otherMaskLen = (otherMask == null) ? ((otherAddress instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(otherMask);
.getSubnetMaskLength(thisMask); int otherMaskLen = (otherMask == null) ? ((otherAddress instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength(otherMask); if (thisMaskLen < otherMaskLen) { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen),
if (!isIPv6) { ofMatch.setNetworkSource(NetUtils.byteArray4ToInt(address.getAddress())); int maskLength = (mask == null) ? 32 : NetUtils.getSubnetMaskLength(mask); wildcards = (wildcards & ~OFMatch.OFPFW_NW_SRC_MASK) | ((32 - maskLength) << OFMatch.OFPFW_NW_SRC_SHIFT); } else { if (!isIPv6) { ofMatch.setNetworkDestination(NetUtils.byteArray4ToInt(address.getAddress())); int maskLength = (mask == null) ? 32 : NetUtils.getSubnetMaskLength(mask); wildcards = (wildcards & ~OFMatch.OFPFW_NW_DST_MASK) | ((32 - maskLength) << OFMatch.OFPFW_NW_DST_SHIFT); } else {