Serializable classes should have serialVersionUID
[controller.git] / opendaylight / arphandler / src / main / java / org / opendaylight / controller / arphandler / ARPRequest.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
14 import org.opendaylight.controller.hosttracker.hostAware.HostNodeConnector;
15 import org.opendaylight.controller.switchmanager.Subnet;
16 /*
17  * ARP Request event wrapper Consists of IP and Subnet (and a
18  * HostNodeConnector if is unicast) For unicast request, construct with a
19  * specified host
20  */
21 public class ARPRequest extends ARPEvent {
22     private static final long serialVersionUID = 1L;
23     private final Subnet subnet;
24     private final HostNodeConnector host;
25
26     @Override
27     public int hashCode() {
28         final int prime = 31;
29         int result = super.hashCode();
30         result = prime * result + ((host == null) ? 0 : host.hashCode());
31         result = prime * result + ((subnet == null) ? 0 : subnet.hashCode());
32         return result;
33     }
34
35     @Override
36     public boolean equals(Object obj) {
37         if (this == obj) {
38             return true;
39         }
40         if (obj == null) {
41             return false;
42         }
43         if (!(obj instanceof ARPRequest)) {
44             return false;
45         }
46         ARPRequest other = (ARPRequest) obj;
47         if (host == null) {
48             if (other.host != null) {
49                 return false;
50             }
51         } else if (!host.equals(other.host)) {
52             return false;
53         }
54         if (subnet == null) {
55             if (other.subnet != null) {
56                 return false;
57             }
58         } else if (!subnet.equals(other.subnet)) {
59             return false;
60         }
61         return true;
62     }
63
64     // broadcast
65     public ARPRequest(InetAddress ip, Subnet subnet) {
66         super(ip);
67         this.subnet = subnet;
68         this.host = null;
69     }
70
71     // unicast
72     public ARPRequest(HostNodeConnector host, Subnet subnet) {
73         super(host.getNetworkAddress());
74         this.host = host;
75         this.subnet = subnet;
76     }
77
78     public Subnet getSubnet() {
79         return subnet;
80     }
81
82     public HostNodeConnector getHost() {
83         return host;
84     }
85
86     /*
87      * (non-Javadoc)
88      *
89      * @see java.lang.Object#toString()
90      */
91     @Override
92     public String toString() {
93         StringBuilder builder = new StringBuilder();
94         builder.append("ARPRequest [");
95         if (subnet != null) {
96             builder.append("subnet=")
97                     .append(subnet)
98                     .append(", ");
99         }
100         if (host != null) {
101             builder.append("host=")
102                     .append(host);
103         }
104         builder.append("]");
105         return builder.toString();
106     }
107 }