Working on Bay-Area-Region Demo.
- added latitude / longitude parameters to regions, so the icons can be "placed" on a GEO-map
Change-Id: I5cf939f22597d4658ab603459b2b3059ba0db0c9
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 7c2a5b8..295995f 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
@@ -22,20 +22,46 @@
*/
public abstract class BasicElementConfig<S> extends AllowedEntityConfig<S> {
- protected static final String NAME = "name";
- protected static final String UI_TYPE = "uiType";
+ /**
+ * Key for friendly name.
+ */
+ public static final String NAME = "name";
- protected static final String LATITUDE = "latitude";
- protected static final String LONGITUDE = "longitude";
+ /**
+ * Key for UI type (glyph identifier).
+ */
+ public static final String UI_TYPE = "uiType";
+ /**
+ * Key for latitude.
+ */
+ public static final String LATITUDE = "latitude";
+
+ /**
+ * Key for longitude.
+ */
+ public static final String LONGITUDE = "longitude";
+
+ /**
+ * Key for rack address.
+ */
protected static final String RACK_ADDRESS = "rackAddress";
+
+ /**
+ * Key for owner.
+ */
protected static final String OWNER = "owner";
+ /**
+ * Threshold for detecting double value is zero.
+ */
protected static final double ZERO_THRESHOLD = Double.MIN_VALUE * 2.0;
+
private static final double DEFAULT_COORD = 0.0;
/**
- * Returns friendly label for the element.
+ * Returns friendly label for the element. If not set, returns the
+ * element identifier.
*
* @return friendly label or element identifier itself if not set
*/
@@ -55,7 +81,7 @@
/**
* Returns the UI type (glyph image to be used) for the element in
- * the Topology View.
+ * the Topology View. If not set, null is returned.
*
* @return the UI type
*/
@@ -65,7 +91,8 @@
/**
* Sets the UI type (glyph image to be used) for the element in
- * the Topology View.
+ * the Topology View. Setting this to null will indicate that the
+ * default glyph image should be used for the element type.
*
* @param uiType the UI type; null for default
* @return self
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
index 2d15fa5..e27157e 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
@@ -18,7 +18,6 @@
import com.google.common.base.MoreObjects;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.config.Config;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
@@ -28,46 +27,30 @@
/**
* Basic configuration for network regions.
*/
-public final class BasicRegionConfig extends Config<RegionId> {
+public final class BasicRegionConfig extends BasicElementConfig<RegionId> {
- private static final String NAME = "name";
private static final String TYPE = "type";
private static final String DEVICES = "devices";
@Override
public boolean isValid() {
- return hasOnlyFields(NAME, TYPE, DEVICES);
+ return hasOnlyFields(ALLOWED, NAME, LATITUDE, LONGITUDE, UI_TYPE,
+ RACK_ADDRESS, OWNER, TYPE, DEVICES);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
- .add("name", name())
- .add("type", type())
- .add("devices", devices())
+ .add(NAME, name())
+ .add(TYPE, type())
+ .add(UI_TYPE, uiType())
+ .add(LATITUDE, latitude())
+ .add(LONGITUDE, longitude())
+ .add(DEVICES, devices())
.toString();
}
/**
- * Returns the region name.
- *
- * @return the region name
- */
- public String name() {
- return get(NAME, null);
- }
-
- /**
- * Sets the name of this region.
- *
- * @param name name of region, or null to unset
- * @return the config of the region
- */
- public BasicRegionConfig name(String name) {
- return (BasicRegionConfig) setOrClear(NAME, name);
- }
-
- /**
* Returns the region type.
*
* @return the region type
diff --git a/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java b/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java
index 1926a3d..d229e92 100644
--- a/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java
+++ b/core/api/src/main/java/org/onosproject/net/region/DefaultRegion.java
@@ -19,6 +19,8 @@
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.AbstractAnnotated;
+import org.onosproject.net.Annotations;
import java.util.List;
import java.util.Objects;
@@ -27,7 +29,7 @@
/**
* Default implementation of a region.
*/
-public final class DefaultRegion implements Region {
+public final class DefaultRegion extends AbstractAnnotated implements Region {
private final RegionId id;
private final String name;
@@ -40,9 +42,12 @@
* @param id region identifier
* @param name friendly name
* @param type region type
+ * @param annots annotations
* @param masters list of sets of cluster node identifiers; in order of mastership
*/
- public DefaultRegion(RegionId id, String name, Type type, List<Set<NodeId>> masters) {
+ public DefaultRegion(RegionId id, String name, Type type,
+ Annotations annots, List<Set<NodeId>> masters) {
+ super(annots);
this.id = id;
this.name = name;
this.type = type;
diff --git a/core/api/src/main/java/org/onosproject/net/region/Region.java b/core/api/src/main/java/org/onosproject/net/region/Region.java
index afe1805..ed8fff18 100644
--- a/core/api/src/main/java/org/onosproject/net/region/Region.java
+++ b/core/api/src/main/java/org/onosproject/net/region/Region.java
@@ -17,6 +17,7 @@
package org.onosproject.net.region;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotated;
import java.util.List;
import java.util.Set;
@@ -26,7 +27,7 @@
* logical region. Optionally, devices in the region can share the same
* cluster nodes mastership affinities.
*/
-public interface Region {
+public interface Region extends Annotated {
/**
* Coarse representation of the type of the region.
@@ -58,6 +59,11 @@
BUILDING,
/**
+ * Region represents a data center.
+ */
+ DATA_CENTER,
+
+ /**
* Region represents a building floor.
*/
FLOOR,
diff --git a/core/api/src/main/java/org/onosproject/net/region/RegionStore.java b/core/api/src/main/java/org/onosproject/net/region/RegionStore.java
index 49cc378..b8527c7 100644
--- a/core/api/src/main/java/org/onosproject/net/region/RegionStore.java
+++ b/core/api/src/main/java/org/onosproject/net/region/RegionStore.java
@@ -16,6 +16,7 @@
package org.onosproject.net.region;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotations;
import org.onosproject.net.DeviceId;
import org.onosproject.store.Store;
@@ -67,12 +68,13 @@
* @param regionId region identifier
* @param name friendly name
* @param type region type
+ * @param annots annotations
* @param masterNodeIds list of master nodes; null implies empty list
* @return new region descriptor
* @throws IllegalArgumentException if item already exists
*/
Region createRegion(RegionId regionId, String name, Region.Type type,
- List<Set<NodeId>> masterNodeIds);
+ Annotations annots, List<Set<NodeId>> masterNodeIds);
/**
* Updates the specified new region using the supplied data.
@@ -80,12 +82,13 @@
* @param regionId region identifier
* @param name friendly name
* @param type region type
+ * @param annots annotations
* @param masterNodeIds list of master nodes; null implies empty list
* @return new region descriptor
* @throws IllegalArgumentException if item already exists
*/
Region updateRegion(RegionId regionId, String name, Region.Type type,
- List<Set<NodeId>> masterNodeIds);
+ Annotations annots, List<Set<NodeId>> masterNodeIds);
/**
* Removes the specified region using the new set of data.
diff --git a/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java b/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java
index 51c5676..358c4e1 100644
--- a/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java
+++ b/core/api/src/test/java/org/onosproject/net/config/basics/BasicRegionConfigTest.java
@@ -115,7 +115,7 @@
@Test
public void region3Config() {
loadRegion(R3);
- checkRegion(null, null, R3_DEVS);
+ checkRegion(R3, null, R3_DEVS);
}
@Test
@@ -128,8 +128,10 @@
@Test
public void clearName() {
loadRegion(R1);
+ checkRegion(EUROPE, Region.Type.CONTINENT, R1_DEVS);
cfg.name(null);
- checkRegion(null, Region.Type.CONTINENT, R1_DEVS);
+ // if the friendly name is cleared, name() returns the identifier
+ checkRegion(R1, Region.Type.CONTINENT, R1_DEVS);
}
@Test
@@ -150,14 +152,14 @@
public void modifyDevices() {
loadRegion(R3);
cfg.devices(ALT_DEVICES);
- checkRegion(null, null, ALT_DEVICES);
+ checkRegion(R3, null, ALT_DEVICES);
}
@Test
public void clearDevices() {
loadRegion(R3);
cfg.devices(null);
- checkRegion(null, null, null);
+ checkRegion(R3, null, null);
}
diff --git a/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java b/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java
index 392c565..9e85f3f 100644
--- a/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java
+++ b/core/api/src/test/java/org/onosproject/net/region/DefaultRegionTest.java
@@ -21,6 +21,8 @@
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onosproject.cluster.NodeId;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import java.util.Set;
@@ -34,13 +36,16 @@
public class DefaultRegionTest {
private static final RegionId ID1 = RegionId.regionId("r1");
+ private static final Annotations NO_ANNOTS = DefaultAnnotations.EMPTY;
@Test
public void basics() {
- ImmutableList<Set<NodeId>> masters = ImmutableList
- .of(ImmutableSet.of(nodeId("n1"), nodeId("n2")),
- ImmutableSet.of(nodeId("n3"), nodeId("n4")));
- Region r = new DefaultRegion(ID1, "R1", METRO, masters);
+ ImmutableList<Set<NodeId>> masters =
+ ImmutableList.of(
+ ImmutableSet.of(nodeId("n1"), nodeId("n2")),
+ ImmutableSet.of(nodeId("n3"), nodeId("n4"))
+ );
+ Region r = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, masters);
assertEquals("incorrect id", ID1, r.id());
assertEquals("incorrect name", "R1", r.name());
assertEquals("incorrect type", METRO, r.type());
@@ -49,9 +54,9 @@
@Test
public void equality() {
- Region a = new DefaultRegion(ID1, "R1", METRO, null);
- Region b = new DefaultRegion(ID1, "R1", METRO, null);
- Region c = new DefaultRegion(ID1, "R2", METRO, null);
+ Region a = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, null);
+ Region b = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, null);
+ Region c = new DefaultRegion(ID1, "R2", METRO, NO_ANNOTS, null);
new EqualsTester().addEqualityGroup(a, b).addEqualityGroup(c).testEquals();
}
diff --git a/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java b/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java
index b8db969..1c840fa 100644
--- a/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java
+++ b/core/api/src/test/java/org/onosproject/ui/model/topo/UiTopoLayoutTest.java
@@ -17,6 +17,8 @@
package org.onosproject.ui.model.topo;
import org.junit.Test;
+import org.onosproject.net.Annotations;
+import org.onosproject.net.DefaultAnnotations;
import org.onosproject.net.region.DefaultRegion;
import org.onosproject.net.region.Region;
import org.onosproject.net.region.RegionId;
@@ -44,10 +46,11 @@
private static final double DELTA = Double.MIN_VALUE * 2.0;
+ private static final Annotations NO_ANNOTS = DefaultAnnotations.EMPTY;
private static final UiTopoLayoutId OTHER_ID = layoutId("other-id");
private static final RegionId REGION_ID = regionId("some-region");
private static final Region REGION =
- new DefaultRegion(REGION_ID, "Region-1", CAMPUS, null);
+ new DefaultRegion(REGION_ID, "Region-1", CAMPUS, NO_ANNOTS, null);
private static final String GEOMAP = "geo1";
private static final String SPRITE = "spr1";