ONOS-5411: Introduce basic region config.
Change-Id: I3f58e5758d0b350a9e8a03093a1475dbbacfc446
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
new file mode 100644
index 0000000..200b375
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicRegionConfig.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.config.basics;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.region.Region;
+import org.onosproject.net.region.RegionId;
+
+import java.util.List;
+
+/**
+ * Basic configuration for network regions.
+ */
+public final class BasicRegionConfig extends Config<RegionId> {
+
+ private static final String TYPE = "type";
+ private static final String DEVICES = "devices";
+
+ @Override
+ public boolean isValid() {
+ return hasOnlyFields(TYPE, DEVICES);
+ }
+
+ /**
+ * Returns the region type.
+ *
+ * @return the region type
+ */
+ public Region.Type getType() {
+ String t = get(TYPE, null);
+ return t == null ? null : regionTypeFor(t);
+ }
+
+ private Region.Type regionTypeFor(String t) {
+ try {
+ return Region.Type.valueOf(t.toUpperCase());
+ } catch (IllegalArgumentException ignored) {
+ }
+ return null;
+ }
+
+ /**
+ * Returns the identities of the devices in this region.
+ *
+ * @return list of device identifiers
+ */
+ public List<DeviceId> getDevices() {
+ return getList(DEVICES, DeviceId::deviceId);
+ }
+
+ // TODO: implement setters
+}
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/BasicUiTopoLayoutConfig.java b/core/api/src/main/java/org/onosproject/net/config/basics/BasicUiTopoLayoutConfig.java
new file mode 100644
index 0000000..5ba8093
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/BasicUiTopoLayoutConfig.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.config.basics;
+
+import org.onosproject.net.config.Config;
+import org.onosproject.net.region.RegionId;
+import org.onosproject.ui.model.topo.UiTopoLayoutId;
+
+import static org.onosproject.net.region.RegionId.regionId;
+
+/**
+ * Basic configuration for UI topology layouts.
+ */
+public class BasicUiTopoLayoutConfig extends Config<UiTopoLayoutId> {
+
+ private static final String REGION = "region";
+ private static final String PARENT = "parent";
+
+ @Override
+ public boolean isValid() {
+ return hasOnlyFields(REGION, PARENT);
+ }
+
+ /**
+ * Returns the identifier of the backing region. This will be
+ * null if there is no backing region.
+ *
+ * @return backing region identity
+ */
+ public RegionId getRegion() {
+ String r = get(REGION, null);
+ return r == null ? null : regionId(r);
+ }
+
+ /**
+ * Returns the identifier of the parent layout.
+ *
+ * @return layout identifier of parent
+ */
+ public UiTopoLayoutId getParent() {
+ String p = get(PARENT, null);
+ return p == null ? UiTopoLayoutId.DEFAULT_ID : UiTopoLayoutId.layoutId(p);
+ }
+
+ // TODO: implement setters
+}
diff --git a/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java b/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
index da075d4..104dfe5 100644
--- a/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
+++ b/core/api/src/main/java/org/onosproject/net/config/basics/SubjectFactories.java
@@ -22,6 +22,7 @@
import org.onosproject.net.HostId;
import org.onosproject.net.LinkKey;
import org.onosproject.net.config.SubjectFactory;
+import org.onosproject.net.region.RegionId;
import static com.google.common.base.Preconditions.checkArgument;
@@ -37,18 +38,25 @@
// Required for resolving application identifiers
private static CoreService coreService;
+ /**
+ * Application ID subject factory.
+ */
public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY =
new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") {
@Override
public ApplicationId createSubject(String key) {
return coreService.registerApplication(key);
}
+
@Override
public String subjectKey(ApplicationId subject) {
return subject.name();
}
};
+ /**
+ * Device ID subject factory.
+ */
public static final SubjectFactory<DeviceId> DEVICE_SUBJECT_FACTORY =
new SubjectFactory<DeviceId>(DeviceId.class, "devices") {
@Override
@@ -57,18 +65,25 @@
}
};
+ /**
+ * Connect point subject factory.
+ */
public static final SubjectFactory<ConnectPoint> CONNECT_POINT_SUBJECT_FACTORY =
new SubjectFactory<ConnectPoint>(ConnectPoint.class, "ports") {
@Override
public ConnectPoint createSubject(String key) {
return ConnectPoint.deviceConnectPoint(key);
}
+
@Override
public String subjectKey(ConnectPoint subject) {
return key(subject);
}
};
+ /**
+ * Host ID subject factory.
+ */
public static final SubjectFactory<HostId> HOST_SUBJECT_FACTORY =
new SubjectFactory<HostId>(HostId.class, "hosts") {
@Override
@@ -77,6 +92,9 @@
}
};
+ /**
+ * Link key subject factory.
+ */
public static final SubjectFactory<LinkKey> LINK_SUBJECT_FACTORY =
new SubjectFactory<LinkKey>(LinkKey.class, "links") {
@Override
@@ -84,8 +102,9 @@
String[] cps = key.split("-");
checkArgument(cps.length == 2, "Incorrect link key format: %s", key);
return LinkKey.linkKey(ConnectPoint.deviceConnectPoint(cps[0]),
- ConnectPoint.deviceConnectPoint(cps[1]));
+ ConnectPoint.deviceConnectPoint(cps[1]));
}
+
@Override
public String subjectKey(LinkKey subject) {
return key(subject.src()) + "-" + key(subject.dst());
@@ -93,6 +112,17 @@
};
/**
+ * Region ID subject factory.
+ */
+ public static final SubjectFactory<RegionId> REGION_SUBJECT_FACTORY =
+ new SubjectFactory<RegionId>(RegionId.class, "regions") {
+ @Override
+ public RegionId createSubject(String key) {
+ return RegionId.regionId(key);
+ }
+ };
+
+ /**
* Provides reference to the core service, which is required for
* application subject factory.
*
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 3297608..f4ffb02 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
@@ -490,8 +490,12 @@
log.debug("Synthetic link: {}", synthetic);
});
+
synthLinks.clear();
synthLinks.addAll(slinks);
+
+ // TODO : compute and add host-device links to synthLinks...
+
}
private UiSynthLink inferSyntheticLink(UiDeviceLink link) {