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 private HostNodeConnector() {
49 public HostNodeConnector(InetAddress ip) throws ConstructionException {
53 public HostNodeConnector(InetAddress ip, NodeConnector nc)
54 throws ConstructionException {
55 this(new EthernetAddress(new byte[] { (byte) 0x00, (byte) 0x00,
56 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }), ip, nc,
60 public HostNodeConnector(byte[] mac, InetAddress ip, NodeConnector nc,
61 short vlan) throws ConstructionException {
62 this(new EthernetAddress(mac.clone()), ip, nc, vlan);
65 public HostNodeConnector(EthernetAddress eaddr, InetAddress naddr,
66 NodeConnector nc, short vlan) throws ConstructionException {
68 this.nodeConnector = nc;
73 * @return the NodeConnector
75 public NodeConnector getnodeConnector() {
76 return this.nodeConnector;
82 public Node getnodeconnectorNode() {
83 return this.nodeConnector.getNode();
89 public Long getnodeconnectornodeId() {
90 return (Long) this.nodeConnector.getNode().getID();
96 public Short getnodeconnectorportId() {
97 return (Short) this.nodeConnector.getID();
101 * @return the DataLayerAddress
103 public byte[] getDataLayerAddressBytes() {
104 byte[] macaddr = null;
105 if (getDataLayerAddress() instanceof EthernetAddress) {
106 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
107 macaddr = e.getValue();
115 public short getVlan() {
119 public boolean isStaticHost() {
120 return this.staticHost;
123 public HostNodeConnector setStaticHost(boolean statically_learned) {
124 this.staticHost = statically_learned;
128 public HostNodeConnector initArpSendCountDown() {
129 this.arpSendCountDown = 24;
133 public short getArpSendCountDown() {
134 return (this.arpSendCountDown);
137 public HostNodeConnector setArpSendCountDown(short cntdown) {
138 this.arpSendCountDown = cntdown;
143 * @see java.lang.Object#hashCode()
146 public int hashCode() {
147 return HashCodeBuilder.reflectionHashCode(this);
151 * @see java.lang.Object#equals(java.lang.Object)
154 public boolean equals(Object obj) {
155 return EqualsBuilder.reflectionEquals(this, obj);
158 public boolean equalsByIP(InetAddress networkAddress) {
159 return (this.getNetworkAddress().equals(networkAddress));
162 public boolean isRewriteEnabled() {
163 byte[] emptyArray = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
164 (byte) 0x00, (byte) 0x00, (byte) 0x00 };
165 byte[] macaddr = null;
166 if (getDataLayerAddress() instanceof EthernetAddress) {
167 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
168 macaddr = e.getValue();
172 return !Arrays.equals(emptyArray, macaddr);
176 * @see java.lang.Object#toString()
179 public String toString() {
180 return "HostNodeConnector[" + ReflectionToStringBuilder.toString(this)
184 public boolean isV4Host() {
185 return (getNetworkAddress() instanceof Inet4Address);
188 public boolean isV6Host() {
189 return (getNetworkAddress() instanceof Inet6Address);
192 public String toJson() {
193 return "{\"host\":\"" + super.toString() + "\", " + "\"vlan\":\""
194 + String.valueOf(vlan) + "\",\"NodeConnector\":\""
195 + nodeConnector.toString() + "\"," + "\"static\":\""
196 + String.valueOf(isStaticHost()) + "\"}";