Implement REST APIs for link flow statistics
Change-Id: I65ca3cec9dd1771a70811afd319619827f7b9010
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
index 4b8c474..eb53152 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/CodecManager.java
@@ -47,6 +47,7 @@
import org.onosproject.net.intent.HostToHostIntent;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.PointToPointIntent;
+import org.onosproject.net.statistic.Load;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyCluster;
import org.slf4j.Logger;
@@ -97,6 +98,7 @@
registerCodec(Group.class, new GroupCodec());
registerCodec(Driver.class, new DriverCodec());
registerCodec(GroupBucket.class, new GroupBucketCodec());
+ registerCodec(Load.class, new LoadCodec());
log.info("Started");
}
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/LoadCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/LoadCodec.java
new file mode 100644
index 0000000..0e55592
--- /dev/null
+++ b/core/common/src/main/java/org/onosproject/codec/impl/LoadCodec.java
@@ -0,0 +1,45 @@
+/*
+ * 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.statistic.Load;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Codec for the Load class.
+ */
+public class LoadCodec extends JsonCodec<Load> {
+
+ private static final String RATE = "rate";
+ private static final String LATEST = "latest";
+ private static final String VALID = "valid";
+ private static final String TIME = "time";
+
+ @Override
+ public ObjectNode encode(Load load, CodecContext context) {
+ checkNotNull(load, "Load cannot be null");
+ return context.mapper().createObjectNode()
+ .put(RATE, load.rate())
+ .put(LATEST, load.latest())
+ .put(VALID, load.isValid())
+ .put(TIME, load.time());
+ }
+}