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 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Maps; |
| 19 | import com.google.common.collect.Sets; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 20 | import org.jboss.netty.util.Timeout; |
| 21 | import org.jboss.netty.util.TimerTask; |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 22 | import org.onlab.packet.Ethernet; |
| 23 | import org.onlab.packet.ONOSLLDP; |
| 24 | import org.onlab.util.Timer; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.ConnectPoint; |
| 26 | import org.onosproject.net.Device; |
| 27 | import org.onosproject.net.DeviceId; |
| 28 | import org.onosproject.net.Link.Type; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 29 | import org.onosproject.net.LinkKey; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.Port; |
| 31 | import org.onosproject.net.PortNumber; |
| 32 | import org.onosproject.net.link.DefaultLinkDescription; |
| 33 | import org.onosproject.net.link.LinkDescription; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 34 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 35 | import org.onosproject.net.packet.OutboundPacket; |
| 36 | import org.onosproject.net.packet.PacketContext; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 37 | import org.slf4j.Logger; |
| 38 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 39 | import java.nio.ByteBuffer; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 40 | import java.util.Map; |
| 41 | import java.util.Set; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 42 | import java.util.stream.Collectors; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 43 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 44 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 45 | import static org.onosproject.net.PortNumber.portNumber; |
| 46 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
| 47 | import static org.slf4j.LoggerFactory.getLogger; |
| 48 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Run discovery process from a physical switch. Ports are initially labeled as |
| 51 | * slow ports. When an LLDP is successfully received, label the remote port as |
| 52 | * fast. Every probeRate milliseconds, loop over all fast ports and send an |
| 53 | * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology |
| 54 | * discovery implementation. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 55 | */ |
| 56 | public class LinkDiscovery implements TimerTask { |
| 57 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 58 | private final Logger log = getLogger(getClass()); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 59 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 60 | private static final String SRC_MAC = "DE:AD:BE:EF:BA:11"; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 61 | |
| 62 | private final Device device; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 63 | private final DiscoveryContext context; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 64 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 65 | private final ONOSLLDP lldpPacket; |
| 66 | private final Ethernet ethPacket; |
| 67 | private Ethernet bddpEth; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 68 | |
| 69 | private Timeout timeout; |
| 70 | private volatile boolean isStopped; |
| 71 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 72 | // Set of ports to be probed |
| 73 | private final Set<Long> ports = Sets.newConcurrentHashSet(); |
| 74 | |
| 75 | // Most recent time a link was seen |
| 76 | private final Map<LinkKey, Long> linkTimes = Maps.newConcurrentMap(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Instantiates discovery manager for the given physical switch. Creates a |
| 80 | * generic LLDP packet that will be customized for the port it is sent out on. |
| 81 | * Starts the the timer for the discovery process. |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 82 | * |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 83 | * @param device the physical switch |
| 84 | * @param context discovery context |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 85 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 86 | public LinkDiscovery(Device device, DiscoveryContext context) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 87 | this.device = device; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 88 | this.context = context; |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 89 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 90 | lldpPacket = new ONOSLLDP(); |
| 91 | lldpPacket.setChassisId(device.chassisId()); |
| 92 | lldpPacket.setDevice(device.id().toString()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 93 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 94 | ethPacket = new Ethernet(); |
| 95 | ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
| 96 | ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA); |
| 97 | ethPacket.setPayload(this.lldpPacket); |
| 98 | ethPacket.setPad(true); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 99 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 100 | bddpEth = new Ethernet(); |
| 101 | bddpEth.setPayload(lldpPacket); |
| 102 | bddpEth.setEtherType(Ethernet.TYPE_BSN); |
| 103 | bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST); |
| 104 | bddpEth.setPad(true); |
| 105 | log.info("Using BDDP to discover network"); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 106 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 107 | isStopped = true; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 108 | start(); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 109 | log.debug("Started discovery manager for switch {}", device.id()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 110 | |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Add physical port port to discovery process. |
| 115 | * Send out initial LLDP and label it as slow port. |
| 116 | * |
| 117 | * @param port the port |
| 118 | */ |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 119 | public void addPort(Port port) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 120 | boolean newPort = ports.add(port.number().toLong()); |
| 121 | boolean isMaster = context.mastershipService().isLocalMaster(device.id()); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 122 | if (newPort && isMaster) { |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 123 | log.debug("Sending init probe to port {}@{}", port.number().toLong(), device.id()); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 124 | sendProbes(port.number().toLong()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 125 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 129 | * Method called by remote port to acknowledge receipt of LLDP sent by |
| 130 | * this port. If slow port, updates label to fast. If fast port, decrements |
| 131 | * number of unacknowledged probes. |
| 132 | * |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 133 | * @param key link key |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 134 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 135 | private void ackProbe(LinkKey key) { |
| 136 | long portNumber = key.src().port().toLong(); |
| 137 | if (ports.contains(portNumber)) { |
| 138 | linkTimes.put(key, System.currentTimeMillis()); |
| 139 | } else { |
| 140 | log.debug("Got ackProbe for non-existing port: {}", portNumber); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /** |
| 146 | * Handles an incoming LLDP packet. Creates link in topology and sends ACK |
| 147 | * to port where LLDP originated. |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 148 | * |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 149 | * @param packetContext packet context |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 150 | * @return true if handled |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 151 | */ |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 152 | public boolean handleLLDP(PacketContext packetContext) { |
| 153 | Ethernet eth = packetContext.inPacket().parsed(); |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 154 | if (eth == null) { |
| 155 | return false; |
| 156 | } |
| 157 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 158 | ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth); |
| 159 | if (onoslldp != null) { |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 160 | PortNumber srcPort = portNumber(onoslldp.getPort()); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 161 | PortNumber dstPort = packetContext.inPacket().receivedFrom().port(); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 162 | DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString()); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 163 | DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId(); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 164 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 165 | ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort); |
| 166 | ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort); |
| 167 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 168 | ackProbe(LinkKey.linkKey(src, dst)); |
| 169 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 170 | LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ? |
| 171 | new DefaultLinkDescription(src, dst, Type.DIRECT) : |
| 172 | new DefaultLinkDescription(src, dst, Type.INDIRECT); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 173 | |
| 174 | try { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 175 | context.providerService().linkDetected(ld); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 176 | } catch (IllegalStateException e) { |
| 177 | return true; |
| 178 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 179 | return true; |
| 180 | } |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 185 | /** |
| 186 | * Execute this method every t milliseconds. Loops over all ports |
| 187 | * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow |
| 188 | * port. |
| 189 | * |
| 190 | * @param t timeout |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 191 | */ |
| 192 | @Override |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 193 | public void run(Timeout t) { |
Yuta HIGUCHI | 3419858 | 2014-11-10 16:24:58 -0800 | [diff] [blame] | 194 | if (isStopped()) { |
| 195 | return; |
| 196 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 197 | |
| 198 | if (!context.mastershipService().isLocalMaster(device.id())) { |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 199 | if (!isStopped()) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 200 | timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS); |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 201 | } |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 202 | return; |
| 203 | } |
| 204 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 205 | // Prune stale links |
| 206 | linkTimes.entrySet().stream() |
| 207 | .filter(e -> isStale(e.getKey(), e.getValue())) |
| 208 | .map(Map.Entry::getKey).collect(Collectors.toSet()) |
| 209 | .forEach(this::pruneLink); |
| 210 | |
| 211 | // Probe ports |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 212 | log.trace("Sending probes from {}", device.id()); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 213 | ports.forEach(this::sendProbes); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 214 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 215 | if (!isStopped()) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 216 | timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS); |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 217 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 220 | private void pruneLink(LinkKey key) { |
| 221 | linkTimes.remove(key); |
| 222 | LinkDescription desc = new DefaultLinkDescription(key.src(), key.dst(), Type.DIRECT); |
| 223 | context.providerService().linkVanished(desc); |
| 224 | } |
| 225 | |
| 226 | private boolean isStale(LinkKey key, long lastSeen) { |
| 227 | return lastSeen < (System.currentTimeMillis() - context.staleLinkAge()); |
| 228 | } |
| 229 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 230 | public synchronized void stop() { |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 231 | isStopped = true; |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 232 | timeout.cancel(); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 235 | public synchronized void start() { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 236 | if (isStopped) { |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 237 | isStopped = false; |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 238 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 239 | } else { |
| 240 | log.warn("LinkDiscovery started multiple times?"); |
| 241 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /** |
| 245 | * Creates packet_out LLDP for specified output port. |
| 246 | * |
| 247 | * @param port the port |
| 248 | * @return Packet_out message with LLDP data |
| 249 | */ |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 250 | private OutboundPacket createOutBoundLLDP(Long port) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 251 | if (port == null) { |
| 252 | return null; |
| 253 | } |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 254 | lldpPacket.setPortId(port.intValue()); |
| 255 | ethPacket.setSourceMACAddress(SRC_MAC); |
| 256 | return new DefaultOutboundPacket(device.id(), |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 257 | builder().setOutput(portNumber(port)).build(), |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 258 | ByteBuffer.wrap(ethPacket.serialize())); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Creates packet_out BDDP for specified output port. |
| 263 | * |
| 264 | * @param port the port |
| 265 | * @return Packet_out message with LLDP data |
| 266 | */ |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 267 | private OutboundPacket createOutBoundBDDP(Long port) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 268 | if (port == null) { |
| 269 | return null; |
| 270 | } |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 271 | lldpPacket.setPortId(port.intValue()); |
| 272 | bddpEth.setSourceMACAddress(SRC_MAC); |
| 273 | return new DefaultOutboundPacket(device.id(), |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 274 | builder().setOutput(portNumber(port)).build(), |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 275 | ByteBuffer.wrap(bddpEth.serialize())); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | private void sendProbes(Long portNumber) { |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 279 | log.trace("Sending probes out to {}@{}", portNumber, device.id()); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 280 | OutboundPacket pkt = createOutBoundLLDP(portNumber); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 281 | context.packetService().emit(pkt); |
| 282 | if (context.useBDDP()) { |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 283 | OutboundPacket bpkt = createOutBoundBDDP(portNumber); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 284 | context.packetService().emit(bpkt); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 285 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Thomas Vachuska | fc52fec | 2015-05-18 19:13:56 -0700 | [diff] [blame] | 288 | public synchronized boolean isStopped() { |
| 289 | return isStopped || timeout.isCancelled(); |
alshabib | 0ed6a20 | 2014-10-19 12:42:57 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame^] | 292 | boolean containsPort(long portNumber) { |
| 293 | return ports.contains(portNumber); |
| 294 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 295 | } |