Implement finding a primary based on the shard name and do basic wiring of Distribute...
[controller.git] / opendaylight / 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
27     @Override
28     public int hashCode() {
29         final int prime = 31;
30         int result = super.hashCode();
31         result = prime * result + ((sIP == null) ? 0 : sIP.hashCode());
32         result = prime * result + Arrays.hashCode(sMac);
33         result = prime * result + Arrays.hashCode(tMac);
34         return result;
35     }
36
37     @Override
38     public boolean equals(Object obj) {
39         if (this == obj) {
40             return true;
41         }
42         if (obj == null) {
43             return false;
44         }
45         if (!(obj instanceof ARPReply)) {
46             return false;
47         }
48         ARPReply other = (ARPReply) obj;
49         if (sIP == null) {
50             if (other.sIP != null) {
51                 return false;
52             }
53         } else if (!sIP.equals(other.sIP)) {
54             return false;
55         }
56         if (!Arrays.equals(sMac, other.sMac)) {
57             return false;
58         }
59         if (!Arrays.equals(tMac, other.tMac)) {
60             return false;
61         }
62         return true;
63     }
64
65     public ARPReply(NodeConnector port, InetAddress sIP, byte[] sMAC, InetAddress tIP, byte[] tMAC) {
66         super(tIP);
67         this.tMac = tMAC;
68         this.sIP = sIP;
69         this.sMac = sMAC;
70         this.port = port;
71     }
72
73     public ARPReply(InetAddress tIP, byte[] tMAC) {
74         super(tIP);
75         this.tMac = tMAC;
76         this.sIP = null;
77         this.sMac = null;
78         this.port = null;
79     }
80
81     public byte[] getTargetMac() {
82         return tMac;
83     }
84
85     public byte[] getSourceMac() {
86         return sMac;
87     }
88
89     public InetAddress getSourceIP() {
90         return sIP;
91     }
92
93     public NodeConnector getPort() {
94         return port;
95     }
96
97     /*
98      * (non-Javadoc)
99      *
100      * @see java.lang.Object#toString()
101      */
102     @Override
103     public String toString() {
104         StringBuilder builder = new StringBuilder();
105         builder.append("ARPReply [");
106         if (port != null) {
107             builder.append("port=")
108                     .append(port)
109                     .append(", ");
110         }
111         if (tMac != null) {
112             builder.append("tMac=")
113                     .append(HexEncode.bytesToHexString(tMac))
114                     .append(", ");
115         }
116         if (sMac != null) {
117             builder.append("sMac=")
118                     .append(HexEncode.bytesToHexString(sMac))
119                     .append(", ");
120         }
121         if (sIP != null) {
122             builder.append("sIP=")
123                     .append(sIP);
124         }
125         builder.append("]");
126         return builder.toString();
127     }
128 }