Implement json cli in PacketProcessors and PacketRequests
Change-Id: Iea833fa2b5ecc9abf65d56f869c8c5f33c4bbb4b
diff --git a/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java
index ced2f5c..2844b5e 100644
--- a/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/PacketProcessorsListCommand.java
@@ -15,11 +15,16 @@
*/
package org.onosproject.cli.net;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.packet.PacketProcessorEntry;
import org.onosproject.net.packet.PacketService;
+import java.util.List;
+
import static org.onosproject.net.packet.PacketProcessor.ADVISOR_MAX;
import static org.onosproject.net.packet.PacketProcessor.DIRECTOR_MAX;
@@ -36,13 +41,27 @@
protected void execute() {
PacketService service = get(PacketService.class);
if (outputJson()) {
- // TODO: implement this
- print("Not implemented.");
+ print("%s", json(service.getProcessors()));
} else {
service.getProcessors().forEach(this::print);
}
}
+ private JsonNode json(List<PacketProcessorEntry> processors) {
+ ObjectMapper mapper = new ObjectMapper();
+ ArrayNode result = mapper.createArrayNode();
+
+ for (PacketProcessorEntry p : processors) {
+ result.add(mapper.createObjectNode()
+ .put("priority", priorityFormat(p.priority()))
+ .put("class", p.processor().getClass().getName())
+ .put("packets", p.invocations())
+ .put("avgNanos", p.averageNanos()));
+ }
+
+ return result;
+ }
+
private void print(PacketProcessorEntry entry) {
print(FMT, priorityFormat(entry.priority()),
entry.processor().getClass().getName(),
diff --git a/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java
index 2bf1feb..2634592 100644
--- a/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/PacketRequestsListCommand.java
@@ -15,11 +15,16 @@
*/
package org.onosproject.cli.net;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.packet.PacketRequest;
import org.onosproject.net.packet.PacketService;
+import java.util.List;
+
/**
* Lists packet requests.
*/
@@ -33,13 +38,27 @@
protected void execute() {
PacketService service = get(PacketService.class);
if (outputJson()) {
- // TODO: implement this
- print("Not implemented.");
+ print("%s", json(service.getRequests()));
} else {
service.getRequests().forEach(this::print);
}
}
+ private JsonNode json(List<PacketRequest> requests) {
+ ObjectMapper mapper = new ObjectMapper();
+ ArrayNode result = mapper.createArrayNode();
+
+ for (PacketRequest r : requests) {
+ result.add(mapper.createObjectNode()
+ .put("nodeId", r.nodeId().toString())
+ .put("appId", r.appId().name())
+ .put("priority", r.priority().toString())
+ .put("criteria", r.selector().criteria().toString()));
+ }
+
+ return result;
+ }
+
private void print(PacketRequest request) {
print(FMT, request.nodeId(), request.appId().name(), request.priority(), request.selector().criteria());
}