ONOS-4326: Working on topology topo2start processing.
- Added getPeers() to UiTopoLayoutService.
- Fixed wipe-out command to leave the default layout alone.
- Fixed handling of null-region (associated with default layout).
- Added refresh() method to model cache.
- Fixed regions-topo-2 device IDs
Change-Id: Iee49b47ff6702bed9751be7b63392577422d4763
diff --git a/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java b/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java
index 0f2c273..287cc43 100644
--- a/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java
+++ b/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java
@@ -57,6 +57,15 @@
UiTopoLayout getLayout(UiTopoLayoutId layoutId);
/**
+ * Returns the set of peer layouts of the specified layout. That is,
+ * those layouts that share the same parent.
+ *
+ * @param layoutId layout identifier
+ * @return set of peer layouts; empty set if layout has no peers
+ */
+ Set<UiTopoLayout> getPeers(UiTopoLayoutId layoutId);
+
+ /**
* Returns the set of the child layouts of the specified layout.
*
* @param layoutId layout identifier
diff --git a/core/api/src/main/java/org/onosproject/ui/model/topo/UiRegion.java b/core/api/src/main/java/org/onosproject/ui/model/topo/UiRegion.java
index 023300c..c478424 100644
--- a/core/api/src/main/java/org/onosproject/ui/model/topo/UiRegion.java
+++ b/core/api/src/main/java/org/onosproject/ui/model/topo/UiRegion.java
@@ -29,12 +29,27 @@
import java.util.Set;
import static com.google.common.base.MoreObjects.toStringHelper;
+import static org.onosproject.net.region.RegionId.regionId;
/**
* Represents a region.
*/
public class UiRegion extends UiNode {
+ private static final String NULL_NAME = "<null-region>";
+
+ /**
+ * The identifier for the null-region. That is, a container for devices,
+ * hosts, and links for those that belong to no region.
+ */
+ public static final RegionId NULL_ID = regionId(NULL_NAME);
+
+ private static final String[] DEFAULT_LAYER_TAGS = {
+ UiNode.LAYER_OPTICAL,
+ UiNode.LAYER_PACKET,
+ UiNode.LAYER_DEFAULT
+ };
+
// loose bindings to things in this region
private final Set<DeviceId> deviceIds = new HashSet<>();
private final Set<HostId> hostIds = new HashSet<>();
@@ -53,10 +68,12 @@
* @param region backing region
*/
public UiRegion(UiTopology topology, Region region) {
+ // Implementation Note: if region is null, this UiRegion is being used
+ // as a container for devices, hosts, links that belong to no region.
this.topology = topology;
this.region = region;
- // unless told otherwise, we'll use a single, default layer
- layerOrder.add(UiNode.LAYER_DEFAULT);
+
+ setLayerOrder(DEFAULT_LAYER_TAGS);
}
@Override
@@ -83,7 +100,7 @@
* @return region ID
*/
public RegionId id() {
- return region.id();
+ return region == null ? NULL_ID : region.id();
}
@Override
@@ -93,11 +110,12 @@
@Override
public String name() {
- return region.name();
+ return region == null ? NULL_NAME : region.name();
}
/**
- * Returns the region instance backing this UI region.
+ * Returns the region instance backing this UI region. If this instance
+ * represents the "null-region", the value returned will be null.
*
* @return the backing region instance
*/
@@ -132,7 +150,17 @@
* @return region type
*/
public Region.Type type() {
- return region.type();
+ return region == null ? null : region.type();
+ }
+
+
+ /**
+ * Returns the count of devices in this region.
+ *
+ * @return the device count
+ */
+ public int deviceCount() {
+ return deviceIds.size();
}
/**
@@ -195,7 +223,7 @@
* optical layer should be rendered "below" nodes in the packet layer,
* this method should return:
* <pre>
- * [UiNode.LAYER_OPTICAL, UiNode.LAYER_PACKET]
+ * [UiNode.LAYER_OPTICAL, UiNode.LAYER_PACKET, UiNode.LAYER_DEFAULT]
* </pre>
*
* @return layer ordering
diff --git a/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayoutId.java b/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayoutId.java
index 289cacd..3dea4bb 100644
--- a/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayoutId.java
+++ b/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayoutId.java
@@ -23,10 +23,13 @@
*/
public final class UiTopoLayoutId extends Identifier<String> {
+ private static final String DEFAULT_STR = "_default_";
+
/**
* Default topology layout identifier.
*/
- public static final UiTopoLayoutId DEFAULT_ID = UiTopoLayoutId.layoutId("_default_");
+ public static final UiTopoLayoutId DEFAULT_ID =
+ UiTopoLayoutId.layoutId(DEFAULT_STR);
// For serialization
private UiTopoLayoutId() {
@@ -45,4 +48,13 @@
public static UiTopoLayoutId layoutId(String value) {
return new UiTopoLayoutId(value);
}
+
+ /**
+ * Returns true if this is the identifier for the default layout.
+ *
+ * @return true if this is the default layout identifier
+ */
+ public boolean isDefault() {
+ return DEFAULT_STR.equals(identifier);
+ }
}
diff --git a/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopology.java b/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopology.java
index 5ce91da..dd601eb 100644
--- a/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopology.java
+++ b/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopology.java
@@ -61,6 +61,9 @@
private final Map<HostId, UiHost> hostLookup = new HashMap<>();
private final Map<UiLinkId, UiLink> linkLookup = new HashMap<>();
+ // a container for devices, hosts, etc. belonging to no region
+ private final UiRegion nullRegion = new UiRegion(this, null);
+
@Override
public String toString() {
@@ -89,6 +92,8 @@
deviceLookup.clear();
hostLookup.clear();
linkLookup.clear();
+
+ nullRegion.destroy();
}
@@ -145,6 +150,16 @@
}
/**
+ * Returns a reference to the null-region. That is, the container for
+ * devices, hosts, and links that belong to no region.
+ *
+ * @return the null-region
+ */
+ public UiRegion nullRegion() {
+ return nullRegion;
+ }
+
+ /**
* Returns the region with the specified identifier, or null if
* no such region exists.
*
@@ -186,6 +201,15 @@
}
/**
+ * Returns all devices in the model.
+ *
+ * @return all devices
+ */
+ public Set<UiDevice> allDevices() {
+ return new HashSet<>(deviceLookup.values());
+ }
+
+ /**
* Returns the device with the specified identifier, or null if
* no such device exists.
*