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.hosttracker.hostAware;
12 import java.net.Inet4Address;
13 import java.net.Inet6Address;
14 import java.net.InetAddress;
15 import java.util.Arrays;
17 import javax.xml.bind.annotation.XmlAccessType;
18 import javax.xml.bind.annotation.XmlAccessorType;
19 import javax.xml.bind.annotation.XmlElement;
20 import javax.xml.bind.annotation.XmlRootElement;
22 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
23 import org.opendaylight.controller.sal.core.ConstructionException;
24 import org.opendaylight.controller.sal.core.Host;
25 import org.opendaylight.controller.sal.core.Node;
26 import org.opendaylight.controller.sal.core.NodeConnector;
27 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
29 @XmlRootElement(name="host")
30 @XmlAccessorType(XmlAccessType.NONE)
31 public class HostNodeConnector extends Host {
32 private static final long serialVersionUID = 1L;
34 private NodeConnector nodeConnector;
38 private boolean staticHost;
39 private transient short arpSendCountDown;
42 * Private constructor used for JAXB mapping
44 @SuppressWarnings("unused")
45 private HostNodeConnector() {
48 public HostNodeConnector(InetAddress ip) throws ConstructionException {
52 public HostNodeConnector(InetAddress ip, NodeConnector nc)
53 throws ConstructionException {
54 this(new EthernetAddress(new byte[] { (byte) 0x00, (byte) 0x00,
55 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }), ip, nc,
59 public HostNodeConnector(byte[] mac, InetAddress ip, NodeConnector nc,
60 short vlan) throws ConstructionException {
61 this(new EthernetAddress(mac.clone()), ip, nc, vlan);
64 public HostNodeConnector(EthernetAddress eaddr, InetAddress naddr,
65 NodeConnector nc, short vlan) throws ConstructionException {
67 this.nodeConnector = nc;
72 * @return the NodeConnector
74 public NodeConnector getnodeConnector() {
75 return this.nodeConnector;
81 public Node getnodeconnectorNode() {
82 return this.nodeConnector.getNode();
86 * @return the DataLayerAddress
88 public byte[] getDataLayerAddressBytes() {
89 byte[] macaddr = null;
90 if (getDataLayerAddress() instanceof EthernetAddress) {
91 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
92 macaddr = e.getValue();
100 public short getVlan() {
104 public boolean isStaticHost() {
105 return this.staticHost;
108 public HostNodeConnector setStaticHost(boolean statically_learned) {
109 this.staticHost = statically_learned;
113 public HostNodeConnector initArpSendCountDown() {
114 this.arpSendCountDown = 24;
118 public short getArpSendCountDown() {
119 return (this.arpSendCountDown);
122 public HostNodeConnector setArpSendCountDown(short cntdown) {
123 this.arpSendCountDown = cntdown;
128 public int hashCode() {
129 final int prime = 31;
130 int result = super.hashCode();
131 result = prime * result
132 + ((nodeConnector == null) ? 0 : nodeConnector.hashCode());
133 result = prime * result + (staticHost ? 1231 : 1237);
134 result = prime * result + vlan;
139 public boolean equals(Object obj) {
142 if (!super.equals(obj))
144 if (getClass() != obj.getClass())
146 HostNodeConnector other = (HostNodeConnector) obj;
147 if (nodeConnector == null) {
148 if (other.nodeConnector != null)
150 } else if (!nodeConnector.equals(other.nodeConnector))
152 if (staticHost != other.staticHost)
154 if (vlan != other.vlan)
159 public boolean equalsByIP(InetAddress networkAddress) {
160 return (this.getNetworkAddress().equals(networkAddress));
163 public boolean isRewriteEnabled() {
164 byte[] emptyArray = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
165 (byte) 0x00, (byte) 0x00, (byte) 0x00 };
166 byte[] macaddr = null;
167 if (getDataLayerAddress() instanceof EthernetAddress) {
168 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
169 macaddr = e.getValue();
173 return !Arrays.equals(emptyArray, macaddr);
177 * @see java.lang.Object#toString()
180 public String toString() {
181 return "HostNodeConnector[" + ReflectionToStringBuilder.toString(this)
185 public boolean isV4Host() {
186 return (getNetworkAddress() instanceof Inet4Address);
189 public boolean isV6Host() {
190 return (getNetworkAddress() instanceof Inet6Address);
193 public String toJson() {
194 return "{\"host\":\"" + super.toString() + "\", " + "\"vlan\":\""
195 + String.valueOf(vlan) + "\",\"NodeConnector\":\""
196 + nodeConnector.toString() + "\"," + "\"static\":\""
197 + String.valueOf(isStaticHost()) + "\"}";