Add clusterID info to Null Device ID so that multiple Null Device Providers can run on different nodes without collision.
Change-Id: I3c834a5f23f4813b9234beed3ae1c0e93e69360e
diff --git a/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java b/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
index fb18f7b..b9e50ba 100644
--- a/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
+++ b/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
@@ -24,6 +24,7 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.ChassisId;
+import org.onosproject.cluster.ClusterService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
@@ -52,13 +53,16 @@
/**
* Provider which advertises fake/nonexistant devices to the core.
+ * nodeID is passed as part of the fake device id so that multiple nodes can run simultaneously.
* To be used for benchmarking only.
*/
@Component(immediate = true)
public class NullDeviceProvider extends AbstractProvider implements DeviceProvider {
private static final Logger log = getLogger(NullDeviceProvider.class);
- private static final String SCHEME = "null";
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry providerRegistry;
@@ -69,8 +73,8 @@
namedThreads("null-device-creator"));
-
//currently hardcoded. will be made configurable via rest/cli.
+ private static final String SCHEME = null;
private static final int NUMDEVICES = 10;
private static final int NUMPORTSPERDEVICE = 10;
@@ -156,7 +160,11 @@
private void advertiseDevices() {
DeviceId did;
ChassisId cid;
- for (int i = 0; i < NUMDEVICES; i++) {
+
+ // nodeIdHash takes into account for nodeID to avoid collisions when running multi-node providers.
+ int nodeIdHash = (clusterService.getLocalNode().hashCode() % NUMDEVICES) * NUMDEVICES;
+
+ for (int i = nodeIdHash; i < nodeIdHash + NUMDEVICES; i++) {
did = DeviceId.deviceId(String.format("%s:%d", SCHEME, i));
cid = new ChassisId(i);
DeviceDescription desc =