added mastership to lldpdiscovery
Change-Id: I94bcf04eff134a2bb63325468f26406108608c92
Showing
3 changed files
with
24 additions
and
3 deletions
... | @@ -16,5 +16,15 @@ | ... | @@ -16,5 +16,15 @@ |
16 | <packaging>bundle</packaging> | 16 | <packaging>bundle</packaging> |
17 | 17 | ||
18 | <description>ONOS host tracking provider</description> | 18 | <description>ONOS host tracking provider</description> |
19 | + <dependencies> | ||
20 | + <dependency> | ||
21 | + <groupId>org.onlab.onos</groupId> | ||
22 | + <artifactId>onos-api</artifactId> | ||
23 | + <classifier>tests</classifier> | ||
24 | + <scope>test</scope> | ||
25 | + </dependency> | ||
26 | + </dependencies> | ||
27 | + | ||
28 | + | ||
19 | 29 | ||
20 | </project> | 30 | </project> | ... | ... |
... | @@ -5,6 +5,7 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -5,6 +5,7 @@ import org.apache.felix.scr.annotations.Component; |
5 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
6 | import org.apache.felix.scr.annotations.Reference; | 6 | import org.apache.felix.scr.annotations.Reference; |
7 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 7 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
8 | +import org.onlab.onos.mastership.MastershipService; | ||
8 | import org.onlab.onos.net.ConnectPoint; | 9 | import org.onlab.onos.net.ConnectPoint; |
9 | import org.onlab.onos.net.Device; | 10 | import org.onlab.onos.net.Device; |
10 | import org.onlab.onos.net.DeviceId; | 11 | import org.onlab.onos.net.DeviceId; |
... | @@ -46,6 +47,9 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -46,6 +47,9 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
46 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
47 | protected PacketService packetSevice; | 48 | protected PacketService packetSevice; |
48 | 49 | ||
50 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
51 | + protected MastershipService masterService; | ||
52 | + | ||
49 | private LinkProviderService providerService; | 53 | private LinkProviderService providerService; |
50 | 54 | ||
51 | private final boolean useBDDP = true; | 55 | private final boolean useBDDP = true; |
... | @@ -95,7 +99,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -95,7 +99,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { |
95 | switch (event.type()) { | 99 | switch (event.type()) { |
96 | case DEVICE_ADDED: | 100 | case DEVICE_ADDED: |
97 | discoverers.put(device.id(), | 101 | discoverers.put(device.id(), |
98 | - new LinkDiscovery(device, packetSevice, | 102 | + new LinkDiscovery(device, packetSevice, masterService, |
99 | providerService, useBDDP)); | 103 | providerService, useBDDP)); |
100 | break; | 104 | break; |
101 | case PORT_ADDED: | 105 | case PORT_ADDED: | ... | ... |
... | @@ -30,10 +30,12 @@ import java.util.concurrent.atomic.AtomicInteger; | ... | @@ -30,10 +30,12 @@ import java.util.concurrent.atomic.AtomicInteger; |
30 | 30 | ||
31 | import org.jboss.netty.util.Timeout; | 31 | import org.jboss.netty.util.Timeout; |
32 | import org.jboss.netty.util.TimerTask; | 32 | import org.jboss.netty.util.TimerTask; |
33 | +import org.onlab.onos.mastership.MastershipService; | ||
33 | import org.onlab.onos.net.ConnectPoint; | 34 | import org.onlab.onos.net.ConnectPoint; |
34 | import org.onlab.onos.net.Device; | 35 | import org.onlab.onos.net.Device; |
35 | import org.onlab.onos.net.DeviceId; | 36 | import org.onlab.onos.net.DeviceId; |
36 | import org.onlab.onos.net.Link.Type; | 37 | import org.onlab.onos.net.Link.Type; |
38 | +import org.onlab.onos.net.MastershipRole; | ||
37 | import org.onlab.onos.net.Port; | 39 | import org.onlab.onos.net.Port; |
38 | import org.onlab.onos.net.PortNumber; | 40 | import org.onlab.onos.net.PortNumber; |
39 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; | 41 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
... | @@ -79,22 +81,24 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -79,22 +81,24 @@ public class LinkDiscovery implements TimerTask { |
79 | private final boolean useBDDP; | 81 | private final boolean useBDDP; |
80 | private final LinkProviderService linkProvider; | 82 | private final LinkProviderService linkProvider; |
81 | private final PacketService pktService; | 83 | private final PacketService pktService; |
84 | + private final MastershipService mastershipService; | ||
82 | private Timeout timeout; | 85 | private Timeout timeout; |
83 | 86 | ||
84 | /** | 87 | /** |
85 | * Instantiates discovery manager for the given physical switch. Creates a | 88 | * Instantiates discovery manager for the given physical switch. Creates a |
86 | * generic LLDP packet that will be customized for the port it is sent out on. | 89 | * generic LLDP packet that will be customized for the port it is sent out on. |
87 | * Starts the the timer for the discovery process. | 90 | * Starts the the timer for the discovery process. |
88 | - * | ||
89 | * @param device the physical switch | 91 | * @param device the physical switch |
92 | + * @param masterService | ||
90 | * @param useBDDP flag to also use BDDP for discovery | 93 | * @param useBDDP flag to also use BDDP for discovery |
91 | */ | 94 | */ |
92 | public LinkDiscovery(Device device, PacketService pktService, | 95 | public LinkDiscovery(Device device, PacketService pktService, |
93 | - LinkProviderService providerService, Boolean... useBDDP) { | 96 | + MastershipService masterService, LinkProviderService providerService, Boolean... useBDDP) { |
94 | this.device = device; | 97 | this.device = device; |
95 | this.probeRate = 3000; | 98 | this.probeRate = 3000; |
96 | this.linkProvider = providerService; | 99 | this.linkProvider = providerService; |
97 | this.pktService = pktService; | 100 | this.pktService = pktService; |
101 | + this.mastershipService = masterService; | ||
98 | this.slowPorts = Collections.synchronizedSet(new HashSet<Long>()); | 102 | this.slowPorts = Collections.synchronizedSet(new HashSet<Long>()); |
99 | this.fastPorts = Collections.synchronizedSet(new HashSet<Long>()); | 103 | this.fastPorts = Collections.synchronizedSet(new HashSet<Long>()); |
100 | this.portProbeCount = new HashMap<>(); | 104 | this.portProbeCount = new HashMap<>(); |
... | @@ -337,6 +341,8 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -337,6 +341,8 @@ public class LinkDiscovery implements TimerTask { |
337 | } | 341 | } |
338 | 342 | ||
339 | private void sendProbes(Long portNumber) { | 343 | private void sendProbes(Long portNumber) { |
344 | + if (mastershipService.getLocalRole(this.device.id()) == | ||
345 | + MastershipRole.MASTER) { | ||
340 | OutboundPacket pkt = this.createOutBoundLLDP(portNumber); | 346 | OutboundPacket pkt = this.createOutBoundLLDP(portNumber); |
341 | pktService.emit(pkt); | 347 | pktService.emit(pkt); |
342 | if (useBDDP) { | 348 | if (useBDDP) { |
... | @@ -344,5 +350,6 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -344,5 +350,6 @@ public class LinkDiscovery implements TimerTask { |
344 | pktService.emit(bpkt); | 350 | pktService.emit(bpkt); |
345 | } | 351 | } |
346 | } | 352 | } |
353 | + } | ||
347 | 354 | ||
348 | } | 355 | } | ... | ... |
-
Please register or login to post a comment