Search in sources :

Example 1 with OvsdbBridge

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

the class DefaultOvsdbClient method createBridge.

@Override
public boolean createBridge(OvsdbBridge ovsdbBridge) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    String ovsUuid = getOvsUuid(DATABASENAME);
    if (dbSchema == null || ovsUuid == null) {
        log.error("Can't find database Open_vSwitch");
        return false;
    }
    Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, OvsdbTable.BRIDGE);
    bridge.setOtherConfig(ovsdbBridge.otherConfigs());
    if (ovsdbBridge.failMode().isPresent()) {
        String failMode = ovsdbBridge.failMode().get().name().toLowerCase();
        bridge.setFailMode(Sets.newHashSet(failMode));
    }
    if (ovsdbBridge.datapathType().isPresent()) {
        String datapathType = ovsdbBridge.datapathType().get();
        bridge.setDatapathType(datapathType);
    }
    if (ovsdbBridge.controlProtocols().isPresent()) {
        bridge.setProtocols(ovsdbBridge.controlProtocols().get().stream().map(ControlProtocolVersion::toString).collect(Collectors.toCollection(HashSet::new)));
    }
    if (ovsdbBridge.mcastSnoopingEnable().isPresent()) {
        boolean mcastSnoopingFlag = ovsdbBridge.mcastSnoopingEnable().get();
        bridge.setMcastSnoopingEnable(mcastSnoopingFlag);
    }
    String bridgeUuid = getBridgeUuid(ovsdbBridge.name());
    if (bridgeUuid == null) {
        bridge.setName(ovsdbBridge.name());
        bridgeUuid = insertConfig(BRIDGE, UUID, DATABASENAME, BRIDGES, ovsUuid, bridge.getRow());
    } else {
        // update the bridge if it's already existing
        updateConfig(BRIDGE, UUID, bridgeUuid, bridge.getRow());
    }
    if (bridgeUuid == null) {
        log.warn("Failed to create bridge {} on {}", ovsdbBridge.name(), nodeId);
        return false;
    }
    createPort(ovsdbBridge.name(), ovsdbBridge.name());
    setControllersWithUuid(Uuid.uuid(bridgeUuid), ovsdbBridge.controllers());
    log.info("Created bridge {}", ovsdbBridge.name());
    return true;
}
Also used : ControlProtocolVersion(org.onosproject.net.behaviour.ControlProtocolVersion) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema) HashSet(java.util.HashSet)

Example 2 with OvsdbBridge

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

the class DefaultOvsdbClient method getBridges.

@Override
public Set<OvsdbBridge> getBridges() {
    Set<OvsdbBridge> ovsdbBridges = new HashSet<>();
    OvsdbTableStore tableStore = getTableStore(DATABASENAME);
    if (tableStore == null) {
        return ovsdbBridges;
    }
    OvsdbRowStore rowStore = tableStore.getRows(BRIDGE);
    if (rowStore == null) {
        return ovsdbBridges;
    }
    ConcurrentMap<String, Row> rows = rowStore.getRowStore();
    for (String uuid : rows.keySet()) {
        Row bridgeRow = getRow(DATABASENAME, BRIDGE, uuid);
        OvsdbBridge ovsdbBridge = getOvsdbBridge(bridgeRow, Uuid.uuid(uuid));
        if (ovsdbBridge != null) {
            ovsdbBridges.add(ovsdbBridge);
        }
    }
    return ovsdbBridges;
}
Also used : OvsdbTableStore(org.onosproject.ovsdb.controller.OvsdbTableStore) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) HashSet(java.util.HashSet)

Example 3 with OvsdbBridge

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

the class OvsdbBridgeConfig method getBridges.

@Override
public Collection<BridgeDescription> getBridges() {
    OvsdbClientService client = getOvsdbClientService(handler());
    if (client == null) {
        return Collections.emptyList();
    }
    Set<OvsdbBridge> bridges = client.getBridges();
    return bridges.stream().map(bridge -> DefaultBridgeDescription.builder().name(bridge.name()).datapathId(bridge.datapathId().get()).build()).collect(Collectors.toSet());
}
Also used : DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) Collection(java.util.Collection) BridgeName(org.onosproject.net.behaviour.BridgeName) PortNumber(org.onosproject.net.PortNumber) Set(java.util.Set) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) List(java.util.List) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DriverHandler(org.onosproject.net.driver.DriverHandler) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) PortDescription(org.onosproject.net.device.PortDescription) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) IpAddress(org.onlab.packet.IpAddress) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge)

