ONOS-792 - topology related REST GET APIs
- GET /topology
- GET /topology/clusters
- GET /topology/cluster/{clusterId}
- GET /topology/cluster/{clusterId}/devices
- GET /topology/cluster/{clusterId}/links
- GET /topology/broadcast/{connectPoint}
- GET /topology/infrastructure/{connectPoint}
Change-Id: I2a5053b9e7f8bb7f4e3daa4b82b31376a47578cf
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/CodecManager.java b/web/api/src/main/java/org/onosproject/codec/impl/CodecManager.java
index 10f2b57..d176077 100644
--- a/web/api/src/main/java/org/onosproject/codec/impl/CodecManager.java
+++ b/web/api/src/main/java/org/onosproject/codec/impl/CodecManager.java
@@ -43,6 +43,8 @@
import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.net.topology.Topology;
+import org.onosproject.net.topology.TopologyCluster;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,6 +82,8 @@
registerCodec(Criterion.class, new CriterionCodec());
registerCodec(Ethernet.class, new EthernetCodec());
registerCodec(Constraint.class, new ConstraintCodec());
+ registerCodec(Topology.class, new TopologyCodec());
+ registerCodec(TopologyCluster.class, new TopologyClusterCodec());
log.info("Started");
}
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/TopologyClusterCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/TopologyClusterCodec.java
new file mode 100644
index 0000000..4ab5dcd
--- /dev/null
+++ b/web/api/src/main/java/org/onosproject/codec/impl/TopologyClusterCodec.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 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.codec.impl;
+
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.topology.TopologyCluster;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Topology cluster JSON codec.
+ */
+public class TopologyClusterCodec extends JsonCodec<TopologyCluster> {
+
+ @Override
+ public ObjectNode encode(TopologyCluster cluster, CodecContext context) {
+ checkNotNull(cluster, "Cluster cannot be null");
+
+ return context.mapper().createObjectNode()
+ .put("id", cluster.id().index())
+ .put("deviceCount", cluster.deviceCount())
+ .put("linkCount", cluster.linkCount())
+ .put("root", cluster.root().toString());
+ }
+}
diff --git a/web/api/src/main/java/org/onosproject/codec/impl/TopologyCodec.java b/web/api/src/main/java/org/onosproject/codec/impl/TopologyCodec.java
new file mode 100644
index 0000000..9ea6b0c
--- /dev/null
+++ b/web/api/src/main/java/org/onosproject/codec/impl/TopologyCodec.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 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.codec.impl;
+
+import org.onosproject.codec.CodecContext;
+import org.onosproject.codec.JsonCodec;
+import org.onosproject.net.topology.Topology;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Topology JSON codec.
+ */
+public class TopologyCodec extends JsonCodec<Topology> {
+
+ @Override
+ public ObjectNode encode(Topology topology, CodecContext context) {
+ checkNotNull(topology, "Topology cannot be null");
+
+ return context.mapper().createObjectNode()
+ .put("time", topology.time())
+ .put("devices", topology.deviceCount())
+ .put("links", topology.linkCount())
+ .put("clusters", topology.clusterCount());
+ }
+}