suibin
Committed by Gerrit Code Review

Add clusterID info to Null Device ID so that multiple Null Device Providers can …

…run on different nodes without collision.

Change-Id: I3c834a5f23f4813b9234beed3ae1c0e93e69360e
...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 24 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.onlab.packet.ChassisId; 26 import org.onlab.packet.ChassisId;
27 +import org.onosproject.cluster.ClusterService;
27 import org.onosproject.net.Device; 28 import org.onosproject.net.Device;
28 import org.onosproject.net.DeviceId; 29 import org.onosproject.net.DeviceId;
29 import org.onosproject.net.MastershipRole; 30 import org.onosproject.net.MastershipRole;
...@@ -52,13 +53,16 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -52,13 +53,16 @@ import static org.slf4j.LoggerFactory.getLogger;
52 53
53 /** 54 /**
54 * Provider which advertises fake/nonexistant devices to the core. 55 * Provider which advertises fake/nonexistant devices to the core.
56 + * nodeID is passed as part of the fake device id so that multiple nodes can run simultaneously.
55 * To be used for benchmarking only. 57 * To be used for benchmarking only.
56 */ 58 */
57 @Component(immediate = true) 59 @Component(immediate = true)
58 public class NullDeviceProvider extends AbstractProvider implements DeviceProvider { 60 public class NullDeviceProvider extends AbstractProvider implements DeviceProvider {
59 61
60 private static final Logger log = getLogger(NullDeviceProvider.class); 62 private static final Logger log = getLogger(NullDeviceProvider.class);
61 - private static final String SCHEME = "null"; 63 +
64 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
65 + protected ClusterService clusterService;
62 66
63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 67 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 protected DeviceProviderRegistry providerRegistry; 68 protected DeviceProviderRegistry providerRegistry;
...@@ -69,8 +73,8 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid ...@@ -69,8 +73,8 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
69 namedThreads("null-device-creator")); 73 namedThreads("null-device-creator"));
70 74
71 75
72 -
73 //currently hardcoded. will be made configurable via rest/cli. 76 //currently hardcoded. will be made configurable via rest/cli.
77 + private static final String SCHEME = null;
74 private static final int NUMDEVICES = 10; 78 private static final int NUMDEVICES = 10;
75 private static final int NUMPORTSPERDEVICE = 10; 79 private static final int NUMPORTSPERDEVICE = 10;
76 80
...@@ -156,7 +160,11 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid ...@@ -156,7 +160,11 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
156 private void advertiseDevices() { 160 private void advertiseDevices() {
157 DeviceId did; 161 DeviceId did;
158 ChassisId cid; 162 ChassisId cid;
159 - for (int i = 0; i < NUMDEVICES; i++) { 163 +
164 + // nodeIdHash takes into account for nodeID to avoid collisions when running multi-node providers.
165 + int nodeIdHash = (clusterService.getLocalNode().hashCode() % NUMDEVICES) * NUMDEVICES;
166 +
167 + for (int i = nodeIdHash; i < nodeIdHash + NUMDEVICES; i++) {
160 did = DeviceId.deviceId(String.format("%s:%d", SCHEME, i)); 168 did = DeviceId.deviceId(String.format("%s:%d", SCHEME, i));
161 cid = new ChassisId(i); 169 cid = new ChassisId(i);
162 DeviceDescription desc = 170 DeviceDescription desc =
......