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 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 16 | package org.onosproject.provider.lldpcommon; |
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.Sets; |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 19 | |
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.Set; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 41 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 42 | import static java.util.concurrent.TimeUnit.MILLISECONDS; |
| 43 | import static org.onosproject.net.PortNumber.portNumber; |
| 44 | import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; |
| 45 | import static org.slf4j.LoggerFactory.getLogger; |
Ayaka Koshibe | 3ddb7b2 | 2015-12-10 17:32:59 -0800 | [diff] [blame] | 46 | import static org.onosproject.cluster.ClusterMetadata.NO_NAME; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 47 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 48 | /** |
| 49 | * Run discovery process from a physical switch. Ports are initially labeled as |
| 50 | * slow ports. When an LLDP is successfully received, label the remote port as |
| 51 | * fast. Every probeRate milliseconds, loop over all fast ports and send an |
| 52 | * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology |
| 53 | * discovery implementation. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 54 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 55 | public class LinkDiscovery implements TimerTask { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 56 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 57 | private final Logger log = getLogger(getClass()); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 58 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 59 | private static final String SRC_MAC = "DE:AD:BE:EF:BA:11"; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 60 | |
| 61 | private final Device device; |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 62 | private final LinkDiscoveryContext context; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 63 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 64 | private final Ethernet ethPacket; |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 65 | private final Ethernet bddpEth; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 66 | |
| 67 | private Timeout timeout; |
| 68 | private volatile boolean isStopped; |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 69 | // This LinkDiscovery can handle remote link probes (default false). |
| 70 | private volatile boolean fingerprinted; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 71 | // Set of ports to be probed |
| 72 | private final Set<Long> ports = Sets.newConcurrentHashSet(); |
| 73 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 74 | /** |
| 75 | * Instantiates discovery manager for the given physical switch. Creates a |
| 76 | * generic LLDP packet that will be customized for the port it is sent out on. |
| 77 | * Starts the the timer for the discovery process. |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 78 | * |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 79 | * @param device the physical switch |
| 80 | * @param context discovery context |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 81 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 82 | public LinkDiscovery(Device device, LinkDiscoveryContext context) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 83 | this.device = device; |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 84 | this.context = context; |
alshabib | 3d643ec | 2014-10-22 18:33:00 -0700 | [diff] [blame] | 85 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 86 | ethPacket = new Ethernet(); |
| 87 | ethPacket.setEtherType(Ethernet.TYPE_LLDP); |
| 88 | ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 89 | ethPacket.setPad(true); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 90 | |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 91 | bddpEth = new Ethernet(); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 92 | bddpEth.setEtherType(Ethernet.TYPE_BSN); |
| 93 | bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST); |
| 94 | bddpEth.setPad(true); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 95 | |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 96 | fingerprinted = false; |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 97 | isStopped = true; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 98 | start(); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 99 | log.debug("Started discovery manager for switch {}", device.id()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 100 | |
| 101 | } |
| 102 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 103 | public synchronized void stop() { |
Jon Hall | 3edc08a | 2015-09-14 16:59:07 -0700 | [diff] [blame] | 104 | if (!isStopped) { |
| 105 | isStopped = true; |
| 106 | timeout.cancel(); |
| 107 | } else { |
| 108 | log.warn("LinkDiscovery stopped multiple times?"); |
| 109 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 112 | public synchronized void start() { |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 113 | if (isStopped) { |
| 114 | isStopped = false; |
| 115 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); |
| 116 | } else { |
| 117 | log.warn("LinkDiscovery started multiple times?"); |
| 118 | } |
| 119 | } |
| 120 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 121 | public synchronized boolean isStopped() { |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 122 | return isStopped || timeout.isCancelled(); |
| 123 | } |
| 124 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 125 | /** |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 126 | * Add physical port to discovery process. |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 127 | * Send out initial LLDP and label it as slow port. |
| 128 | * |
| 129 | * @param port the port |
| 130 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 131 | public void addPort(Port port) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 132 | boolean newPort = ports.add(port.number().toLong()); |
| 133 | boolean isMaster = context.mastershipService().isLocalMaster(device.id()); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 134 | if (newPort && isMaster) { |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 135 | log.debug("Sending initial probe to port {}@{}", port.number().toLong(), device.id()); |
Jonathan Hart | 45066bc | 2015-07-28 11:18:34 -0700 | [diff] [blame] | 136 | sendProbes(port.number().toLong()); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 137 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 141 | * removed physical port from discovery process. |
| 142 | * @param port the port number |
| 143 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 144 | public void removePort(PortNumber port) { |
HIGUCHI Yuta | 9a9edf8 | 2015-10-21 11:23:20 -0700 | [diff] [blame] | 145 | ports.remove(port.toLong()); |
| 146 | } |
| 147 | |
| 148 | /** |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 149 | * Handles an incoming LLDP packet. Creates link in topology and adds the |
| 150 | * link for staleness tracking. |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 151 | * |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 152 | * @param packetContext packet context |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 153 | * @return true if handled |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 154 | */ |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 155 | public boolean handleLldp(PacketContext packetContext) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 156 | Ethernet eth = packetContext.inPacket().parsed(); |
Jonathan Hart | e8600eb | 2015-01-12 10:30:45 -0800 | [diff] [blame] | 157 | if (eth == null) { |
| 158 | return false; |
| 159 | } |
| 160 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 161 | ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth); |
| 162 | if (onoslldp != null) { |
Ayaka Koshibe | 3ddb7b2 | 2015-12-10 17:32:59 -0800 | [diff] [blame] | 163 | if (notMy(onoslldp)) { |
| 164 | return true; |
| 165 | } |
| 166 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 167 | PortNumber srcPort = portNumber(onoslldp.getPort()); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 168 | PortNumber dstPort = packetContext.inPacket().receivedFrom().port(); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 169 | DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString()); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 170 | DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId(); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 171 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 172 | ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort); |
| 173 | ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort); |
| 174 | |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 175 | LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ? |
| 176 | new DefaultLinkDescription(src, dst, Type.DIRECT) : |
| 177 | new DefaultLinkDescription(src, dst, Type.INDIRECT); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 178 | |
| 179 | try { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 180 | context.providerService().linkDetected(ld); |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 181 | context.touchLink(LinkKey.linkKey(src, dst)); |
Sahil Lele | 3a0cdd5 | 2015-07-21 14:16:31 -0700 | [diff] [blame] | 182 | } catch (IllegalStateException e) { |
| 183 | return true; |
| 184 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 185 | return true; |
| 186 | } |
| 187 | return false; |
| 188 | } |
| 189 | |
Ayaka Koshibe | 3ddb7b2 | 2015-12-10 17:32:59 -0800 | [diff] [blame] | 190 | // true if *NOT* this cluster's own probe. |
| 191 | private boolean notMy(ONOSLLDP onoslldp) { |
| 192 | if (onoslldp.getDomainTLV() == null) { |
| 193 | // not finger-printed - but we can check the source |
| 194 | DeviceId src = DeviceId.deviceId(onoslldp.getDeviceString()); |
| 195 | if (context.deviceService().getDevice(src) == null) { |
| 196 | return true; |
| 197 | } |
| 198 | return false; |
| 199 | } |
| 200 | |
| 201 | String us = context.fingerprint(); |
| 202 | String them = onoslldp.getDomainString(); |
| 203 | // if: Our and/or their MetadataService in poorly state, conservative 'yes' |
| 204 | if (NO_NAME.equals(us) || NO_NAME.equals(them)) { |
| 205 | return true; |
| 206 | } else { |
| 207 | return !us.equals(them); |
| 208 | } |
| 209 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 210 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 211 | /** |
| 212 | * Execute this method every t milliseconds. Loops over all ports |
| 213 | * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow |
| 214 | * port. |
| 215 | * |
| 216 | * @param t timeout |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 217 | */ |
| 218 | @Override |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 219 | public void run(Timeout t) { |
Yuta HIGUCHI | 3419858 | 2014-11-10 16:24:58 -0800 | [diff] [blame] | 220 | if (isStopped()) { |
| 221 | return; |
| 222 | } |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 223 | |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 224 | if (context.mastershipService().isLocalMaster(device.id())) { |
| 225 | log.trace("Sending probes from {}", device.id()); |
| 226 | ports.forEach(this::sendProbes); |
Yuta HIGUCHI | f672588 | 2014-10-29 15:25:51 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 229 | if (!isStopped()) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 230 | timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS); |
Yuta HIGUCHI | 3225578 | 2014-11-04 22:32:14 -0800 | [diff] [blame] | 231 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 232 | } |
| 233 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 234 | /** |
| 235 | * Creates packet_out LLDP for specified output port. |
| 236 | * |
| 237 | * @param port the port |
| 238 | * @return Packet_out message with LLDP data |
| 239 | */ |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 240 | private OutboundPacket createOutBoundLldp(Long port) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 241 | if (port == null) { |
| 242 | return null; |
| 243 | } |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 244 | ONOSLLDP lldp = getLinkProbe(port); |
| 245 | ethPacket.setSourceMACAddress(SRC_MAC).setPayload(lldp); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 246 | return new DefaultOutboundPacket(device.id(), |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 247 | builder().setOutput(portNumber(port)).build(), |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 248 | ByteBuffer.wrap(ethPacket.serialize())); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Creates packet_out BDDP for specified output port. |
| 253 | * |
| 254 | * @param port the port |
| 255 | * @return Packet_out message with LLDP data |
| 256 | */ |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 257 | private OutboundPacket createOutBoundBddp(Long port) { |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 258 | if (port == null) { |
| 259 | return null; |
| 260 | } |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 261 | ONOSLLDP lldp = getLinkProbe(port); |
| 262 | bddpEth.setSourceMACAddress(SRC_MAC).setPayload(lldp); |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 263 | return new DefaultOutboundPacket(device.id(), |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 264 | builder().setOutput(portNumber(port)).build(), |
Thomas Vachuska | 96f3ea7 | 2015-09-08 13:50:12 -0700 | [diff] [blame] | 265 | ByteBuffer.wrap(bddpEth.serialize())); |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 268 | private ONOSLLDP getLinkProbe(Long port) { |
| 269 | return fingerprinted |
| 270 | ? ONOSLLDP.fingerprintedLLDP(device.id().toString(), device.chassisId(), |
| 271 | port.intValue(), context.fingerprint()) |
| 272 | : ONOSLLDP.onosLLDP(device.id().toString(), device.chassisId(), |
| 273 | port.intValue()); |
| 274 | } |
| 275 | |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 276 | private void sendProbes(Long portNumber) { |
Yuta HIGUCHI | 4128938 | 2014-12-19 17:47:12 -0800 | [diff] [blame] | 277 | log.trace("Sending probes out to {}@{}", portNumber, device.id()); |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 278 | OutboundPacket pkt = createOutBoundLldp(portNumber); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 279 | context.packetService().emit(pkt); |
Jonathan Hart | b35540a | 2015-11-17 09:30:56 -0800 | [diff] [blame] | 280 | if (context.useBddp()) { |
| 281 | OutboundPacket bpkt = createOutBoundBddp(portNumber); |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 282 | context.packetService().emit(bpkt); |
Thomas Vachuska | e1bcb0b | 2014-10-27 17:45:10 -0700 | [diff] [blame] | 283 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 286 | public boolean containsPort(long portNumber) { |
Thomas Vachuska | 05453c9 | 2015-09-09 14:40:49 -0700 | [diff] [blame] | 287 | return ports.contains(portNumber); |
| 288 | } |
Thomas Vachuska | e4ebac9 | 2015-09-10 11:39:05 -0700 | [diff] [blame] | 289 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 290 | public void enableFingerprint() { |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 291 | fingerprinted = true; |
| 292 | } |
| 293 | |
Ray Milkey | 957390e | 2016-02-09 10:02:46 -0800 | [diff] [blame] | 294 | public void disableFingerprint() { |
Ayaka Koshibe | 12c8c08 | 2015-12-08 12:48:46 -0800 | [diff] [blame] | 295 | fingerprinted = false; |
| 296 | } |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 297 | } |