use of org.onosproject.ovsdb.controller.OvsdbConstant.MIRROR 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;
}
Aggregations