Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
| 2 | * 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 | **/ |
| 15 | |
| 16 | package net.floodlightcontroller.linkdiscovery; |
| 17 | |
| 18 | import net.floodlightcontroller.linkdiscovery.ILinkDiscovery.LinkType; |
| 19 | |
| 20 | import org.openflow.protocol.OFPhysicalPort.OFPortState; |
| 21 | |
| 22 | public 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 | |
| 43 | /** The port states stored here are topology's last knowledge of |
| 44 | * the state of the port. This mostly mirrors the state |
| 45 | * maintained in the port list in IOFSwitch (i.e. the one returned |
| 46 | * from getPort), except that during a port status message the |
| 47 | * IOFSwitch port state will already have been updated with the |
| 48 | * new port state, so topology needs to keep its own copy so that |
| 49 | * it can determine if the port state has changed and therefore |
| 50 | * requires the new state to be written to storage. |
| 51 | */ |
| 52 | |
| 53 | |
| 54 | |
| 55 | public boolean linkStpBlocked() { |
| 56 | return ((srcPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue()) || |
| 57 | ((dstPortState & OFPortState.OFPPS_STP_MASK.getValue()) == OFPortState.OFPPS_STP_BLOCK.getValue()); |
| 58 | } |
| 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) { |
| 129 | if (this == obj) |
| 130 | return true; |
| 131 | if (obj == null) |
| 132 | return false; |
| 133 | if (!(obj instanceof LinkInfo)) |
| 134 | return false; |
| 135 | LinkInfo other = (LinkInfo) obj; |
| 136 | |
| 137 | if (firstSeenTime == null) { |
| 138 | if (other.firstSeenTime != null) |
| 139 | return false; |
| 140 | } else if (!firstSeenTime.equals(other.firstSeenTime)) |
| 141 | return false; |
| 142 | |
| 143 | if (lastLldpReceivedTime == null) { |
| 144 | if (other.lastLldpReceivedTime != null) |
| 145 | return false; |
| 146 | } else if (!lastLldpReceivedTime.equals(other.lastLldpReceivedTime)) |
| 147 | return false; |
| 148 | |
| 149 | if (lastBddpReceivedTime == null) { |
| 150 | if (other.lastBddpReceivedTime != null) |
| 151 | return false; |
| 152 | } else if (!lastBddpReceivedTime.equals(other.lastBddpReceivedTime)) |
| 153 | return false; |
| 154 | |
| 155 | if (srcPortState == null) { |
| 156 | if (other.srcPortState != null) |
| 157 | return false; |
| 158 | } else if (!srcPortState.equals(other.srcPortState)) |
| 159 | return false; |
| 160 | |
| 161 | if (dstPortState == null) { |
| 162 | if (other.dstPortState != null) |
| 163 | return false; |
| 164 | } else if (!dstPortState.equals(other.dstPortState)) |
| 165 | return false; |
| 166 | |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | /* (non-Javadoc) |
| 172 | * @see java.lang.Object#toString() |
| 173 | */ |
| 174 | @Override |
| 175 | public String toString() { |
| 176 | return "LinkInfo [unicastValidTime=" + ((lastLldpReceivedTime == null) ? "null" : lastLldpReceivedTime) |
| 177 | + ", multicastValidTime=" + ((lastBddpReceivedTime == null) ? "null" : lastBddpReceivedTime) |
| 178 | + ", srcPortState=" + ((srcPortState == null) ? "null" : srcPortState) |
| 179 | + ", dstPortState=" + ((dstPortState == null) ? "null" : srcPortState) |
| 180 | + "]"; |
| 181 | } |
| 182 | } |