X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2FSubnet.java;h=2794109c242bc420677b1e6209bc72921a8a7f6d;hp=16c09fe3f6a4ddfe62623293b055b53eabde15c0;hb=795acce15158be694bbc8a580ff2feda4cf0b555;hpb=5fe4a2c1eb78c0d0fe349354f39df4861ded6ee3;ds=sidebyside diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java index 16c09fe3f6..2794109c24 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Subnet.java @@ -25,6 +25,7 @@ public class Subnet implements Cloneable, Serializable { private static final long serialVersionUID = 1L; // Key fields private InetAddress networkAddress; + private transient InetAddress subnetPrefix; private short subnetMaskLength; // Property fields private short vlan; @@ -114,6 +115,7 @@ public class Subnet implements Cloneable, Serializable { */ public Subnet setNetworkAddress(InetAddress networkAddress) { this.networkAddress = networkAddress; + this.subnetPrefix = null; return this; } @@ -159,17 +161,15 @@ public class Subnet implements Cloneable, Serializable { if (ip == null) { return false; } - InetAddress thisPrefix = getPrefixForAddress(this.networkAddress); - InetAddress otherPrefix = getPrefixForAddress(ip); - if ((thisPrefix == null) || (otherPrefix == null)) { - return false; - } - if (thisPrefix.equals(otherPrefix)) { - return true; + if(subnetPrefix == null) { + subnetPrefix = getPrefixForAddress(this.networkAddress); } - else { - return false; + InetAddress otherPrefix = getPrefixForAddress(ip); + boolean isSubnetOf = true; + if (((subnetPrefix == null) || (otherPrefix == null)) || (!subnetPrefix.equals(otherPrefix)) ) { + isSubnetOf = false; } + return isSubnetOf; } public short getVlan() { @@ -248,17 +248,7 @@ public class Subnet implements Cloneable, Serializable { } public boolean isMutualExclusive(Subnet otherSubnet) { - if (this.networkAddress.getClass() != otherSubnet.networkAddress - .getClass()) { - return true; - } - if (this.isSubnetOf(otherSubnet.getNetworkAddress())) { - return false; - } - if (otherSubnet.isSubnetOf(this.getNetworkAddress())) { - return false; - } - return true; + return !(isSubnetOf(otherSubnet.getNetworkAddress()) || otherSubnet.isSubnetOf(getNetworkAddress())); } /**