Exposed the newly added port specific portStatistics API via REST
Change-Id: I12a59b950f2d9123afc048e126ad7b457e5d7188
Showing
1 changed file
with
30 additions
and
0 deletions
... | @@ -35,6 +35,7 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -35,6 +35,7 @@ import org.onosproject.net.ConnectPoint; |
35 | import org.onosproject.net.Device; | 35 | import org.onosproject.net.Device; |
36 | import org.onosproject.net.DeviceId; | 36 | import org.onosproject.net.DeviceId; |
37 | import org.onosproject.net.Link; | 37 | import org.onosproject.net.Link; |
38 | +import org.onosproject.net.PortNumber; | ||
38 | import org.onosproject.net.device.DeviceService; | 39 | import org.onosproject.net.device.DeviceService; |
39 | import org.onosproject.net.device.PortStatistics; | 40 | import org.onosproject.net.device.PortStatistics; |
40 | import org.onosproject.net.flow.FlowRuleService; | 41 | import org.onosproject.net.flow.FlowRuleService; |
... | @@ -215,4 +216,33 @@ public class StatisticsWebResource extends AbstractWebResource { | ... | @@ -215,4 +216,33 @@ public class StatisticsWebResource extends AbstractWebResource { |
215 | return ok(root).build(); | 216 | return ok(root).build(); |
216 | } | 217 | } |
217 | 218 | ||
219 | + /** | ||
220 | + * Gets port statistics of a specified device and port. | ||
221 | + * @onos.rsModel StatisticsPorts | ||
222 | + * @param deviceId device ID | ||
223 | + * @param port port | ||
224 | + * @return 200 OK with JSON encoded array of port statistics for the specified port | ||
225 | + */ | ||
226 | + @GET | ||
227 | + @Path("ports/{deviceId}/{port}") | ||
228 | + @Produces(MediaType.APPLICATION_JSON) | ||
229 | + public Response getPortStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId, | ||
230 | + @PathParam("port") String port) { | ||
231 | + final DeviceService service = get(DeviceService.class); | ||
232 | + final PortNumber portNumber = portNumber(port); | ||
233 | + final PortStatistics portStatsEntry = | ||
234 | + service.getStatisticsForPort(DeviceId.deviceId(deviceId), portNumber); | ||
235 | + final ObjectNode root = mapper().createObjectNode(); | ||
236 | + final ArrayNode rootArrayNode = root.putArray("statistics"); | ||
237 | + final ObjectNode deviceStatsNode = mapper().createObjectNode(); | ||
238 | + deviceStatsNode.put("device", deviceId); | ||
239 | + final ArrayNode statisticsNode = deviceStatsNode.putArray("ports"); | ||
240 | + if (portStatsEntry != null) { | ||
241 | + statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this)); | ||
242 | + } | ||
243 | + rootArrayNode.add(deviceStatsNode); | ||
244 | + | ||
245 | + return ok(root).build(); | ||
246 | + } | ||
247 | + | ||
218 | } | 248 | } | ... | ... |
-
Please register or login to post a comment