Enhancing null providers for use in demos.
Change-Id: I079d19a98fba2312bd4b17d2e275b34f4dee6f19
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/CustomTopologySimulator.java b/providers/null/src/main/java/org/onosproject/provider/nil/CustomTopologySimulator.java
new file mode 100644
index 0000000..016b187
--- /dev/null
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/CustomTopologySimulator.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.provider.nil;
+
+import com.google.common.collect.Maps;
+import org.onlab.packet.MacAddress;
+import org.onlab.packet.VlanId;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+
+import java.util.Map;
+
+import static org.onlab.util.Tools.toHex;
+import static org.onosproject.provider.nil.NullProviders.SCHEME;
+
+/**
+ * Custom topology defined by a concise language.
+ */
+public class CustomTopologySimulator extends TopologySimulator {
+
+ private int nextDeviceId = 0;
+ private int nextHostId = 0;
+
+ private Map<String, DeviceId> nameToId = Maps.newConcurrentMap();
+
+ /**
+ * Returns the next device id.
+ *
+ * @return the next device id
+ */
+ public DeviceId nextDeviceId() {
+ return DeviceId.deviceId(SCHEME + ":" + toHex(++nextDeviceId));
+ }
+
+ /**
+ * Returns the next host id.
+ *
+ * @return the next host id
+ */
+ public HostId nextHostId() {
+ return HostId.hostId(MacAddress.valueOf(nextHostId), VlanId.NONE);
+ }
+
+ /**
+ * Returns the identifier of the device with the specified alias.
+ *
+ * @param name device name
+ * @return device identifier
+ */
+ public DeviceId deviceId(String name) {
+ return nameToId.get(name);
+ }
+
+ /**
+ * Creates simulated device.
+ *
+ * @param id device identifier
+ * @param name device name
+ * @param type device type
+ * @param portCount number of device ports
+ */
+ public void createDevice(DeviceId id, String name, Device.Type type, int portCount) {
+ int chassisId = Integer.parseInt(id.uri().getSchemeSpecificPart());
+ createDevice(id, chassisId, type, portCount);
+ nameToId.put(name, id);
+ }
+
+ @Override
+ protected void createDevices() {
+ }
+
+ @Override
+ protected void createLinks() {
+ }
+
+ @Override
+ protected void createHosts() {
+ }
+}