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

The following examples show how to use org.onosproject.net.device.DeviceService#getPortStatistics() . 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 statistics of all devices.
 * @onos.rsModel StatisticsPorts
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatistics() {
    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.getPortStatistics(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 statistics of a specified devices.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
    final DeviceService service = get(DeviceService.class);
    final Iterable<PortStatistics> portStatsEntries =
            service.getPortStatistics(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 statistics of a device by null device identifier.
 */
@Test(expected = NullPointerException.class)
public void testGetPortsStatisticsByNullId() {
    manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
    VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
    DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);

    // test the getPortStatistics() method using a null device identifier
    deviceService.getPortStatistics(null);
}
 
Example 5
Source File: OFSwitchManager.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public List<PortStatistics> getPortStatistics(NetworkId networkId, DeviceId deviceId) {
    DeviceService deviceService = virtualNetService.get(networkId, DeviceService.class);
    List<PortStatistics> portStatistics = deviceService.getPortStatistics(deviceId);
    return portStatistics;
}