Merge "BUG-2218: Keep existing link augmentations during discovery process"
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / action / SetDlSrc.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.action;
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.opendaylight.controller.sal.utils.HexEncode;
19
20 /**
21  * Set source datalayer address action
22  *
23  */
24 @XmlRootElement
25 @XmlAccessorType(XmlAccessType.NONE)
26 public class SetDlSrc extends Action {
27     private static final long serialVersionUID = 1L;
28     private byte[] address;
29
30     /* Dummy constructor for JAXB */
31     @SuppressWarnings("unused")
32     private SetDlSrc() {
33     }
34
35     public SetDlSrc(byte[] dlAddress) {
36         type = ActionType.SET_DL_SRC;
37         if (dlAddress != null) {
38             this.address = dlAddress.clone();
39         } else {
40             this.address = null;
41         }
42     }
43
44     /**
45      * Returns the datalayer address that this action will set
46      *
47      * @return byte[]
48      */
49     public byte[] getDlAddress() {
50         return address.clone();
51     }
52
53     @XmlElement(name = "address")
54     public String getDlAddressString() {
55         return HexEncode.bytesToHexString(address);
56     }
57
58     @Override
59     public boolean equals(Object obj) {
60         if (this == obj) {
61             return true;
62         }
63         if (!super.equals(obj)) {
64             return false;
65         }
66         if (getClass() != obj.getClass()) {
67             return false;
68         }
69         SetDlSrc other = (SetDlSrc) obj;
70         if (!Arrays.equals(address, other.address)) {
71             return false;
72         }
73         return true;
74     }
75
76     @Override
77     public int hashCode() {
78         final int prime = 31;
79         int result = super.hashCode();
80         result = prime * result + Arrays.hashCode(address);
81         return result;
82     }
83
84     @Override
85     public String toString() {
86         return type + "[address = " + HexEncode.bytesToHexString(address) + "]";
87     }
88 }