blob: a08a3a5d2cb723582cf422b5ca988a22ac61e3f2 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2 * Copyright 2011,2012 Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford University
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 **/
17
18/**
19 * @author Srini
20 */
21
22package net.floodlightcontroller.devicemanager.internal;
23
24public class AttachmentPoint {
25 long sw;
26 short port;
27 long activeSince;
28 long lastSeen;
29
30 // Timeout for moving attachment points from OF/broadcast
31 // domain to another.
32 public static final long INACTIVITY_INTERVAL = 30000; // 30 seconds
33 public static final long EXTERNAL_TO_EXTERNAL_TIMEOUT = 5000; // 5 seconds
34 public static final long OPENFLOW_TO_EXTERNAL_TIMEOUT = 30000; // 30 seconds
35 public static final long CONSISTENT_TIMEOUT = 30000; // 30 seconds
36
37 public AttachmentPoint(long sw, short port, long activeSince,
38 long lastSeen) {
39 this.sw = sw;
40 this.port = port;
41 this.activeSince = activeSince;
42 this.lastSeen = lastSeen;
43 }
44
45 public AttachmentPoint(long sw, short port, long lastSeen) {
46 this.sw = sw;
47 this.port = port;
48 this.lastSeen = lastSeen;
49 this.activeSince = lastSeen;
50 }
51
52 public AttachmentPoint(AttachmentPoint ap) {
53 this.sw = ap.sw;
54 this.port = ap.port;
55 this.activeSince = ap.activeSince;
56 this.lastSeen = ap.lastSeen;
57 }
58
59 public long getSw() {
60 return sw;
61 }
62 public void setSw(long sw) {
63 this.sw = sw;
64 }
65 public short getPort() {
66 return port;
67 }
68 public void setPort(short port) {
69 this.port = port;
70 }
71 public long getActiveSince() {
72 return activeSince;
73 }
74 public void setActiveSince(long activeSince) {
75 this.activeSince = activeSince;
76 }
77 public long getLastSeen() {
78 return lastSeen;
79 }
80 public void setLastSeen(long lastSeen) {
81 if (this.lastSeen + INACTIVITY_INTERVAL < lastSeen)
82 this.activeSince = lastSeen;
83 if (this.lastSeen < lastSeen)
84 this.lastSeen = lastSeen;
85 }
86
87 /**
88 * Hash is generated using only switch and port
89 */
90 @Override
91 public int hashCode() {
92 final int prime = 31;
93 int result = 1;
94 result = prime * result + port;
95 result = prime * result + (int) (sw ^ (sw >>> 32));
96 return result;
97 }
98
99 /**
100 * Compares only the switch and port
101 */
102 @Override
103 public boolean equals(Object obj) {
104 if (this == obj)
105 return true;
106 if (obj == null)
107 return false;
108 if (getClass() != obj.getClass())
109 return false;
110 AttachmentPoint other = (AttachmentPoint) obj;
111 if (port != other.port)
112 return false;
113 if (sw != other.sw)
114 return false;
115 return true;
116 }
117
118 @Override
119 public String toString() {
120 return "AttachmentPoint [sw=" + sw + ", port=" + port
121 + ", activeSince=" + activeSince + ", lastSeen=" + lastSeen
122 + "]";
123 }
124}