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