-
/*
* Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
*
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;
}
}