blob: 35221ca16b67ce25c41eba356c98f1d4d6cf34aa [file] [log] [blame]
Ray Milkeyb7f0f642016-01-22 16:08:14 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkeyb7f0f642016-01-22 16:08:14 -08003 *
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
7 *
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.
15 */
16package org.onosproject.provider.netcfglinks;
17
Ray Milkeyb7f0f642016-01-22 16:08:14 -080018import org.onlab.packet.Ethernet;
19import org.onlab.packet.ONOSLLDP;
pierff7e43d2020-01-29 16:19:22 +010020import org.onosproject.cluster.ClusterMetadata;
21import org.onosproject.cluster.ClusterMetadataEvent;
22import org.onosproject.cluster.ClusterMetadataEventListener;
Ayaka Koshibe48229222016-05-16 18:04:26 -070023import org.onosproject.cluster.ClusterMetadataService;
Ray Milkeyb7f0f642016-01-22 16:08:14 -080024import org.onosproject.core.ApplicationId;
25import org.onosproject.core.CoreService;
26import org.onosproject.mastership.MastershipService;
27import org.onosproject.net.ConnectPoint;
28import org.onosproject.net.DefaultAnnotations;
29import org.onosproject.net.Device;
30import org.onosproject.net.DeviceId;
31import org.onosproject.net.Link;
32import org.onosproject.net.LinkKey;
33import org.onosproject.net.Port;
34import org.onosproject.net.PortNumber;
35import org.onosproject.net.config.NetworkConfigEvent;
36import org.onosproject.net.config.NetworkConfigListener;
37import org.onosproject.net.config.NetworkConfigRegistry;
38import org.onosproject.net.config.basics.BasicLinkConfig;
39import org.onosproject.net.device.DeviceEvent;
40import org.onosproject.net.device.DeviceListener;
41import org.onosproject.net.device.DeviceService;
42import org.onosproject.net.flow.DefaultTrafficSelector;
43import org.onosproject.net.flow.TrafficSelector;
44import org.onosproject.net.link.DefaultLinkDescription;
Ray Milkeyb7f0f642016-01-22 16:08:14 -080045import org.onosproject.net.link.LinkProviderRegistry;
46import org.onosproject.net.link.LinkProviderService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070047import org.onosproject.net.link.ProbedLinkProvider;
Ray Milkeyb7f0f642016-01-22 16:08:14 -080048import org.onosproject.net.packet.InboundPacket;
49import org.onosproject.net.packet.PacketContext;
50import org.onosproject.net.packet.PacketPriority;
51import org.onosproject.net.packet.PacketProcessor;
52import org.onosproject.net.packet.PacketService;
53import org.onosproject.net.provider.AbstractProvider;
54import org.onosproject.net.provider.ProviderId;
Ray Milkey957390e2016-02-09 10:02:46 -080055import org.onosproject.provider.lldpcommon.LinkDiscovery;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070056import org.onosproject.provider.lldpcommon.LinkDiscoveryContext;
57import org.osgi.service.component.annotations.Activate;
58import org.osgi.service.component.annotations.Component;
59import org.osgi.service.component.annotations.Deactivate;
60import org.osgi.service.component.annotations.Reference;
61import org.osgi.service.component.annotations.ReferenceCardinality;
Ray Milkeyb7f0f642016-01-22 16:08:14 -080062import org.slf4j.Logger;
63import org.slf4j.LoggerFactory;
64
Ray Milkeyd84f89b2018-08-17 14:54:17 -070065import java.util.HashSet;
66import java.util.Map;
67import java.util.Optional;
68import java.util.Set;
69import java.util.concurrent.ConcurrentHashMap;
pierff7e43d2020-01-29 16:19:22 +010070import java.util.concurrent.atomic.AtomicReference;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070071
Ray Milkeyb7f0f642016-01-22 16:08:14 -080072import static org.onlab.packet.Ethernet.TYPE_BSN;
73import static org.onlab.packet.Ethernet.TYPE_LLDP;
74import static org.onosproject.net.PortNumber.portNumber;
Ray Milkeyd17309c2018-10-18 09:34:54 -070075import static org.onosproject.provider.netcfglinks.OsgiPropertyConstants.DISCOVERY_DELAY_DEFAULT;
76import static org.onosproject.provider.netcfglinks.OsgiPropertyConstants.PROP_DISCOVERY_DELAY;
Thomas Vachuska4167c3f2018-10-16 07:16:31 -070077import static org.onosproject.provider.netcfglinks.OsgiPropertyConstants.PROP_PROBE_RATE;
78import static org.onosproject.provider.netcfglinks.OsgiPropertyConstants.PROBE_RATE_DEFAULT;
Ray Milkeyb7f0f642016-01-22 16:08:14 -080079
80/**
81 * Provider to pre-discover links and devices based on a specified network
82 * config.
83 */
84
Thomas Vachuska4167c3f2018-10-16 07:16:31 -070085@Component(immediate = true,
86 property = {
87 PROP_PROBE_RATE + ":Integer=" + PROBE_RATE_DEFAULT,
Ray Milkeyd17309c2018-10-18 09:34:54 -070088 PROP_DISCOVERY_DELAY + ":Integer=" + DISCOVERY_DELAY_DEFAULT,
Thomas Vachuska4167c3f2018-10-16 07:16:31 -070089 })
Ray Milkeyb7f0f642016-01-22 16:08:14 -080090public class NetworkConfigLinksProvider
91 extends AbstractProvider
Ayaka Koshibe48229222016-05-16 18:04:26 -070092 implements ProbedLinkProvider {
Ray Milkeyb7f0f642016-01-22 16:08:14 -080093
Ray Milkeyd84f89b2018-08-17 14:54:17 -070094 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyb7f0f642016-01-22 16:08:14 -080095 protected LinkProviderRegistry providerRegistry;
96
Ray Milkeyd84f89b2018-08-17 14:54:17 -070097 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyb7f0f642016-01-22 16:08:14 -080098 protected DeviceService deviceService;
99
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700100 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800101 protected PacketService packetService;
102
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700103 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800104 protected MastershipService masterService;
105
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700106 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800107 protected NetworkConfigRegistry netCfgService;
108
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700109 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800110 protected CoreService coreService;
111
Ray Milkeyd84f89b2018-08-17 14:54:17 -0700112 @Reference(cardinality = ReferenceCardinality.MANDATORY)
pierff7e43d2020-01-29 16:19:22 +0100113 protected ClusterMetadataService clusterMetadataService;
Ayaka Koshibe48229222016-05-16 18:04:26 -0700114
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700115 /** LLDP and BDDP probe rate specified in millis. */
Thomas Vachuska4167c3f2018-10-16 07:16:31 -0700116 private int probeRate = PROBE_RATE_DEFAULT;
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800117
Thomas Vachuska00b5d4f2018-10-30 15:13:20 -0700118 /** Number of millis beyond which an LLDP packet will not be accepted. */
Ray Milkeybd508ed2019-03-19 14:22:02 -0700119 private int maxLldpAge = DISCOVERY_DELAY_DEFAULT;
Samuel Jero31e16f52018-09-21 10:34:28 -0400120
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800121 // Device link discovery helpers.
122 protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
123
Ray Milkey957390e2016-02-09 10:02:46 -0800124 private final LinkDiscoveryContext context = new InternalDiscoveryContext();
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800125
126 private LinkProviderService providerService;
127
128 private static final String PROVIDER_NAME =
129 "org.onosproject.provider.netcfglinks";
130 private final Logger log = LoggerFactory.getLogger(getClass());
131
132 private ApplicationId appId;
133 private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
134 private final InternalDeviceListener deviceListener = new InternalDeviceListener();
135 private final InternalConfigListener cfgListener = new InternalConfigListener();
136
Ray Milkeycd6ab182016-02-03 11:13:09 -0800137 protected Set<LinkKey> configuredLinks = new HashSet<>();
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800138
pierff7e43d2020-01-29 16:19:22 +0100139 // Cache for clustermetadata
140 private AtomicReference<ClusterMetadata> clusterMetadata = new AtomicReference<>();
141
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800142 public NetworkConfigLinksProvider() {
alessio2c8a5902022-03-18 19:51:43 +0100143 super(new ProviderId("netcfglinks", PROVIDER_NAME));
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800144 }
145
Sho SHIMIZU9efeb812016-08-18 09:29:20 -0700146 private String buildSrcMac() {
pierff7e43d2020-01-29 16:19:22 +0100147 String srcMac = ProbedLinkProvider.fingerprintMac(clusterMetadata.get());
Ayaka Koshibe48229222016-05-16 18:04:26 -0700148 String defMac = ProbedLinkProvider.defaultMac();
149 if (srcMac.equals(defMac)) {
150 log.warn("Couldn't generate fingerprint. Using default value {}", defMac);
151 return defMac;
152 }
153 log.trace("Generated MAC address {}", srcMac);
154 return srcMac;
155 }
156
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800157 private void createLinks() {
158 netCfgService.getSubjects(LinkKey.class)
159 .forEach(linkKey -> configuredLinks.add(linkKey));
160 }
161
pierff7e43d2020-01-29 16:19:22 +0100162 private final ClusterMetadataEventListener metadataListener = new InternalClusterMetadataListener();
163
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800164 @Activate
165 protected void activate() {
166 log.info("Activated");
167 appId = coreService.registerApplication(PROVIDER_NAME);
168 packetService.addProcessor(packetProcessor, PacketProcessor.advisor(0));
169 providerService = providerRegistry.register(this);
170 deviceService.addListener(deviceListener);
171 netCfgService.addListener(cfgListener);
pierff7e43d2020-01-29 16:19:22 +0100172 clusterMetadataService.addListener(metadataListener);
173 clusterMetadata.set(clusterMetadataService.getClusterMetadata());
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800174 requestIntercepts();
175 loadDevices();
176 createLinks();
177 }
178
179 @Deactivate
180 protected void deactivate() {
181 withdrawIntercepts();
182 providerRegistry.unregister(this);
Deepa Vaddireddy21f5ae82017-05-10 18:27:30 +0530183 deviceService.removeListener(deviceListener);
184 netCfgService.removeListener(cfgListener);
pierff7e43d2020-01-29 16:19:22 +0100185 clusterMetadataService.removeListener(metadataListener);
Deepa Vaddireddy21f5ae82017-05-10 18:27:30 +0530186 packetService.removeProcessor(packetProcessor);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800187 disable();
188 log.info("Deactivated");
189 }
190
191 /**
192 * Loads available devices and registers their ports to be probed.
193 */
194 private void loadDevices() {
195 deviceService.getAvailableDevices()
196 .forEach(d -> updateDevice(d)
197 .ifPresent(ld -> updatePorts(ld, d.id())));
198 }
199
200 private Optional<LinkDiscovery> updateDevice(Device device) {
201 if (device == null) {
202 return Optional.empty();
203 }
204
205 LinkDiscovery ld = discoverers.computeIfAbsent(device.id(),
DongRyeol Chac80570b2018-11-07 11:55:32 +0900206 did -> new LinkDiscovery(device.id(), context));
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800207 if (ld.isStopped()) {
208 ld.start();
209 }
210 return Optional.of(ld);
211 }
212
213 /**
214 * Updates ports of the specified device to the specified discovery helper.
215 */
216 private void updatePorts(LinkDiscovery discoverer, DeviceId deviceId) {
217 deviceService.getPorts(deviceId).forEach(p -> updatePort(discoverer, p));
218 }
219
220
221 private void updatePort(LinkDiscovery discoverer, Port port) {
222 if (port == null) {
223 return;
224 }
225 if (port.number().isLogical()) {
226 // silently ignore logical ports
227 return;
228 }
229
230 discoverer.addPort(port);
231 }
232
233 /**
234 * Disables link discovery processing.
235 */
236 private void disable() {
237
238 providerRegistry.unregister(this);
239 discoverers.values().forEach(LinkDiscovery::stop);
240 discoverers.clear();
241
242 providerService = null;
243 }
244
245 /**
246 * Provides processing context for the device link discovery helpers.
247 */
Ray Milkey957390e2016-02-09 10:02:46 -0800248 private class InternalDiscoveryContext implements LinkDiscoveryContext {
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800249 @Override
250 public MastershipService mastershipService() {
251 return masterService;
252 }
253
254 @Override
255 public LinkProviderService providerService() {
256 return providerService;
257 }
258
259 @Override
260 public PacketService packetService() {
261 return packetService;
262 }
263
264 @Override
265 public long probeRate() {
266 return probeRate;
267 }
268
269 @Override
270 public boolean useBddp() {
271 return true;
272 }
273
274 @Override
275 public void touchLink(LinkKey key) {
Ray Milkey957390e2016-02-09 10:02:46 -0800276 }
277
278 @Override
DongRyeol Chace65cc02018-07-23 15:02:28 +0900279 public void setTtl(LinkKey key, short ttl) {
280 }
281
282 @Override
Ray Milkey957390e2016-02-09 10:02:46 -0800283 public String fingerprint() {
Ayaka Koshibe48229222016-05-16 18:04:26 -0700284 return buildSrcMac();
Ray Milkey957390e2016-02-09 10:02:46 -0800285 }
286
287 @Override
288 public DeviceService deviceService() {
289 return deviceService;
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800290 }
Samuel Jero31e16f52018-09-21 10:34:28 -0400291
292 @Override
293 public String lldpSecret() {
pierff7e43d2020-01-29 16:19:22 +0100294 return clusterMetadata.get() != null ?
295 clusterMetadata.get().getClusterSecret() : null;
Samuel Jero31e16f52018-09-21 10:34:28 -0400296 }
297
298 @Override
299 public long maxDiscoveryDelay() {
Ray Milkeybd508ed2019-03-19 14:22:02 -0700300 return maxLldpAge;
Samuel Jero31e16f52018-09-21 10:34:28 -0400301 }
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800302 }
303
Samuel Jero31e16f52018-09-21 10:34:28 -0400304 // true if *NOT* this cluster's own probe.
305 private boolean isOthercluster(String mac) {
306 // if we are using DEFAULT_MAC, clustering hadn't initialized, so conservative 'yes'
307 String ourMac = context.fingerprint();
308 if (ProbedLinkProvider.defaultMac().equalsIgnoreCase(ourMac)) {
309 return true;
310 }
311 return !mac.equalsIgnoreCase(ourMac);
312 }
313
314 //doesn't validate. Used just to decide if this is expected link.
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800315 LinkKey extractLinkKey(PacketContext packetContext) {
316 Ethernet eth = packetContext.inPacket().parsed();
317 if (eth == null) {
318 return null;
319 }
320
321 ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
322 if (onoslldp != null) {
323 PortNumber srcPort = portNumber(onoslldp.getPort());
324 PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
325 DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
326 DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
327
328 ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
329 ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
330 return LinkKey.linkKey(src, dst);
331 }
332 return null;
333 }
334
Samuel Jero31e16f52018-09-21 10:34:28 -0400335 private boolean verify(PacketContext packetContext) {
336 Ethernet eth = packetContext.inPacket().parsed();
337 if (eth == null) {
338 return false;
339 }
340
341 ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
342 if (onoslldp != null) {
343 if (!isOthercluster(eth.getSourceMAC().toString())) {
344 return false;
345 }
346
347 if (!ONOSLLDP.verify(onoslldp, context.lldpSecret(), context.maxDiscoveryDelay())) {
348 log.warn("LLDP Packet failed to validate!");
349 return false;
350 }
351 return true;
352 }
353 return false;
354 }
355
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800356 /**
Ray Milkeycd6ab182016-02-03 11:13:09 -0800357 * Removes after stopping discovery helper for specified device.
358 * @param deviceId device to remove
359 */
360 private void removeDevice(final DeviceId deviceId) {
361 discoverers.computeIfPresent(deviceId, (did, ld) -> {
362 ld.stop();
363 return null;
364 });
365
366 }
367
368 /**
369 * Removes a port from the specified discovery helper.
370 * @param port the port
371 */
372 private void removePort(Port port) {
373 if (port.element() instanceof Device) {
374 Device d = (Device) port.element();
375 LinkDiscovery ld = discoverers.get(d.id());
376 if (ld != null) {
377 ld.removePort(port.number());
378 }
379 } else {
380 log.warn("Attempted to remove non-Device port", port);
381 }
382 }
383
384
385 /**
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800386 * Processes incoming packets.
387 */
388 private class InternalPacketProcessor implements PacketProcessor {
389 @Override
390 public void process(PacketContext context) {
391 if (context == null || context.isHandled()) {
392 return;
393 }
394
395 Ethernet eth = context.inPacket().parsed();
396 if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) {
397 return;
398 }
399
400 InboundPacket inPacket = context.inPacket();
401 LinkKey linkKey = extractLinkKey(context);
402 if (linkKey != null) {
403 if (configuredLinks.contains(linkKey)) {
404 log.debug("Found configured link {}", linkKey);
405 LinkDiscovery ld = discoverers.get(inPacket.receivedFrom().deviceId());
406 if (ld == null) {
407 return;
408 }
409 if (ld.handleLldp(context)) {
410 context.block();
411 }
412 } else {
Samuel Jero31e16f52018-09-21 10:34:28 -0400413 if (verify(context)) {
414 log.debug("Found link that was not in the configuration {}", linkKey);
415 providerService.linkDetected(
416 new DefaultLinkDescription(linkKey.src(),
417 linkKey.dst(),
418 Link.Type.DIRECT,
419 DefaultLinkDescription.NOT_EXPECTED,
420 DefaultAnnotations.EMPTY));
421 }
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800422 }
423 }
424 }
425 }
426
427 /**
428 * Requests packet intercepts.
429 */
430 private void requestIntercepts() {
431 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
432 selector.matchEthType(TYPE_LLDP);
433 packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
434 appId, Optional.empty());
435
436 selector.matchEthType(TYPE_BSN);
437
438 packetService.requestPackets(selector.build(), PacketPriority.CONTROL,
439 appId, Optional.empty());
440
441 }
442
443 /**
444 * Withdraws packet intercepts.
445 */
446 private void withdrawIntercepts() {
447 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
448 selector.matchEthType(TYPE_LLDP);
449 packetService.cancelPackets(selector.build(), PacketPriority.CONTROL,
450 appId, Optional.empty());
451 selector.matchEthType(TYPE_BSN);
452 packetService.cancelPackets(selector.build(), PacketPriority.CONTROL,
453 appId, Optional.empty());
454 }
455
456 /**
457 * Processes device events.
458 */
459 private class InternalDeviceListener implements DeviceListener {
460 @Override
461 public void event(DeviceEvent event) {
462 if (event.type() == DeviceEvent.Type.PORT_STATS_UPDATED) {
463 return;
464 }
465 Device device = event.subject();
466 Port port = event.port();
467 if (device == null) {
468 log.error("Device is null.");
469 return;
470 }
471 log.trace("{} {} {}", event.type(), event.subject(), event);
472 final DeviceId deviceId = device.id();
473 switch (event.type()) {
474 case DEVICE_ADDED:
475 case DEVICE_UPDATED:
476 updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
477 break;
478 case PORT_ADDED:
479 case PORT_UPDATED:
480 if (port.isEnabled()) {
481 updateDevice(device).ifPresent(ld -> updatePort(ld, port));
482 } else {
483 log.debug("Port down {}", port);
Ray Milkeycd6ab182016-02-03 11:13:09 -0800484 removePort(port);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800485 providerService.linksVanished(new ConnectPoint(port.element().id(),
486 port.number()));
487 }
488 break;
489 case PORT_REMOVED:
490 log.debug("Port removed {}", port);
Ray Milkeycd6ab182016-02-03 11:13:09 -0800491 removePort(port);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800492 providerService.linksVanished(new ConnectPoint(port.element().id(),
493 port.number()));
494 break;
495 case DEVICE_REMOVED:
496 case DEVICE_SUSPENDED:
497 log.debug("Device removed {}", deviceId);
Ray Milkeycd6ab182016-02-03 11:13:09 -0800498 removeDevice(deviceId);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800499 providerService.linksVanished(deviceId);
500 break;
501 case DEVICE_AVAILABILITY_CHANGED:
502 if (deviceService.isAvailable(deviceId)) {
503 log.debug("Device up {}", deviceId);
504 updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId));
505 } else {
506 log.debug("Device down {}", deviceId);
Ray Milkeycd6ab182016-02-03 11:13:09 -0800507 removeDevice(deviceId);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800508 providerService.linksVanished(deviceId);
509 }
510 break;
511 case PORT_STATS_UPDATED:
512 break;
513 default:
514 log.debug("Unknown event {}", event);
515 }
516 }
517 }
518
519 private class InternalConfigListener implements NetworkConfigListener {
520
521 private void addLink(LinkKey linkKey) {
David Glantz3a454442022-01-26 14:39:56 -0600522 DefaultLinkDescription linkDescription =
523 new DefaultLinkDescription(linkKey.src(), linkKey.dst(),
524 Link.Type.DIRECT);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800525 configuredLinks.add(linkKey);
David Glantz3a454442022-01-26 14:39:56 -0600526 providerService.linkDetected(linkDescription);
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800527 }
528
529 private void removeLink(LinkKey linkKey) {
530 DefaultLinkDescription linkDescription =
531 new DefaultLinkDescription(linkKey.src(), linkKey.dst(),
532 Link.Type.DIRECT);
533 configuredLinks.remove(linkKey);
534 providerService.linkVanished(linkDescription);
535 }
536
537 @Override
538 public void event(NetworkConfigEvent event) {
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800539 if (event.configClass().equals(BasicLinkConfig.class)) {
540 log.info("net config event of type {} for basic link {}",
541 event.type(), event.subject());
542 LinkKey linkKey = (LinkKey) event.subject();
543 if (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
544 addLink(linkKey);
545 } else if (event.type() == NetworkConfigEvent.Type.CONFIG_REMOVED) {
546 removeLink(linkKey);
547 }
Charles Chane527eff2016-05-18 14:04:57 -0700548 log.info("Link reconfigured");
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800549 }
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800550 }
551 }
552
pierff7e43d2020-01-29 16:19:22 +0100553 private class InternalClusterMetadataListener implements ClusterMetadataEventListener {
554 @Override
555 public void event(ClusterMetadataEvent event) {
556 clusterMetadata.set(event.subject());
557 }
558 }
559
Ray Milkeyb7f0f642016-01-22 16:08:14 -0800560}