Merge "BUG-2329 Add test for anyxmls inside rpc resonse for netcfon-connector"
[controller.git] / opendaylight / adsal / arphandler / src / main / java / org / opendaylight / controller / arphandler / ARPReply.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.arphandler;
11
12 import java.net.InetAddress;
13 import java.util.Arrays;
14
15 import org.opendaylight.controller.sal.core.NodeConnector;
16 import org.opendaylight.controller.sal.utils.HexEncode;
17 /*
18  * ARP Reply event wrapper
19  */
20 public class ARPReply extends ARPEvent {
21     private static final long serialVersionUID = 1L;
22     private final NodeConnector port;
23     private final byte[] tMac;
24     private final byte[] sMac;
25     private final InetAddress sIP;
26     private final short vlan;
27
28     @Override
29     public int hashCode() {
30         final int prime = 31;
31         int result = super.hashCode();
32         result = prime * result + ((port == null) ? 0 : port.hashCode());
33         result = prime * result + ((sIP == null) ? 0 : sIP.hashCode());
34         result = prime * result + Arrays.hashCode(sMac);
35         result = prime * result + Arrays.hashCode(tMac);
36         result = prime * result + vlan;
37         return result;
38     }
39
40     @Override
41     public boolean equals(Object obj) {
42         if (this == obj) {
43             return true;
44         }
45         if (!super.equals(obj)) {
46             return false;
47         }
48         if (!(obj instanceof ARPReply)) {
49             return false;
50         }
51         ARPReply other = (ARPReply) obj;
52         if (port == null) {
53             if (other.port != null) {
54                 return false;
55             }
56         } else if (!port.equals(other.port)) {
57             return false;
58         }
59         if (sIP == null) {
60             if (other.sIP != null) {
61                 return false;
62             }
63         } else if (!sIP.equals(other.sIP)) {
64             return false;
65         }
66         if (!Arrays.equals(sMac, other.sMac)) {
67             return false;
68         }
69         if (!Arrays.equals(tMac, other.tMac)) {
70             return false;
71         }
72         if (vlan != other.vlan) {
73             return false;
74         }
75         return true;
76     }
77
78     public ARPReply(NodeConnector port, InetAddress sIP, byte[] sMAC, InetAddress tIP, byte[] tMAC, short vlan) {
79         super(tIP);
80         this.tMac = tMAC;
81         this.sIP = sIP;
82         this.sMac = sMAC;
83         this.port = port;
84         this.vlan = vlan;
85     }
86
87     public ARPReply(InetAddress tIP, byte[] tMAC, short vlan) {
88         super(tIP);
89         this.tMac = tMAC;
90         this.sIP = null;
91         this.sMac = null;
92         this.port = null;
93         this.vlan = vlan;
94     }
95
96     public byte[] getTargetMac() {
97         return tMac;
98     }
99
100     public byte[] getSourceMac() {
101         return sMac;
102     }
103
104     public InetAddress getSourceIP() {
105         return sIP;
106     }
107
108     public NodeConnector getPort() {
109         return port;
110     }
111
112     public short getVlan() {
113         return vlan;
114     }
115
116     /*
117      * (non-Javadoc)
118      *
119      * @see java.lang.Object#toString()
120      */
121     @Override
122     public String toString() {
123         StringBuilder builder = new StringBuilder();
124         builder.append("ARPReply [");
125         if (port != null) {
126             builder.append("port=")
127                     .append(port)
128                     .append(", ");
129         }
130         if (tMac != null) {
131             builder.append("tMac=")
132                     .append(HexEncode.bytesToHexString(tMac))
133                     .append(", ");
134         }
135         if (sMac != null) {
136             builder.append("sMac=")
137                     .append(HexEncode.bytesToHexString(sMac))
138                     .append(", ");
139         }
140         if (sIP != null) {
141             builder.append("sIP=")
142                     .append(sIP);
143         }
144         if (vlan != 0) {
145             builder.append(", vlan=")
146             .append(vlan);
147         }
148         builder.append("]");
149         return builder.toString();
150     }
151 }