This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
+
+NOTE: This file is deprecated as wiring is now done via blueprint. This file is kept for
+ backwards compatibility. Runtime modifications are not honored.
-->
<snapshot>
<required-capabilities>
*/
package org.opendaylight.openflowplugin.applications.topology.lldp;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class LLDPActivator implements BindingAwareProvider, AutoCloseable {
+public class LLDPActivator implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(LLDPActivator.class);
- private static LLDPDiscoveryProvider provider = new LLDPDiscoveryProvider();
+
private static String lldpSecureKey;
- public LLDPActivator(String secureKey) {
+ private final ListenerRegistration<NotificationListener> lldpNotificationRegistration;
+
+ public LLDPActivator(NotificationProviderService notificationService, LLDPDiscoveryListener lldpDiscoveryListener,
+ String secureKey) {
lldpSecureKey = secureKey;
- }
- public void onSessionInitiated(final ProviderContext session) {
- DataProviderService dataService = session.<DataProviderService>getSALService(DataProviderService.class);
- provider.setDataService(dataService);
- NotificationProviderService notificationService = session.<NotificationProviderService>getSALService(NotificationProviderService.class);
- provider.setNotificationService(notificationService);
- provider.start();
+ LOG.info("Starting LLDPActivator with lldpSecureKey: {}", lldpSecureKey);
+
+ lldpNotificationRegistration = notificationService.registerNotificationListener(lldpDiscoveryListener);
+
+ LOG.info("LLDPDiscoveryListener started.");
}
@Override
- public void close() throws Exception {
- if(provider != null) {
- try {
- provider.close();
- } catch (Exception e) {
- LOG.warn("Exception when closing down topology-lldp-discovery",e);
- }
- }
+ public void close() {
+ lldpNotificationRegistration.close();
+
+ LOG.info("LLDPDiscoveryListener stopped.");
}
public static String getLldpSecureKey() {
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-class LLDPDiscoveryListener implements PacketProcessingListener {
+public class LLDPDiscoveryListener implements PacketProcessingListener {
private static final Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryListener.class);
- private LLDPLinkAger lldpLinkAger;
- private NotificationProviderService notificationService;
+ private final LLDPLinkAger lldpLinkAger;
+ private final NotificationProviderService notificationService;
- LLDPDiscoveryListener(NotificationProviderService notificationService) {
+ public LLDPDiscoveryListener(NotificationProviderService notificationService, LLDPLinkAger lldpLinkAger) {
this.notificationService = notificationService;
+ this.lldpLinkAger = lldpLinkAger;
}
+ @Override
public void onPacketReceived(PacketReceived lldp) {
NodeConnectorRef src = LLDPDiscoveryUtils.lldpToNodeConnectorRef(lldp.getPayload(), true);
if(src != null) {
lldpLinkAger.put(ld);
}
}
-
- public void setLldpLinkAger(LLDPLinkAger lldpLinkAger) {
- this.lldpLinkAger = lldpLinkAger;
- }
-}
+}
\ No newline at end of file
+++ /dev/null
-/**
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.applications.topology.lldp;
-
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
-import org.opendaylight.openflowplugin.applications.topology.lldp.utils.LLDPDiscoveryUtils;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LLDPDiscoveryProvider implements AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryProvider.class);
- private DataProviderService dataService;
- private NotificationProviderService notificationService;
-
- private ListenerRegistration<NotificationListener> listenerRegistration;
- private LLDPLinkAger lldpLinkAger;
-
- public DataProviderService getDataService() {
- return this.dataService;
- }
-
- public void setDataService(final DataProviderService dataService) {
- this.dataService = dataService;
- }
-
- public NotificationProviderService getNotificationService() {
- return this.notificationService;
- }
-
- public void setNotificationService(final NotificationProviderService notificationService) {
- this.notificationService = notificationService;
- }
-
- public void start() {
- lldpLinkAger = new LLDPLinkAger(LLDPDiscoveryUtils.LLDP_INTERVAL, LLDPDiscoveryUtils.LLDP_EXPIRATION_TIME);
- lldpLinkAger.setNotificationService(notificationService);
-
- LLDPDiscoveryListener committer = new LLDPDiscoveryListener(notificationService);
- committer.setLldpLinkAger(lldpLinkAger);
-
- ListenerRegistration<NotificationListener> registerNotificationListener =
- notificationService.registerNotificationListener(committer);
- this.listenerRegistration = registerNotificationListener;
- LOG.info("LLDPDiscoveryListener Started.");
- }
-
- public void close() {
- try {
- LOG.info("LLDPDiscoveryListener stopped.");
- if (this.listenerRegistration!=null) {
- this.listenerRegistration.close();
- }
- lldpLinkAger.close();
- } catch (Exception e) {
- throw new Error(e);
- }
- }
-}
public class LLDPLinkAger implements AutoCloseable {
private final long linkExpirationTime;
- private Map<LinkDiscovered, Date> linkToDate;
- private Timer timer;
- private NotificationProviderService notificationService;
+ private final Map<LinkDiscovered, Date> linkToDate;
+ private final Timer timer;
+ private final NotificationProviderService notificationService;
/**
* default ctor - start timer
*/
- public LLDPLinkAger(final long lldpInterval, final long linkExpirationTime) {
+ public LLDPLinkAger(final long lldpInterval, final long linkExpirationTime,
+ final NotificationProviderService notificationService) {
this.linkExpirationTime = linkExpirationTime;
+ this.notificationService = notificationService;
linkToDate = new ConcurrentHashMap<>();
timer = new Timer();
timer.schedule(new LLDPAgingTask(), 0, lldpInterval);
linkToDate.clear();
}
- public void setNotificationService(NotificationProviderService notificationService) {
- this.notificationService = notificationService;
- }
-
private class LLDPAgingTask extends TimerTask {
@Override
*/
package org.opendaylight.openflowplugin.applications.topology.lldp.utils;
-import org.apache.commons.lang3.ArrayUtils;
-import java.nio.charset.Charset;
import com.google.common.hash.HashCode;
+import com.google.common.hash.HashFunction;
+import com.google.common.hash.Hasher;
+import com.google.common.hash.Hashing;
+import java.lang.management.ManagementFactory;
+import java.nio.charset.Charset;
+import java.security.NoSuchAlgorithmException;
+import java.util.Arrays;
+import org.apache.commons.lang3.ArrayUtils;
+import org.opendaylight.controller.liblldp.BitBufferHelper;
+import org.opendaylight.controller.liblldp.CustomTLVKey;
import org.opendaylight.controller.liblldp.Ethernet;
import org.opendaylight.controller.liblldp.LLDP;
-import org.opendaylight.controller.liblldp.BitBufferHelper;
import org.opendaylight.controller.liblldp.LLDPTLV;
import org.opendaylight.controller.liblldp.NetUtils;
-import com.google.common.hash.Hasher;
-import com.google.common.hash.Hashing;
-import com.google.common.hash.HashFunction;
import org.opendaylight.openflowplugin.applications.topology.lldp.LLDPActivator;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
-import java.util.Arrays;
-import java.security.NoSuchAlgorithmException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
-import java.lang.management.ManagementFactory;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.controller.liblldp.CustomTLVKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LLDPDiscoveryUtils {
private static final Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryUtils.class);
- // Send LLDP every five seconds
- public static final Long LLDP_INTERVAL = (long) (1000*5);
-
- // Let up to three intervals pass before we decide we are expired.
- public static final Long LLDP_EXPIRATION_TIME = LLDP_INTERVAL*3;
-
public static String macToString(byte[] mac) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.impl.rev150530;
-import org.opendaylight.openflowplugin.applications.topology.lldp.LLDPActivator;
+import org.opendaylight.controller.sal.common.util.NoopAutoCloseable;
-public class TopologyLldpDiscoveryImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.impl.rev150530.AbstractTopologyLldpDiscoveryImplModule {
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public class TopologyLldpDiscoveryImplModule extends AbstractTopologyLldpDiscoveryImplModule {
public TopologyLldpDiscoveryImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
}
@Override
- public void customValidation() {
- // add custom validation form module attributes here.
+ public AutoCloseable createInstance() {
+ // LLDPActivator instance is created via blueprint so this in a no-op.
+ return NoopAutoCloseable.INSTANCE;
}
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- LLDPActivator provider = new LLDPActivator(getLldpSecureKey());
- getBrokerDependency().registerProvider(provider);
- return provider;
- }
-
}
* Do not modify this file unless it is present under src/main directory
*/
package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.impl.rev150530;
-public class TopologyLldpDiscoveryImplModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.impl.rev150530.AbstractTopologyLldpDiscoveryImplModuleFactory {
+
+/**
+ * @deprecated Replaced by blueprint wiring
+ */
+@Deprecated
+public class TopologyLldpDiscoveryImplModuleFactory extends AbstractTopologyLldpDiscoveryImplModuleFactory {
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ odl:use-default-for-reference-types="true">
+
+ <reference id="notificationService" interface="org.opendaylight.controller.sal.binding.api.NotificationProviderService"/>
+
+ <odl:clustered-app-config id="topologyLLDPConfig"
+ binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.lldp.discovery.config.rev160511.TopologyLldpDiscoveryConfig">
+ <odl:default-config><![CDATA[
+ <topology-lldp-discovery-config xmlns="urn:opendaylight:params:xml:ns:yang:topology-lldp-discovery:config">
+ <lldp-secure-key>aa9251f8-c7c0-4322-b8d6-c3a84593bda3</lldp-secure-key>
+ </topology-lldp-discovery-config>
+ ]]></odl:default-config>
+ </odl:clustered-app-config>
+
+ <bean id="lldpLinkAger" class="org.opendaylight.openflowplugin.applications.topology.lldp.LLDPLinkAger"
+ destroy-method="close">
+ <!-- Interval to send LLDP (five seconds) -->
+ <argument value="5000"/>
+ <!-- Expiration interval for aging out links (3 * the interval) -->
+ <argument value="15000"/>
+ <argument ref="notificationService"/>
+ </bean>
+
+ <bean id="lldpDiscoveryListener" class="org.opendaylight.openflowplugin.applications.topology.lldp.LLDPDiscoveryListener">
+ <argument ref="notificationService"/>
+ <argument ref="lldpLinkAger"/>
+ </bean>
+
+ <bean id="LLDPActivator" class="org.opendaylight.openflowplugin.applications.topology.lldp.LLDPActivator"
+ destroy-method="close">
+ <argument ref="notificationService"/>
+ <argument ref="lldpDiscoveryListener"/>
+ <argument>
+ <bean factory-ref="topologyLLDPConfig" factory-method="getLldpSecureKey"/>
+ </argument>
+ </bean>
+</blueprint>
\ No newline at end of file
--- /dev/null
+module topology-lldp-discovery-config {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:topology-lldp-discovery:config";
+ prefix "topology-lldp-discovery-config";
+
+ description
+ "Configuration for Topology LLDP discovery application.";
+
+ revision "2016-05-11" {
+ description
+ "Initial revision.";
+ }
+
+ container topology-lldp-discovery-config {
+ leaf lldp-secure-key {
+ description "Provided key will be used to generate LLDP custom security hash";
+ type string;
+ mandatory true;
+ }
+ }
+}
\ No newline at end of file
identity topology-lldp-discovery-impl {
base config:module-type;
config:java-name-prefix TopologyLldpDiscoveryImpl;
+ status deprecated;
}
augment "/config:modules/config:module/config:configuration" {