Enhancement to switchmanager CLI commands to display all the properties of node and...
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / MacAddress.java
index 2bfeb46248416b58327a503a97fa5212c22076ac..2dfa9168fe91905b52a2312e6f493692fe6d6172 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
@@ -14,81 +13,105 @@ import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+import org.opendaylight.controller.sal.utils.HexEncode;
 
 /**
- * The class contains the controller MAC address and node MAC address.
- *
- *
+ * The class contains MAC address property.
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-public class MacAddress extends Property {
+public class MacAddress extends Property implements Cloneable {
     private static final long serialVersionUID = 1L;
-    @XmlElement
-    private byte[] controllerMacAddress;
-    @XmlElement
-    private byte[] nodeMacAddress;
-    public static final String MacPropName = "macAddress";
+    @XmlElement(name="value")
+    private final String address;
+    public static final String name = "macAddress";
 
     /*
      * Private constructor used for JAXB mapping
      */
     private MacAddress() {
-        super(MacPropName);
-        this.controllerMacAddress = null;
-        this.nodeMacAddress = null;
+        super(name);
+        this.address = null;
     }
 
-       /**
-        * Constructor to create DatalinkAddress property which contains the
-        * controller MAC address and node MAC address. The property will be
-        * attached to a {@link org.opendaylight.controller.sal.core.Node}.
-        * 
-        * @param controllerMacAddress Data Link Address for the controller
-        * @param nodeMacAddress Data Link Address for the node
-        * 
-        * @return the constructed object
-        */
-    public MacAddress(byte[] controllerMacAddress, byte[] nodeMacAddress) {
-        super(MacPropName);
-       
-        this.controllerMacAddress = controllerMacAddress;
-        this.nodeMacAddress = nodeMacAddress;
+    /**
+     * Constructor to create DatalinkAddress property which contains the MAC
+     * address. The property will be attached to a
+     * {@link org.opendaylight.controller.sal.core.Node}.
+     *
+     *
+     * @param nodeMacAddress
+     *            Data Link Address for the node in byte array format
+     *
+     * @return the constructed object
+     */
+    public MacAddress(byte[] nodeMacAddress) {
+        super(name);
+        this.address = HexEncode.bytesToHexStringFormat(nodeMacAddress);
     }
 
     /**
-     * @return the controller MAC address
+     * Constructor to create DatalinkAddress property which contains the MAC
+     * address. The property will be attached to a
+     * {@link org.opendaylight.controller.sal.core.Node}.
+     *
+     *
+     * @param nodeMacAddress
+     *            Data Link Address for the node in String format
+     *
+     * @return the constructed object
      */
-    public byte[] getControllerMacAddress() {
-        return this.controllerMacAddress;
+    public MacAddress(String nodeMacAddress) {
+        super(name);
+        this.address = nodeMacAddress;
     }
 
     /**
-     * @return the node MAC address
+     * @return the node MAC address in byte array format
      */
-    public byte[] getNodeMacAddress() {
-        return this.nodeMacAddress;
+    public byte[] getMacAddress() {
+        return HexEncode.bytesFromHexString(this.address);
     }
 
+    @Override
     public MacAddress clone() {
-       return new MacAddress(this.controllerMacAddress, this.nodeMacAddress);
+        return new MacAddress(this.address);
     }
 
     @Override
     public int hashCode() {
-        return HashCodeBuilder.reflectionHashCode(this);
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result
+                + ((address == null) ? 0 : address.hashCode());
+        return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        return EqualsBuilder.reflectionEquals(this, obj);
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        MacAddress other = (MacAddress) obj;
+        if (!address.equals(other.address)) {
+            return false;
+        }
+        return true;
     }
 
     @Override
     public String toString() {
-        return "MacAddress[" + ReflectionToStringBuilder.toString(this) + "]";
+        return "MacAddress[" + address + "]";
+    }
+
+    @Override
+    public String getStringValue() {
+        return address;
     }
 }