use of org.onosproject.ovsdb.controller.OvsdbConstant.PORT 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();
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.PORT 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.PORT 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.PORT 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;
}
}
use of org.onosproject.ovsdb.controller.OvsdbConstant.PORT in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getInterfacebyPort.
private Interface getInterfacebyPort(String portUuid, String portName) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Row portRow = getRow(DATABASENAME, PORT, portUuid);
Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT);
if (port == null) {
return null;
}
OvsdbSet setInterfaces = (OvsdbSet) port.getInterfacesColumn().data();
Set<Uuid> interfaces = setInterfaces.set();
return interfaces.stream().map(intf -> (Interface) TableGenerator.getTable(dbSchema, getRow(DATABASENAME, INTERFACE, intf.value()), OvsdbTable.INTERFACE)).filter(intf -> Objects.nonNull(intf) && portName.equalsIgnoreCase(intf.getName())).findFirst().orElse(null);
}
Aggregations