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());
}
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);
}
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);
}
Aggregations