use of org.onosproject.ovsdb.controller.OvsdbRowStore in project onos by opennetworkinglab.
the class DefaultOvsdbClient method setControllersWithUuid.
private void setControllersWithUuid(Uuid bridgeUuid, List<ControllerInfo> controllers) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
if (dbSchema == null) {
log.debug("There is no schema");
return;
}
List<Controller> oldControllers = getControllers(bridgeUuid);
if (oldControllers == null) {
log.warn("There are no controllers");
return;
}
Set<ControllerInfo> newControllers = new HashSet<>(controllers);
List<Controller> removeControllers = new ArrayList<>();
oldControllers.forEach(controller -> {
ControllerInfo controllerInfo = new ControllerInfo((String) controller.getTargetColumn().data());
if (newControllers.contains(controllerInfo)) {
newControllers.remove(controllerInfo);
} else {
removeControllers.add(controller);
}
});
OvsdbRowStore controllerRowStore = getRowStore(DATABASENAME, CONTROLLER);
if (controllerRowStore == null) {
log.debug("There is no controller table");
return;
}
newControllers.stream().map(c -> {
Controller controller = (Controller) TableGenerator.createTable(dbSchema, OvsdbTable.CONTROLLER);
controller.setTarget(c.target());
return controller;
}).forEach(c -> insertConfig(CONTROLLER, UUID, BRIDGE, BRIDGE_CONTROLLER, bridgeUuid.value(), c.getRow()));
// Controller removal is extremely dangerous operation, because with
// empty controller list, all existing flow rules will be wiped out.
// To harden the setController operation, we need to double check whether
// the updated controller list size is bigger than the remove controller list size
List<Controller> updatedControllers = getControllers(bridgeUuid);
if (updatedControllers != null && updatedControllers.size() > removeControllers.size()) {
removeControllers.forEach(c -> deleteConfig(CONTROLLER, UUID, c.getRow().uuid().value(), BRIDGE, BRIDGE_CONTROLLER, c.getRow().uuid()));
} else {
log.warn("New controllers were not properly configured to OVS " + "bridge {} or failed to retrieve controller list from OVS " + "bridge {}", bridgeUuid, bridgeUuid);
}
}
use of org.onosproject.ovsdb.controller.OvsdbRowStore 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.OvsdbRowStore 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);
}
use of org.onosproject.ovsdb.controller.OvsdbRowStore in project onos by opennetworkinglab.
the class DefaultOvsdbClient method removeQos.
@Override
public void removeQos(PortNumber portNumber) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, PORT);
if (rowStore == null) {
log.debug("The qos uuid is null");
return;
}
ConcurrentMap<String, Row> ovsTableRows = rowStore.getRowStore();
Row portRow = ovsTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
if (portRow == null) {
log.warn("Couldn't find port {} in ovsdb port table.", portNumber.name());
return;
}
OvsdbSet ovsdbSet = ((OvsdbSet) portRow.getColumn(PORT_QOS).data());
@SuppressWarnings("unchecked") Set<Uuid> qosIdSet = ovsdbSet.set();
if (qosIdSet == null || qosIdSet.isEmpty()) {
return;
}
Uuid qosUuid = (Uuid) qosIdSet.toArray()[0];
Condition condition = ConditionUtil.isEqual(UUID, portRow.uuid());
List<Condition> conditions = Lists.newArrayList(condition);
Mutation mutation = MutationUtil.delete(PORT_QOS, qosUuid);
List<Mutation> mutations = Lists.newArrayList(mutation);
ArrayList<Operation> operations = Lists.newArrayList();
Mutate mutate = new Mutate(dbSchema.getTableSchema(PORT), conditions, mutations);
operations.add(mutate);
transactConfig(DATABASENAME, operations);
}
use of org.onosproject.ovsdb.controller.OvsdbRowStore in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getBridgeUuid.
@Override
public String getBridgeUuid(String bridgeName) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
if (rowStore == null) {
log.debug("The bridge uuid is null");
return null;
}
ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
if (bridgeTableRows == null) {
log.debug("The bridge uuid is null");
return null;
}
for (String uuid : bridgeTableRows.keySet()) {
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeTableRows.get(uuid), OvsdbTable.BRIDGE);
if (bridge.getName().equals(bridgeName)) {
return uuid;
}
}
return null;
}
Aggregations