Added support to display paths; s= set source; d = set dest; f = cycle between p…
…aths; a = swap src/dst; esc = clear selections
Showing
1 changed file
with
21 additions
and
17 deletions
| ... | @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
| 4 | import com.fasterxml.jackson.databind.node.ArrayNode; | 4 | import com.fasterxml.jackson.databind.node.ArrayNode; |
| 5 | import com.fasterxml.jackson.databind.node.ObjectNode; | 5 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 6 | import org.onlab.onos.net.ConnectPoint; | 6 | import org.onlab.onos.net.ConnectPoint; |
| 7 | -import org.onlab.onos.net.Device; | ||
| 8 | import org.onlab.onos.net.ElementId; | 7 | import org.onlab.onos.net.ElementId; |
| 9 | import org.onlab.onos.net.Link; | 8 | import org.onlab.onos.net.Link; |
| 9 | +import org.onlab.onos.net.Path; | ||
| 10 | import org.onlab.onos.net.device.DeviceService; | 10 | import org.onlab.onos.net.device.DeviceService; |
| 11 | import org.onlab.onos.net.host.HostService; | 11 | import org.onlab.onos.net.host.HostService; |
| 12 | import org.onlab.onos.net.link.LinkService; | 12 | import org.onlab.onos.net.link.LinkService; |
| ... | @@ -83,7 +83,6 @@ public class TopologyResource extends BaseResource { | ... | @@ -83,7 +83,6 @@ public class TopologyResource extends BaseResource { |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | - | ||
| 87 | /** | 86 | /** |
| 88 | * Returns a JSON array of all paths between the specified hosts. | 87 | * Returns a JSON array of all paths between the specified hosts. |
| 89 | * | 88 | * |
| ... | @@ -97,22 +96,17 @@ public class TopologyResource extends BaseResource { | ... | @@ -97,22 +96,17 @@ public class TopologyResource extends BaseResource { |
| 97 | public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) { | 96 | public Response paths(@PathParam("src") String src, @PathParam("dst") String dst) { |
| 98 | ObjectMapper mapper = new ObjectMapper(); | 97 | ObjectMapper mapper = new ObjectMapper(); |
| 99 | 98 | ||
| 100 | - DeviceService deviceService = get(DeviceService.class); | ||
| 101 | TopologyService topologyService = get(TopologyService.class); | 99 | TopologyService topologyService = get(TopologyService.class); |
| 102 | - Topology topology = topologyService.currentTopology(); | 100 | + Topology topology = topologyService.currentTopology(); |
| 103 | 101 | ||
| 104 | ArrayNode pathsNode = mapper.createArrayNode(); | 102 | ArrayNode pathsNode = mapper.createArrayNode(); |
| 105 | - Device srcDevice = deviceService.getDevice(deviceId(src)); | 103 | + for (Path path : topologyService.getPaths(topology, deviceId(src), deviceId(dst))) { |
| 106 | - Device dstDevice = deviceService.getDevice(deviceId(dst)); | 104 | + pathsNode.add(json(mapper, path)); |
| 107 | - | 105 | + } |
| 108 | -// if (srcDevice != null && dstDevice != null) { | ||
| 109 | -// for (Path path : topologyService.getPaths(topology, srcDevice, dstDevice)) | ||
| 110 | -// pathsNode.add(json(mapper, path)); | ||
| 111 | -// } | ||
| 112 | 106 | ||
| 113 | // Now put the vertexes and edges into a root node and ship them off | 107 | // Now put the vertexes and edges into a root node and ship them off |
| 114 | ObjectNode rootNode = mapper.createObjectNode(); | 108 | ObjectNode rootNode = mapper.createObjectNode(); |
| 115 | - rootNode.put("paths", pathsNode); | 109 | + rootNode.set("paths", pathsNode); |
| 116 | return Response.ok(rootNode.toString()).build(); | 110 | return Response.ok(rootNode.toString()).build(); |
| 117 | } | 111 | } |
| 118 | 112 | ||
| ... | @@ -134,14 +128,11 @@ public class TopologyResource extends BaseResource { | ... | @@ -134,14 +128,11 @@ public class TopologyResource extends BaseResource { |
| 134 | } | 128 | } |
| 135 | 129 | ||
| 136 | 130 | ||
| 137 | - | ||
| 138 | - | ||
| 139 | - | ||
| 140 | // Produces JSON for a graph vertex. | 131 | // Produces JSON for a graph vertex. |
| 141 | private ObjectNode json(ObjectMapper mapper, ElementId id, int group, | 132 | private ObjectNode json(ObjectMapper mapper, ElementId id, int group, |
| 142 | boolean isOnline) { | 133 | boolean isOnline) { |
| 143 | return mapper.createObjectNode() | 134 | return mapper.createObjectNode() |
| 144 | - .put("name", id.uri().getSchemeSpecificPart()) | 135 | + .put("name", id.uri().toString()) |
| 145 | .put("group", group) | 136 | .put("group", group) |
| 146 | .put("online", isOnline); | 137 | .put("online", isOnline); |
| 147 | } | 138 | } |
| ... | @@ -158,6 +149,19 @@ public class TopologyResource extends BaseResource { | ... | @@ -158,6 +149,19 @@ public class TopologyResource extends BaseResource { |
| 158 | .put("source", src).put("target", dst).put("value", count); | 149 | .put("source", src).put("target", dst).put("value", count); |
| 159 | } | 150 | } |
| 160 | 151 | ||
| 152 | + // Produces JSON representation of a network path. | ||
| 153 | + private ArrayNode json(ObjectMapper mapper, Path path) { | ||
| 154 | + ArrayNode pathNode = mapper.createArrayNode(); | ||
| 155 | + for (Link link : path.links()) { | ||
| 156 | + ObjectNode linkNode = mapper.createObjectNode() | ||
| 157 | + .put("src", id(link.src())) | ||
| 158 | + .put("dst", id(link.dst())); | ||
| 159 | + pathNode.add(linkNode); | ||
| 160 | + } | ||
| 161 | + return pathNode; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + | ||
| 161 | // Aggregate link of all links between the same devices regardless of | 165 | // Aggregate link of all links between the same devices regardless of |
| 162 | // their direction. | 166 | // their direction. |
| 163 | private class AggLink { | 167 | private class AggLink { |
| ... | @@ -188,7 +192,7 @@ public class TopologyResource extends BaseResource { | ... | @@ -188,7 +192,7 @@ public class TopologyResource extends BaseResource { |
| 188 | // Returns a formatted string for the element associated with the given | 192 | // Returns a formatted string for the element associated with the given |
| 189 | // connection point. | 193 | // connection point. |
| 190 | private static String id(ConnectPoint cp) { | 194 | private static String id(ConnectPoint cp) { |
| 191 | - return cp.elementId().uri().getSchemeSpecificPart(); | 195 | + return cp.elementId().uri().toString(); |
| 192 | } | 196 | } |
| 193 | 197 | ||
| 194 | } | 198 | } | ... | ... |
-
Please register or login to post a comment