use of org.onosproject.ovsdb.rfc.table.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.rfc.table.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);
}
use of org.onosproject.ovsdb.rfc.table.Port in project onos by opennetworkinglab.
the class DefaultOvsdbClient method getPortUuid.
@Override
public String getPortUuid(String portName, String bridgeUuid) {
DatabaseSchema dbSchema = schema.get(DATABASENAME);
Row bridgeRow = getRow(DATABASENAME, BRIDGE, bridgeUuid);
Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, bridgeRow, OvsdbTable.BRIDGE);
if (bridge != null) {
OvsdbSet setPorts = (OvsdbSet) bridge.getPortsColumn().data();
@SuppressWarnings("unchecked") Set<Uuid> ports = setPorts.set();
if (ports == null || ports.isEmpty()) {
log.warn("The port uuid is null");
return null;
}
for (Uuid uuid : ports) {
Row portRow = getRow(DATABASENAME, PORT, uuid.value());
Port port = (Port) TableGenerator.getTable(dbSchema, portRow, OvsdbTable.PORT);
if (port != null && portName.equalsIgnoreCase(port.getName())) {
return uuid.value();
}
}
}
return null;
}
use of org.onosproject.ovsdb.rfc.table.Port in project onos by opennetworkinglab.
the class DefaultOvsdbClient method createInterface.
@Override
public boolean createInterface(String bridgeName, OvsdbInterface ovsdbIface) {
String bridgeUuid = getBridgeUuid(bridgeName);
if (bridgeUuid == null) {
log.warn("Couldn't find bridge {} in {}", bridgeName, nodeId.getIpAddress());
return false;
}
if (getPortUuid(ovsdbIface.name(), bridgeUuid) != null) {
log.warn("Interface {} already exists", ovsdbIface.name());
return false;
}
ArrayList<Operation> operations = Lists.newArrayList();
DatabaseSchema dbSchema = schema.get(DATABASENAME);
// insert a new port with the interface name
Port port = (Port) TableGenerator.createTable(dbSchema, OvsdbTable.PORT);
port.setName(ovsdbIface.name());
Insert portInsert = new Insert(dbSchema.getTableSchema(PORT), PORT, port.getRow());
portInsert.getRow().put(INTERFACES, Uuid.uuid(INTERFACE));
operations.add(portInsert);
// update the bridge table with the new port
Condition condition = ConditionUtil.isEqual(UUID, Uuid.uuid(bridgeUuid));
Mutation mutation = MutationUtil.insert(PORTS, Uuid.uuid(PORT));
List<Condition> conditions = Lists.newArrayList(condition);
List<Mutation> mutations = Lists.newArrayList(mutation);
operations.add(new Mutate(dbSchema.getTableSchema(BRIDGE), conditions, mutations));
Interface intf = (Interface) TableGenerator.createTable(dbSchema, OvsdbTable.INTERFACE);
intf.setName(ovsdbIface.name());
if (ovsdbIface.type() != null) {
intf.setType(ovsdbIface.typeToString());
}
if (ovsdbIface.mtu().isPresent()) {
Set<Long> mtuSet = Sets.newConcurrentHashSet();
mtuSet.add(ovsdbIface.mtu().get());
intf.setMtu(mtuSet);
intf.setMtuRequest(mtuSet);
}
intf.setOptions(ovsdbIface.options());
ovsdbIface.data().forEach((k, v) -> {
if (k == Interface.InterfaceColumn.EXTERNALIDS) {
intf.setExternalIds(v);
}
});
Insert intfInsert = new Insert(dbSchema.getTableSchema(INTERFACE), INTERFACE, intf.getRow());
operations.add(intfInsert);
transactConfig(DATABASENAME, operations);
log.info("Created interface {}", ovsdbIface);
return true;
}
Aggregations