Committed by
Gerrit Code Review
Added back summary mode for routes CLI command
Change-Id: Idc39a1c81d6a597b0c55885e4e93d5b8ead62650
Showing
1 changed file
with
21 additions
and
0 deletions
... | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
20 | import com.fasterxml.jackson.databind.node.ArrayNode; | 20 | import com.fasterxml.jackson.databind.node.ArrayNode; |
21 | import com.fasterxml.jackson.databind.node.ObjectNode; | 21 | import com.fasterxml.jackson.databind.node.ObjectNode; |
22 | import org.apache.karaf.shell.commands.Command; | 22 | import org.apache.karaf.shell.commands.Command; |
23 | +import org.apache.karaf.shell.commands.Option; | ||
23 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
24 | import org.onosproject.incubator.net.routing.Route; | 25 | import org.onosproject.incubator.net.routing.Route; |
25 | import org.onosproject.incubator.net.routing.RouteService; | 26 | import org.onosproject.incubator.net.routing.RouteService; |
... | @@ -35,6 +36,12 @@ import java.util.Map; | ... | @@ -35,6 +36,12 @@ import java.util.Map; |
35 | description = "Lists all routes in the route store") | 36 | description = "Lists all routes in the route store") |
36 | public class RoutesListCommand extends AbstractShellCommand { | 37 | public class RoutesListCommand extends AbstractShellCommand { |
37 | 38 | ||
39 | + @Option(name = "-s", aliases = "--summary", | ||
40 | + description = "Show summary of routes") | ||
41 | + private boolean summary = false; | ||
42 | + | ||
43 | + private static final String FORMAT_SUMMARY = | ||
44 | + "Number of routes in table %s: %s"; | ||
38 | private static final String FORMAT_HEADER = | 45 | private static final String FORMAT_HEADER = |
39 | " Network Next Hop"; | 46 | " Network Next Hop"; |
40 | private static final String FORMAT_ROUTE = | 47 | private static final String FORMAT_ROUTE = |
... | @@ -49,6 +56,20 @@ public class RoutesListCommand extends AbstractShellCommand { | ... | @@ -49,6 +56,20 @@ public class RoutesListCommand extends AbstractShellCommand { |
49 | 56 | ||
50 | Map<RouteTableId, Collection<Route>> allRoutes = service.getAllRoutes(); | 57 | Map<RouteTableId, Collection<Route>> allRoutes = service.getAllRoutes(); |
51 | 58 | ||
59 | + if (summary) { | ||
60 | + if (outputJson()) { | ||
61 | + ObjectMapper mapper = new ObjectMapper(); | ||
62 | + ObjectNode result = mapper.createObjectNode(); | ||
63 | + result.put("totalRoutes4", allRoutes.get(new RouteTableId("ipv4")).size()); | ||
64 | + result.put("totalRoutes6", allRoutes.get(new RouteTableId("ipv6")).size()); | ||
65 | + print("%s", result); | ||
66 | + } else { | ||
67 | + allRoutes.forEach((id, routes) -> print(FORMAT_SUMMARY, id, routes.size())); | ||
68 | + } | ||
69 | + | ||
70 | + return; | ||
71 | + } | ||
72 | + | ||
52 | if (outputJson()) { | 73 | if (outputJson()) { |
53 | ObjectMapper mapper = new ObjectMapper(); | 74 | ObjectMapper mapper = new ObjectMapper(); |
54 | ObjectNode result = mapper.createObjectNode(); | 75 | ObjectNode result = mapper.createObjectNode(); | ... | ... |
-
Please register or login to post a comment