2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.hosttracker.hostAware;
11 import java.io.Serializable;
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.opendaylight.controller.sal.core.ConstructionException;
23 import org.opendaylight.controller.sal.core.Host;
24 import org.opendaylight.controller.sal.core.Node;
25 import org.opendaylight.controller.sal.core.NodeConnector;
26 import org.opendaylight.controller.sal.packet.address.EthernetAddress;
28 @XmlRootElement(name = "host")
29 @XmlAccessorType(XmlAccessType.NONE)
30 public class HostNodeConnector extends Host implements Serializable {
31 private static final long serialVersionUID = 1L;
33 private NodeConnector nodeConnector;
37 private boolean staticHost;
38 private short arpSendCountDown;
41 * Private constructor used for JAXB mapping
43 @SuppressWarnings("unused")
44 private HostNodeConnector() {
47 public HostNodeConnector(InetAddress ip) throws ConstructionException {
51 public HostNodeConnector(InetAddress ip, NodeConnector nc)
52 throws ConstructionException {
53 this(new EthernetAddress(new byte[] { (byte) 0x00, (byte) 0x00,
54 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }), ip, nc,
58 public HostNodeConnector(byte[] mac, InetAddress ip, NodeConnector nc,
59 short vlan) throws ConstructionException {
60 this(new EthernetAddress(mac.clone()), ip, nc, vlan);
63 public HostNodeConnector(EthernetAddress eaddr, InetAddress naddr,
64 NodeConnector nc, short vlan) throws ConstructionException {
66 this.nodeConnector = nc;
71 * @return the NodeConnector
73 public NodeConnector getnodeConnector() {
74 return this.nodeConnector;
80 public Node getnodeconnectorNode() {
81 return this.nodeConnector.getNode();
85 * @return the DataLayerAddress
87 public byte[] getDataLayerAddressBytes() {
88 byte[] macaddr = null;
89 if (getDataLayerAddress() instanceof EthernetAddress) {
90 EthernetAddress e = (EthernetAddress) getDataLayerAddress();
91 macaddr = e.getValue();
99 public short getVlan() {
103 public boolean isStaticHost() {
104 return this.staticHost;
107 public HostNodeConnector setStaticHost(boolean statically_learned) {
108 this.staticHost = statically_learned;
112 public HostNodeConnector initArpSendCountDown() {
113 this.arpSendCountDown = 24;
117 public short getArpSendCountDown() {
118 return (this.arpSendCountDown);
121 public HostNodeConnector setArpSendCountDown(short cntdown) {
122 this.arpSendCountDown = cntdown;
127 public int hashCode() {
128 final int prime = 31;
129 int result = super.hashCode();
130 result = prime * result
131 + ((nodeConnector == null) ? 0 : nodeConnector.hashCode());
132 result = prime * result + (staticHost ? 1231 : 1237);
133 result = prime * result + vlan;
138 public boolean equals(Object obj) {
141 if (!super.equals(obj))
143 if (getClass() != obj.getClass())
145 HostNodeConnector other = (HostNodeConnector) obj;
146 if (nodeConnector == null) {
147 if (other.nodeConnector != null)
149 } else if (!nodeConnector.equals(other.nodeConnector))
151 if (staticHost != other.staticHost)
153 if (vlan != other.vlan)
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 public String toString() {
177 return "HostNodeConnector [nodeConnector=" + nodeConnector + ", vlan="
178 + vlan + ", staticHost=" + staticHost + "]";
181 public boolean isV4Host() {
182 return (getNetworkAddress() instanceof Inet4Address);
185 public boolean isV6Host() {
186 return (getNetworkAddress() instanceof Inet6Address);
189 public String toJson() {
190 return "{\"host\":\"" + super.toString() + "\", " + "\"vlan\":\""
191 + String.valueOf(vlan) + "\",\"NodeConnector\":\""
192 + nodeConnector.toString() + "\"," + "\"static\":\""
193 + String.valueOf(isStaticHost()) + "\"}";