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 java.util.Arrays;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
18 import org.opendaylight.controller.sal.utils.HexEncode;
20 * The class contains MAC address property.
23 @XmlAccessorType(XmlAccessType.NONE)
24 public class MacAddress extends Property implements Cloneable {
25 private static final long serialVersionUID = 1L;
26 @XmlElement(name="macAddress")
27 private final byte[] 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
47 * @return the constructed object
49 public MacAddress(byte[] nodeMacAddress) {
51 this.address = nodeMacAddress.clone();
55 * @return the node MAC address
57 public byte[] getMacAddress() {
58 return this.address.clone();
62 public MacAddress clone() {
63 return new MacAddress(this.address);
67 public int hashCode() {
69 int result = super.hashCode();
70 result = prime * result + Arrays.hashCode(address);
75 public boolean equals(Object obj) {
79 if (!super.equals(obj)) {
82 if (getClass() != obj.getClass()) {
85 MacAddress other = (MacAddress) obj;
86 if (!Arrays.equals(address, other.address)) {
93 public String toString() {
94 return "MacAddress [address=" +
95 HexEncode.bytesToHexStringFormat(address) + "]";