BUG 2302 : odl-clustering-test-app should not be part of the odl-restconf-all feature set
[controller.git] / opendaylight / hosttracker_new / implementation / src / main / java / org / opendaylight / controller / hosttracker / internal / AttachmentPoint.java
1 /*
2  * Copyright (c) 2011,2012 Big Switch Networks, Inc.
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the
5  * "License"); you may not use this file except in compliance with the
6  * License. You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  *
16  * This file incorporates work covered by the following copyright and
17  * permission notice:
18  *
19  *    Originally created by David Erickson, Stanford University
20  *
21  *    Licensed under the Apache License, Version 2.0 (the "License");
22  *    you may not use this file except in compliance with the
23  *    License. You may obtain a copy of the License at
24  *
25  *         http://www.apache.org/licenses/LICENSE-2.0
26  *
27  *    Unless required by applicable law or agreed to in writing,
28  *    software distributed under the License is distributed on an "AS
29  *    IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
30  *    express or implied. See the License for the specific language
31  *    governing permissions and limitations under the License.
32  */
33
34 /**
35  * @author Srini
36  */
37
38 package org.opendaylight.controller.hosttracker.internal;
39
40 import org.opendaylight.controller.sal.core.NodeConnector;
41
42 public class AttachmentPoint {
43     NodeConnector port;
44     long activeSince;
45     long lastSeen;
46
47     // Timeout for moving attachment points from OF/broadcast
48     // domain to another.
49     public static final long INACTIVITY_INTERVAL = 30000; // 30 seconds
50     public static final long EXTERNAL_TO_EXTERNAL_TIMEOUT = 5000; // 5 seconds
51     public static final long OPENFLOW_TO_EXTERNAL_TIMEOUT = 30000; // 30 seconds
52     public static final long CONSISTENT_TIMEOUT = 30000; // 30 seconds
53
54     public AttachmentPoint(NodeConnector port, long activeSince, long lastSeen) {
55         this.port = port;
56         this.activeSince = activeSince;
57         this.lastSeen = lastSeen;
58     }
59
60     public AttachmentPoint(NodeConnector port, long lastSeen) {
61         this.port = port;
62         this.lastSeen = lastSeen;
63         this.activeSince = lastSeen;
64     }
65
66     public AttachmentPoint(AttachmentPoint ap) {
67         this.port = ap.port;
68         this.activeSince = ap.activeSince;
69         this.lastSeen = ap.lastSeen;
70     }
71
72     public NodeConnector getPort() {
73         return port;
74     }
75
76     public void setPort(NodeConnector port) {
77         this.port = port;
78     }
79
80     public long getActiveSince() {
81         return activeSince;
82     }
83
84     public void setActiveSince(long activeSince) {
85         this.activeSince = activeSince;
86     }
87
88     public long getLastSeen() {
89         return lastSeen;
90     }
91
92     public void setLastSeen(long lastSeen) {
93         if (this.lastSeen + INACTIVITY_INTERVAL < lastSeen)
94             this.activeSince = lastSeen;
95         if (this.lastSeen < lastSeen)
96             this.lastSeen = lastSeen;
97     }
98
99     @Override
100     public int hashCode() {
101         final int prime = 31;
102         int result = 1;
103         result = prime * result + ((port == null) ? 0 : port.hashCode());
104         return result;
105     }
106
107     @Override
108     public boolean equals(Object obj) {
109         if (this == obj)
110             return true;
111         if (obj == null)
112             return false;
113         if (getClass() != obj.getClass())
114             return false;
115         AttachmentPoint other = (AttachmentPoint) obj;
116         if (port == null) {
117             if (other.port != null)
118                 return false;
119         } else if (!port.equals(other.port))
120             return false;
121         return true;
122     }
123
124     @Override
125     public String toString() {
126         return "AttachmentPoint [port=" + port + ", activeSince=" + activeSince
127                 + ", lastSeen=" + lastSeen + "]";
128     }
129 }