Search in sources :

Example 6 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class ServerTableStatisticsDiscovery method getTableStatistics.

@Override
public List<TableStatisticsEntry> getTableStatistics() {
    // Retrieve the device ID from the handler
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // Get the device
    RestSBDevice device = super.getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides the server's NIC table statistics
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_RULE_TABLE_STATS, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get NIC table statistics from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // Load the JSON into object
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to get NIC table statistics from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (jsonNode == null) {
        log.error("Failed to get NIC table statistics from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    List<TableStatisticsEntry> tableStats = Lists.newArrayList();
    JsonNode nicNode = objNode.path(PARAM_NICS);
    for (JsonNode nn : nicNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        // The index of the NIC that hosts rules table(s)
        long nicIndex = nicObjNode.path(Constants.PARAM_ID).asLong();
        JsonNode tableNode = nicObjNode.path(PARAM_NIC_TABLE);
        if (tableNode == null) {
            throw new IllegalArgumentException("No tables reported for NIC " + nicIndex);
        }
        for (JsonNode tn : tableNode) {
            ObjectNode tableObjNode = (ObjectNode) tn;
            // NIC table attributes
            int tableIndex = tableObjNode.path(PARAM_ID).asInt();
            checkArgument(tableIndex >= 0, MSG_NIC_TABLE_INDEX_NEGATIVE);
            long tableActiveEntries = tableObjNode.path(PARAM_NIC_TABLE_ACTIVE_ENTRIES).asLong();
            checkArgument(tableActiveEntries >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
            long tablePktsLookedUp = tableObjNode.path(PARAM_NIC_TABLE_PKTS_LOOKED_UP).asLong();
            checkArgument(tablePktsLookedUp >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
            long tablePktsMatched = tableObjNode.path(PARAM_NIC_TABLE_PKTS_MATCHED).asLong();
            checkArgument(tablePktsMatched >= 0, MSG_NIC_TABLE_COUNTER_NEGATIVE);
            long tableMaxsize = tableObjNode.path(PARAM_NIC_TABLE_MAX_SIZE).asLong();
            checkArgument(tableMaxsize >= 0, MSG_NIC_TABLE_SIZE_NEGATIVE);
            // Server's device ID and NIC ID compose a NIC device ID
            DeviceId nicDeviceId = DeviceId.deviceId(deviceId.toString() + ":nic" + String.valueOf(nicIndex));
            TableStatisticsEntry tableStat = DefaultTableStatisticsEntry.builder().withDeviceId(nicDeviceId).withTableId(IndexTableId.of(tableIndex)).withActiveFlowEntries(tableActiveEntries).withPacketsLookedUpCount(tablePktsLookedUp).withPacketsMatchedCount(tablePktsMatched).withMaxSize(tableMaxsize > 0 ? tableMaxsize : -1).build();
            tableStats.add(tableStat);
            log.debug("[Device {}] NIC {} with table statistics: {}", deviceId, nicIndex, tableStat);
        }
    }
    return ImmutableList.copyOf(tableStats);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultTableStatisticsEntry(org.onosproject.net.flow.DefaultTableStatisticsEntry) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 7 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class RestDeviceProvider method roleChanged.

@Override
public void roleChanged(DeviceId deviceId, MastershipRole newRole) {
    log.debug("Received role {} request for device {}", newRole, deviceId);
    RestSBDevice device = controller.getDevice(deviceId);
    if (device != null && testDeviceConnection(device)) {
        providerService.receivedRoleReply(deviceId, newRole, newRole);
    } else {
        log.warn("Device not present or available {}", deviceId);
        providerService.receivedRoleReply(deviceId, newRole, MastershipRole.NONE);
    }
}
Also used : RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice)

Example 8 with RestSBDevice

use of org.onosproject.protocol.rest.RestSBDevice in project onos by opennetworkinglab.

the class RestDeviceProvider method getDesc.

private DeviceDescription getDesc(RestSBDevice restSBDev) {
    DeviceId deviceId = restSBDev.deviceId();
    Driver driver = getDriver(restSBDev);
    if (restSBDev.isProxy()) {
        if (driver != null && driver.hasBehaviour(DevicesDiscovery.class)) {
            // Creates the driver to communicate with the server
            DevicesDiscovery devicesDiscovery = devicesDiscovery(restSBDev, driver);
            return devicesDiscovery.deviceDetails(deviceId);
        } else {
            log.warn("Driver not found for {}", restSBDev);
            return null;
        }
    } else if (driver != null && driver.hasBehaviour(DeviceDescriptionDiscovery.class)) {
        DriverHandler h = driverService.createHandler(deviceId);
        DeviceDescriptionDiscovery deviceDiscovery = h.behaviour(DeviceDescriptionDiscovery.class);
        return deviceDiscovery.discoverDeviceDetails();
    }
    ChassisId cid = new ChassisId();
    String ipAddress = restSBDev.ip().toString();
    SparseAnnotations annotations = DefaultAnnotations.builder().set(IPADDRESS, ipAddress).set(AnnotationKeys.PROTOCOL, REST.toUpperCase()).build();
    String manufacturer = UNKNOWN;
    String hwVersion = UNKNOWN;
    String swVersion = UNKNOWN;
    String serialNumber = UNKNOWN;
    Device device = deviceService.getDevice(deviceId);
    if (device != null) {
        manufacturer = device.manufacturer();
        hwVersion = device.hwVersion();
        swVersion = device.swVersion();
        serialNumber = device.serialNumber();
    }
    return new DefaultDeviceDescription(deviceId.uri(), Device.Type.SWITCH, manufacturer, hwVersion, swVersion, serialNumber, cid, annotations);
}
Also used : SparseAnnotations(org.onosproject.net.SparseAnnotations) ChassisId(org.onlab.packet.ChassisId) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DeviceId(org.onosproject.net.DeviceId) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) DefaultRestSBDevice(org.onosproject.protocol.rest.DefaultRestSBDevice) Device(org.onosproject.net.Device) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DriverHandler(org.onosproject.net.driver.DriverHandler) Driver(org.onosproject.net.driver.Driver) DevicesDiscovery(org.onosproject.net.behaviour.DevicesDiscovery)

Aggregations

RestSBDevice (org.onosproject.protocol.rest.RestSBDevice)8 DeviceId (org.onosproject.net.DeviceId)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 Map (java.util.Map)4 ProcessingException (javax.ws.rs.ProcessingException)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ChassisId (org.onlab.packet.ChassisId)2 DefaultRestSBDevice (org.onosproject.protocol.rest.DefaultRestSBDevice)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Bandwidth (org.onlab.util.Bandwidth)1 RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)1 ServerDeviceDescription (org.onosproject.drivers.server.devices.ServerDeviceDescription)1 CpuCacheHierarchyDevice (org.onosproject.drivers.server.devices.cpu.CpuCacheHierarchyDevice)1 CpuDevice (org.onosproject.drivers.server.devices.cpu.CpuDevice)1 MemoryHierarchyDevice (org.onosproject.drivers.server.devices.memory.MemoryHierarchyDevice)1 NicDevice (org.onosproject.drivers.server.devices.nic.NicDevice)1