Java Code Examples for org.onosproject.net.device.DeviceService#getPortDeltaStatistics()

The following examples show how to use org.onosproject.net.device.DeviceService#getPortDeltaStatistics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatisticsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets port delta statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatistics() {
    final DeviceService service = get(DeviceService.class);
    final Iterable<Device> devices = service.getDevices();
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    for (final Device device : devices) {
        final ObjectNode deviceStatsNode = mapper().createObjectNode();
        deviceStatsNode.put("device", device.id().toString());
        final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
        final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(device.id());
        if (portStatsEntries != null) {
            for (final PortStatistics entry : portStatsEntries) {
                statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
            }
        }
        rootArrayNode.add(deviceStatsNode);
    }

    return ok(root).build();
}
 
Example 2
Source File: StatisticsWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Gets port delta statistics of a specified devices.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
    final DeviceService service = get(DeviceService.class);
    final Iterable<PortStatistics> portStatsEntries =
            service.getPortDeltaStatistics(DeviceId.deviceId(deviceId));
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntries != null) {
        for (final PortStatistics entry : portStatsEntries) {
            statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
        }
    }
    rootArrayNode.add(deviceStatsNode);

    return ok(root).build();
}
 
Example 3
Source File: PortViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void populateTable(TableModel tm, ObjectNode payload) {
    String uri = string(payload, "devId");
    boolean nz = bool(payload, NZ);
    boolean delta = bool(payload, DELTA);
    if (!Strings.isNullOrEmpty(uri)) {
        DeviceId deviceId = DeviceId.deviceId(uri);
        DeviceService ds = get(DeviceService.class);
        List<PortStatistics> stats = delta ?
                ds.getPortDeltaStatistics(deviceId) :
                ds.getPortStatistics(deviceId);
        for (PortStatistics stat : stats) {
            populateRow(tm.addRow(), stat);
        }
    }
}
 
Example 4
Source File: VirtualNetworkDeviceManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests querying the port delta statistics of a device by null device identifier.
 */
@Test(expected = NullPointerException.class)
public void testGetPortsDeltaStatisticsByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);

    // test the getPortDeltaStatistics() method using a null device identifier
    deviceService.getPortDeltaStatistics(null);
}