use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.
the class DefaultOvsdbClient method applyQos.
@Override
public void applyQos(PortNumber portNumber, String qosName) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore portRowStore = getRowStore(DATABASENAME, PORT);
if (portRowStore == null) {
log.debug("The port uuid is null");
return;
}
OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
if (qosRowStore == null) {
log.debug("The qos uuid is null");
return;
}
// Due to Qos Table doesn't have a unique identifier except uuid, unlike
// Bridge or Port Table has a name column,in order to make the api more
// general, put qos name in external_ids column of Qos Table if this qos
// created by onos.
ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
ConcurrentMap<String, Row> portTableRows = portRowStore.getRowStore();
Row qosRow = qosTableRows.values().stream().filter(r -> {
OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
return qosName.equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
}).findFirst().orElse(null);
Row portRow = portTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
if (portRow != null && qosRow != null) {
String qosId = qosRow.uuid().value();
Uuid portUuid = portRow.uuid();
Map<String, Column> columns = new HashMap<>();
Row newPortRow = new Row(PORT, portUuid, columns);
Port newport = new Port(dbSchema, newPortRow);
columns.put(Port.PortColumn.QOS.columnName(), newport.getQosColumn());
newport.setQos(Uuid.uuid(qosId));
updateConfig(PORT, UUID, portUuid.value(), newport.getRow());
}
}
use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema 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.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getMirrorUuid.
@Override
public String getMirrorUuid(String mirrorName) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, MIRROR);
if (rowStore == null) {
log.warn("The mirror uuid is null");
return null;
}
ConcurrentMap<String, Row> mirrorTableRows = rowStore.getRowStore();
if (mirrorTableRows == null) {
log.warn("The mirror uuid is null");
return null;
}
for (String uuid : mirrorTableRows.keySet()) {
Mirror mirror = (Mirror) TableGenerator.getTable(dbSchema, mirrorTableRows.get(uuid), OvsdbTable.MIRROR);
String name = mirror.getName();
if (name.contains(mirrorName)) {
return uuid;
}
}
log.warn("Mirroring not found");
return null;
}
use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getOvsdbQueue.
private OvsdbQueue getOvsdbQueue(Row row) {
DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
Queue queue = (Queue) TableGenerator.getTable(dbSchema, row, OvsdbTable.QUEUE);
if (queue == null) {
return null;
}
OvsdbSet dscpOvsdbSet = ((OvsdbSet) queue.getDscpColumn().data());
Set dscpSet = dscpOvsdbSet.set();
Long dscp = null;
if (dscpSet != null && !dscpSet.isEmpty()) {
dscp = Long.valueOf(dscpSet.toArray()[0].toString());
}
Map<String, String> otherConfigs;
Map<String, String> externalIds;
otherConfigs = ((OvsdbMap) queue.getOtherConfigColumn().data()).map();
externalIds = ((OvsdbMap) queue.getExternalIdsColumn().data()).map();
return OvsdbQueue.builder().dscp(dscp).otherConfigs(otherConfigs).externalIds(externalIds).build();
}
use of org.onosproject.ovsdb.rfc.schema.DatabaseSchema in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getControllers.
private List<Controller> getControllers(Uuid bridgeUuid) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
if (dbSchema == null) {
return null;
}
OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
if (rowStore == null) {
log.debug("There is no bridge table");
return null;
}
Row bridgeRow = rowStore.getRow(bridgeUuid.value());
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
// FIXME remove log
log.warn("type of controller column", bridge.getControllerColumn().data().getClass());
Set<Uuid> controllerUuids = (Set<Uuid>) ((OvsdbSet) bridge.getControllerColumn().data()).set();
OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, CONTROLLER);
if (controllerRowStore == null) {
log.debug("There is no controller table");
return null;
}
List<Controller> ovsdbControllers = new ArrayList<>();
ConcurrentMap<String, Row> controllerTableRows = controllerRowStore.getRowStore();
controllerTableRows.forEach((key, row) -> {
if (!controllerUuids.contains(Uuid.uuid(key))) {
return;
}
Controller controller = (Controller) TableGenerator.getTable(dbSchema, row, OvsdbTable.CONTROLLER);
ovsdbControllers.add(controller);
});
return ovsdbControllers;
}
Aggregations