@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)); } }
@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)); } }
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) {
InetAddress prefix1 = getSubnetPrefix(testAddress, filterMaskLen); InetAddress prefix2 = getSubnetPrefix(filterAddress, filterMaskLen); return (!prefix1.equals(prefix2));
private Status validateSubnetAddress() { if (!NetUtils.isIPAddressValid(subnet)) { return new Status(StatusCode.BADREQUEST, String.format("Invalid Subnet configuration: Invalid address: %s", subnet)); } if ((this.getIPMaskLen() == 0) || (this.getIPMaskLen() == 32)) { return new Status(StatusCode.BADREQUEST, String.format("Invalid Subnet configuration: Invalid mask: /%s", this.getIPMaskLen())); } //checks that address doesn't start with 0 or 255 String address = subnet.split("/")[0]; if (address.startsWith("0.") || address.startsWith("255.")) { return new Status(StatusCode.BADREQUEST, String.format("Invalid Subnet configuration: Invalid address: %s", address)); } byte[] bytePrefix = NetUtils.getSubnetPrefix(this.getIPAddress(), this.getIPMaskLen()).getAddress(); long prefix = BitBufferHelper.getLong(bytePrefix); if (prefix == 0) { return new Status(StatusCode.BADREQUEST, "Invalid network source address: subnet zero"); } //check that host is not set to all 0's or 1's long hostAddress = BitBufferHelper.getLong(this.getIPAddress().getAddress()) - prefix; if (hostAddress == 0 || hostAddress == Math.pow(2, 32-this.getIPMaskLen()) - 1) { return new Status(StatusCode.BADREQUEST, String.format("Invalid subnet gateway address: /%s", subnet)); } return new Status(StatusCode.SUCCESS); }
InetAddress subnetMask = null; if (thisMaskLen < otherMaskLen) { subnetPrefix = NetUtils.getSubnetPrefix(otherAddress, otherMaskLen); subnetMask = otherMask; } else { subnetPrefix = NetUtils.getSubnetPrefix(thisAddress, thisMaskLen); subnetMask = thisMask;
.getSubnetMaskLength(otherMask); if (thisMaskLen < otherMaskLen) { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen), otherMask)); } else { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(thisAddress, thisMaskLen), thisMask));