use of org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE 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.OvsdbConstant.BRIDGE in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createMirror.
@Override
public boolean createMirror(String bridgeName, OvsdbMirror mirror) {
/**
* Retrieves bridge's uuid. It is necessary to update
* Bridge table.
*/
String bridgeUuid = getBridgeUuid(bridgeName);
if (bridgeUuid == null) {
log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
return false;
}
OvsdbMirror.Builder mirrorBuilder = OvsdbMirror.builder();
mirrorBuilder.mirroringName(mirror.mirroringName());
mirrorBuilder.selectAll(mirror.selectAll());
/**
* Retrieves the uuid of the monitored dst ports.
*/
mirrorBuilder.monitorDstPorts(mirror.monitorDstPorts().parallelStream().map(dstPort -> {
String dstPortUuid = getPortUuid(dstPort.value(), bridgeUuid);
if (dstPortUuid != null) {
return Uuid.uuid(dstPortUuid);
}
log.warn("Couldn't find port {} in {}", dstPort.value(), nodeId.getIpAddress());
return null;
}).filter(Objects::nonNull).collect(Collectors.toSet()));
/**
* Retrieves the uuid of the monitored src ports.
*/
mirrorBuilder.monitorSrcPorts(mirror.monitorSrcPorts().parallelStream().map(srcPort -> {
String srcPortUuid = getPortUuid(srcPort.value(), bridgeUuid);
if (srcPortUuid != null) {
return Uuid.uuid(srcPortUuid);
}
log.warn("Couldn't find port {} in {}", srcPort.value(), nodeId.getIpAddress());
return null;
}).filter(Objects::nonNull).collect(Collectors.toSet()));
mirrorBuilder.monitorVlans(mirror.monitorVlans());
mirrorBuilder.mirrorPort(mirror.mirrorPort());
mirrorBuilder.mirrorVlan(mirror.mirrorVlan());
mirrorBuilder.externalIds(mirror.externalIds());
mirror = mirrorBuilder.build();
if (mirror.monitorDstPorts().isEmpty() && mirror.monitorSrcPorts().isEmpty() && mirror.monitorVlans().isEmpty()) {
log.warn("Invalid monitoring data");
return false;
}
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Mirror mirrorEntry = (Mirror) TableGenerator.createTable(dbSchema, OvsdbTable.MIRROR);
mirrorEntry.setName(mirror.mirroringName());
mirrorEntry.setSelectDstPort(mirror.monitorDstPorts());
mirrorEntry.setSelectSrcPort(mirror.monitorSrcPorts());
mirrorEntry.setSelectVlan(mirror.monitorVlans());
mirrorEntry.setExternalIds(mirror.externalIds());
/**
* If mirror port, retrieves the uuid of the mirror port.
*/
if (mirror.mirrorPort() != null) {
String outputPortUuid = getPortUuid(mirror.mirrorPort().value(), bridgeUuid);
if (outputPortUuid == null) {
log.warn("Couldn't find port {} in {}", mirror.mirrorPort().value(), nodeId.getIpAddress());
return false;
}
mirrorEntry.setOutputPort(Uuid.uuid(outputPortUuid));
} else if (mirror.mirrorVlan() != null) {
mirrorEntry.setOutputVlan(mirror.mirrorVlan());
} else {
log.warn("Invalid mirror, no mirror port and no mirror vlan");
return false;
}
ArrayList<Operation> operations = Lists.newArrayList();
Insert mirrorInsert = new Insert(dbSchema.getTableSchema("Mirror"), "Mirror", mirrorEntry.getRow());
operations.add(mirrorInsert);
// update the bridge table
Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid));
Mutation mutation = MutationUtil.insert(MIRRORS, Uuid.uuid("Mirror"));
List<Condition> conditions = Lists.newArrayList(condition);
List<Mutation> mutations = Lists.newArrayList(mutation);
operations.add(new Mutate(dbSchema.getTableSchema("Bridge"), conditions, mutations));
transactConfig(DATABASENAME, operations);
log.info("Created mirror {}", mirror.mirroringName());
return true;
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getPorts.
@Override
public List<OvsdbPortName> getPorts(List<String> portNames, DeviceId deviceId) {
Uuid bridgeUuid = getBridgeUuid(deviceId);
if (bridgeUuid == null) {
log.error("Can't find the bridge for the deviceId {}", deviceId);
return Collections.emptyList();
}
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Row bridgeRow = getRow(DATABASENAME, BRIDGE, bridgeUuid.value());
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
if (bridge == null) {
return Collections.emptyList();
}
OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
Set<Uuid> portSet = setPorts.set();
if (portSet.isEmpty()) {
return Collections.emptyList();
}
Map<Uuid, Port> portMap = portSet.stream().collect(Collectors.toMap(java.util.function.Function.identity(), port -> (Port) TableGenerator.getTable(dbSchema, getRow(DATABASENAME, PORT, port.value()), OvsdbTable.PORT)));
List<OvsdbPortName> portList = portMap.entrySet().stream().filter(port -> Objects.nonNull(port.getValue()) && portNames.contains(port.getValue().getName()) && Objects.nonNull(getInterfacebyPort(port.getKey().value(), port.getValue().getName()))).map(port -> new OvsdbPortName(port.getValue().getName())).collect(Collectors.toList());
return Collections.unmodifiableList(portList);
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getControllers.
@Override
public Set<ControllerInfo> getControllers(DeviceId openflowDeviceId) {
Uuid bridgeUuid = getBridgeUuid(openflowDeviceId);
if (bridgeUuid == null) {
log.warn("bad bridge Uuid");
return null;
}
List<Controller> controllers = getControllers(bridgeUuid);
if (controllers == null) {
log.warn("bad list of controllers");
return null;
}
return controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toSet());
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE in project onos by opennetworkinglab.
the class DefaultOvsdbClient method dropInterface.
@Override
public boolean dropInterface(String ifaceName) {
OvsdbRowStore rowStore = getRowStore(DATABASENAME, BRIDGE);
if (rowStore == null) {
log.warn("Failed to get BRIDGE table");
return false;
}
ConcurrentMap<String, Row> bridgeTableRows = rowStore.getRowStore();
if (bridgeTableRows == null) {
log.warn("Failed to get BRIDGE table rows");
return false;
}
// interface name is unique
Optional<String> bridgeId = bridgeTableRows.keySet().stream().filter(uuid -> getPortUuid(ifaceName, uuid) != null).findFirst();
if (bridgeId.isPresent()) {
String portId = getPortUuid(ifaceName, bridgeId.get());
deleteConfig(PORT, UUID, portId, BRIDGE, PORTS, Uuid.uuid(portId));
return true;
} else {
log.warn("Unable to find the interface with name {}", ifaceName);
return false;
}
}
Aggregations