Add IfNewHostNotify to DeviceManager
[controller.git] / opendaylight / sal / api / src / main / java / org / opendaylight / controller / sal / core / MacAddress.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.sal.core;
10
11 import java.util.Arrays;
12
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;
17
18 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
19
20 /**
21  * The class contains MAC address property.
22  */
23 @XmlRootElement
24 @XmlAccessorType(XmlAccessType.NONE)
25 public class MacAddress extends Property implements Cloneable {
26     private static final long serialVersionUID = 1L;
27     @XmlElement(name="macAddress")
28     private final byte[] address;
29     public static final String name = "macAddress";
30
31     /*
32      * Private constructor used for JAXB mapping
33      */
34     private MacAddress() {
35         super(name);
36         this.address = null;
37     }
38
39     /**
40      * Constructor to create DatalinkAddress property which contains the MAC
41      * address. The property will be attached to a
42      * {@link org.opendaylight.controller.sal.core.Node}.
43      *
44      *
45      * @param nodeMacAddress
46      *            Data Link Address for the node
47      *
48      * @return the constructed object
49      */
50     public MacAddress(byte[] nodeMacAddress) {
51         super(name);
52         this.address = nodeMacAddress.clone();
53     }
54
55     /**
56      * @return the node MAC address
57      */
58     public byte[] getMacAddress() {
59         return this.address.clone();
60     }
61
62     @Override
63     public MacAddress clone() {
64         return new MacAddress(this.address);
65     }
66
67     @Override
68     public int hashCode() {
69         final int prime = 31;
70         int result = super.hashCode();
71         result = prime * result + Arrays.hashCode(address);
72         return result;
73     }
74
75     @Override
76     public boolean equals(Object obj) {
77         if (this == obj) {
78             return true;
79         }
80         if (!super.equals(obj)) {
81             return false;
82         }
83         if (getClass() != obj.getClass()) {
84             return false;
85         }
86         MacAddress other = (MacAddress) obj;
87         if (!Arrays.equals(address, other.address)) {
88             return false;
89         }
90         return true;
91     }
92
93     @Override
94     public String toString() {
95         return "MacAddress[" + ReflectionToStringBuilder.toString(this) + "]";
96     }
97 }