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.EqualsBuilder;
23 import org.apache.commons.lang3.builder.HashCodeBuilder;
24 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
25 import org.opendaylight.controller.sal.core.ConstructionException;
26 import org.opendaylight.controller.sal.core.Host;
27 import org.opendaylight.controller.sal.core.Node;
28 import org.opendaylight.controller.sal.core.NodeConnector;
29 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
31 @XmlRootElement(name="host")
32 @XmlAccessorType(XmlAccessType.NONE)
33 public class HostNodeConnector extends Host {
34 private static final long serialVersionUID = 1L;
36 private NodeConnector nodeConnector;
40 private boolean staticHost;
41 private transient short arpSendCountDown;
44 * Private constructor used for JAXB mapping
46 @SuppressWarnings("unused")
47 private HostNodeConnector() {
50 public HostNodeConnector(InetAddress ip) throws ConstructionException {
54 public HostNodeConnector(InetAddress ip, NodeConnector nc)
55 throws ConstructionException {
56 this(new EthernetAddress(new byte[] { (byte) 0x00, (byte) 0x00,
57 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }), ip, nc,
61 public HostNodeConnector(byte[] mac, InetAddress ip, NodeConnector nc,
62 short vlan) throws ConstructionException {
63 this(new EthernetAddress(mac.clone()), ip, nc, vlan);
66 public HostNodeConnector(EthernetAddress eaddr, InetAddress naddr,
67 NodeConnector nc, short vlan) throws ConstructionException {
69 this.nodeConnector = nc;
74 * @return the NodeConnector
76 public NodeConnector getnodeConnector() {
77 return this.nodeConnector;
83 public Node getnodeconnectorNode() {
84 return this.nodeConnector.getNode();
90 public Long getnodeconnectornodeId() {
91 return (Long) this.nodeConnector.getNode().getID();
97 public Short getnodeconnectorportId() {
98 return (Short) this.nodeConnector.getID();
102 * @return the DataLayerAddress
104 public byte[] getDataLayerAddressBytes() {
105 byte[] macaddr = null;
106 if (getDataLayerAddress() instanceof EthernetAddress) {
107 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
108 macaddr = e.getValue();
116 public short getVlan() {
120 public boolean isStaticHost() {
121 return this.staticHost;
124 public HostNodeConnector setStaticHost(boolean statically_learned) {
125 this.staticHost = statically_learned;
129 public HostNodeConnector initArpSendCountDown() {
130 this.arpSendCountDown = 24;
134 public short getArpSendCountDown() {
135 return (this.arpSendCountDown);
138 public HostNodeConnector setArpSendCountDown(short cntdown) {
139 this.arpSendCountDown = cntdown;
144 * @see java.lang.Object#hashCode()
147 public int hashCode() {
148 return HashCodeBuilder.reflectionHashCode(this);
152 * @see java.lang.Object#equals(java.lang.Object)
155 public boolean equals(Object obj) {
156 return EqualsBuilder.reflectionEquals(this, obj);
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()) + "\"}";