2 * Copyright IBM Corporation, 2013. 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
8 package org.opendaylight.controller.hosttracker;
10 import java.io.Serializable;
11 import java.net.InetAddress;
14 * IP + Mac key class implementation using the marker interface IHostId
15 * @author Deepak Udapudi
18 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
20 public class IPMacHostId implements IHostId, Serializable {
22 private static final long serialVersionUID = 1L;
23 private InetAddress ipAddress;
24 private DataLinkAddress macAddr;
26 public IPMacHostId(InetAddress ipAddress, DataLinkAddress macAddr) {
28 this.ipAddress = ipAddress;
29 this.macAddr = macAddr;
32 public InetAddress getIpAddress() {
36 public void setIpAddress(InetAddress ipAddress) {
37 this.ipAddress = ipAddress;
40 public DataLinkAddress getMacAddr() {
44 public void setMacAddr(DataLinkAddress macAddr) {
45 this.macAddr = macAddr;
49 public int hashCode() {
52 result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
53 result = prime * result + ((macAddr == null) ? 0 : macAddr.hashCode());
58 public boolean equals(Object obj) {
63 if (getClass() != obj.getClass())
65 IPMacHostId other = (IPMacHostId) obj;
66 if (ipAddress == null) {
67 if (other.ipAddress != null)
69 } else if (!ipAddress.equals(other.ipAddress))
71 if (macAddr == null) {
72 if (other.macAddr != null)
74 } else if (!macAddr.equals(other.macAddr))
79 public static IHostId fromIPAndMac(InetAddress ip, DataLinkAddress mac) {
80 return new IPMacHostId(ip, mac);