Search in sources :

Example 6 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerInterfaceConfig method getInterfaces.

@Override
public List<DeviceInterfaceDescription> getInterfaces() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and the device itself
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to get interfaces for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for interface discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No interfaces available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<DeviceInterfaceDescription> intfDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        List<VlanId> devVlanIds = getVlanIdListForDevice(nic);
        Mode devMode = getDeviceMode(devVlanIds);
        // Create an interface description and add it to the list
        intfDescriptions.add(new DefaultDeviceInterfaceDescription(nic.name(), devMode, devVlanIds, RATE_LIMIT_STATUS, NO_LIMIT));
    }
    return ImmutableList.copyOf(intfDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) DeviceInterfaceDescription(org.onosproject.net.device.DeviceInterfaceDescription) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) Mode(org.onosproject.net.device.DeviceInterfaceDescription.Mode) DefaultDeviceInterfaceDescription(org.onosproject.net.device.DefaultDeviceInterfaceDescription) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) VlanId(org.onlab.packet.VlanId)

Example 7 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerPortAdmin method isEnabled.

@Override
public CompletableFuture<Boolean> isEnabled(PortNumber number) {
    // Retrieve the device ID
    DeviceId deviceId = super.getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // ...and the device itself
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to discover ports for device {}", deviceId);
        return completedFuture(false);
    }
    // Iterate server's NICs to find the correct port
    for (NicDevice nic : device.nics()) {
        if (nic.portNumber() == number.toLong()) {
            return completedFuture(nic.status());
        }
    }
    return completedFuture(false);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DeviceId(org.onosproject.net.DeviceId) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice)

Example 8 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method parseNicStatistics.

/**
 * Parse the input JSON object, looking for NIC-related
 * statistics. Upon success, construct and return a list
 * of NIC statistics objects.
 *
 * @param deviceId the device ID that sent the JSON object
 * @param objNode input JSON node with NIC statistics information
 * @return list of (per port) PortStatistics
 */
private Collection<PortStatistics> parseNicStatistics(DeviceId deviceId, JsonNode objNode) {
    if ((deviceId == null) || (objNode == null)) {
        return Collections.EMPTY_LIST;
    }
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        return Collections.EMPTY_LIST;
    }
    Collection<PortStatistics> nicStats = Lists.newArrayList();
    JsonNode nicNode = objNode.path(PARAM_NICS);
    if (nicNode.isMissingNode()) {
        return nicStats;
    }
    for (JsonNode nn : nicNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        // All the NIC attributes
        String nicName = get(nn, PARAM_NAME);
        checkArgument(!Strings.isNullOrEmpty(nicName), MSG_NIC_NAME_NULL);
        long portNumber = device.portNumberFromName(nicName);
        checkArgument(portNumber >= 0, MSG_NIC_PORT_NUMBER_NEGATIVE);
        long rxCount = nicObjNode.path(PARAM_NIC_STATS_RX_COUNT).asLong();
        long rxBytes = nicObjNode.path(PARAM_NIC_STATS_RX_BYTES).asLong();
        long rxDropped = nicObjNode.path(PARAM_NIC_STATS_RX_DROPS).asLong();
        long rxErrors = nicObjNode.path(PARAM_NIC_STATS_RX_ERRORS).asLong();
        long txCount = nicObjNode.path(PARAM_NIC_STATS_TX_COUNT).asLong();
        long txBytes = nicObjNode.path(PARAM_NIC_STATS_TX_BYTES).asLong();
        long txDropped = nicObjNode.path(PARAM_NIC_STATS_TX_DROPS).asLong();
        long txErrors = nicObjNode.path(PARAM_NIC_STATS_TX_ERRORS).asLong();
        // Construct a NIC statistics object and add it to the set
        nicStats.add(DefaultPortStatistics.builder().setDeviceId(deviceId).setPort(PortNumber.portNumber(portNumber)).setPacketsReceived(rxCount).setPacketsSent(txCount).setBytesReceived(rxBytes).setBytesSent(txBytes).setPacketsRxDropped(rxDropped).setPacketsRxErrors(rxErrors).setPacketsTxDropped(txDropped).setPacketsTxErrors(txErrors).build());
    }
    return nicStats;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics)

Aggregations

RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)8 DefaultRestServerSBDevice (org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NicDevice (org.onosproject.drivers.server.devices.nic.NicDevice)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3 ProcessingException (javax.ws.rs.ProcessingException)3 DeviceId (org.onosproject.net.DeviceId)3 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)3 PortStatistics (org.onosproject.net.device.PortStatistics)3 TreeSet (java.util.TreeSet)2 DefaultNicDevice (org.onosproject.drivers.server.impl.devices.DefaultNicDevice)2 DefaultCpuStatistics (org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics)2 DefaultMemoryStatistics (org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics)2 DefaultMonitoringStatistics (org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics)2 DefaultTimingStatistics (org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics)2 CpuStatistics (org.onosproject.drivers.server.stats.CpuStatistics)2