Fixed null providers & custom topo simulator to work across stop/starts.

Change-Id: Id8eeca73c8fc021c351d365ef009b3a95562763a
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullControlCommand.java b/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullControlCommand.java
index bfca14e..0b3fbe3 100644
--- a/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullControlCommand.java
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/cli/NullControlCommand.java
@@ -19,7 +19,6 @@
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cfg.ComponentConfigService;
 import org.onosproject.cli.AbstractShellCommand;
-import org.onosproject.provider.nil.CustomTopologySimulator;
 import org.onosproject.provider.nil.NullProviders;
 import org.onosproject.provider.nil.TopologySimulator;
 
@@ -32,38 +31,32 @@
         description = "Starts or stops topology simulation")
 public class NullControlCommand extends AbstractShellCommand {
 
-    private static final String CUSTOM = "custom";
-
     @Argument(index = 0, name = "cmd", description = "Control command: start/stop",
-            required = true, multiValued = false)
+            required = true)
     String cmd = null;
 
     @Argument(index = 1, name = "topoShape",
             description = "Topology shape: e.g. configured, linear, reroute, " +
-                    "centipede, tree, spineleaf, mesh, fattree, custom",
-            required = false, multiValued = false)
+                    "centipede, tree, spineleaf, mesh, fattree, custom")
     String topoShape = null;
 
     @Override
     protected void execute() {
         ComponentConfigService service = get(ComponentConfigService.class);
+        // If there is an existing topology; make sure it's stopped before restarting
+        if (cmd.equals(START)) {
+            NullProviders npService = get(NullProviders.class);
+            TopologySimulator simulator = npService.currentSimulator();
+            if (simulator != null) {
+                simulator.tearDownTopology();
+            }
+        }
+
         if (topoShape != null) {
             service.setProperty(NullProviders.class.getName(), "topoShape", topoShape);
         }
         service.setProperty(NullProviders.class.getName(), "enabled",
                             cmd.equals(START) ? "true" : "false");
-
-        // If we are re-starting the "custom" topology, reset the counts
-        //  on the auto-assigned IDs for null-devices and null-hosts, so that
-        //  scripts can rely on consistent assignment of IDs to nodes.
-        if (CUSTOM.equals(topoShape) && START.equals(cmd)) {
-            NullProviders npService = get(NullProviders.class);
-            TopologySimulator simulator = npService.currentSimulator();
-            if (simulator instanceof CustomTopologySimulator) {
-                CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
-                sim.resetIdSeeds();
-            }
-        }
     }
 
 }