X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2FSwitch.java;h=e0c120a05f50644c2b46da25304cac407c56e234;hb=efa48be30a4054e7cfce114e66c5b5667b1c4a5c;hp=afca30c3a1c89a9a1ce254e925e0cc33ae89b142;hpb=9e43cfabdc83df4c5db51ce6e22e0cecca12aa9a;p=controller.git diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Switch.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Switch.java index afca30c3a1..e0c120a05f 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Switch.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/Switch.java @@ -11,15 +11,14 @@ package org.opendaylight.controller.switchmanager; import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ReflectionToStringBuilder; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; +import org.opendaylight.controller.sal.utils.HexEncode; /** * The class describes switch related information including L2 address, ports, @@ -29,7 +28,7 @@ public class Switch implements Serializable { private static final long serialVersionUID = 1L; private byte[] dataLayerAddress; private Set nodeConnectors; - private List spanPorts; + private final List spanPorts; private Node node; /* @@ -45,7 +44,7 @@ public class Switch implements Serializable { this.node = node; this.nodeConnectors = new HashSet(); this.spanPorts = new ArrayList(2); - this.dataLayerAddress = deriveMacAddress(); + this.dataLayerAddress = null; } /** @@ -67,7 +66,7 @@ public class Switch implements Serializable { * @return the nodeConnectors */ public Set getNodeConnectors() { - return nodeConnectors; + return new HashSet(nodeConnectors); } /** @@ -88,7 +87,7 @@ public class Switch implements Serializable { } public List getSpanPorts() { - return spanPorts; + return new ArrayList(this.spanPorts); } public Node getNode() { @@ -99,18 +98,6 @@ public class Switch implements Serializable { this.node = node; } - private byte[] deriveMacAddress() { - long dpid = (Long) this.node.getID(); - byte[] mac = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - for (short i = 0; i < 6; i++) { - mac[5 - i] = (byte) dpid; - dpid >>= 8; - } - - return mac; - } - public void addSpanPorts(List portList) { for (NodeConnector port : portList) { spanPorts.add(port); @@ -125,16 +112,60 @@ public class Switch implements Serializable { @Override public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(dataLayerAddress); + result = prime * result + ((node == null) ? 0 : node.hashCode()); + result = prime * result + + ((nodeConnectors == null) ? 0 : nodeConnectors.hashCode()); + result = prime * result + + ((spanPorts == null) ? 0 : spanPorts.hashCode()); + return result; } @Override public boolean equals(Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Switch other = (Switch) obj; + if (!Arrays.equals(dataLayerAddress, other.dataLayerAddress)) { + return false; + } + if (node == null) { + if (other.node != null) { + return false; + } + } else if (!node.equals(other.node)) { + return false; + } + if (nodeConnectors == null) { + if (other.nodeConnectors != null) { + return false; + } + } else if (!nodeConnectors.equals(other.nodeConnectors)) { + return false; + } + if (spanPorts == null) { + if (other.spanPorts != null) { + return false; + } + } else if (!spanPorts.equals(other.spanPorts)) { + return false; + } + return true; } @Override public String toString() { - return "Switch[" + ReflectionToStringBuilder.toString(this) + "]"; + return "Switch [dataLayerAddress=" + HexEncode.bytesToHexStringFormat(dataLayerAddress) + + ", nodeConnectors=" + nodeConnectors + ", spanPorts=" + + spanPorts + ", node=" + node + "]"; } }