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)
23 public class MacAddress extends Property implements Cloneable {
24 private static final long serialVersionUID = 1L;
25 @XmlElement(name="value")
26 private final String address;
27 public static final String name = "macAddress";
30 * Private constructor used for JAXB mapping
32 private MacAddress() {
38 * Constructor to create DatalinkAddress property which contains the MAC
39 * address. The property will be attached to a
40 * {@link org.opendaylight.controller.sal.core.Node}.
43 * @param nodeMacAddress
44 * Data Link Address for the node in byte array format
46 * @return the constructed object
48 public MacAddress(byte[] nodeMacAddress) {
50 this.address = HexEncode.bytesToHexStringFormat(nodeMacAddress);
54 * Constructor to create DatalinkAddress property which contains the MAC
55 * address. The property will be attached to a
56 * {@link org.opendaylight.controller.sal.core.Node}.
59 * @param nodeMacAddress
60 * Data Link Address for the node in String format
62 * @return the constructed object
64 public MacAddress(String nodeMacAddress) {
66 this.address = nodeMacAddress;
70 * @return the node MAC address in byte array format
72 public byte[] getMacAddress() {
73 return HexEncode.bytesFromHexString(this.address);
77 public MacAddress clone() {
78 return new MacAddress(this.address);
82 public int hashCode() {
84 int result = super.hashCode();
85 result = prime * result
86 + ((address == null) ? 0 : address.hashCode());
91 public boolean equals(Object obj) {
95 if (!super.equals(obj)) {
98 if (getClass() != obj.getClass()) {
101 MacAddress other = (MacAddress) obj;
102 if (!address.equals(other.address)) {
109 public String toString() {
110 return "MacAddress[" + address + "]";
114 public String getStringValue() {