Refactored LLDP link discovery to be shared by multiple providers
Change-Id: Ia2253ff6bb39186e936ddbaff0c416aa5be6e117
diff --git a/providers/lldp/app.xml b/providers/lldp/app.xml
new file mode 100644
index 0000000..509bcca
--- /dev/null
+++ b/providers/lldp/app.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 20166 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<app name="org.onosproject.lldpprovider" origin="ON.Lab" version="${project.version}"
+ category="default" url="http://onosproject.org"
+ featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+ features="${project.artifactId}">
+ <description>${project.description}</description>
+ <artifact>mvn:${project.groupId}/onos-lldp-provider/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</artifact>
+
+</app>
diff --git a/providers/lldp/features.xml b/providers/lldp/features.xml
new file mode 100644
index 0000000..e4d4721
--- /dev/null
+++ b/providers/lldp/features.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ --><features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature>onos-api</feature>
+ <bundle>mvn:${project.groupId}/onos-lldp-provider/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</bundle>
+ </feature>
+</features>
+
diff --git a/providers/lldp/pom.xml b/providers/lldp/pom.xml
index 03f945d..65afe07 100644
--- a/providers/lldp/pom.xml
+++ b/providers/lldp/pom.xml
@@ -48,6 +48,12 @@
<dependency>
<groupId>org.onosproject</groupId>
+ <artifactId>onos-lldp-provider-common</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
index 3a6b7e3..23f67d1 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
@@ -62,6 +62,8 @@
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
+import org.onosproject.provider.lldpcommon.LinkDiscoveryContext;
+import org.onosproject.provider.lldpcommon.LinkDiscovery;
import org.onosproject.store.service.ConsistentMapException;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
@@ -169,7 +171,7 @@
label = "Number of millis beyond which links will be considered stale")
private int staleLinkAge = DEFAULT_STALE_LINK_AGE;
- private final DiscoveryContext context = new InternalDiscoveryContext();
+ private final LinkDiscoveryContext context = new InternalDiscoveryContext();
private final InternalRoleListener roleListener = new InternalRoleListener();
private final InternalDeviceListener deviceListener = new InternalDeviceListener();
private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
@@ -718,7 +720,7 @@
/**
* Provides processing context for the device link discovery helpers.
*/
- private class InternalDiscoveryContext implements DiscoveryContext {
+ private class InternalDiscoveryContext implements LinkDiscoveryContext {
@Override
public MastershipService mastershipService() {
return masterService;
diff --git a/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java b/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java
index 20d615a..8b47f44 100644
--- a/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java
+++ b/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java
@@ -76,6 +76,7 @@
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketServiceAdapter;
import org.onosproject.net.provider.ProviderId;
+import org.onosproject.provider.lldpcommon.LinkDiscovery;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList;
diff --git a/providers/lldpcommon/pom.xml b/providers/lldpcommon/pom.xml
new file mode 100644
index 0000000..bbd0874
--- /dev/null
+++ b/providers/lldpcommon/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2014 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>onos-providers</artifactId>
+ <groupId>org.onosproject</groupId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+
+ <artifactId>onos-lldp-provider-common</artifactId>
+ <packaging>bundle</packaging>
+
+ <description>Common code for providers that use LLDP.</description>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onlab-osgi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-api</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java
similarity index 93%
rename from providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
rename to providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java
index c0a50f9..125df58 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java
+++ b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscovery.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.provider.lldp.impl;
+package org.onosproject.provider.lldpcommon;
import com.google.common.collect.Sets;
@@ -52,14 +52,14 @@
* LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
* discovery implementation.
*/
-class LinkDiscovery implements TimerTask {
+public class LinkDiscovery implements TimerTask {
private final Logger log = getLogger(getClass());
private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
private final Device device;
- private final DiscoveryContext context;
+ private final LinkDiscoveryContext context;
private final Ethernet ethPacket;
private final Ethernet bddpEth;
@@ -79,7 +79,7 @@
* @param device the physical switch
* @param context discovery context
*/
- LinkDiscovery(Device device, DiscoveryContext context) {
+ public LinkDiscovery(Device device, LinkDiscoveryContext context) {
this.device = device;
this.context = context;
@@ -100,7 +100,7 @@
}
- synchronized void stop() {
+ public synchronized void stop() {
if (!isStopped) {
isStopped = true;
timeout.cancel();
@@ -109,7 +109,7 @@
}
}
- synchronized void start() {
+ public synchronized void start() {
if (isStopped) {
isStopped = false;
timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
@@ -118,7 +118,7 @@
}
}
- synchronized boolean isStopped() {
+ public synchronized boolean isStopped() {
return isStopped || timeout.isCancelled();
}
@@ -128,7 +128,7 @@
*
* @param port the port
*/
- void addPort(Port port) {
+ public void addPort(Port port) {
boolean newPort = ports.add(port.number().toLong());
boolean isMaster = context.mastershipService().isLocalMaster(device.id());
if (newPort && isMaster) {
@@ -141,7 +141,7 @@
* removed physical port from discovery process.
* @param port the port number
*/
- void removePort(PortNumber port) {
+ public void removePort(PortNumber port) {
ports.remove(port.toLong());
}
@@ -152,7 +152,7 @@
* @param packetContext packet context
* @return true if handled
*/
- boolean handleLldp(PacketContext packetContext) {
+ public boolean handleLldp(PacketContext packetContext) {
Ethernet eth = packetContext.inPacket().parsed();
if (eth == null) {
return false;
@@ -283,15 +283,15 @@
}
}
- boolean containsPort(long portNumber) {
+ public boolean containsPort(long portNumber) {
return ports.contains(portNumber);
}
- protected void enableFingerprint() {
+ public void enableFingerprint() {
fingerprinted = true;
}
- protected void disableFingerprint() {
+ public void disableFingerprint() {
fingerprinted = false;
}
}
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscoveryContext.java
similarity index 93%
rename from providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
rename to providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscoveryContext.java
index 74732ea..302fd4c 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java
+++ b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/LinkDiscoveryContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Open Networking Laboratory
+ * Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.provider.lldp.impl;
+package org.onosproject.provider.lldpcommon;
import org.onosproject.mastership.MastershipService;
import org.onosproject.net.LinkKey;
@@ -24,7 +24,7 @@
/**
* Shared context for use by link discovery.
*/
-interface DiscoveryContext {
+public interface LinkDiscoveryContext {
/**
* Returns the shared mastership service reference.
diff --git a/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/package-info.java b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/package-info.java
new file mode 100644
index 0000000..f64d57f
--- /dev/null
+++ b/providers/lldpcommon/src/main/java/org/onosproject/provider/lldpcommon/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Shared code for providers that use LLDP.
+ */
+package org.onosproject.provider.lldpcommon;
diff --git a/providers/netcfglinks/app.xml b/providers/netcfglinks/app.xml
new file mode 100644
index 0000000..5877360
--- /dev/null
+++ b/providers/netcfglinks/app.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<app name="org.onosproject.netcfglinksprovider" origin="ON.Lab" version="${project.version}"
+ category="default" url="http://onosproject.org"
+ featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
+ features="${project.artifactId}">
+ <description>${project.description}</description>
+ <artifact>mvn:${project.groupId}/onos-netcfg-links-provider/${project.version}</artifact>
+ <artifact>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</artifact>
+
+</app>
diff --git a/providers/netcfglinks/features.xml b/providers/netcfglinks/features.xml
new file mode 100644
index 0000000..5594656
--- /dev/null
+++ b/providers/netcfglinks/features.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ --><features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+ <feature name="${project.artifactId}" version="${project.version}"
+ description="${project.description}">
+ <feature>onos-api</feature>
+ <bundle>mvn:${project.groupId}/onos-netcfg-links-provider/${project.version}</bundle>
+ <bundle>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</bundle>
+ </feature>
+</features>
+
diff --git a/providers/netcfglinks/pom.xml b/providers/netcfglinks/pom.xml
index aeb2c34..9eda837 100644
--- a/providers/netcfglinks/pom.xml
+++ b/providers/netcfglinks/pom.xml
@@ -45,6 +45,12 @@
</dependency>
<dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-lldp-provider-common</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/DiscoveryContext.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/DiscoveryContext.java
deleted file mode 100644
index c9c3433..0000000
--- a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/DiscoveryContext.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.provider.netcfglinks;
-
-import org.onosproject.mastership.MastershipService;
-import org.onosproject.net.LinkKey;
-import org.onosproject.net.link.LinkProviderService;
-import org.onosproject.net.packet.PacketService;
-
-/**
- * Shared context for use by link discovery.
- */
-interface DiscoveryContext {
-
- /**
- * Returns the shared mastership service reference.
- *
- * @return mastership service
- */
- MastershipService mastershipService();
-
- /**
- * Returns the shared link provider service reference.
- *
- * @return link provider service
- */
- LinkProviderService providerService();
-
- /**
- * Returns the shared packet service reference.
- *
- * @return packet service
- */
- PacketService packetService();
-
- /**
- * Returns the probe rate in millis.
- *
- * @return probe rate
- */
- long probeRate();
-
- /**
- * Indicates whether to emit BDDP.
- *
- * @return true to emit BDDP
- */
- boolean useBddp();
-
- /**
- * Touches the link identified by the given key to indicate that it's active.
- *
- * @param key link key
- */
- void touchLink(LinkKey key);
-}
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/LinkDiscovery.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/LinkDiscovery.java
deleted file mode 100644
index 4997775..0000000
--- a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/LinkDiscovery.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright 2015 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.provider.netcfglinks;
-
-import java.nio.ByteBuffer;
-import java.util.Set;
-
-import org.jboss.netty.util.Timeout;
-import org.jboss.netty.util.TimerTask;
-import org.onlab.packet.Ethernet;
-import org.onlab.packet.ONOSLLDP;
-import org.onlab.util.Timer;
-import org.onosproject.net.ConnectPoint;
-import org.onosproject.net.Device;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.Link.Type;
-import org.onosproject.net.LinkKey;
-import org.onosproject.net.Port;
-import org.onosproject.net.PortNumber;
-import org.onosproject.net.link.DefaultLinkDescription;
-import org.onosproject.net.link.LinkDescription;
-import org.onosproject.net.packet.DefaultOutboundPacket;
-import org.onosproject.net.packet.OutboundPacket;
-import org.onosproject.net.packet.PacketContext;
-import org.slf4j.Logger;
-
-import com.google.common.collect.Sets;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static org.onosproject.net.PortNumber.portNumber;
-import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Run discovery process from a physical switch. Ports are initially labeled as
- * slow ports. When an LLDP is successfully received, label the remote port as
- * fast. Every probeRate milliseconds, loop over all fast ports and send an
- * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
- * discovery implementation.
- */
-class LinkDiscovery implements TimerTask {
-
- private final Logger log = getLogger(getClass());
-
- private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
-
- private final Device device;
- private final DiscoveryContext context;
-
- private final ONOSLLDP lldpPacket;
- private final Ethernet ethPacket;
- private final Ethernet bddpEth;
-
- private Timeout timeout;
- private volatile boolean isStopped;
-
- // Set of ports to be probed
- private final Set<Long> ports = Sets.newConcurrentHashSet();
-
- /**
- * Instantiates discovery manager for the given physical switch. Creates a
- * generic LLDP packet that will be customized for the port it is sent out on.
- * Starts the the timer for the discovery process.
- *
- * @param device the physical switch
- * @param context discovery context
- */
- LinkDiscovery(Device device, DiscoveryContext context) {
- this.device = device;
- this.context = context;
-
- lldpPacket = new ONOSLLDP();
- lldpPacket.setChassisId(device.chassisId());
- lldpPacket.setDevice(device.id().toString());
-
- ethPacket = new Ethernet();
- ethPacket.setEtherType(Ethernet.TYPE_LLDP);
- ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA);
- ethPacket.setPayload(this.lldpPacket);
- ethPacket.setPad(true);
-
- bddpEth = new Ethernet();
- bddpEth.setPayload(lldpPacket);
- bddpEth.setEtherType(Ethernet.TYPE_BSN);
- bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST);
- bddpEth.setPad(true);
-
- isStopped = true;
- start();
- log.debug("Started discovery manager for switch {}", device.id());
-
- }
-
- synchronized void stop() {
- if (!isStopped) {
- isStopped = true;
- timeout.cancel();
- } else {
- log.warn("LinkDiscovery stopped multiple times?");
- }
- }
-
- synchronized void start() {
- if (isStopped) {
- isStopped = false;
- timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
- } else {
- log.warn("LinkDiscovery started multiple times?");
- }
- }
-
- synchronized boolean isStopped() {
- return isStopped || timeout.isCancelled();
- }
-
- /**
- * Add physical port to discovery process.
- * Send out initial LLDP and label it as slow port.
- *
- * @param port the port
- */
- void addPort(Port port) {
- boolean newPort = ports.add(port.number().toLong());
- boolean isMaster = context.mastershipService().isLocalMaster(device.id());
- if (newPort && isMaster) {
- log.debug("Sending initial probe to port {}@{}", port.number().toLong(), device.id());
- sendProbes(port.number().toLong());
- }
- }
-
- /**
- * removed physical port from discovery process.
- * @param port the port number
- */
- void removePort(PortNumber port) {
- ports.remove(port.toLong());
- }
-
- /**
- * Handles an incoming LLDP packet. Creates link in topology and adds the
- * link for staleness tracking.
- *
- * @param packetContext packet context
- * @return true if handled
- */
- boolean handleLldp(PacketContext packetContext) {
- Ethernet eth = packetContext.inPacket().parsed();
- if (eth == null) {
- return false;
- }
-
- ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
- if (onoslldp != null) {
- PortNumber srcPort = portNumber(onoslldp.getPort());
- PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
- DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
- DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
-
- ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
- ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
-
- LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ?
- new DefaultLinkDescription(src, dst, Type.DIRECT, DefaultLinkDescription.EXPECTED) :
- new DefaultLinkDescription(src, dst, Type.INDIRECT, DefaultLinkDescription.EXPECTED);
-
- try {
- context.providerService().linkDetected(ld);
- context.touchLink(LinkKey.linkKey(src, dst));
- } catch (IllegalStateException e) {
- return true;
- }
- return true;
- }
- return false;
- }
-
-
- /**
- * Execute this method every t milliseconds. Loops over all ports
- * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow
- * port.
- *
- * @param t timeout
- */
- @Override
- public void run(Timeout t) {
- if (isStopped()) {
- return;
- }
-
- if (context.mastershipService().isLocalMaster(device.id())) {
- log.trace("Sending probes from {}", device.id());
- ports.forEach(this::sendProbes);
- }
-
- if (!isStopped()) {
- timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS);
- }
- }
-
- /**
- * Creates packet_out LLDP for specified output port.
- *
- * @param port the port
- * @return Packet_out message with LLDP data
- */
- private OutboundPacket createOutBoundLldp(Long port) {
- if (port == null) {
- return null;
- }
- lldpPacket.setPortId(port.intValue());
- ethPacket.setSourceMACAddress(SRC_MAC);
- return new DefaultOutboundPacket(device.id(),
- builder().setOutput(portNumber(port)).build(),
- ByteBuffer.wrap(ethPacket.serialize()));
- }
-
- /**
- * Creates packet_out BDDP for specified output port.
- *
- * @param port the port
- * @return Packet_out message with LLDP data
- */
- private OutboundPacket createOutBoundBddp(Long port) {
- if (port == null) {
- return null;
- }
- lldpPacket.setPortId(port.intValue());
- bddpEth.setSourceMACAddress(SRC_MAC);
- return new DefaultOutboundPacket(device.id(),
- builder().setOutput(portNumber(port)).build(),
- ByteBuffer.wrap(bddpEth.serialize()));
- }
-
- private void sendProbes(Long portNumber) {
- log.trace("Sending probes out to {}@{}", portNumber, device.id());
- OutboundPacket pkt = createOutBoundLldp(portNumber);
- context.packetService().emit(pkt);
- if (context.useBddp()) {
- OutboundPacket bpkt = createOutBoundBddp(portNumber);
- context.packetService().emit(bpkt);
- }
- }
-
- boolean containsPort(long portNumber) {
- return ports.contains(portNumber);
- }
-
-}
diff --git a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java
index 2671d93..02d030e 100644
--- a/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java
+++ b/providers/netcfglinks/src/main/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProvider.java
@@ -60,6 +60,8 @@
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
+import org.onosproject.provider.lldpcommon.LinkDiscoveryContext;
+import org.onosproject.provider.lldpcommon.LinkDiscovery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,7 +106,7 @@
// Device link discovery helpers.
protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
- private final DiscoveryContext context = new InternalDiscoveryContext();
+ private final LinkDiscoveryContext context = new InternalDiscoveryContext();
private LinkProviderService providerService;
@@ -206,7 +208,7 @@
/**
* Provides processing context for the device link discovery helpers.
*/
- private class InternalDiscoveryContext implements DiscoveryContext {
+ private class InternalDiscoveryContext implements LinkDiscoveryContext {
@Override
public MastershipService mastershipService() {
return masterService;
@@ -234,7 +236,16 @@
@Override
public void touchLink(LinkKey key) {
- //linkTimes.put(key, System.currentTimeMillis());
+ }
+
+ @Override
+ public String fingerprint() {
+ return "";
+ }
+
+ @Override
+ public DeviceService deviceService() {
+ return deviceService;
}
}
diff --git a/providers/netcfglinks/src/test/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProviderTest.java b/providers/netcfglinks/src/test/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProviderTest.java
index 70d2245..a16ba15 100644
--- a/providers/netcfglinks/src/test/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProviderTest.java
+++ b/providers/netcfglinks/src/test/java/org/onosproject/provider/netcfglinks/NetworkConfigLinksProviderTest.java
@@ -104,6 +104,15 @@
public void addListener(DeviceListener listener) {
deviceListener = listener;
}
+
+ @Override
+ public Device getDevice(DeviceId deviceId) {
+ if (deviceId.equals(dev1.id())) {
+ return dev1;
+ } else {
+ return dev2;
+ }
+ }
}
/**
diff --git a/providers/pom.xml b/providers/pom.xml
index 08364bc..795e815 100644
--- a/providers/pom.xml
+++ b/providers/pom.xml
@@ -33,7 +33,6 @@
<modules>
<module>openflow</module>
- <module>lldp</module>
<module>host</module>
<module>netcfghost</module>
<module>netconf</module>
@@ -43,6 +42,8 @@
<module>bgp</module>
<module>snmp</module>
<module>rest</module>
+ <module>lldpcommon</module>
+ <module>lldp</module>
<module>netcfglinks</module>
</modules>