Search in sources :

Example 1 with QueueDescription

use of org.onosproject.net.behaviour.QueueDescription 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 QueueDescription

use of org.onosproject.net.behaviour.QueueDescription 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)

Example 3 with QueueDescription

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

the class DefaultOvsdbClient method bindQueues.

@Override
public void bindQueues(QosId qosId, Map<Long, QueueDescription> queues) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        log.debug("The qos uuid is null");
        return;
    }
    OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
    if (queueRowStore == null) {
        log.debug("The queue uuid is null");
        return;
    }
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosId.name().equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    if (qosRow == null) {
        log.warn("Can't find QoS {}", qosId);
        return;
    }
    Uuid qosUuid = qosRow.uuid();
    Map<Long, Uuid> newQueues = new HashMap<>();
    for (Map.Entry<Long, QueueDescription> entry : queues.entrySet()) {
        Row queueRow = queueTableRows.values().stream().filter(r -> {
            OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
            return entry.getValue().queueId().name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
        }).findFirst().orElse(null);
        if (queueRow != null) {
            newQueues.put(entry.getKey(), queueRow.uuid());
        }
    }
    // update the qos table
    ArrayList<Operation> operations = Lists.newArrayList();
    Condition condition = ConditionUtil.isEqual(UUID, qosUuid);
    Mutation mutation = MutationUtil.insert(QUEUES, newQueues);
    List<Condition> conditions = Collections.singletonList(condition);
    List<Mutation> mutations = Collections.singletonList(mutation);
    operations.add(new Mutate(dbSchema.getTableSchema(QOS), conditions, mutations));
    transactConfig(DATABASENAME, operations);
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) HashMap(java.util.HashMap) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

QueueDescription (org.onosproject.net.behaviour.QueueDescription)3 Map (java.util.Map)2 Bandwidth (org.onlab.util.Bandwidth)2 DeviceId (org.onosproject.net.DeviceId)2 DefaultQueueDescription (org.onosproject.net.behaviour.DefaultQueueDescription)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 HashMap (java.util.HashMap)1 Set (java.util.Set)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors (java.util.stream.Collectors)1 ProcessingException (javax.ws.rs.ProcessingException)1