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