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)
25 public class Host implements Serializable {
26 private static final long serialVersionUID = 1L;
28 private DataLinkAddress dataLayerAddress;
29 private InetAddress networkAddress;
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
41 * @param dataLayerAddress Data Link Address for the host
42 * @param networkAddress Network Address for the host
44 * @return the constructed object
46 public Host(DataLinkAddress dataLayerAddress, InetAddress networkAddress)
47 throws ConstructionException {
48 if (dataLayerAddress == null) {
49 throw new ConstructionException("Passed null datalink address");
51 if (networkAddress == null) {
52 throw new ConstructionException("Passed null network address");
54 this.dataLayerAddress = dataLayerAddress;
55 this.networkAddress = networkAddress;
61 * @param h Host to copy values from
63 * @return constructed copy
65 public Host(Host h) throws ConstructionException {
67 throw new ConstructionException("Passed null host");
69 this.dataLayerAddress = h.getDataLayerAddress();
70 this.networkAddress = h.getNetworkAddress();
74 * @return the dataLayerAddress
76 public DataLinkAddress getDataLayerAddress() {
77 return this.dataLayerAddress;
81 * @return the networkAddress
83 public InetAddress getNetworkAddress() {
84 return networkAddress;
87 @XmlElement(name = "networkAddress")
88 public String getNetworkAddressAsString() {
89 return networkAddress.getHostAddress();
93 public int hashCode() {
98 + ((dataLayerAddress == null) ? 0 : dataLayerAddress.hashCode());
99 result = prime * result
100 + ((networkAddress == null) ? 0 : networkAddress.hashCode());
105 public boolean equals(Object obj) {
110 if (getClass() != obj.getClass())
112 Host other = (Host) obj;
113 if (dataLayerAddress == null) {
114 if (other.dataLayerAddress != null)
116 } else if (!dataLayerAddress.equals(other.dataLayerAddress))
118 if (networkAddress == null) {
119 if (other.networkAddress != null)
121 } else if (!networkAddress.equals(other.networkAddress))
127 public String toString() {
128 return "Host [dataLayerAddress=" + dataLayerAddress
129 + ", networkAddress=" + networkAddress + "]";