Search in sources :

Example 1 with QueueId

use of org.onosproject.net.behaviour.QueueId in project onos by opennetworkinglab.

the class OvsdbQueueConfig method getQueues.

@Override
public Collection<QueueDescription> getQueues() {
    OvsdbClientService ovsdbClient = getOvsdbClient(handler());
    if (ovsdbClient == null) {
        return Collections.emptyList();
    }
    Set<OvsdbQueue> queues = ovsdbClient.getQueues();
    return queues.stream().map(q -> DefaultQueueDescription.builder().queueId(QueueId.queueId(q.externalIds().get(QUEUE_EXTERNAL_ID_KEY))).type(types(q)).dscp(q.dscp().isPresent() ? q.dscp().get().intValue() : null).maxRate(q.otherConfigs().get(MAX_RATE) != null ? Bandwidth.bps(Long.parseLong(q.otherConfigs().get(MAX_RATE))) : Bandwidth.bps(0L)).minRate(q.otherConfigs().get(MIN_RATE) != null ? Bandwidth.bps(Long.parseLong(q.otherConfigs().get(MIN_RATE))) : Bandwidth.bps(0L)).burst(q.otherConfigs().get(BURST) != null ? Long.valueOf(q.otherConfigs().get(BURST)) : 0L).priority(q.otherConfigs().get(PRIORITY) != null ? Long.valueOf(q.otherConfigs().get(PRIORITY)) : 0L).build()).collect(Collectors.toSet());
}
Also used : QUEUE_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE_EXTERNAL_ID_KEY) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) QueueId(org.onosproject.net.behaviour.QueueId) MIN_RATE(org.onosproject.ovsdb.controller.OvsdbConstant.MIN_RATE) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) DefaultQueueDescription(org.onosproject.net.behaviour.DefaultQueueDescription) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) BURST(org.onosproject.ovsdb.controller.OvsdbConstant.BURST) PRIORITY(org.onosproject.ovsdb.controller.OvsdbConstant.PRIORITY) EnumSet(java.util.EnumSet) IpAddress(org.onlab.packet.IpAddress) Logger(org.slf4j.Logger) Bandwidth(org.onlab.util.Bandwidth) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue) DriverHandler(org.onosproject.net.driver.DriverHandler) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Type(org.onosproject.net.behaviour.QueueDescription.Type) MAX_RATE(org.onosproject.ovsdb.controller.OvsdbConstant.MAX_RATE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) QueueConfigBehaviour(org.onosproject.net.behaviour.QueueConfigBehaviour) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue)

Example 2 with QueueId

use of org.onosproject.net.behaviour.QueueId in project onos by opennetworkinglab.

the class ServerQueueConfig method getQueues.

@Override
public Collection<QueueDescription> getQueues() {
    // 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 queue administration
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_NIC_QUEUE_ADMIN, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to get NIC queues 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 queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (objNode == null) {
        log.error("Failed to get NIC queues from device: {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    Collection<QueueDescription> queueDescs = Sets.newHashSet();
    // Fetch NICs' array
    JsonNode nicsNode = objNode.path(PARAM_NICS);
    for (JsonNode nn : nicsNode) {
        ObjectNode nicObjNode = (ObjectNode) nn;
        int nicId = nicObjNode.path(PARAM_ID).asInt();
        JsonNode queuesNode = nicObjNode.path(PARAM_QUEUES);
        // Each NIC has a set of queues
        for (JsonNode qn : queuesNode) {
            ObjectNode queueObjNode = (ObjectNode) qn;
            // Get the attributes of a queue
            int queueIdInt = queueObjNode.path(PARAM_ID).asInt();
            String queueTypeStr = get(qn, PARAM_TYPE);
            long queueRateInt = queueObjNode.path(PARAM_NIC_MAX_RATE).asLong();
            QueueId queueId = QueueId.queueId("nic" + nicId + ":" + queueIdInt);
            EnumSet<Type> queueTypes = getQueueTypesFromString(queueTypeStr);
            Bandwidth queueRate = Bandwidth.mbps(queueRateInt);
            queueDescs.add(DefaultQueueDescription.builder().queueId(queueId).type(queueTypes).maxRate(queueRate).build());
        }
    }
    log.info("[Device {}] NIC queues: {}", deviceId, queueDescs);
    return ImmutableList.copyOf(queueDescs);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) InputStream(java.io.InputStream) QueueId(org.onosproject.net.behaviour.QueueId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultQueueDescription(org.onosproject.net.behaviour.DefaultQueueDescription) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Type(org.onosproject.net.behaviour.QueueDescription.Type) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Bandwidth(org.onlab.util.Bandwidth) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

Bandwidth (org.onlab.util.Bandwidth)2 DeviceId (org.onosproject.net.DeviceId)2 DefaultQueueDescription (org.onosproject.net.behaviour.DefaultQueueDescription)2 QueueDescription (org.onosproject.net.behaviour.QueueDescription)2 Type (org.onosproject.net.behaviour.QueueDescription.Type)2 QueueId (org.onosproject.net.behaviour.QueueId)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ProcessingException (javax.ws.rs.ProcessingException)1 IpAddress (org.onlab.packet.IpAddress)1 QueueConfigBehaviour (org.onosproject.net.behaviour.QueueConfigBehaviour)1