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();
88 public Long getnodeconnectornodeId() {
89 return (Long) this.nodeConnector.getNode().getID();
95 public Short getnodeconnectorportId() {
96 return (Short) this.nodeConnector.getID();
100 * @return the DataLayerAddress
102 public byte[] getDataLayerAddressBytes() {
103 byte[] macaddr = null;
104 if (getDataLayerAddress() instanceof EthernetAddress) {
105 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
106 macaddr = e.getValue();
114 public short getVlan() {
118 public boolean isStaticHost() {
119 return this.staticHost;
122 public HostNodeConnector setStaticHost(boolean statically_learned) {
123 this.staticHost = statically_learned;
127 public HostNodeConnector initArpSendCountDown() {
128 this.arpSendCountDown = 24;
132 public short getArpSendCountDown() {
133 return (this.arpSendCountDown);
136 public HostNodeConnector setArpSendCountDown(short cntdown) {
137 this.arpSendCountDown = cntdown;
142 public int hashCode() {
143 final int prime = 31;
144 int result = super.hashCode();
145 result = prime * result
146 + ((nodeConnector == null) ? 0 : nodeConnector.hashCode());
147 result = prime * result + (staticHost ? 1231 : 1237);
148 result = prime * result + vlan;
153 public boolean equals(Object obj) {
156 if (!super.equals(obj))
158 if (getClass() != obj.getClass())
160 HostNodeConnector other = (HostNodeConnector) obj;
161 if (nodeConnector == null) {
162 if (other.nodeConnector != null)
164 } else if (!nodeConnector.equals(other.nodeConnector))
166 if (staticHost != other.staticHost)
168 if (vlan != other.vlan)
173 public boolean equalsByIP(InetAddress networkAddress) {
174 return (this.getNetworkAddress().equals(networkAddress));
177 public boolean isRewriteEnabled() {
178 byte[] emptyArray = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
179 (byte) 0x00, (byte) 0x00, (byte) 0x00 };
180 byte[] macaddr = null;
181 if (getDataLayerAddress() instanceof EthernetAddress) {
182 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
183 macaddr = e.getValue();
187 return !Arrays.equals(emptyArray, macaddr);
191 * @see java.lang.Object#toString()
194 public String toString() {
195 return "HostNodeConnector[" + ReflectionToStringBuilder.toString(this)
199 public boolean isV4Host() {
200 return (getNetworkAddress() instanceof Inet4Address);
203 public boolean isV6Host() {
204 return (getNetworkAddress() instanceof Inet6Address);
207 public String toJson() {
208 return "{\"host\":\"" + super.toString() + "\", " + "\"vlan\":\""
209 + String.valueOf(vlan) + "\",\"NodeConnector\":\""
210 + nodeConnector.toString() + "\"," + "\"static\":\""
211 + String.valueOf(isStaticHost()) + "\"}";