Ray Milkey

Refactored LLDP link discovery to be shared by multiple providers

Change-Id: Ia2253ff6bb39186e936ddbaff0c416aa5be6e117
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 20166 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.lldpprovider" origin="ON.Lab" version="${project.version}"
18 + category="default" url="http://onosproject.org"
19 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
20 + features="${project.artifactId}">
21 + <description>${project.description}</description>
22 + <artifact>mvn:${project.groupId}/onos-lldp-provider/${project.version}</artifact>
23 + <artifact>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</artifact>
24 +
25 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + --><features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
17 + <feature name="${project.artifactId}" version="${project.version}"
18 + description="${project.description}">
19 + <feature>onos-api</feature>
20 + <bundle>mvn:${project.groupId}/onos-lldp-provider/${project.version}</bundle>
21 + <bundle>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</bundle>
22 + </feature>
23 +</features>
24 +
...@@ -48,6 +48,12 @@ ...@@ -48,6 +48,12 @@
48 48
49 <dependency> 49 <dependency>
50 <groupId>org.onosproject</groupId> 50 <groupId>org.onosproject</groupId>
51 + <artifactId>onos-lldp-provider-common</artifactId>
52 + <version>1.5.0-SNAPSHOT</version>
53 + </dependency>
54 +
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
51 <artifactId>onos-api</artifactId> 57 <artifactId>onos-api</artifactId>
52 <classifier>tests</classifier> 58 <classifier>tests</classifier>
53 <scope>test</scope> 59 <scope>test</scope>
......
...@@ -62,6 +62,8 @@ import org.onosproject.net.packet.PacketProcessor; ...@@ -62,6 +62,8 @@ import org.onosproject.net.packet.PacketProcessor;
62 import org.onosproject.net.packet.PacketService; 62 import org.onosproject.net.packet.PacketService;
63 import org.onosproject.net.provider.AbstractProvider; 63 import org.onosproject.net.provider.AbstractProvider;
64 import org.onosproject.net.provider.ProviderId; 64 import org.onosproject.net.provider.ProviderId;
65 +import org.onosproject.provider.lldpcommon.LinkDiscoveryContext;
66 +import org.onosproject.provider.lldpcommon.LinkDiscovery;
65 import org.onosproject.store.service.ConsistentMapException; 67 import org.onosproject.store.service.ConsistentMapException;
66 import org.osgi.service.component.ComponentContext; 68 import org.osgi.service.component.ComponentContext;
67 import org.slf4j.Logger; 69 import org.slf4j.Logger;
...@@ -169,7 +171,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -169,7 +171,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
169 label = "Number of millis beyond which links will be considered stale") 171 label = "Number of millis beyond which links will be considered stale")
170 private int staleLinkAge = DEFAULT_STALE_LINK_AGE; 172 private int staleLinkAge = DEFAULT_STALE_LINK_AGE;
171 173
172 - private final DiscoveryContext context = new InternalDiscoveryContext(); 174 + private final LinkDiscoveryContext context = new InternalDiscoveryContext();
173 private final InternalRoleListener roleListener = new InternalRoleListener(); 175 private final InternalRoleListener roleListener = new InternalRoleListener();
174 private final InternalDeviceListener deviceListener = new InternalDeviceListener(); 176 private final InternalDeviceListener deviceListener = new InternalDeviceListener();
175 private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); 177 private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor();
...@@ -718,7 +720,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -718,7 +720,7 @@ public class LldpLinkProvider extends AbstractProvider implements LinkProvider {
718 /** 720 /**
719 * Provides processing context for the device link discovery helpers. 721 * Provides processing context for the device link discovery helpers.
720 */ 722 */
721 - private class InternalDiscoveryContext implements DiscoveryContext { 723 + private class InternalDiscoveryContext implements LinkDiscoveryContext {
722 @Override 724 @Override
723 public MastershipService mastershipService() { 725 public MastershipService mastershipService() {
724 return masterService; 726 return masterService;
......
...@@ -76,6 +76,7 @@ import org.onosproject.net.packet.PacketContext; ...@@ -76,6 +76,7 @@ import org.onosproject.net.packet.PacketContext;
76 import org.onosproject.net.packet.PacketProcessor; 76 import org.onosproject.net.packet.PacketProcessor;
77 import org.onosproject.net.packet.PacketServiceAdapter; 77 import org.onosproject.net.packet.PacketServiceAdapter;
78 import org.onosproject.net.provider.ProviderId; 78 import org.onosproject.net.provider.ProviderId;
79 +import org.onosproject.provider.lldpcommon.LinkDiscovery;
79 80
80 import com.google.common.collect.ArrayListMultimap; 81 import com.google.common.collect.ArrayListMultimap;
81 import com.google.common.collect.ImmutableList; 82 import com.google.common.collect.ImmutableList;
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <artifactId>onos-providers</artifactId>
24 + <groupId>org.onosproject</groupId>
25 + <version>1.5.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 +
30 + <artifactId>onos-lldp-provider-common</artifactId>
31 + <packaging>bundle</packaging>
32 +
33 + <description>Common code for providers that use LLDP.</description>
34 +
35 + <dependencies>
36 +
37 + <dependency>
38 + <groupId>org.onosproject</groupId>
39 + <artifactId>onlab-osgi</artifactId>
40 + </dependency>
41 +
42 + <dependency>
43 + <groupId>junit</groupId>
44 + <artifactId>junit</artifactId>
45 + <version>4.11</version>
46 + <scope>test</scope>
47 + </dependency>
48 +
49 + <dependency>
50 + <groupId>org.easymock</groupId>
51 + <artifactId>easymock</artifactId>
52 + <scope>test</scope>
53 + </dependency>
54 +
55 + <dependency>
56 + <groupId>org.onosproject</groupId>
57 + <artifactId>onos-api</artifactId>
58 + <version>${project.version}</version>
59 + <classifier>tests</classifier>
60 + <scope>test</scope>
61 + </dependency>
62 +
63 + </dependencies>
64 +
65 +</project>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.provider.lldp.impl; 16 +package org.onosproject.provider.lldpcommon;
17 17
18 import com.google.common.collect.Sets; 18 import com.google.common.collect.Sets;
19 19
...@@ -52,14 +52,14 @@ import static org.onosproject.cluster.ClusterMetadata.NO_NAME; ...@@ -52,14 +52,14 @@ import static org.onosproject.cluster.ClusterMetadata.NO_NAME;
52 * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology 52 * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
53 * discovery implementation. 53 * discovery implementation.
54 */ 54 */
55 -class LinkDiscovery implements TimerTask { 55 +public class LinkDiscovery implements TimerTask {
56 56
57 private final Logger log = getLogger(getClass()); 57 private final Logger log = getLogger(getClass());
58 58
59 private static final String SRC_MAC = "DE:AD:BE:EF:BA:11"; 59 private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
60 60
61 private final Device device; 61 private final Device device;
62 - private final DiscoveryContext context; 62 + private final LinkDiscoveryContext context;
63 63
64 private final Ethernet ethPacket; 64 private final Ethernet ethPacket;
65 private final Ethernet bddpEth; 65 private final Ethernet bddpEth;
...@@ -79,7 +79,7 @@ class LinkDiscovery implements TimerTask { ...@@ -79,7 +79,7 @@ class LinkDiscovery implements TimerTask {
79 * @param device the physical switch 79 * @param device the physical switch
80 * @param context discovery context 80 * @param context discovery context
81 */ 81 */
82 - LinkDiscovery(Device device, DiscoveryContext context) { 82 + public LinkDiscovery(Device device, LinkDiscoveryContext context) {
83 this.device = device; 83 this.device = device;
84 this.context = context; 84 this.context = context;
85 85
...@@ -100,7 +100,7 @@ class LinkDiscovery implements TimerTask { ...@@ -100,7 +100,7 @@ class LinkDiscovery implements TimerTask {
100 100
101 } 101 }
102 102
103 - synchronized void stop() { 103 + public synchronized void stop() {
104 if (!isStopped) { 104 if (!isStopped) {
105 isStopped = true; 105 isStopped = true;
106 timeout.cancel(); 106 timeout.cancel();
...@@ -109,7 +109,7 @@ class LinkDiscovery implements TimerTask { ...@@ -109,7 +109,7 @@ class LinkDiscovery implements TimerTask {
109 } 109 }
110 } 110 }
111 111
112 - synchronized void start() { 112 + public synchronized void start() {
113 if (isStopped) { 113 if (isStopped) {
114 isStopped = false; 114 isStopped = false;
115 timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); 115 timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
...@@ -118,7 +118,7 @@ class LinkDiscovery implements TimerTask { ...@@ -118,7 +118,7 @@ class LinkDiscovery implements TimerTask {
118 } 118 }
119 } 119 }
120 120
121 - synchronized boolean isStopped() { 121 + public synchronized boolean isStopped() {
122 return isStopped || timeout.isCancelled(); 122 return isStopped || timeout.isCancelled();
123 } 123 }
124 124
...@@ -128,7 +128,7 @@ class LinkDiscovery implements TimerTask { ...@@ -128,7 +128,7 @@ class LinkDiscovery implements TimerTask {
128 * 128 *
129 * @param port the port 129 * @param port the port
130 */ 130 */
131 - void addPort(Port port) { 131 + public void addPort(Port port) {
132 boolean newPort = ports.add(port.number().toLong()); 132 boolean newPort = ports.add(port.number().toLong());
133 boolean isMaster = context.mastershipService().isLocalMaster(device.id()); 133 boolean isMaster = context.mastershipService().isLocalMaster(device.id());
134 if (newPort && isMaster) { 134 if (newPort && isMaster) {
...@@ -141,7 +141,7 @@ class LinkDiscovery implements TimerTask { ...@@ -141,7 +141,7 @@ class LinkDiscovery implements TimerTask {
141 * removed physical port from discovery process. 141 * removed physical port from discovery process.
142 * @param port the port number 142 * @param port the port number
143 */ 143 */
144 - void removePort(PortNumber port) { 144 + public void removePort(PortNumber port) {
145 ports.remove(port.toLong()); 145 ports.remove(port.toLong());
146 } 146 }
147 147
...@@ -152,7 +152,7 @@ class LinkDiscovery implements TimerTask { ...@@ -152,7 +152,7 @@ class LinkDiscovery implements TimerTask {
152 * @param packetContext packet context 152 * @param packetContext packet context
153 * @return true if handled 153 * @return true if handled
154 */ 154 */
155 - boolean handleLldp(PacketContext packetContext) { 155 + public boolean handleLldp(PacketContext packetContext) {
156 Ethernet eth = packetContext.inPacket().parsed(); 156 Ethernet eth = packetContext.inPacket().parsed();
157 if (eth == null) { 157 if (eth == null) {
158 return false; 158 return false;
...@@ -283,15 +283,15 @@ class LinkDiscovery implements TimerTask { ...@@ -283,15 +283,15 @@ class LinkDiscovery implements TimerTask {
283 } 283 }
284 } 284 }
285 285
286 - boolean containsPort(long portNumber) { 286 + public boolean containsPort(long portNumber) {
287 return ports.contains(portNumber); 287 return ports.contains(portNumber);
288 } 288 }
289 289
290 - protected void enableFingerprint() { 290 + public void enableFingerprint() {
291 fingerprinted = true; 291 fingerprinted = true;
292 } 292 }
293 293
294 - protected void disableFingerprint() { 294 + public void disableFingerprint() {
295 fingerprinted = false; 295 fingerprinted = false;
296 } 296 }
297 } 297 }
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.provider.lldp.impl; 16 +package org.onosproject.provider.lldpcommon;
17 17
18 import org.onosproject.mastership.MastershipService; 18 import org.onosproject.mastership.MastershipService;
19 import org.onosproject.net.LinkKey; 19 import org.onosproject.net.LinkKey;
...@@ -24,7 +24,7 @@ import org.onosproject.net.packet.PacketService; ...@@ -24,7 +24,7 @@ import org.onosproject.net.packet.PacketService;
24 /** 24 /**
25 * Shared context for use by link discovery. 25 * Shared context for use by link discovery.
26 */ 26 */
27 -interface DiscoveryContext { 27 +public interface LinkDiscoveryContext {
28 28
29 /** 29 /**
30 * Returns the shared mastership service reference. 30 * Returns the shared mastership service reference.
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
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 + */
16 +
17 +/**
18 + * Shared code for providers that use LLDP.
19 + */
20 +package org.onosproject.provider.lldpcommon;
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<app name="org.onosproject.netcfglinksprovider" origin="ON.Lab" version="${project.version}"
18 + category="default" url="http://onosproject.org"
19 + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features"
20 + features="${project.artifactId}">
21 + <description>${project.description}</description>
22 + <artifact>mvn:${project.groupId}/onos-netcfg-links-provider/${project.version}</artifact>
23 + <artifact>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</artifact>
24 +
25 +</app>
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + --><features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
17 + <feature name="${project.artifactId}" version="${project.version}"
18 + description="${project.description}">
19 + <feature>onos-api</feature>
20 + <bundle>mvn:${project.groupId}/onos-netcfg-links-provider/${project.version}</bundle>
21 + <bundle>mvn:${project.groupId}/onos-lldp-provider-common/${project.version}</bundle>
22 + </feature>
23 +</features>
24 +
...@@ -45,6 +45,12 @@ ...@@ -45,6 +45,12 @@
45 </dependency> 45 </dependency>
46 46
47 <dependency> 47 <dependency>
48 + <groupId>org.onosproject</groupId>
49 + <artifactId>onos-lldp-provider-common</artifactId>
50 + <version>1.5.0-SNAPSHOT</version>
51 + </dependency>
52 +
53 + <dependency>
48 <groupId>junit</groupId> 54 <groupId>junit</groupId>
49 <artifactId>junit</artifactId> 55 <artifactId>junit</artifactId>
50 <version>4.11</version> 56 <version>4.11</version>
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
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 - */
16 -package org.onosproject.provider.netcfglinks;
17 -
18 -import org.onosproject.mastership.MastershipService;
19 -import org.onosproject.net.LinkKey;
20 -import org.onosproject.net.link.LinkProviderService;
21 -import org.onosproject.net.packet.PacketService;
22 -
23 -/**
24 - * Shared context for use by link discovery.
25 - */
26 -interface DiscoveryContext {
27 -
28 - /**
29 - * Returns the shared mastership service reference.
30 - *
31 - * @return mastership service
32 - */
33 - MastershipService mastershipService();
34 -
35 - /**
36 - * Returns the shared link provider service reference.
37 - *
38 - * @return link provider service
39 - */
40 - LinkProviderService providerService();
41 -
42 - /**
43 - * Returns the shared packet service reference.
44 - *
45 - * @return packet service
46 - */
47 - PacketService packetService();
48 -
49 - /**
50 - * Returns the probe rate in millis.
51 - *
52 - * @return probe rate
53 - */
54 - long probeRate();
55 -
56 - /**
57 - * Indicates whether to emit BDDP.
58 - *
59 - * @return true to emit BDDP
60 - */
61 - boolean useBddp();
62 -
63 - /**
64 - * Touches the link identified by the given key to indicate that it's active.
65 - *
66 - * @param key link key
67 - */
68 - void touchLink(LinkKey key);
69 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
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 - */
16 -package org.onosproject.provider.netcfglinks;
17 -
18 -import java.nio.ByteBuffer;
19 -import java.util.Set;
20 -
21 -import org.jboss.netty.util.Timeout;
22 -import org.jboss.netty.util.TimerTask;
23 -import org.onlab.packet.Ethernet;
24 -import org.onlab.packet.ONOSLLDP;
25 -import org.onlab.util.Timer;
26 -import org.onosproject.net.ConnectPoint;
27 -import org.onosproject.net.Device;
28 -import org.onosproject.net.DeviceId;
29 -import org.onosproject.net.Link.Type;
30 -import org.onosproject.net.LinkKey;
31 -import org.onosproject.net.Port;
32 -import org.onosproject.net.PortNumber;
33 -import org.onosproject.net.link.DefaultLinkDescription;
34 -import org.onosproject.net.link.LinkDescription;
35 -import org.onosproject.net.packet.DefaultOutboundPacket;
36 -import org.onosproject.net.packet.OutboundPacket;
37 -import org.onosproject.net.packet.PacketContext;
38 -import org.slf4j.Logger;
39 -
40 -import com.google.common.collect.Sets;
41 -
42 -import static java.util.concurrent.TimeUnit.MILLISECONDS;
43 -import static org.onosproject.net.PortNumber.portNumber;
44 -import static org.onosproject.net.flow.DefaultTrafficTreatment.builder;
45 -import static org.slf4j.LoggerFactory.getLogger;
46 -
47 -/**
48 - * Run discovery process from a physical switch. Ports are initially labeled as
49 - * slow ports. When an LLDP is successfully received, label the remote port as
50 - * fast. Every probeRate milliseconds, loop over all fast ports and send an
51 - * LLDP, send an LLDP for a single slow port. Based on FlowVisor topology
52 - * discovery implementation.
53 - */
54 -class LinkDiscovery implements TimerTask {
55 -
56 - private final Logger log = getLogger(getClass());
57 -
58 - private static final String SRC_MAC = "DE:AD:BE:EF:BA:11";
59 -
60 - private final Device device;
61 - private final DiscoveryContext context;
62 -
63 - private final ONOSLLDP lldpPacket;
64 - private final Ethernet ethPacket;
65 - private final Ethernet bddpEth;
66 -
67 - private Timeout timeout;
68 - private volatile boolean isStopped;
69 -
70 - // Set of ports to be probed
71 - private final Set<Long> ports = Sets.newConcurrentHashSet();
72 -
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.
77 - *
78 - * @param device the physical switch
79 - * @param context discovery context
80 - */
81 - LinkDiscovery(Device device, DiscoveryContext context) {
82 - this.device = device;
83 - this.context = context;
84 -
85 - lldpPacket = new ONOSLLDP();
86 - lldpPacket.setChassisId(device.chassisId());
87 - lldpPacket.setDevice(device.id().toString());
88 -
89 - ethPacket = new Ethernet();
90 - ethPacket.setEtherType(Ethernet.TYPE_LLDP);
91 - ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA);
92 - ethPacket.setPayload(this.lldpPacket);
93 - ethPacket.setPad(true);
94 -
95 - bddpEth = new Ethernet();
96 - bddpEth.setPayload(lldpPacket);
97 - bddpEth.setEtherType(Ethernet.TYPE_BSN);
98 - bddpEth.setDestinationMACAddress(ONOSLLDP.BDDP_MULTICAST);
99 - bddpEth.setPad(true);
100 -
101 - isStopped = true;
102 - start();
103 - log.debug("Started discovery manager for switch {}", device.id());
104 -
105 - }
106 -
107 - synchronized void stop() {
108 - if (!isStopped) {
109 - isStopped = true;
110 - timeout.cancel();
111 - } else {
112 - log.warn("LinkDiscovery stopped multiple times?");
113 - }
114 - }
115 -
116 - synchronized void start() {
117 - if (isStopped) {
118 - isStopped = false;
119 - timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS);
120 - } else {
121 - log.warn("LinkDiscovery started multiple times?");
122 - }
123 - }
124 -
125 - synchronized boolean isStopped() {
126 - return isStopped || timeout.isCancelled();
127 - }
128 -
129 - /**
130 - * Add physical port to discovery process.
131 - * Send out initial LLDP and label it as slow port.
132 - *
133 - * @param port the port
134 - */
135 - void addPort(Port port) {
136 - boolean newPort = ports.add(port.number().toLong());
137 - boolean isMaster = context.mastershipService().isLocalMaster(device.id());
138 - if (newPort && isMaster) {
139 - log.debug("Sending initial probe to port {}@{}", port.number().toLong(), device.id());
140 - sendProbes(port.number().toLong());
141 - }
142 - }
143 -
144 - /**
145 - * removed physical port from discovery process.
146 - * @param port the port number
147 - */
148 - void removePort(PortNumber port) {
149 - ports.remove(port.toLong());
150 - }
151 -
152 - /**
153 - * Handles an incoming LLDP packet. Creates link in topology and adds the
154 - * link for staleness tracking.
155 - *
156 - * @param packetContext packet context
157 - * @return true if handled
158 - */
159 - boolean handleLldp(PacketContext packetContext) {
160 - Ethernet eth = packetContext.inPacket().parsed();
161 - if (eth == null) {
162 - return false;
163 - }
164 -
165 - ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth);
166 - if (onoslldp != null) {
167 - PortNumber srcPort = portNumber(onoslldp.getPort());
168 - PortNumber dstPort = packetContext.inPacket().receivedFrom().port();
169 - DeviceId srcDeviceId = DeviceId.deviceId(onoslldp.getDeviceString());
170 - DeviceId dstDeviceId = packetContext.inPacket().receivedFrom().deviceId();
171 -
172 - ConnectPoint src = new ConnectPoint(srcDeviceId, srcPort);
173 - ConnectPoint dst = new ConnectPoint(dstDeviceId, dstPort);
174 -
175 - LinkDescription ld = eth.getEtherType() == Ethernet.TYPE_LLDP ?
176 - new DefaultLinkDescription(src, dst, Type.DIRECT, DefaultLinkDescription.EXPECTED) :
177 - new DefaultLinkDescription(src, dst, Type.INDIRECT, DefaultLinkDescription.EXPECTED);
178 -
179 - try {
180 - context.providerService().linkDetected(ld);
181 - context.touchLink(LinkKey.linkKey(src, dst));
182 - } catch (IllegalStateException e) {
183 - return true;
184 - }
185 - return true;
186 - }
187 - return false;
188 - }
189 -
190 -
191 - /**
192 - * Execute this method every t milliseconds. Loops over all ports
193 - * labeled as fast and sends out an LLDP. Send out an LLDP on a single slow
194 - * port.
195 - *
196 - * @param t timeout
197 - */
198 - @Override
199 - public void run(Timeout t) {
200 - if (isStopped()) {
201 - return;
202 - }
203 -
204 - if (context.mastershipService().isLocalMaster(device.id())) {
205 - log.trace("Sending probes from {}", device.id());
206 - ports.forEach(this::sendProbes);
207 - }
208 -
209 - if (!isStopped()) {
210 - timeout = Timer.getTimer().newTimeout(this, context.probeRate(), MILLISECONDS);
211 - }
212 - }
213 -
214 - /**
215 - * Creates packet_out LLDP for specified output port.
216 - *
217 - * @param port the port
218 - * @return Packet_out message with LLDP data
219 - */
220 - private OutboundPacket createOutBoundLldp(Long port) {
221 - if (port == null) {
222 - return null;
223 - }
224 - lldpPacket.setPortId(port.intValue());
225 - ethPacket.setSourceMACAddress(SRC_MAC);
226 - return new DefaultOutboundPacket(device.id(),
227 - builder().setOutput(portNumber(port)).build(),
228 - ByteBuffer.wrap(ethPacket.serialize()));
229 - }
230 -
231 - /**
232 - * Creates packet_out BDDP for specified output port.
233 - *
234 - * @param port the port
235 - * @return Packet_out message with LLDP data
236 - */
237 - private OutboundPacket createOutBoundBddp(Long port) {
238 - if (port == null) {
239 - return null;
240 - }
241 - lldpPacket.setPortId(port.intValue());
242 - bddpEth.setSourceMACAddress(SRC_MAC);
243 - return new DefaultOutboundPacket(device.id(),
244 - builder().setOutput(portNumber(port)).build(),
245 - ByteBuffer.wrap(bddpEth.serialize()));
246 - }
247 -
248 - private void sendProbes(Long portNumber) {
249 - log.trace("Sending probes out to {}@{}", portNumber, device.id());
250 - OutboundPacket pkt = createOutBoundLldp(portNumber);
251 - context.packetService().emit(pkt);
252 - if (context.useBddp()) {
253 - OutboundPacket bpkt = createOutBoundBddp(portNumber);
254 - context.packetService().emit(bpkt);
255 - }
256 - }
257 -
258 - boolean containsPort(long portNumber) {
259 - return ports.contains(portNumber);
260 - }
261 -
262 -}
...@@ -60,6 +60,8 @@ import org.onosproject.net.packet.PacketProcessor; ...@@ -60,6 +60,8 @@ import org.onosproject.net.packet.PacketProcessor;
60 import org.onosproject.net.packet.PacketService; 60 import org.onosproject.net.packet.PacketService;
61 import org.onosproject.net.provider.AbstractProvider; 61 import org.onosproject.net.provider.AbstractProvider;
62 import org.onosproject.net.provider.ProviderId; 62 import org.onosproject.net.provider.ProviderId;
63 +import org.onosproject.provider.lldpcommon.LinkDiscoveryContext;
64 +import org.onosproject.provider.lldpcommon.LinkDiscovery;
63 import org.slf4j.Logger; 65 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory; 66 import org.slf4j.LoggerFactory;
65 67
...@@ -104,7 +106,7 @@ public class NetworkConfigLinksProvider ...@@ -104,7 +106,7 @@ public class NetworkConfigLinksProvider
104 // Device link discovery helpers. 106 // Device link discovery helpers.
105 protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>(); 107 protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>();
106 108
107 - private final DiscoveryContext context = new InternalDiscoveryContext(); 109 + private final LinkDiscoveryContext context = new InternalDiscoveryContext();
108 110
109 private LinkProviderService providerService; 111 private LinkProviderService providerService;
110 112
...@@ -206,7 +208,7 @@ public class NetworkConfigLinksProvider ...@@ -206,7 +208,7 @@ public class NetworkConfigLinksProvider
206 /** 208 /**
207 * Provides processing context for the device link discovery helpers. 209 * Provides processing context for the device link discovery helpers.
208 */ 210 */
209 - private class InternalDiscoveryContext implements DiscoveryContext { 211 + private class InternalDiscoveryContext implements LinkDiscoveryContext {
210 @Override 212 @Override
211 public MastershipService mastershipService() { 213 public MastershipService mastershipService() {
212 return masterService; 214 return masterService;
...@@ -234,7 +236,16 @@ public class NetworkConfigLinksProvider ...@@ -234,7 +236,16 @@ public class NetworkConfigLinksProvider
234 236
235 @Override 237 @Override
236 public void touchLink(LinkKey key) { 238 public void touchLink(LinkKey key) {
237 - //linkTimes.put(key, System.currentTimeMillis()); 239 + }
240 +
241 + @Override
242 + public String fingerprint() {
243 + return "";
244 + }
245 +
246 + @Override
247 + public DeviceService deviceService() {
248 + return deviceService;
238 } 249 }
239 } 250 }
240 251
......
...@@ -104,6 +104,15 @@ public class NetworkConfigLinksProviderTest { ...@@ -104,6 +104,15 @@ public class NetworkConfigLinksProviderTest {
104 public void addListener(DeviceListener listener) { 104 public void addListener(DeviceListener listener) {
105 deviceListener = listener; 105 deviceListener = listener;
106 } 106 }
107 +
108 + @Override
109 + public Device getDevice(DeviceId deviceId) {
110 + if (deviceId.equals(dev1.id())) {
111 + return dev1;
112 + } else {
113 + return dev2;
114 + }
115 + }
107 } 116 }
108 117
109 /** 118 /**
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
33 33
34 <modules> 34 <modules>
35 <module>openflow</module> 35 <module>openflow</module>
36 - <module>lldp</module>
37 <module>host</module> 36 <module>host</module>
38 <module>netcfghost</module> 37 <module>netcfghost</module>
39 <module>netconf</module> 38 <module>netconf</module>
...@@ -43,6 +42,8 @@ ...@@ -43,6 +42,8 @@
43 <module>bgp</module> 42 <module>bgp</module>
44 <module>snmp</module> 43 <module>snmp</module>
45 <module>rest</module> 44 <module>rest</module>
45 + <module>lldpcommon</module>
46 + <module>lldp</module>
46 <module>netcfglinks</module> 47 <module>netcfglinks</module>
47 </modules> 48 </modules>
48 49
......