2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.sal.core;
11 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlElement;
14 import javax.xml.bind.annotation.XmlRootElement;
16 import org.opendaylight.controller.sal.utils.HexEncode;
19 * The class contains MAC address property.
22 @XmlAccessorType(XmlAccessType.NONE)
24 public class MacAddress extends Property implements Cloneable {
25 private static final long serialVersionUID = 1L;
26 @XmlElement(name="value")
27 private final String address;
28 public static final String name = "macAddress";
31 * Private constructor used for JAXB mapping
33 private MacAddress() {
39 * Constructor to create DatalinkAddress property which contains the MAC
40 * address. The property will be attached to a
41 * {@link org.opendaylight.controller.sal.core.Node}.
44 * @param nodeMacAddress
45 * Data Link Address for the node in byte array format
47 * @return the constructed object
49 public MacAddress(byte[] nodeMacAddress) {
51 this.address = HexEncode.bytesToHexStringFormat(nodeMacAddress);
55 * Constructor to create DatalinkAddress property which contains the MAC
56 * address. The property will be attached to a
57 * {@link org.opendaylight.controller.sal.core.Node}.
60 * @param nodeMacAddress
61 * Data Link Address for the node in String format
63 * @return the constructed object
65 public MacAddress(String nodeMacAddress) {
67 this.address = nodeMacAddress;
71 * @return the node MAC address in byte array format
73 public byte[] getMacAddress() {
74 return HexEncode.bytesFromHexString(this.address);
78 public MacAddress clone() {
79 return new MacAddress(this.address);
83 public int hashCode() {
85 int result = super.hashCode();
86 result = prime * result
87 + ((address == null) ? 0 : address.hashCode());
92 public boolean equals(Object obj) {
96 if (!super.equals(obj)) {
99 if (getClass() != obj.getClass()) {
102 MacAddress other = (MacAddress) obj;
103 if (!address.equals(other.address)) {
110 public String toString() {
111 return "MacAddress[" + address + "]";
115 public String getStringValue() {