Example 4 with OvsdbBridge

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

the class DefaultOvsdbClient method getOvsdbBridge.

private OvsdbBridge getOvsdbBridge(Row row, Uuid bridgeUuid) {
    DatabaseSchema dbSchema = getDatabaseSchema(DATABASENAME);
    Bridge bridge = (Bridge) TableGenerator.getTable(dbSchema, row, OvsdbTable.BRIDGE);
    if (bridge == null) {
        return null;
    }
    OvsdbSet datapathIdSet = (OvsdbSet) bridge.getDatapathIdColumn().data();
    @SuppressWarnings("unchecked") Set<String> datapathIds = datapathIdSet.set();
    if (datapathIds == null || datapathIds.isEmpty()) {
        return null;
    }
    String datapathId = (String) datapathIds.toArray()[0];
    String bridgeName = bridge.getName();
    if ((datapathId == null) || (bridgeName == null)) {
        return null;
    }
    List<Controller> controllers = getControllers(bridgeUuid);
    if (controllers != null) {
        List<ControllerInfo> controllerInfos = controllers.stream().map(controller -> new ControllerInfo((String) controller.getTargetColumn().data())).collect(Collectors.toList());
        return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).controllers(controllerInfos).build();
    } else {
        return OvsdbBridge.builder().name(bridgeName).datapathId(datapathId).build();
    }
}
Also used : OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) QUEUE_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE_EXTERNAL_ID_KEY) Controller(org.onosproject.ovsdb.rfc.table.Controller) ColumnSchemaNotFoundException(org.onosproject.ovsdb.rfc.exception.ColumnSchemaNotFoundException) OFPORT(org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT) PortNumber(org.onosproject.net.PortNumber) QueueId(org.onosproject.net.behaviour.QueueId) FromJsonUtil(org.onosproject.ovsdb.rfc.utils.FromJsonUtil) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Update(org.onosproject.ovsdb.rfc.operations.Update) Qos(org.onosproject.ovsdb.rfc.table.Qos) Callback(org.onosproject.ovsdb.rfc.jsonrpc.Callback) Set(java.util.Set) MIRRORS(org.onosproject.ovsdb.controller.OvsdbConstant.MIRRORS) OvsdbQueue(org.onosproject.ovsdb.controller.OvsdbQueue) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) MIRROR(org.onosproject.ovsdb.controller.OvsdbConstant.MIRROR) Mirror(org.onosproject.ovsdb.rfc.table.Mirror) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) OperationResult(org.onosproject.ovsdb.rfc.message.OperationResult) OvsdbStore(org.onosproject.ovsdb.controller.OvsdbStore) DeviceId(org.onosproject.net.DeviceId) DATABASENAME(org.onosproject.ovsdb.controller.OvsdbConstant.DATABASENAME) Interface(org.onosproject.ovsdb.rfc.table.Interface) JsonRpcWriterUtil(org.onosproject.ovsdb.rfc.utils.JsonRpcWriterUtil) MirroringStatistics(org.onosproject.net.behaviour.MirroringStatistics) PORTS(org.onosproject.ovsdb.controller.OvsdbConstant.PORTS) ArrayList(java.util.ArrayList) DeviceCpuStats(org.onosproject.net.behaviour.DeviceCpuStats) Lists(com.google.common.collect.Lists) OvsdbInterface(org.onosproject.ovsdb.controller.OvsdbInterface) INTERFACE(org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACE) BRIDGE_CONTROLLER(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE_CONTROLLER) OvsdbPortName(org.onosproject.ovsdb.controller.OvsdbPortName) QUEUE(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUE) QosId(org.onosproject.net.behaviour.QosId) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) EXTERNAL_ID(org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID) EXTERNAL_ID_INTERFACE_ID(org.onosproject.ovsdb.controller.OvsdbConstant.EXTERNAL_ID_INTERFACE_ID) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbTable(org.onosproject.ovsdb.rfc.table.OvsdbTable) Channel(io.netty.channel.Channel) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) Column(org.onosproject.ovsdb.rfc.notation.Column) MutationUtil(org.onosproject.ovsdb.rfc.utils.MutationUtil) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Row(org.onosproject.ovsdb.rfc.notation.Row) CONTROLLER(org.onosproject.ovsdb.controller.OvsdbConstant.CONTROLLER) TableGenerator(org.onosproject.ovsdb.rfc.table.TableGenerator) ControlProtocolVersion(org.onosproject.net.behaviour.ControlProtocolVersion) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) OvsdbPortNumber(org.onosproject.ovsdb.controller.OvsdbPortNumber) OvsdbTableStore(org.onosproject.ovsdb.controller.OvsdbTableStore) QOS_EXTERNAL_ID_KEY(org.onosproject.ovsdb.controller.OvsdbConstant.QOS_EXTERNAL_ID_KEY) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) SettableFuture(com.google.common.util.concurrent.SettableFuture) DeviceMemoryStats(org.onosproject.net.behaviour.DeviceMemoryStats) QUEUES(org.onosproject.ovsdb.controller.OvsdbConstant.QUEUES) Delete(org.onosproject.ovsdb.rfc.operations.Delete) UUID(org.onosproject.ovsdb.controller.OvsdbConstant.UUID) ConditionUtil(org.onosproject.ovsdb.rfc.utils.ConditionUtil) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) OFPORT_ERROR(org.onosproject.ovsdb.controller.OvsdbConstant.OFPORT_ERROR) TYPEVXLAN(org.onosproject.ovsdb.controller.OvsdbConstant.TYPEVXLAN) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Operation(org.onosproject.ovsdb.rfc.operations.Operation) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) Queue(org.onosproject.ovsdb.rfc.table.Queue) OvsdbQos(org.onosproject.ovsdb.controller.OvsdbQos) Insert(org.onosproject.ovsdb.rfc.operations.Insert) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) OvsdbMirror(org.onosproject.ovsdb.controller.OvsdbMirror) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentMap(java.util.concurrent.ConcurrentMap) BRIDGE(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGE) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) HashSet(java.util.HashSet) PORT(org.onosproject.ovsdb.controller.OvsdbConstant.PORT) ImmutableList(com.google.common.collect.ImmutableList) TableUpdates(org.onosproject.ovsdb.rfc.message.TableUpdates) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) PORT_QOS(org.onosproject.ovsdb.controller.OvsdbConstant.PORT_QOS) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema) TableSchema(org.onosproject.ovsdb.rfc.schema.TableSchema) ColumnSchema(org.onosproject.ovsdb.rfc.schema.ColumnSchema) IpAddress(org.onlab.packet.IpAddress) Port(org.onosproject.ovsdb.rfc.table.Port) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) VersionMismatchException(org.onosproject.ovsdb.rfc.exception.VersionMismatchException) MirroringName(org.onosproject.net.behaviour.MirroringName) BRIDGES(org.onosproject.ovsdb.controller.OvsdbConstant.BRIDGES) Maps(com.google.common.collect.Maps) INTERFACES(org.onosproject.ovsdb.controller.OvsdbConstant.INTERFACES) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) QOS(org.onosproject.ovsdb.controller.OvsdbConstant.QOS) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Collections(java.util.Collections) Condition(org.onosproject.ovsdb.rfc.notation.Condition) Controller(org.onosproject.ovsdb.rfc.table.Controller) Bridge(org.onosproject.ovsdb.rfc.table.Bridge) OvsdbBridge(org.onosproject.ovsdb.controller.OvsdbBridge) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Aggregations

OvsdbBridge (org.onosproject.ovsdb.controller.OvsdbBridge)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 IpAddress (org.onlab.packet.IpAddress)2 DeviceId (org.onosproject.net.DeviceId)2 PortNumber (org.onosproject.net.PortNumber)2 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)2 OvsdbNodeId (org.onosproject.ovsdb.controller.OvsdbNodeId)2 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1