blob: f75736018f8422dfa5161e6d7cb3d19fd0193928 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.* Originally created by David Erickson, Stanford University
3 ** Licensed under the Apache License, Version 2.0 (the "License"); you may
4 * not use this file except in compliance with the License. You may obtain
5 * a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 * License for the specific language governing permissions and limitations
13 * under the License.
14 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080015
Jonathan Hart23701d12014-04-03 10:45:48 -070016package net.onrc.onos.core.linkdiscovery;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
Jonathan Hart23701d12014-04-03 10:45:48 -070018import net.onrc.onos.core.linkdiscovery.ILinkDiscovery.LinkType;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20import org.openflow.protocol.OFPhysicalPort.OFPortState;
21
22public class LinkInfo {
23
24 public LinkInfo(Long firstSeenTime,
25 Long lastLldpReceivedTime,
26 Long lastBddpReceivedTime,
27 int srcPortState,
28 int dstPortState) {
29 super();
30 this.srcPortState = srcPortState;
31 this.dstPortState = dstPortState;
32 this.firstSeenTime = firstSeenTime;
33 this.lastLldpReceivedTime = lastLldpReceivedTime;
34 this.lastBddpReceivedTime = lastBddpReceivedTime;
35 }
36
37 protected Integer srcPortState;
38 protected Integer dstPortState;
39 protected Long firstSeenTime;
40 protected Long lastLldpReceivedTime; /* Standard LLLDP received time */
41 protected Long lastBddpReceivedTime; /* Modified LLDP received time */
42
Ray Milkey269ffb92014-04-03 14:43:30 -070043 /**
44 * The port states stored here are topology's last knowledge of
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080045 * the state of the port. This mostly mirrors the state
46 * maintained in the port list in IOFSwitch (i.e. the one returned
47 * from getPort), except that during a port status message the
48 * IOFSwitch port state will already have been updated with the
49 * new port state, so topology needs to keep its own copy so that
50 * it can determine if the port state has changed and therefore
51 * requires the new state to be written to storage.
52 */
53
54
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080055 public boolean linkStpBlocked() {
56 return ((srcPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue()) ||
Ray Milkey269ffb92014-04-03 14:43:30 -070057 ((dstPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue());
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 }
59
60 public Long getFirstSeenTime() {
61 return firstSeenTime;
62 }
63
64 public void setFirstSeenTime(Long firstSeenTime) {
65 this.firstSeenTime = firstSeenTime;
66 }
67
68 public Long getUnicastValidTime() {
69 return lastLldpReceivedTime;
70 }
71
72 public void setUnicastValidTime(Long unicastValidTime) {
73 this.lastLldpReceivedTime = unicastValidTime;
74 }
75
76 public Long getMulticastValidTime() {
77 return lastBddpReceivedTime;
78 }
79
80 public void setMulticastValidTime(Long multicastValidTime) {
81 this.lastBddpReceivedTime = multicastValidTime;
82 }
83
84 public Integer getSrcPortState() {
85 return srcPortState;
86 }
87
88 public void setSrcPortState(Integer srcPortState) {
89 this.srcPortState = srcPortState;
90 }
91
92 public Integer getDstPortState() {
93 return dstPortState;
94 }
95
96 public void setDstPortState(int dstPortState) {
97 this.dstPortState = dstPortState;
98 }
99
100 public LinkType getLinkType() {
101 if (lastLldpReceivedTime != null) {
102 return LinkType.DIRECT_LINK;
103 } else if (lastBddpReceivedTime != null) {
104 return LinkType.MULTIHOP_LINK;
105 }
106 return LinkType.INVALID_LINK;
107 }
108
109 /* (non-Javadoc)
110 * @see java.lang.Object#hashCode()
111 */
112 @Override
113 public int hashCode() {
114 final int prime = 5557;
115 int result = 1;
116 result = prime * result + ((firstSeenTime == null) ? 0 : firstSeenTime.hashCode());
117 result = prime * result + ((lastLldpReceivedTime == null) ? 0 : lastLldpReceivedTime.hashCode());
118 result = prime * result + ((lastBddpReceivedTime == null) ? 0 : lastBddpReceivedTime.hashCode());
119 result = prime * result + ((srcPortState == null) ? 0 : srcPortState.hashCode());
120 result = prime * result + ((dstPortState == null) ? 0 : dstPortState.hashCode());
121 return result;
122 }
123
124 /* (non-Javadoc)
125 * @see java.lang.Object#equals(java.lang.Object)
126 */
127 @Override
128 public boolean equals(Object obj) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700129 if (this == obj) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800130 return true;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700131 }
132 if (obj == null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800133 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700134 }
135 if (!(obj instanceof LinkInfo)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800136 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700137 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800138 LinkInfo other = (LinkInfo) obj;
139
140 if (firstSeenTime == null) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700141 if (other.firstSeenTime != null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800142 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700143 }
144 } else if (!firstSeenTime.equals(other.firstSeenTime)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800145 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700146 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800147
148 if (lastLldpReceivedTime == null) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700149 if (other.lastLldpReceivedTime != null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800150 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700151 }
152 } else if (!lastLldpReceivedTime.equals(other.lastLldpReceivedTime)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800153 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700154 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800155
156 if (lastBddpReceivedTime == null) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700157 if (other.lastBddpReceivedTime != null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800158 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700159 }
160 } else if (!lastBddpReceivedTime.equals(other.lastBddpReceivedTime)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800161 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700162 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800163
164 if (srcPortState == null) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700165 if (other.srcPortState != null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800166 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700167 }
168 } else if (!srcPortState.equals(other.srcPortState)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800169 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700170 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800171
172 if (dstPortState == null) {
Ray Milkeyb29e6262014-04-09 16:02:14 -0700173 if (other.dstPortState != null) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800174 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700175 }
176 } else if (!dstPortState.equals(other.dstPortState)) {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800177 return false;
Ray Milkeyb29e6262014-04-09 16:02:14 -0700178 }
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800179
180 return true;
181 }
182
183
184 /* (non-Javadoc)
185 * @see java.lang.Object#toString()
186 */
187 @Override
188 public String toString() {
189 return "LinkInfo [unicastValidTime=" + ((lastLldpReceivedTime == null) ? "null" : lastLldpReceivedTime)
190 + ", multicastValidTime=" + ((lastBddpReceivedTime == null) ? "null" : lastBddpReceivedTime)
191 + ", srcPortState=" + ((srcPortState == null) ? "null" : srcPortState)
192 + ", dstPortState=" + ((dstPortState == null) ? "null" : srcPortState)
193 + "]";
194 }
195}