- In SwitchHandler.java, Transmit Thread waits if the priority queue is empty.
[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 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;
15
16 import org.opendaylight.controller.sal.utils.HexEncode;
17
18 /**
19  * The class contains MAC address property.
20  */
21 @XmlRootElement
22 @XmlAccessorType(XmlAccessType.NONE)
23 public class MacAddress extends Property implements Cloneable {
24     private static final long serialVersionUID = 1L;
25     @XmlElement(name="macAddress")
26     private final String address;
27     public static final String name = "macAddress";
28
29     /*
30      * Private constructor used for JAXB mapping
31      */
32     private MacAddress() {
33         super(name);
34         this.address = null;
35     }
36
37     /**
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}.
41      *
42      *
43      * @param nodeMacAddress
44      *            Data Link Address for the node in byte array format
45      *
46      * @return the constructed object
47      */
48     public MacAddress(byte[] nodeMacAddress) {
49         super(name);
50         this.address = HexEncode.bytesToHexStringFormat(nodeMacAddress);
51     }
52
53     /**
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}.
57      *
58      *
59      * @param nodeMacAddress
60      *            Data Link Address for the node in String format
61      *
62      * @return the constructed object
63      */
64     public MacAddress(String nodeMacAddress) {
65         super(name);
66         this.address = nodeMacAddress;
67     }
68
69     /**
70      * @return the node MAC address in byte array format
71      */
72     public byte[] getMacAddress() {
73         return HexEncode.bytesFromHexString(this.address);
74     }
75
76     @Override
77     public MacAddress clone() {
78         return new MacAddress(this.address);
79     }
80
81     @Override
82     public int hashCode() {
83         final int prime = 31;
84         int result = super.hashCode();
85         result = prime * result
86                 + ((address == null) ? 0 : address.hashCode());
87         return result;
88     }
89
90     @Override
91     public boolean equals(Object obj) {
92         if (this == obj) {
93             return true;
94         }
95         if (!super.equals(obj)) {
96             return false;
97         }
98         if (getClass() != obj.getClass()) {
99             return false;
100         }
101         MacAddress other = (MacAddress) obj;
102         if (!address.equals(other.address)) {
103             return false;
104         }
105         return true;
106     }
107
108     @Override
109     public String toString() {
110         return "MacAddress[" + address + "]";
111     }
112 }