Search in sources :

Example 11 with Interface

use of org.onosproject.ovsdb.rfc.table.Interface 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;
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Port(org.onosproject.ovsdb.rfc.table.Port) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) Interface(org.onosproject.ovsdb.rfc.table.Interface) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

Interface (org.onosproject.ovsdb.rfc.table.Interface)11 OvsdbInterface (org.onosproject.ovsdb.controller.OvsdbInterface)9 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)9 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)8 OvsdbPortName (org.onosproject.ovsdb.controller.OvsdbPortName)7 OvsdbPortNumber (org.onosproject.ovsdb.controller.OvsdbPortNumber)7 Insert (org.onosproject.ovsdb.rfc.operations.Insert)6 Lists (com.google.common.collect.Lists)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Objects (java.util.Objects)5 Optional (java.util.Optional)5 Set (java.util.Set)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Function (com.google.common.base.Function)4 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 Maps (com.google.common.collect.Maps)4 Sets (com.google.common.collect.Sets)4 Futures (com.google.common.util.concurrent.Futures)4