Topo2: Add grid (x,y) option to null-provider devices and hosts (and basic element config).
Change-Id: Ia9eed66bda03174a6986d07fec40eb2a8f7728e3
diff --git a/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullHost.java b/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullHost.java
index 26bca8c..ee4c835 100644
--- a/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullHost.java
+++ b/providers/null/src/main/java/org/onosproject/provider/nil/cli/CreateNullHost.java
@@ -40,6 +40,8 @@
@Command(scope = "onos", name = "null-create-host",
description = "Adds a simulated end-station host to the custom topology simulation")
public class CreateNullHost extends AbstractShellCommand {
+ private static final String GEO = "geo";
+ private static final String GRID = "grid";
@Argument(index = 0, name = "deviceName", description = "Name of device where host is attached",
required = true, multiValued = false)
@@ -49,13 +51,19 @@
required = true, multiValued = false)
String hostIp = null;
- @Argument(index = 2, name = "latitude", description = "Geo latitude",
+ @Argument(index = 2, name = "latOrY",
+ description = "Geo latitude / Grid y-coord",
required = true, multiValued = false)
- Double latitude = null;
+ Double latOrY = null;
- @Argument(index = 3, name = "longitude", description = "Geo longitude",
+ @Argument(index = 3, name = "longOrX",
+ description = "Geo longitude / Grid x-coord",
required = true, multiValued = false)
- Double longitude = null;
+ Double longOrX = null;
+
+ @Argument(index = 4, name = "locType", description = "Location type {geo|grid}",
+ required = false, multiValued = false)
+ String locType = GEO;
@Override
protected void execute() {
@@ -68,14 +76,25 @@
return;
}
+ if (!(GEO.equals(locType) || GRID.equals(locType))) {
+ error("locType must be 'geo' or 'grid'.");
+ return;
+ }
+
CustomTopologySimulator sim = (CustomTopologySimulator) simulator;
DeviceId deviceId = sim.deviceId(deviceName);
HostId id = sim.nextHostId();
HostLocation location = findAvailablePort(deviceId);
BasicHostConfig cfg = cfgService.addConfig(id, BasicHostConfig.class);
- cfg.latitude(latitude)
- .longitude(longitude)
- .apply();
+
+ cfg.locType(locType);
+
+ if (GEO.equals(locType)) {
+ cfg.latitude(latOrY).longitude(longOrX);
+ } else {
+ cfg.gridX(longOrX).gridY(latOrY);
+ }
+ cfg.apply();
sim.createHost(id, location, IpAddress.valueOf(hostIp));
}