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 b4d1045bac2e461c4c408b6ae04e5531f07e4b53..2dfa9168fe91905b52a2312e6f493692fe6d6172 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
  *
 
 package org.opendaylight.controller.sal.core;
 
-import java.util.Arrays;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 
-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() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result + Arrays.hashCode(controllerMacAddress);
-        result = prime * result + Arrays.hashCode(nodeMacAddress);
+        result = prime * result
+                + ((address == null) ? 0 : address.hashCode());
         return result;
     }
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (!super.equals(obj))
+        }
+        if (!super.equals(obj)) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         MacAddress other = (MacAddress) obj;
-        if (!Arrays.equals(controllerMacAddress, other.controllerMacAddress))
-            return false;
-        if (!Arrays.equals(nodeMacAddress, other.nodeMacAddress))
+        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;
     }
 }