use of org.onosproject.ovsdb.rfc.table.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.rfc.table.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.rfc.table.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.rfc.table.Port in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createPort.
@Override
public void createPort(String bridgeName, String portName) {
String bridgeUuid = getBridgeUuid(bridgeName);
if (bridgeUuid == null) {
log.error("Can't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
return;
}
DatabaseSchema dbSchema = schema.get(DATABASENAME);
String portUuid = getPortUuid(portName, bridgeUuid);
Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
port.setName(portName);
if (portUuid == null) {
insertConfig(PORT, UUID, BRIDGE, PORTS, bridgeUuid, port.getRow());
}
}
use of org.onosproject.ovsdb.rfc.table.Port 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());
}
}
Aggregations