use of org.onosproject.ovsdb.controller.OvsdbQos in project onos by opennetworkinglab.
the class OvsdbQosConfig method addQoS.
@Override
public boolean addQoS(QosDescription qos) {
OvsdbClientService ovsdbClient = getOvsdbClient(handler());
OvsdbQos ovsdbQos = OvsdbQos.builder(qos).build();
return ovsdbClient.createQos(ovsdbQos);
}
use of org.onosproject.ovsdb.controller.OvsdbQos in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createQos.
@Override
public boolean createQos(OvsdbQos ovsdbQos) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Qos qos = (Qos) TableGenerator.createTable(dbSchema, OvsdbTable.QOS);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
if (rowStore == null) {
log.debug("The qos uuid is null");
return false;
}
ArrayList<Operation> operations = Lists.newArrayList();
Set<String> types = Sets.newHashSet();
Map<Long, Uuid> queues = Maps.newHashMap();
types.add(ovsdbQos.qosType());
qos.setOtherConfig(ovsdbQos.otherConfigs());
qos.setExternalIds(ovsdbQos.externalIds());
qos.setType(types);
if (ovsdbQos.qosQueues().isPresent()) {
for (Map.Entry<Long, String> entry : ovsdbQos.qosQueues().get().entrySet()) {
OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
if (queueRowStore != null) {
ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
Row queueRow = queueTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return entry.getValue().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
if (queueRow != null) {
queues.put(entry.getKey(), queueRow.uuid());
}
}
}
qos.setQueues(queues);
}
Insert qosInsert = new Insert(dbSchema.getTableSchema(QOS), QOS, qos.getRow());
operations.add(qosInsert);
try {
transactConfig(DATABASENAME, operations).get();
} catch (InterruptedException | ExecutionException e) {
return false;
}
return true;
}
use of org.onosproject.ovsdb.controller.OvsdbQos in project onos by opennetworkinglab.
the class OvsdbQosConfig method getQoses.
@Override
public Collection<QosDescription> getQoses() {
OvsdbClientService ovsdbClient = getOvsdbClient(handler());
if (ovsdbClient == null) {
return null;
}
Set<OvsdbQos> qoses = ovsdbClient.getQoses();
return qoses.stream().map(qos -> DefaultQosDescription.builder().qosId(QosId.qosId(qos.externalIds().get(QOS_EXTERNAL_ID_KEY))).type(QOS_EGRESS_POLICER.equals(qos.qosType()) ? QosDescription.Type.EGRESS_POLICER : QosDescription.Type.valueOf(qos.qosType().replace(QOS_TYPE_PREFIX, "").toUpperCase())).maxRate(qos.otherConfigs().get(MAX_RATE) != null ? Bandwidth.bps(Long.parseLong(qos.otherConfigs().get(MAX_RATE))) : Bandwidth.bps(0L)).cbs(qos.otherConfigs().get(CBS) != null ? Long.valueOf(qos.otherConfigs().get(CBS)) : null).cir(qos.otherConfigs().get(CIR) != null ? Long.valueOf(qos.otherConfigs().get(CIR)) : null).build()).collect(Collectors.toSet());
}
use of org.onosproject.ovsdb.controller.OvsdbQos in project onos by opennetworkinglab.
the class OvsdbQosConfig method getQos.
@Override
public QosDescription getQos(QosDescription qosDesc) {
OvsdbClientService ovsdbClient = getOvsdbClient(handler());
if (ovsdbClient == null) {
return null;
}
OvsdbQos qos = ovsdbClient.getQos(qosDesc.qosId());
if (qos == null) {
return null;
}
return DefaultQosDescription.builder().qosId(QosId.qosId(qos.externalIds().get(QOS_EXTERNAL_ID_KEY))).type(QOS_EGRESS_POLICER.equals(qos.qosType()) ? QosDescription.Type.EGRESS_POLICER : QosDescription.Type.valueOf(qos.qosType().replace(QOS_TYPE_PREFIX, "").toUpperCase())).maxRate(qos.otherConfigs().get(MAX_RATE) != null ? Bandwidth.bps(Long.parseLong(qos.otherConfigs().get(MAX_RATE))) : Bandwidth.bps(0L)).cbs(qos.otherConfigs().get(CBS) != null ? Long.valueOf(qos.otherConfigs().get(CBS)) : null).cir(qos.otherConfigs().get(CIR) != null ? Long.valueOf(qos.otherConfigs().get(CIR)) : null).build();
}
use of org.onosproject.ovsdb.controller.OvsdbQos in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getQoses.
@Override
public Set<OvsdbQos> getQoses() {
Set<OvsdbQos> ovsdbQoses = new HashSet<>();
OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
if (rowStore == null) {
log.debug("The qos uuid is null");
return ovsdbQoses;
}
ConcurrentMap<String, Row> rows = rowStore.getRowStore();
ovsdbQoses = rows.keySet().stream().map(uuid -> getRow(DATABASENAME, QOS, uuid)).map(this::getOvsdbQos).filter(Objects::nonNull).collect(Collectors.toSet());
return ovsdbQoses;
}
Aggregations