Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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 implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 15 | */ |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 16 | package org.onlab.onos.provider.of.link.impl; |
| 17 | |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 18 | import static org.onlab.onos.openflow.controller.Dpid.uri; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
| 21 | import java.util.Collections; |
| 22 | import java.util.HashMap; |
| 23 | import java.util.HashSet; |
| 24 | import java.util.Iterator; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 25 | import java.util.Map; |
| 26 | import java.util.Set; |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 27 | import java.util.concurrent.ConcurrentHashMap; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 28 | import java.util.concurrent.TimeUnit; |
| 29 | import java.util.concurrent.atomic.AtomicInteger; |
| 30 | |
| 31 | import org.jboss.netty.util.Timeout; |
| 32 | import org.jboss.netty.util.TimerTask; |
| 33 | import org.onlab.onos.net.ConnectPoint; |
| 34 | import org.onlab.onos.net.DeviceId; |
| 35 | import org.onlab.onos.net.Link.Type; |
| 36 | import org.onlab.onos.net.PortNumber; |
| 37 | import org.onlab.onos.net.link.DefaultLinkDescription; |
| 38 | import org.onlab.onos.net.link.LinkDescription; |
| 39 | import org.onlab.onos.net.link.LinkProviderService; |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 40 | import org.onlab.onos.openflow.controller.Dpid; |
| 41 | import org.onlab.onos.openflow.controller.OpenFlowController; |
| 42 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 43 | import org.onlab.packet.Ethernet; |
| 44 | import org.onlab.packet.ONLabLddp; |
| 45 | import org.onlab.packet.ONLabLddp.DPIDandPort; |
tom | 8bf2e6b | 2014-09-10 20:53:54 -0700 | [diff] [blame] | 46 | import org.onlab.util.Timer; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 47 | import org.projectfloodlight.openflow.protocol.OFFactory; |
| 48 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 49 | import org.projectfloodlight.openflow.protocol.OFPacketOut; |
| 50 | import org.projectfloodlight.openflow.protocol.OFPortDesc; |
| 51 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 52 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 53 | import org.projectfloodlight.openflow.types.OFBufferId; |
| 54 | import org.projectfloodlight.openflow.types.OFPort; |
| 55 | import org.slf4j.Logger; |
| 56 | |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * Run discovery process from a physical switch. Ports are initially labeled as |
| 61 | * slow ports. When an LLDP is successfully received, label the remote port as |
| 62 | * fast. Every probeRate milliseconds, loop over all fast ports and send an |
| 63 | * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology |
| 64 | * discovery implementation. |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 65 | */ |
alshabib | 75e7742 | 2014-10-16 18:03:40 -0700 | [diff] [blame] | 66 | @Deprecated |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 67 | public class LinkDiscovery implements TimerTask { |
| 68 | |
| 69 | private final OpenFlowSwitch sw; |
| 70 | // send 1 probe every probeRate milliseconds |
| 71 | private final long probeRate; |
| 72 | private final Set<Integer> slowPorts; |
| 73 | private final Set<Integer> fastPorts; |
| 74 | // number of unacknowledged probes per port |
| 75 | private final Map<Integer, AtomicInteger> portProbeCount; |
| 76 | // number of probes to send before link is removed |
| 77 | private static final short MAX_PROBE_COUNT = 3; |
| 78 | private Iterator<Integer> slowIterator; |
| 79 | private final OFFactory ofFactory; |
| 80 | private final Logger log = getLogger(getClass()); |
| 81 | private final ONLabLddp lldpPacket; |
| 82 | private final Ethernet ethPacket; |
| 83 | private Ethernet bddpEth; |
| 84 | private final boolean useBDDP; |
| 85 | private final OpenFlowController ctrl; |
| 86 | private final LinkProviderService linkProvider; |
alshabib | 64231d8 | 2014-09-25 18:25:31 -0700 | [diff] [blame] | 87 | protected final Map<Integer, OFPortDesc> ports; |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 88 | private Timeout timeout; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 89 | |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 90 | /* |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 91 | * Instantiates discovery manager for the given physical switch. Creates a |
| 92 | * generic LLDP packet that will be customized for the port it is sent out on. |
| 93 | * Starts the the timer for the discovery process. |
| 94 | * |
| 95 | * @param sw the physical switch |
| 96 | * @param useBDDP flag to also use BDDP for discovery |
| 97 | */ |
| 98 | public LinkDiscovery(final OpenFlowSwitch sw, |
| 99 | OpenFlowController ctrl, LinkProviderService providerService, Boolean... useBDDP) { |
| 100 | this.sw = sw; |
| 101 | this.ofFactory = sw.factory(); |
| 102 | this.ctrl = ctrl; |
alshabib | 7674db4 | 2014-09-12 23:40:46 -0700 | [diff] [blame] | 103 | this.probeRate = 3000; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 104 | this.linkProvider = providerService; |
| 105 | this.slowPorts = Collections.synchronizedSet(new HashSet<Integer>()); |
| 106 | this.fastPorts = Collections.synchronizedSet(new HashSet<Integer>()); |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 107 | this.ports = new ConcurrentHashMap<>(); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 108 | this.portProbeCount = new HashMap<Integer, AtomicInteger>(); |
| 109 | this.lldpPacket = new ONLabLddp(); |
| 110 | this.lldpPacket.setSwitch(this.sw.getId()); |
| 111 | this.ethPacket = new Ethernet(); |
| 112 | this.ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
| 113 | this.ethPacket.setDestinationMACAddress(ONLabLddp.LLDP_NICIRA); |
| 114 | this.ethPacket.setPayload(this.lldpPacket); |
| 115 | this.ethPacket.setPad(true); |
| 116 | this.useBDDP = useBDDP.length > 0 ? useBDDP[0] : false; |
| 117 | if (this.useBDDP) { |
| 118 | this.bddpEth = new Ethernet(); |
| 119 | this.bddpEth.setPayload(this.lldpPacket); |
| 120 | this.bddpEth.setEtherType(Ethernet.TYPE_BSN); |
| 121 | this.bddpEth.setDestinationMACAddress(ONLabLddp.BDDP_MULTICAST); |
| 122 | this.bddpEth.setPad(true); |
| 123 | log.info("Using BDDP to discover network"); |
| 124 | } |
| 125 | for (OFPortDesc port : sw.getPorts()) { |
| 126 | if (port.getPortNo() != OFPort.LOCAL) { |
| 127 | addPort(port); |
| 128 | } |
| 129 | } |
alshabib | 7674db4 | 2014-09-12 23:40:46 -0700 | [diff] [blame] | 130 | timeout = Timer.getTimer().newTimeout(this, 0, |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 131 | TimeUnit.MILLISECONDS); |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 132 | this.log.info("Started discovery manager for switch {}", |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 133 | sw.getId()); |
| 134 | |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Add physical port port to discovery process. |
| 139 | * Send out initial LLDP and label it as slow port. |
| 140 | * |
| 141 | * @param port the port |
| 142 | */ |
| 143 | public void addPort(final OFPortDesc port) { |
| 144 | // Ignore ports that are not on this switch, or already booted. */ |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 145 | this.ports.put(port.getPortNo().getPortNumber(), port); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 146 | synchronized (this) { |
| 147 | this.log.debug("sending init probe to port {}", |
| 148 | port.getPortNo().getPortNumber()); |
| 149 | OFPacketOut pkt; |
| 150 | |
| 151 | pkt = this.createLLDPPacketOut(port); |
| 152 | this.sw.sendMsg(pkt); |
| 153 | if (useBDDP) { |
| 154 | OFPacketOut bpkt = this.createBDDPPacketOut(port); |
| 155 | this.sw.sendMsg(bpkt); |
| 156 | } |
| 157 | |
| 158 | this.slowPorts.add(port.getPortNo().getPortNumber()); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Removes physical port from discovery process. |
| 165 | * |
| 166 | * @param port the port |
| 167 | */ |
alshabib | a159a32 | 2014-09-09 14:50:51 -0700 | [diff] [blame] | 168 | public void removePort(final OFPortDesc port) { |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 169 | // Ignore ports that are not on this switch |
| 170 | |
alshabib | a159a32 | 2014-09-09 14:50:51 -0700 | [diff] [blame] | 171 | int portnum = port.getPortNo().getPortNumber(); |
| 172 | this.ports.remove(portnum); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 173 | synchronized (this) { |
| 174 | if (this.slowPorts.contains(portnum)) { |
| 175 | this.slowPorts.remove(portnum); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 176 | |
| 177 | } else if (this.fastPorts.contains(portnum)) { |
| 178 | this.fastPorts.remove(portnum); |
| 179 | this.portProbeCount.remove(portnum); |
| 180 | // no iterator to update |
| 181 | } else { |
| 182 | this.log.warn( |
| 183 | "tried to dynamically remove non-existing port {}", |
| 184 | portnum); |
| 185 | } |
| 186 | } |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 187 | ConnectPoint cp = new ConnectPoint( |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 188 | DeviceId.deviceId(uri(sw.getId())), |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 189 | PortNumber.portNumber(port.getPortNo().getPortNumber())); |
| 190 | linkProvider.linksVanished(cp); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 191 | |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Method called by remote port to acknowledge receipt of LLDP sent by |
| 196 | * this port. If slow port, updates label to fast. If fast port, decrements |
| 197 | * number of unacknowledged probes. |
| 198 | * |
| 199 | * @param port the port |
| 200 | */ |
| 201 | public void ackProbe(final Integer port) { |
| 202 | final int portNumber = port; |
| 203 | synchronized (this) { |
| 204 | if (this.slowPorts.contains(portNumber)) { |
| 205 | this.log.debug("Setting slow port to fast: {}:{}", |
| 206 | this.sw.getId(), portNumber); |
| 207 | this.slowPorts.remove(portNumber); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 208 | this.fastPorts.add(portNumber); |
| 209 | this.portProbeCount.put(portNumber, new AtomicInteger(0)); |
| 210 | } else { |
| 211 | if (this.fastPorts.contains(portNumber)) { |
| 212 | this.portProbeCount.get(portNumber).set(0); |
| 213 | } else { |
| 214 | this.log.debug( |
| 215 | "Got ackProbe for non-existing port: {}", |
| 216 | portNumber); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Creates packet_out LLDP for specified output port. |
| 224 | * |
| 225 | * @param port the port |
| 226 | * @return Packet_out message with LLDP data |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 227 | */ |
| 228 | private OFPacketOut createLLDPPacketOut(final OFPortDesc port) { |
alshabib | 89e43ef | 2014-09-16 10:36:34 -0700 | [diff] [blame] | 229 | if (port == null) { |
| 230 | return null; |
| 231 | } |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 232 | OFPacketOut.Builder packetOut = this.ofFactory.buildPacketOut(); |
| 233 | packetOut.setBufferId(OFBufferId.NO_BUFFER); |
| 234 | OFAction act = this.ofFactory.actions().buildOutput() |
| 235 | .setPort(port.getPortNo()).build(); |
| 236 | packetOut.setActions(Collections.singletonList(act)); |
| 237 | this.lldpPacket.setPort(port.getPortNo().getPortNumber()); |
| 238 | this.ethPacket.setSourceMACAddress(port.getHwAddr().getBytes()); |
| 239 | |
| 240 | final byte[] lldp = this.ethPacket.serialize(); |
| 241 | packetOut.setData(lldp); |
| 242 | return packetOut.build(); |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Creates packet_out BDDP for specified output port. |
| 247 | * |
| 248 | * @param port the port |
| 249 | * @return Packet_out message with LLDP data |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 250 | */ |
| 251 | private OFPacketOut createBDDPPacketOut(final OFPortDesc port) { |
alshabib | 89e43ef | 2014-09-16 10:36:34 -0700 | [diff] [blame] | 252 | if (port == null) { |
| 253 | return null; |
| 254 | } |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 255 | OFPacketOut.Builder packetOut = sw.factory().buildPacketOut(); |
| 256 | |
| 257 | packetOut.setBufferId(OFBufferId.NO_BUFFER); |
| 258 | |
| 259 | OFActionOutput.Builder act = sw.factory().actions().buildOutput() |
| 260 | .setPort(port.getPortNo()); |
| 261 | OFAction out = act.build(); |
| 262 | packetOut.setActions(Collections.singletonList(out)); |
| 263 | this.lldpPacket.setPort(port.getPortNo().getPortNumber()); |
| 264 | this.bddpEth.setSourceMACAddress(port.getHwAddr().getBytes()); |
| 265 | |
| 266 | final byte[] bddp = this.bddpEth.serialize(); |
| 267 | packetOut.setData(bddp); |
| 268 | |
| 269 | return packetOut.build(); |
| 270 | } |
| 271 | |
| 272 | |
| 273 | private void sendMsg(final OFMessage msg) { |
alshabib | 89e43ef | 2014-09-16 10:36:34 -0700 | [diff] [blame] | 274 | if (msg == null) { |
| 275 | return; |
| 276 | } |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 277 | this.sw.sendMsg(msg); |
| 278 | } |
| 279 | |
| 280 | public String getName() { |
| 281 | return "LinkDiscovery " + this.sw.getStringId(); |
| 282 | } |
| 283 | |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 284 | /* |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 285 | * Handles an incoming LLDP packet. Creates link in topology and sends ACK |
| 286 | * to port where LLDP originated. |
| 287 | */ |
alshabib | 505bc6b | 2014-09-09 15:04:13 -0700 | [diff] [blame] | 288 | public boolean handleLLDP(final byte[] pkt, Integer inPort) { |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 289 | |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 290 | short ethType = ONLabLddp.isOVXLLDP(pkt); |
| 291 | if (ethType == Ethernet.TYPE_LLDP || ethType == Ethernet.TYPE_BSN) { |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 292 | final Integer dstPort = inPort; |
| 293 | final DPIDandPort dp = ONLabLddp.parseLLDP(pkt); |
| 294 | final OpenFlowSwitch srcSwitch = ctrl.getSwitch(new Dpid(dp.getDpid())); |
| 295 | final Integer srcPort = dp.getPort(); |
| 296 | if (srcSwitch == null) { |
alshabib | 505bc6b | 2014-09-09 15:04:13 -0700 | [diff] [blame] | 297 | return true; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 298 | } |
| 299 | this.ackProbe(srcPort); |
| 300 | ConnectPoint src = new ConnectPoint( |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 301 | DeviceId.deviceId(uri(srcSwitch.getId())), |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 302 | PortNumber.portNumber(srcPort)); |
| 303 | |
| 304 | ConnectPoint dst = new ConnectPoint( |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 305 | DeviceId.deviceId(uri(sw.getId())), |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 306 | PortNumber.portNumber(dstPort)); |
| 307 | LinkDescription ld; |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 308 | if (ethType == Ethernet.TYPE_BSN) { |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 309 | ld = new DefaultLinkDescription(src, dst, Type.INDIRECT); |
| 310 | } else { |
| 311 | ld = new DefaultLinkDescription(src, dst, Type.DIRECT); |
| 312 | } |
| 313 | linkProvider.linkDetected(ld); |
alshabib | 505bc6b | 2014-09-09 15:04:13 -0700 | [diff] [blame] | 314 | return true; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 315 | } else { |
| 316 | this.log.debug("Ignoring unknown LLDP"); |
alshabib | 505bc6b | 2014-09-09 15:04:13 -0700 | [diff] [blame] | 317 | return false; |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 321 | private OFPortDesc findPort(Integer inPort) { |
| 322 | return ports.get(inPort); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Execute this method every t milliseconds. Loops over all ports |
| 327 | * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow |
| 328 | * port. |
| 329 | * |
| 330 | * @param t timeout |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 331 | */ |
| 332 | @Override |
| 333 | public void run(final Timeout t) { |
| 334 | this.log.debug("sending probes"); |
| 335 | synchronized (this) { |
| 336 | final Iterator<Integer> fastIterator = this.fastPorts.iterator(); |
| 337 | while (fastIterator.hasNext()) { |
| 338 | final Integer portNumber = fastIterator.next(); |
Yuta HIGUCHI | 70ce843 | 2014-10-15 23:59:10 -0700 | [diff] [blame] | 339 | OFPortDesc port = findPort(portNumber); |
| 340 | if (port == null) { |
| 341 | // port can be null |
| 342 | // #removePort modifies `ports` outside synchronized block |
| 343 | continue; |
| 344 | } |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 345 | final int probeCount = this.portProbeCount.get(portNumber) |
| 346 | .getAndIncrement(); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 347 | if (probeCount < LinkDiscovery.MAX_PROBE_COUNT) { |
| 348 | this.log.debug("sending fast probe to port"); |
| 349 | |
| 350 | OFPacketOut pkt = this.createLLDPPacketOut(port); |
| 351 | this.sendMsg(pkt); |
| 352 | if (useBDDP) { |
| 353 | OFPacketOut bpkt = this.createBDDPPacketOut(port); |
| 354 | this.sendMsg(bpkt); |
| 355 | } |
| 356 | } else { |
| 357 | // Update fast and slow ports |
| 358 | fastIterator.remove(); |
| 359 | this.slowPorts.add(portNumber); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 360 | this.portProbeCount.remove(portNumber); |
| 361 | |
| 362 | // Remove link from topology |
| 363 | final OFPortDesc srcPort = port; |
| 364 | |
| 365 | ConnectPoint cp = new ConnectPoint( |
tom | 782a7cf | 2014-09-11 23:58:38 -0700 | [diff] [blame] | 366 | DeviceId.deviceId(uri(sw.getId())), |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 367 | PortNumber.portNumber(srcPort.getPortNo().getPortNumber())); |
| 368 | linkProvider.linksVanished(cp); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | // send a probe for the next slow port |
alshabib | 818d57c | 2014-09-15 22:34:30 -0700 | [diff] [blame] | 373 | if (!this.slowPorts.isEmpty()) { |
| 374 | this.slowIterator = this.slowPorts.iterator(); |
| 375 | while (this.slowIterator.hasNext()) { |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 376 | final int portNumber = this.slowIterator.next(); |
| 377 | this.log.debug("sending slow probe to port {}", portNumber); |
alshabib | 9ee6817 | 2014-09-09 14:45:14 -0700 | [diff] [blame] | 378 | OFPortDesc port = findPort(portNumber); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 379 | |
| 380 | OFPacketOut pkt = this.createLLDPPacketOut(port); |
| 381 | this.sendMsg(pkt); |
| 382 | if (useBDDP) { |
| 383 | OFPacketOut bpkt = this.createBDDPPacketOut(port); |
| 384 | this.sendMsg(bpkt); |
| 385 | } |
| 386 | |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | // reschedule timer |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 392 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 393 | TimeUnit.MILLISECONDS); |
| 394 | } |
| 395 | |
| 396 | public void removeAllPorts() { |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 397 | for (OFPortDesc port : ports.values()) { |
alshabib | a159a32 | 2014-09-09 14:50:51 -0700 | [diff] [blame] | 398 | removePort(port); |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 402 | public void stop() { |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 403 | timeout.cancel(); |
alshabib | 89e43ef | 2014-09-16 10:36:34 -0700 | [diff] [blame] | 404 | removeAllPorts(); |
alshabib | c944fd0 | 2014-09-10 17:55:17 -0700 | [diff] [blame] | 405 | } |
| 406 | |
alshabib | df652ad | 2014-09-09 11:53:19 -0700 | [diff] [blame] | 407 | } |