Search in sources :

Example 1 with OvsdbInterface

use of org.onosproject.ovsdb.controller.OvsdbInterface in project onos by opennetworkinglab.

the class OvsdbInterfaceConfig method addTunnelMode.

@Override
public boolean addTunnelMode(String ifaceName, TunnelDescription tunnelDesc) {
    OvsdbInterface ovsdbIface = OvsdbInterface.builder(tunnelDesc).build();
    OvsdbClientService ovsdbClient = getOvsdbClient(handler());
    if (!tunnelDesc.deviceId().isPresent()) {
        log.warn("Device ID is required {}", tunnelDesc);
        return false;
    }
    return ovsdbClient.createInterface(tunnelDesc.deviceId().get(), ovsdbIface);
}
Also used : OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService)

Example 2 with OvsdbInterface

use of org.onosproject.ovsdb.controller.OvsdbInterface in project onos by opennetworkinglab.

the class OpenstackRecoverPortsCommand method recoverOvsPort.

/**
 * Recovers the openvswitch port from conf.db corruption.
 *
 * @param controller    ovsdb controller
 * @param ovsdbPort     ovsdb port number
 * @param node          openstack node
 * @param osPort        an openstack port
 * @param ovsPorts      set of openvswitch ports
 *
 * @return a set of recovered port name
 */
private Set<String> recoverOvsPort(OvsdbController controller, int ovsdbPort, OpenstackNode node, Port osPort, List<org.onosproject.net.Port> ovsPorts) {
    OvsdbClientService client = getOvsdbClient(node, ovsdbPort, controller);
    if (client == null) {
        return ImmutableSet.of();
    }
    Set<String> portNames = ovsPorts.stream().filter(ovsPort -> ovsPort.annotations() != null || ovsPort.annotations().keys().contains(PORT_NAME)).map(ovsPort -> ovsPort.annotations().value(PORT_NAME)).collect(Collectors.toSet());
    String tapPort = ifaceNameFromOsPortId(osPort.getId());
    Set<String> recoveredPortNames = Sets.newConcurrentHashSet();
    if (!portNames.contains(tapPort)) {
        Map<String, String> extIdMap = ImmutableMap.of(ATTACHED_MAC, osPort.getMacAddress(), IFACE_ID, osPort.getId(), IFACE_STATUS, StringUtils.lowerCase(osPort.getState().name()), VM_ID, osPort.getDeviceId());
        OvsdbInterface ovsIface = OvsdbInterface.builder().name(tapPort).options(ImmutableMap.of()).data(ImmutableMap.of(EXTERNALIDS, extIdMap)).build();
        client.createInterface(INTEGRATION_BRIDGE, ovsIface);
        recoveredPortNames.add(tapPort);
    }
    return ImmutableSet.copyOf(recoveredPortNames);
}
Also used : EXTERNALIDS(org.onosproject.ovsdb.rfc.table.Interface.InterfaceColumn.EXTERNALIDS) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) DeviceService(org.onosproject.net.device.DeviceService) INTEGRATION_BRIDGE(org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE) StringUtils(org.apache.commons.lang3.StringUtils) Command(org.apache.karaf.shell.api.action.Command) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Map(java.util.Map) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) OpenstackNetworkingUtil.ifaceNameFromOsPortId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.ifaceNameFromOsPortId) Port(org.openstack4j.model.network.Port) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) OpenstackNetworkingUtil.getOvsdbClient(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getOvsdbClient) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Argument(org.apache.karaf.shell.api.action.Argument) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) List(java.util.List) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Completion(org.apache.karaf.shell.api.action.Completion) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Option(org.apache.karaf.shell.api.action.Option) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService)

Example 3 with OvsdbInterface

use of org.onosproject.ovsdb.controller.OvsdbInterface in project onos by opennetworkinglab.

the class OvsdbInterfaceConfig method addPatchMode.

@Override
public boolean addPatchMode(String ifaceName, PatchDescription patchDesc) {
    OvsdbInterface ovsdbIface = OvsdbInterface.builder(patchDesc).build();
    OvsdbClientService ovsdbClient = getOvsdbClient(handler());
    if (!patchDesc.deviceId().isPresent()) {
        log.warn("Device ID is required {}", patchDesc);
        return false;
    }
    return ovsdbClient.createInterface(patchDesc.deviceId().get(), ovsdbIface);
}
Also used : OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService)

Example 4 with OvsdbInterface

use of org.onosproject.ovsdb.controller.OvsdbInterface 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

OvsdbInterface (org.onosproject.ovsdb.controller.OvsdbInterface)4 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Argument (org.apache.karaf.shell.api.action.Argument)1 Command (org.apache.karaf.shell.api.action.Command)1 Completion (org.apache.karaf.shell.api.action.Completion)1 Option (org.apache.karaf.shell.api.action.Option)1 Service (org.apache.karaf.shell.api.action.lifecycle.Service)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 DeviceService (org.onosproject.net.device.DeviceService)1 OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)1 OpenstackNetworkingUtil.getOvsdbClient (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getOvsdbClient)1 OpenstackNetworkingUtil.ifaceNameFromOsPortId (org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.ifaceNameFromOsPortId)1