3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
10 package org.opendaylight.controller.sal.core;
12 import java.io.Serializable;
13 import java.net.InetAddress;
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;
20 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
22 @XmlRootElement(name="host")
23 @XmlAccessorType(XmlAccessType.NONE)
24 public class Host implements Serializable {
25 private static final long serialVersionUID = 1L;
27 private DataLinkAddress dataLayerAddress;
28 private InetAddress networkAddress;
35 * Create an Host representation from the combination Data Link
36 * layer/Network layer address, both are needed to construct the
37 * object. Fake value can also be provided in case are not
40 * @param dataLayerAddress Data Link Address for the host
41 * @param networkAddress Network Address for the host
43 * @return the constructed object
45 public Host(DataLinkAddress dataLayerAddress, InetAddress networkAddress)
46 throws ConstructionException {
47 if (dataLayerAddress == null) {
48 throw new ConstructionException("Passed null datalink address");
50 if (networkAddress == null) {
51 throw new ConstructionException("Passed null network address");
53 this.dataLayerAddress = dataLayerAddress;
54 this.networkAddress = networkAddress;
60 * @param h Host to copy values from
62 * @return constructed copy
64 public Host(Host h) throws ConstructionException {
66 throw new ConstructionException("Passed null host");
68 this.dataLayerAddress = h.getDataLayerAddress();
69 this.networkAddress = h.getNetworkAddress();
73 * @return the dataLayerAddress
75 public DataLinkAddress getDataLayerAddress() {
76 return this.dataLayerAddress;
80 * @return the networkAddress
82 public InetAddress getNetworkAddress() {
83 return networkAddress;
86 @XmlElement(name = "networkAddress")
87 public String getNetworkAddressAsString() {
88 return networkAddress.getHostAddress();
92 public int hashCode() {
97 + ((dataLayerAddress == null) ? 0 : dataLayerAddress.hashCode());
98 result = prime * result
99 + ((networkAddress == null) ? 0 : networkAddress.hashCode());
104 public boolean equals(Object obj) {
109 if (getClass() != obj.getClass())
111 Host other = (Host) obj;
112 if (dataLayerAddress == null) {
113 if (other.dataLayerAddress != null)
115 } else if (!dataLayerAddress.equals(other.dataLayerAddress))
117 if (networkAddress == null) {
118 if (other.networkAddress != null)
120 } else if (!networkAddress.equals(other.networkAddress))
126 public String toString() {
127 return "Host [dataLayerAddress=" + dataLayerAddress
128 + ", networkAddress=" + networkAddress + "]";