Topo2: Add grid (x,y) option to null-provider devices and hosts (and basic element config).

Change-Id: Ia9eed66bda03174a6986d07fec40eb2a8f7728e3
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
index 295995f..65a2783 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicElementConfig.java
@@ -17,8 +17,8 @@
 
 /**
  * Basic configuration for network elements, e.g. devices, hosts. Such elements
- * can have a friendly name, geo-coordinates, logical rack coordinates and
- * an owner entity.
+ * can have a friendly name, geo-coordinates (or grid-coordinates),
+ * logical rack coordinates and an owner entity.
  */
 public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
 
@@ -33,6 +33,11 @@
     public static final String UI_TYPE = "uiType";
 
     /**
+     * Key for location type (geo or grid).
+     */
+    public static final String LOC_TYPE = "locType";
+
+    /**
      * Key for latitude.
      */
     public static final String LATITUDE = "latitude";
@@ -43,6 +48,17 @@
     public static final String LONGITUDE = "longitude";
 
     /**
+     * Key for grid X coordinate.
+     */
+    public static final String GRID_X = "gridx";
+
+    /**
+     * Key for grid Y coordinate.
+     */
+    public static final String GRID_Y = "gridy";
+
+
+    /**
      * Key for rack address.
      */
     protected static final String RACK_ADDRESS = "rackAddress";
@@ -58,6 +74,8 @@
     protected static final double ZERO_THRESHOLD = Double.MIN_VALUE * 2.0;
 
     private static final double DEFAULT_COORD = 0.0;
+    private static final String LOC_TYPE_GEO = "geo";
+    private static final String LOC_TYPE_GRID = "grid";
 
     /**
      * Returns friendly label for the element. If not set, returns the
@@ -101,6 +119,28 @@
         return (BasicElementConfig) setOrClear(UI_TYPE, uiType);
     }
 
+    /**
+     * Returns the location type (geo or grid) for the element in
+     * the Topology View. If not set, returns the default of "geo".
+     *
+     * @return location type (string)
+     */
+    public String locType() {
+        return get(LOC_TYPE, LOC_TYPE_GEO);
+    }
+
+    /**
+     * Sets the location type (geo or grid) for the element in
+     * the Topology View. If null is passsed, it will default to "geo".
+     *
+     * @param locType the UI type; null for default
+     * @return self
+     */
+    public BasicElementConfig locType(String locType) {
+        String lt = LOC_TYPE_GRID.equals(locType) ? LOC_TYPE_GRID : LOC_TYPE_GEO;
+        return (BasicElementConfig) setOrClear(LOC_TYPE, lt);
+    }
+
     private boolean doubleIsZero(double value) {
         return value >= -ZERO_THRESHOLD && value <= ZERO_THRESHOLD;
     }
@@ -156,6 +196,44 @@
     }
 
     /**
+     * Returns element grid x-coordinate.
+     *
+     * @return element x-coordinate
+     */
+    public double gridX() {
+        return get(GRID_X, DEFAULT_COORD);
+    }
+
+    /**
+     * Sets the element grid x-coordinate.
+     *
+     * @param x new x-coordinate; null to clear
+     * @return self
+     */
+    public BasicElementConfig gridX(Double x) {
+        return (BasicElementConfig) setOrClear(GRID_X, x);
+    }
+
+    /**
+     * Returns element grid y-coordinate.
+     *
+     * @return element y-coordinate
+     */
+    public double gridY() {
+        return get(GRID_Y, DEFAULT_COORD);
+    }
+
+    /**
+     * Sets the element grid y-coordinate.
+     *
+     * @param y new y-coordinate; null to clear
+     * @return self
+     */
+    public BasicElementConfig gridY(Double y) {
+        return (BasicElementConfig) setOrClear(GRID_Y, y);
+    }
+
+    /**
      * Returns the element rack address.
      *
      * @return rack address; null if not set