X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2FSubnet.java;h=f33fa18e299f62b8680389150c916a28efb06254;hb=51e9be2b3aac6ea33bf21e5a3a978325d24e9e0e;hp=e15303581f9ad32be958dd3971cd0cf92dc8d8bd;hpb=b4f7106f7b4267b51701eff2d3499c0e12423048;p=controller.git 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 e15303581f..f33fa18e29 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 @@ -21,14 +21,14 @@ import org.opendaylight.controller.sal.core.NodeConnector; * The class describes subnet information including L3 address, vlan and set of * ports associated with the subnet. */ -public class Subnet implements Serializable { +public class Subnet implements Cloneable, Serializable { private static final long serialVersionUID = 1L; // Key fields private InetAddress networkAddress; private short subnetMaskLength; // Property fields private short vlan; - private Set nodeConnectors; + private final Set nodeConnectors; public Subnet(InetAddress ip, short maskLen, short vlan) { this.networkAddress = ip; @@ -38,9 +38,16 @@ public class Subnet implements Serializable { } public Subnet(SubnetConfig conf) { - networkAddress = conf.getIPnum(); + networkAddress = conf.getIPAddress(); subnetMaskLength = conf.getIPMaskLen(); - nodeConnectors = conf.getSubnetNodeConnectors(); + nodeConnectors = conf.getNodeConnectors(); + } + + public Subnet(Subnet subnet) { + networkAddress = subnet.networkAddress; + subnetMaskLength = subnet.subnetMaskLength; + vlan = subnet.vlan; + nodeConnectors = new HashSet(subnet.nodeConnectors); } /** @@ -49,12 +56,8 @@ public class Subnet implements Serializable { * @param sp Set of NodeConnectors to add to the subnet */ public void addNodeConnectors(Set sp) { - if (sp == null) { - return; - } - - for (NodeConnector p : sp) { - this.nodeConnectors.add(p); + if (sp != null) { + this.nodeConnectors.addAll(sp); } } @@ -153,16 +156,20 @@ public class Subnet implements Serializable { } public boolean isSubnetOf(InetAddress ip) { - if (ip == null) + if (ip == null) { return false; + } InetAddress thisPrefix = getPrefixForAddress(this.networkAddress); InetAddress otherPrefix = getPrefixForAddress(ip); - if ((thisPrefix == null) || (otherPrefix == null)) + if ((thisPrefix == null) || (otherPrefix == null)) { return false; - if (thisPrefix.equals(otherPrefix)) + } + if (thisPrefix.equals(otherPrefix)) { return true; - else + } + else { return false; + } } public short getVlan() { @@ -189,27 +196,36 @@ public class Subnet implements Serializable { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } Subnet other = (Subnet) obj; if (networkAddress == null) { - if (other.networkAddress != null) + if (other.networkAddress != null) { return false; - } else if (!networkAddress.equals(other.networkAddress)) + } + } else if (!networkAddress.equals(other.networkAddress)) { return false; + } if (nodeConnectors == null) { - if (other.nodeConnectors != null) + if (other.nodeConnectors != null) { return false; - } else if (!nodeConnectors.equals(other.nodeConnectors)) + } + } else if (!nodeConnectors.equals(other.nodeConnectors)) { return false; - if (subnetMaskLength != other.subnetMaskLength) + } + if (subnetMaskLength != other.subnetMaskLength) { return false; - if (vlan != other.vlan) + } + if (vlan != other.vlan) { return false; + } return true; } @@ -220,7 +236,7 @@ public class Subnet implements Serializable { public String toString() { return ("Subnet [networkAddress=" + networkAddress.getHostAddress() + "/" + subnetMaskLength - + ((vlan == 0) ? "" : (" vlan=" + vlan)) + " " + + ((vlan == 0) ? "" : (", vlan=" + vlan)) + ", " + ((isFlatLayer2()) ? "{[*, *]}" : nodeConnectors.toString()) + "]"); } @@ -236,8 +252,9 @@ public class Subnet implements Serializable { public boolean isMutualExclusive(Subnet otherSubnet) { if (this.networkAddress.getClass() != otherSubnet.networkAddress - .getClass()) + .getClass()) { return true; + } if (this.isSubnetOf(otherSubnet.getNetworkAddress())) { return false; } @@ -246,4 +263,13 @@ public class Subnet implements Serializable { } return true; } + + /** + * Implement clonable interface + */ + @Override + public Subnet clone() { + return new Subnet(this); + } + }