Merge "Bug 2268: Serialize ApppendEntries"
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / core / Host.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.sal.core;
11
12 import java.io.Serializable;
13 import java.net.InetAddress;
14
15 import javax.xml.bind.annotation.XmlAccessType;
16 import javax.xml.bind.annotation.XmlAccessorType;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19
20 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
21
22 @XmlRootElement(name="host")
23 @XmlAccessorType(XmlAccessType.NONE)
24 @Deprecated
25 public class Host implements Serializable {
26     private static final long serialVersionUID = 1L;
27     @XmlElement
28     private DataLinkAddress dataLayerAddress;
29     private InetAddress networkAddress;
30
31     public Host() {
32
33     }
34
35     /**
36      * Create an Host representation from the combination Data Link
37      * layer/Network layer address, both are needed to construct the
38      * object. Fake value can also be provided in case are not
39      * existent.
40      *
41      * @param dataLayerAddress Data Link Address for the host
42      * @param networkAddress Network Address for the host
43      *
44      * @return the constructed object
45      */
46     public Host(DataLinkAddress dataLayerAddress, InetAddress networkAddress)
47             throws ConstructionException {
48         if (dataLayerAddress == null) {
49             throw new ConstructionException("Passed null datalink address");
50         }
51         if (networkAddress == null) {
52             throw new ConstructionException("Passed null network address");
53         }
54         this.dataLayerAddress = dataLayerAddress;
55         this.networkAddress = networkAddress;
56     }
57
58     /**
59      * Copy constructor
60      *
61      * @param h Host to copy values from
62      *
63      * @return constructed copy
64      */
65     public Host(Host h) throws ConstructionException {
66         if (h == null) {
67             throw new ConstructionException("Passed null host");
68         }
69         this.dataLayerAddress = h.getDataLayerAddress();
70         this.networkAddress = h.getNetworkAddress();
71     }
72
73     /**
74      * @return the dataLayerAddress
75      */
76     public DataLinkAddress getDataLayerAddress() {
77         return this.dataLayerAddress;
78     }
79
80     /**
81      * @return the networkAddress
82      */
83     public InetAddress getNetworkAddress() {
84         return networkAddress;
85     }
86
87     @XmlElement(name = "networkAddress")
88     public String getNetworkAddressAsString() {
89         return networkAddress.getHostAddress();
90     }
91
92     @Override
93     public int hashCode() {
94         final int prime = 31;
95         int result = 1;
96         result = prime
97                 * result
98                 + ((dataLayerAddress == null) ? 0 : dataLayerAddress.hashCode());
99         result = prime * result
100                 + ((networkAddress == null) ? 0 : networkAddress.hashCode());
101         return result;
102     }
103
104     @Override
105     public boolean equals(Object obj) {
106         if (this == obj)
107             return true;
108         if (obj == null)
109             return false;
110         if (getClass() != obj.getClass())
111             return false;
112         Host other = (Host) obj;
113         if (dataLayerAddress == null) {
114             if (other.dataLayerAddress != null)
115                 return false;
116         } else if (!dataLayerAddress.equals(other.dataLayerAddress))
117             return false;
118         if (networkAddress == null) {
119             if (other.networkAddress != null)
120                 return false;
121         } else if (!networkAddress.equals(other.networkAddress))
122             return false;
123         return true;
124     }
125
126     @Override
127     public String toString() {
128         return "Host [dataLayerAddress=" + dataLayerAddress
129                 + ", networkAddress=" + networkAddress + "]";
130     }
131 }