* 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<NodeConnector> nodeConnectors;
+ private final Set<NodeConnector> nodeConnectors;
public Subnet(InetAddress ip, short maskLen, short vlan) {
this.networkAddress = ip;
nodeConnectors = conf.getSubnetNodeConnectors();
}
+ public Subnet(Subnet subnet) {
+ networkAddress = subnet.networkAddress;
+ subnetMaskLength = subnet.subnetMaskLength;
+ vlan = subnet.vlan;
+ nodeConnectors = new HashSet<NodeConnector>(subnet.nodeConnectors);
+ }
+
/**
* Add NodeConnectors to a subnet
*
* @param sp Set of NodeConnectors to add to the subnet
*/
public void addNodeConnectors(Set<NodeConnector> sp) {
- if (sp == null) {
- return;
- }
-
- for (NodeConnector p : sp) {
- this.nodeConnectors.add(p);
+ if (sp != null) {
+ this.nodeConnectors.addAll(sp);
}
}
public String toString() {
return ("Subnet [networkAddress=" + networkAddress.getHostAddress()
+ "/" + subnetMaskLength
- + ((vlan == 0) ? "" : (" vlan=" + vlan)) + " "
+ + ((vlan == 0) ? "" : (", vlan=" + vlan)) + ", "
+ ((isFlatLayer2()) ? "{[*, *]}" : nodeConnectors.toString()) + "]");
}
}
return true;
}
+
+ /**
+ * Implement clonable interface
+ */
+ @Override
+ public Subnet clone() {
+ return new Subnet(this);
+ }
+
}