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.apache.commons.lang3.builder.HashCodeBuilder;
21 import org.apache.commons.lang3.builder.EqualsBuilder;
22 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
23 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
25 @XmlRootElement(name="host")
26 @XmlAccessorType(XmlAccessType.NONE)
27 public class Host implements Serializable {
28 private static final long serialVersionUID = 1L;
30 private DataLinkAddress dataLayerAddress;
31 private InetAddress networkAddress;
38 * Create an Host representation from the combination Data Link
39 * layer/Network layer address, both are needed to construct the
40 * object. Fake value can also be provided in case are not
43 * @param dataLayerAddress Data Link Address for the host
44 * @param networkAddress Network Address for the host
46 * @return the constructed object
48 public Host(DataLinkAddress dataLayerAddress, InetAddress networkAddress)
49 throws ConstructionException {
50 if (dataLayerAddress == null) {
51 throw new ConstructionException("Passed null datalink address");
53 if (networkAddress == null) {
54 throw new ConstructionException("Passed null network address");
56 this.dataLayerAddress = dataLayerAddress;
57 this.networkAddress = networkAddress;
63 * @param h Host to copy values from
65 * @return constructed copy
67 public Host(Host h) throws ConstructionException {
69 throw new ConstructionException("Passed null host");
71 this.dataLayerAddress = h.getDataLayerAddress();
72 this.networkAddress = h.getNetworkAddress();
76 * @return the dataLayerAddress
78 public DataLinkAddress getDataLayerAddress() {
79 return this.dataLayerAddress;
83 * @return the networkAddress
85 public InetAddress getNetworkAddress() {
86 return networkAddress;
89 @XmlElement(name = "networkAddress")
90 public String getNetworkAddressAsString() {
91 return networkAddress.getHostAddress();
95 public int hashCode() {
96 return HashCodeBuilder.reflectionHashCode(this);
100 public boolean equals(Object obj) {
101 return EqualsBuilder.reflectionEquals(this, obj);
105 public String toString() {
106 return "Host[" + ReflectionToStringBuilder.toString(this) + "]";