use of org.onosproject.ovsdb.rfc.notation.Uuid 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.rfc.notation.Uuid 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.notation.Uuid 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.rfc.notation.Uuid in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getMirroringStatistics.
@Override
public Set<MirroringStatistics> getMirroringStatistics(DeviceId deviceId) {
Uuid bridgeUuid = getBridgeUuid(deviceId);
if (bridgeUuid == null) {
log.warn("Couldn't find bridge {} in {}", deviceId, nodeId.getIpAddress());
return null;
}
List<MirroringStatistics> mirrorings = getMirrorings(bridgeUuid);
if (mirrorings == null) {
log.warn("Couldn't find mirrors in {}", nodeId.getIpAddress());
return null;
}
return ImmutableSet.copyOf(mirrorings);
}
use of org.onosproject.ovsdb.rfc.notation.Uuid in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getPortError.
@Override
public boolean getPortError(List<OvsdbPortName> portNames, DeviceId bridgeId) {
Uuid bridgeUuid = getBridgeUuid(bridgeId);
List<Interface> interfaceList = portNames.stream().collect(Collectors.toMap(java.util.function.Function.identity(), port -> (Interface) getInterfacebyPort(getPortUuid(port.value(), bridgeUuid.value()), port.value()))).entrySet().stream().filter(intf -> Objects.nonNull(intf.getValue()) && ((OvsdbSet) intf.getValue().getOpenFlowPortColumn().data()).set().stream().findAny().orElse(OFPORT_ERROR_COMPARISON).equals(OFPORT_ERROR)).map(Map.Entry::getValue).collect(Collectors.toList());
interfaceList.forEach(intf -> ((Consumer<Interface>) intf1 -> {
try {
Set<String> setErrors = ((OvsdbSet) intf1.getErrorColumn().data()).set();
log.info("Port has errors. ofport value - {}, Interface - {} has error - {} ", intf1.getOpenFlowPortColumn().data(), intf1.getName(), setErrors.stream().findFirst().get());
} catch (ColumnSchemaNotFoundException | VersionMismatchException e) {
log.debug("Port has errors. ofport value - {}, Interface - {} has error - {} ", intf1.getOpenFlowPortColumn().data(), intf1.getName(), e);
}
}).accept(intf));
return !interfaceList.isEmpty();
}
Aggregations