Showing
2 changed files
with
26 additions
and
2 deletions
| ... | @@ -66,7 +66,7 @@ public class LinksListCommand extends AbstractShellCommand { | ... | @@ -66,7 +66,7 @@ public class LinksListCommand extends AbstractShellCommand { |
| 66 | public static ObjectNode json(ObjectMapper mapper, Link link) { | 66 | public static ObjectNode json(ObjectMapper mapper, Link link) { |
| 67 | ObjectNode result = mapper.createObjectNode(); | 67 | ObjectNode result = mapper.createObjectNode(); |
| 68 | result.set("src", json(mapper, link.src())); | 68 | result.set("src", json(mapper, link.src())); |
| 69 | - result.set("dst", json(mapper, link.src())); | 69 | + result.set("dst", json(mapper, link.dst())); |
| 70 | return result; | 70 | return result; |
| 71 | } | 71 | } |
| 72 | 72 | ... | ... |
| 1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
| 2 | 2 | ||
| 3 | +import com.fasterxml.jackson.databind.JsonNode; | ||
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 5 | +import com.fasterxml.jackson.databind.node.ArrayNode; | ||
| 3 | import org.apache.karaf.shell.commands.Argument; | 6 | import org.apache.karaf.shell.commands.Argument; |
| 4 | import org.apache.karaf.shell.commands.Command; | 7 | import org.apache.karaf.shell.commands.Command; |
| 5 | import org.onlab.onos.net.Link; | 8 | import org.onlab.onos.net.Link; |
| ... | @@ -32,9 +35,30 @@ public class PathListCommand extends TopologyCommand { | ... | @@ -32,9 +35,30 @@ public class PathListCommand extends TopologyCommand { |
| 32 | protected void execute() { | 35 | protected void execute() { |
| 33 | init(); | 36 | init(); |
| 34 | Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst)); | 37 | Set<Path> paths = service.getPaths(topology, deviceId(src), deviceId(dst)); |
| 38 | + if (outputJson()) { | ||
| 39 | + print("%s", json(paths)); | ||
| 40 | + } else { | ||
| 41 | + for (Path path : paths) { | ||
| 42 | + print(pathString(path)); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Produces a JSON array containing the specified paths. | ||
| 49 | + * | ||
| 50 | + * @param paths collection of paths | ||
| 51 | + * @return JSON array | ||
| 52 | + */ | ||
| 53 | + public static JsonNode json(Iterable<Path> paths) { | ||
| 54 | + ObjectMapper mapper = new ObjectMapper(); | ||
| 55 | + ArrayNode result = mapper.createArrayNode(); | ||
| 35 | for (Path path : paths) { | 56 | for (Path path : paths) { |
| 36 | - print(pathString(path)); | 57 | + result.add(LinksListCommand.json(mapper, path) |
| 58 | + .put("cost", path.cost()) | ||
| 59 | + .set("links", LinksListCommand.json(path.links()))); | ||
| 37 | } | 60 | } |
| 61 | + return result; | ||
| 38 | } | 62 | } |
| 39 | 63 | ||
| 40 | /** | 64 | /** | ... | ... |
-
Please register or login to post a comment