Ayaka Koshibe
Committed by Gerrit Code Review

NullLinkProvider only generates links between local devices.

Reference: ONOS-835

Change-Id: Icc378a053e54f2a3ffa0f29abd01782b80588239
...@@ -19,6 +19,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;
19 import static org.onlab.util.Tools.delay; 19 import static org.onlab.util.Tools.delay;
20 import static org.onlab.util.Tools.namedThreads; 20 import static org.onlab.util.Tools.namedThreads;
21 import static org.slf4j.LoggerFactory.getLogger; 21 import static org.slf4j.LoggerFactory.getLogger;
22 +import static org.onosproject.net.MastershipRole.MASTER;
22 23
23 import java.util.Dictionary; 24 import java.util.Dictionary;
24 import java.util.List; 25 import java.util.List;
...@@ -34,6 +35,7 @@ import org.apache.felix.scr.annotations.Modified; ...@@ -34,6 +35,7 @@ import org.apache.felix.scr.annotations.Modified;
34 import org.apache.felix.scr.annotations.Property; 35 import org.apache.felix.scr.annotations.Property;
35 import org.apache.felix.scr.annotations.Reference; 36 import org.apache.felix.scr.annotations.Reference;
36 import org.apache.felix.scr.annotations.ReferenceCardinality; 37 import org.apache.felix.scr.annotations.ReferenceCardinality;
38 +import org.onosproject.mastership.MastershipService;
37 import org.onosproject.net.ConnectPoint; 39 import org.onosproject.net.ConnectPoint;
38 import org.onosproject.net.Device; 40 import org.onosproject.net.Device;
39 import org.onosproject.net.DeviceId; 41 import org.onosproject.net.DeviceId;
...@@ -68,6 +70,9 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -68,6 +70,9 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
68 protected DeviceService deviceService; 70 protected DeviceService deviceService;
69 71
70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
73 + protected MastershipService roleService;
74 +
75 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 protected LinkProviderRegistry providerRegistry; 76 protected LinkProviderRegistry providerRegistry;
72 77
73 private LinkProviderService providerService; 78 private LinkProviderService providerService;
...@@ -98,7 +103,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -98,7 +103,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
98 // For flicker = true, duration between events in msec. 103 // For flicker = true, duration between events in msec.
99 @Property(name = "eventRate", intValue = DEFAULT_RATE, 104 @Property(name = "eventRate", intValue = DEFAULT_RATE,
100 label = "Duration between Link Event") 105 label = "Duration between Link Event")
101 - private int eventRate = 3000; 106 + private int eventRate = DEFAULT_RATE;
102 107
103 public NullLinkProvider() { 108 public NullLinkProvider() {
104 super(new ProviderId("null", "org.onosproject.provider.nil")); 109 super(new ProviderId("null", "org.onosproject.provider.nil"));
...@@ -172,12 +177,16 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -172,12 +177,16 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
172 177
173 @Override 178 @Override
174 public void event(DeviceEvent event) { 179 public void event(DeviceEvent event) {
180 + Device dev = event.subject();
181 + if (!MASTER.equals(roleService.getLocalRole(dev.id()))) {
182 + return;
183 + }
175 switch (event.type()) { 184 switch (event.type()) {
176 case DEVICE_ADDED: 185 case DEVICE_ADDED:
177 - addLink(event.subject()); 186 + addLink(dev);
178 break; 187 break;
179 case DEVICE_REMOVED: 188 case DEVICE_REMOVED:
180 - removeLink(event.subject()); 189 + removeLink(dev);
181 break; 190 break;
182 default: 191 default:
183 break; 192 break;
......