Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
alshabib | 7911a05 | 2014-10-16 17:49:37 -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 | 7911a05 | 2014-10-16 17:49:37 -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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.lldp.impl; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 17 | |
Madan Jampani | 565a66a | 2015-07-25 17:01:13 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 20 | import static org.onosproject.net.PortNumber.portNumber; |
| 21 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
| 22 | import static org.slf4j.LoggerFactory.getLogger; |
| 23 | |
| 24 | import java.nio.ByteBuffer; |
| 25 | import java.util.Collections; |
| 26 | import java.util.HashMap; |
| 27 | import java.util.HashSet; |
| 28 | import java.util.Iterator; |
| 29 | import java.util.Map; |
| 30 | import java.util.Set; |
| 31 | import java.util.concurrent.atomic.AtomicInteger; |
| 32 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 33 | import org.jboss.netty.util.Timeout; |
| 34 | import org.jboss.netty.util.TimerTask; |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 35 | import org.onlab.packet.Ethernet; |
| 36 | import org.onlab.packet.ONOSLLDP; |
| 37 | import org.onlab.util.Timer; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 38 | import org.onosproject.mastership.MastershipService; |
| 39 | import org.onosproject.net.ConnectPoint; |
| 40 | import org.onosproject.net.Device; |
| 41 | import org.onosproject.net.DeviceId; |
| 42 | import org.onosproject.net.Link.Type; |
| 43 | import org.onosproject.net.Port; |
| 44 | import org.onosproject.net.PortNumber; |
| 45 | import org.onosproject.net.link.DefaultLinkDescription; |
| 46 | import org.onosproject.net.link.LinkDescription; |
| 47 | import org.onosproject.net.link.LinkProviderService; |
| 48 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 49 | import org.onosproject.net.packet.OutboundPacket; |
| 50 | import org.onosproject.net.packet.PacketContext; |
| 51 | import org.onosproject.net.packet.PacketService; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 52 | import org.slf4j.Logger; |
| 53 | |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 54 | // TODO: add 'fast discovery' mode: drop LLDPs in destination switch but listen for flow_removed messages |
| 55 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Run discovery process from a physical switch. Ports are initially labeled as |
| 58 | * slow ports. When an LLDP is successfully received, label the remote port as |
| 59 | * fast. Every probeRate milliseconds, loop over all fast ports and send an |
| 60 | * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology |
| 61 | * discovery implementation. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 62 | */ |
| 63 | public class LinkDiscovery implements TimerTask { |
| 64 | |
| 65 | private final Device device; |
| 66 | // send 1 probe every probeRate milliseconds |
| 67 | private final long probeRate; |
| 68 | private final Set<Long> slowPorts; |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 69 | // ports, known to have incoming links |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 70 | private final Set<Long> fastPorts; |
| 71 | // number of unacknowledged probes per port |
| 72 | private final Map<Long, AtomicInteger> portProbeCount; |
| 73 | // number of probes to send before link is removed |
| 74 | private static final short MAX_PROBE_COUNT = 3; |
| 75 | private final Logger log = getLogger(getClass()); |
| 76 | private final ONOSLLDP lldpPacket; |
| 77 | private final Ethernet ethPacket; |
| 78 | private Ethernet bddpEth; |
| 79 | private final boolean useBDDP; |
| 80 | private final LinkProviderService linkProvider; |
| 81 | private final PacketService pktService; |
alshabib | 875d626 | 2014-10-17 16:19:40 -0700 | [diff] [blame] | 82 | private final MastershipService mastershipService; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 83 | private Timeout timeout; |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 84 | private volatile boolean isStopped; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Instantiates discovery manager for the given physical switch. Creates a |
| 88 | * generic LLDP packet that will be customized for the port it is sent out on. |
| 89 | * Starts the the timer for the discovery process. |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 90 | * |
| 91 | * @param device the physical switch |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 92 | * @param pktService packet service |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 93 | * @param masterService mastership service |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 94 | * @param providerService link provider service |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 95 | * @param useBDDP flag to also use BDDP for discovery |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 96 | */ |
| 97 | public LinkDiscovery(Device device, PacketService pktService, |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 98 | MastershipService masterService, |
| 99 | LinkProviderService providerService, Boolean... useBDDP) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 100 | this.device = device; |
| 101 | this.probeRate = 3000; |
| 102 | this.linkProvider = providerService; |
| 103 | this.pktService = pktService; |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 104 | |
| 105 | this.mastershipService = checkNotNull(masterService, "WTF!"); |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 106 | this.slowPorts = Collections.synchronizedSet(new HashSet<>()); |
| 107 | this.fastPorts = Collections.synchronizedSet(new HashSet<>()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 108 | this.portProbeCount = new HashMap<>(); |
| 109 | this.lldpPacket = new ONOSLLDP(); |
| 110 | this.lldpPacket.setChassisId(device.chassisId()); |
| 111 | this.lldpPacket.setDevice(device.id().toString()); |
| 112 | |
| 113 | |
| 114 | this.ethPacket = new Ethernet(); |
| 115 | this.ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
| 116 | this.ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA); |
| 117 | this.ethPacket.setPayload(this.lldpPacket); |
| 118 | this.ethPacket.setPad(true); |
| 119 | this.useBDDP = useBDDP.length > 0 ? useBDDP[0] : false; |
| 120 | if (this.useBDDP) { |
| 121 | this.bddpEth = new Ethernet(); |
| 122 | this.bddpEth.setPayload(this.lldpPacket); |
| 123 | this.bddpEth.setEtherType(Ethernet.TYPE_BSN); |
| 124 | this.bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST); |
| 125 | this.bddpEth.setPad(true); |
| 126 | log.info("Using BDDP to discover network"); |
| 127 | } |
| 128 | |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 129 | this.isStopped = true; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 130 | start(); |
| 131 | this.log.debug("Started discovery manager for switch {}", |
| 132 | device.id()); |
| 133 | |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Add physical port port to discovery process. |
| 138 | * Send out initial LLDP and label it as slow port. |
| 139 | * |
| 140 | * @param port the port |
| 141 | */ |
| 142 | public void addPort(final Port port) { |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 143 | boolean newPort = false; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 144 | synchronized (this) { |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 145 | if (!containsPort(port.number().toLong())) { |
| 146 | newPort = true; |
| 147 | this.slowPorts.add(port.number().toLong()); |
| 148 | } |
| 149 | } |
| 150 | |
Madan Jampani | 565a66a | 2015-07-25 17:01:13 -0700 | [diff] [blame] | 151 | boolean isMaster = mastershipService.isLocalMaster(device.id()); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 152 | if (newPort && isMaster) { |
| 153 | this.log.debug("Sending init probe to port {}@{}", |
| 154 | port.number().toLong(), device.id()); |
| 155 | sendProbes(port.number().toLong()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 156 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Removes physical port from discovery process. |
| 161 | * |
| 162 | * @param port the port |
| 163 | */ |
| 164 | public void removePort(final Port port) { |
| 165 | // Ignore ports that are not on this switch |
| 166 | |
| 167 | long portnum = port.number().toLong(); |
| 168 | synchronized (this) { |
| 169 | if (this.slowPorts.contains(portnum)) { |
| 170 | this.slowPorts.remove(portnum); |
| 171 | |
| 172 | } else if (this.fastPorts.contains(portnum)) { |
| 173 | this.fastPorts.remove(portnum); |
| 174 | this.portProbeCount.remove(portnum); |
| 175 | // no iterator to update |
| 176 | } else { |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 177 | this.log.warn("Tried to dynamically remove non-existing port {}", |
| 178 | portnum); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Method called by remote port to acknowledge receipt of LLDP sent by |
| 185 | * this port. If slow port, updates label to fast. If fast port, decrements |
| 186 | * number of unacknowledged probes. |
| 187 | * |
| 188 | * @param portNumber the port |
| 189 | */ |
| 190 | public void ackProbe(final Long portNumber) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 191 | synchronized (this) { |
| 192 | if (this.slowPorts.contains(portNumber)) { |
| 193 | this.log.debug("Setting slow port to fast: {}:{}", |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 194 | this.device.id(), portNumber); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 195 | this.slowPorts.remove(portNumber); |
| 196 | this.fastPorts.add(portNumber); |
| 197 | this.portProbeCount.put(portNumber, new AtomicInteger(0)); |
alshabib | acd9183 | 2014-10-17 14:38:41 -0700 | [diff] [blame] | 198 | } else if (this.fastPorts.contains(portNumber)) { |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 199 | this.portProbeCount.get(portNumber).set(0); |
alshabib | acd9183 | 2014-10-17 14:38:41 -0700 | [diff] [blame] | 200 | } else { |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 201 | this.log.debug("Got ackProbe for non-existing port: {}", portNumber); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /** |
| 208 | * Handles an incoming LLDP packet. Creates link in topology and sends ACK |
| 209 | * to port where LLDP originated. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 210 | * @param context packet context |
| 211 | * @return true if handled |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 212 | */ |
| 213 | public boolean handleLLDP(PacketContext context) { |
| 214 | Ethernet eth = context.inPacket().parsed(); |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 215 | if (eth == null) { |
| 216 | return false; |
| 217 | } |
| 218 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 219 | ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth); |
| 220 | if (onoslldp != null) { |
| 221 | final PortNumber dstPort = |
| 222 | context.inPacket().receivedFrom().port(); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 223 | final PortNumber srcPort = portNumber(onoslldp.getPort()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 224 | final DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString()); |
| 225 | final DeviceId dstDeviceId = context.inPacket().receivedFrom().deviceId(); |
Jonathan Hart | 43ef46f | 2014-10-23 08:33:33 -0700 | [diff] [blame] | 226 | this.ackProbe(dstPort.toLong()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 227 | ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort); |
| 228 | ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort); |
| 229 | |
| 230 | LinkDescription ld; |
| 231 | if (eth.getEtherType() == Ethernet.TYPE_BSN) { |
| 232 | ld = new DefaultLinkDescription(src, dst, Type.INDIRECT); |
| 233 | } else { |
| 234 | ld = new DefaultLinkDescription(src, dst, Type.DIRECT); |
| 235 | } |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 236 | |
| 237 | try { |
| 238 | linkProvider.linkDetected(ld); |
| 239 | } catch (IllegalStateException e) { |
| 240 | return true; |
| 241 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 242 | return true; |
| 243 | } |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Execute this method every t milliseconds. Loops over all ports |
| 250 | * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow |
| 251 | * port. |
| 252 | * |
| 253 | * @param t timeout |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 254 | */ |
| 255 | @Override |
| 256 | public void run(final Timeout t) { |
Yuta HIGUCHI | 3419858 | 2014-11-10 16:24:58 -0800 | [diff] [blame] | 257 | if (isStopped()) { |
| 258 | return; |
| 259 | } |
Madan Jampani | 565a66a | 2015-07-25 17:01:13 -0700 | [diff] [blame] | 260 | if (!mastershipService.isLocalMaster(device.id())) { |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 261 | if (!isStopped()) { |
| 262 | // reschedule timer |
| 263 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); |
| 264 | } |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 268 | this.log.trace("Sending probes from {}", device.id()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 269 | synchronized (this) { |
| 270 | final Iterator<Long> fastIterator = this.fastPorts.iterator(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 271 | while (fastIterator.hasNext()) { |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 272 | long portNumber = fastIterator.next(); |
| 273 | int probeCount = portProbeCount.get(portNumber).getAndIncrement(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 274 | |
| 275 | if (probeCount < LinkDiscovery.MAX_PROBE_COUNT) { |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 276 | this.log.trace("Sending fast probe to port {}", portNumber); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 277 | sendProbes(portNumber); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 278 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 279 | } else { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 280 | // Link down, demote to slowPorts |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 281 | // Update fast and slow ports |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 282 | fastIterator.remove(); |
| 283 | this.slowPorts.add(portNumber); |
| 284 | this.portProbeCount.remove(portNumber); |
| 285 | |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 286 | ConnectPoint cp = new ConnectPoint(device.id(), |
| 287 | portNumber(portNumber)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 288 | log.debug("Link down -> {}", cp); |
| 289 | linkProvider.linksVanished(cp); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | // send a probe for the next slow port |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 294 | for (long portNumber : slowPorts) { |
| 295 | this.log.trace("Sending slow probe to port {}", portNumber); |
| 296 | sendProbes(portNumber); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 300 | if (!isStopped()) { |
| 301 | // reschedule timer |
| 302 | timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); |
| 303 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 306 | public synchronized void stop() { |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 307 | isStopped = true; |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 308 | timeout.cancel(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 311 | public synchronized void start() { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 312 | if (isStopped) { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 313 | isStopped = false; |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 314 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 315 | } else { |
| 316 | log.warn("LinkDiscovery started multiple times?"); |
| 317 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /** |
| 321 | * Creates packet_out LLDP for specified output port. |
| 322 | * |
| 323 | * @param port the port |
| 324 | * @return Packet_out message with LLDP data |
| 325 | */ |
| 326 | private OutboundPacket createOutBoundLLDP(final Long port) { |
| 327 | if (port == null) { |
| 328 | return null; |
| 329 | } |
| 330 | this.lldpPacket.setPortId(port.intValue()); |
| 331 | this.ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11"); |
| 332 | |
| 333 | final byte[] lldp = this.ethPacket.serialize(); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 334 | return new DefaultOutboundPacket(this.device.id(), |
| 335 | builder().setOutput(portNumber(port)).build(), |
| 336 | ByteBuffer.wrap(lldp)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Creates packet_out BDDP for specified output port. |
| 341 | * |
| 342 | * @param port the port |
| 343 | * @return Packet_out message with LLDP data |
| 344 | */ |
| 345 | private OutboundPacket createOutBoundBDDP(final Long port) { |
| 346 | if (port == null) { |
| 347 | return null; |
| 348 | } |
| 349 | this.lldpPacket.setPortId(port.intValue()); |
| 350 | this.bddpEth.setSourceMACAddress("DE:AD:BE:EF:BA:11"); |
| 351 | |
| 352 | final byte[] bddp = this.bddpEth.serialize(); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 353 | return new DefaultOutboundPacket(this.device.id(), |
| 354 | builder().setOutput(portNumber(port)).build(), |
| 355 | ByteBuffer.wrap(bddp)); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | private void sendProbes(Long portNumber) { |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 359 | log.trace("Sending probes out to {}@{}", portNumber, device.id()); |
| 360 | OutboundPacket pkt = this.createOutBoundLLDP(portNumber); |
| 361 | pktService.emit(pkt); |
| 362 | if (useBDDP) { |
| 363 | OutboundPacket bpkt = this.createOutBoundBDDP(portNumber); |
| 364 | pktService.emit(bpkt); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 365 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 366 | } |
| 367 | |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 368 | public boolean containsPort(Long portNumber) { |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 369 | return slowPorts.contains(portNumber) || fastPorts.contains(portNumber); |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 372 | public synchronized boolean isStopped() { |
| 373 | return isStopped || timeout.isCancelled(); |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 374 | } |
| 375 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 376 | } |