Add missing license headers
[netvirt.git] / vpnservice / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / netvirt / vpnmanager / MacEntry.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  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.netvirt.vpnmanager;
9
10 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
11
12 import java.net.InetAddress;
13 import java.util.concurrent.Delayed;
14 import java.util.concurrent.TimeUnit;
15
16 public class MacEntry implements Delayed {
17
18     private long expiryTime;
19     private String vpnName;
20     private MacAddress macAddress;
21     private InetAddress ipAddress;
22     private String interfaceName;
23
24     public MacEntry(long delay, String vpnName, MacAddress macAddress, InetAddress inetAddress, String interfaceName) {
25         this.expiryTime = System.currentTimeMillis() + delay;
26         this.vpnName = vpnName;
27         this.macAddress = macAddress;
28         this.ipAddress = inetAddress;
29         this.interfaceName = interfaceName;
30     }
31
32     public String getVpnName() {
33         return vpnName;
34     }
35
36     public void setVpnName(String vpnName) {
37         this.vpnName = vpnName;
38     }
39
40
41     @Override
42     public String toString() {
43         return "MacEntry [expiryTime=" + expiryTime + ", vpnName=" + vpnName + ", macAddress=" + macAddress
44               + ", ipAddress=" + ipAddress + ", interfaceName=" + interfaceName + "]";
45     }
46
47     public MacAddress getMacAddress() {
48         return macAddress;
49     }
50
51     public String getInterfaceName() {
52         return interfaceName;
53     }
54
55     public void setInterfaceName(String interfaceName) {
56         this.interfaceName = interfaceName;
57     }
58
59     public InetAddress getIpAddress() {
60         return ipAddress;
61     }
62
63
64     @Override
65     public int compareTo(Delayed obj) {
66         if (this.expiryTime > ((MacEntry) obj).expiryTime) {
67             return -1;
68         } else if (this.expiryTime < ((MacEntry) obj).expiryTime) {
69             return 1;
70         } else {
71             return 0;
72         }
73     }
74
75     @Override
76     public long getDelay(TimeUnit arg0) {
77         long diff = expiryTime - System.currentTimeMillis();
78         return diff;
79     }
80
81     @Override
82     public int hashCode() {
83         final int prime = 31;
84         int result = 1;
85         result = prime * result
86                 + ((macAddress == null) ? 0 : macAddress.hashCode());
87         return result;
88     }
89
90     @Override
91     public boolean equals(Object obj) {
92         boolean result = false;
93         if (getClass() != obj.getClass())
94             return result;
95         else{
96         MacEntry other = (MacEntry) obj;
97         result = vpnName.equals(other.vpnName) && macAddress.equals(other.macAddress) && ipAddress.equals(other.ipAddress) && interfaceName.equals(other.interfaceName);
98         }
99         return result;
100     }
101
102
103 }