Merge "Fix end of TLV in LLDP packet"
[controller.git] / opendaylight / hosttracker / api / src / main / java / org / opendaylight / controller / hosttracker / IPMacHostId.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.hosttracker;
9
10 import java.io.Serializable;
11 import java.net.InetAddress;
12
13 /*
14  * IP + Mac key class implementation using the marker interface IHostId
15  * @author Deepak Udapudi
16  */
17
18 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
19
20 public class IPMacHostId implements IHostId, Serializable {
21
22     private static final long serialVersionUID = 1L;
23     private InetAddress ipAddress;
24     private DataLinkAddress macAddr;
25
26     public IPMacHostId(InetAddress ipAddress, DataLinkAddress macAddr) {
27         super();
28         this.ipAddress = ipAddress;
29         this.macAddr = macAddr;
30     }
31
32     public InetAddress getIpAddress() {
33         return ipAddress;
34     }
35
36     public void setIpAddress(InetAddress ipAddress) {
37         this.ipAddress = ipAddress;
38     }
39
40     public DataLinkAddress getMacAddr() {
41         return macAddr;
42     }
43
44     public void setMacAddr(DataLinkAddress macAddr) {
45         this.macAddr = macAddr;
46     }
47
48     @Override
49     public int hashCode() {
50         final int prime = 31;
51         int result = 1;
52         result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
53         result = prime * result + ((macAddr == null) ? 0 : macAddr.hashCode());
54         return result;
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (this == obj)
60             return true;
61         if (obj == null)
62             return false;
63         if (getClass() != obj.getClass())
64             return false;
65         IPMacHostId other = (IPMacHostId) obj;
66         if (ipAddress == null) {
67             if (other.ipAddress != null)
68                 return false;
69         } else if (!ipAddress.equals(other.ipAddress))
70             return false;
71         if (macAddr == null) {
72             if (other.macAddr != null)
73                 return false;
74         } else if (!macAddr.equals(other.macAddr))
75             return false;
76         return true;
77     }
78
79     public static IHostId fromIPAndMac(InetAddress ip, DataLinkAddress mac) {
80         return new IPMacHostId(ip, mac);
81     }
82
83 }