Search in sources :

Example 1 with OvsdbMap

use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.

the class DefaultOpenstackNodeHandler method isDpdkIntfsCreated.

private boolean isDpdkIntfsCreated(OpenstackNode osNode, Collection<DpdkInterface> dpdkInterfaces) {
    OvsdbClientService client = getOvsdbClient(osNode, ovsdbPortNum, ovsdbController);
    if (client == null) {
        log.info("Failed to get ovsdb client");
        return false;
    }
    Set<OvsdbPort> ports = client.getPorts();
    for (DpdkInterface dpdkIntf : dpdkInterfaces) {
        Optional<OvsdbPort> port = ports.stream().filter(ovsdbPort -> ovsdbPort.portName().value().equals(dpdkIntf.intf())).findAny();
        if (!port.isPresent()) {
            return false;
        }
        Interface intf = client.getInterface(dpdkIntf.intf());
        if (intf == null) {
            return false;
        }
        OvsdbSet mtu = (OvsdbSet) intf.getMtuColumn().data();
        if (mtu == null) {
            return false;
        }
        OvsdbMap option = (OvsdbMap) intf.getOptionsColumn().data();
        if (option == null) {
            return false;
        }
        if (!mtu.set().contains(dpdkIntf.mtu().intValue()) || !option.toString().contains(dpdkIntf.pciAddress())) {
            log.trace("The dpdk interface {} was created but mtu or " + "pci address is different from the config.");
            return false;
        }
    }
    return true;
}
Also used : DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) GENEVE(org.onosproject.openstacknode.api.Constants.GENEVE) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) OSClient(org.openstack4j.api.OSClient) OVSDB_PORT(org.onosproject.openstacknode.impl.OsgiPropertyConstants.OVSDB_PORT) OpenstackNodeUtil.structurePortName(org.onosproject.openstacknode.util.OpenstackNodeUtil.structurePortName) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) BRIDGE_PREFIX(org.onosproject.openstacknode.api.Constants.BRIDGE_PREFIX) GRE(org.onosproject.openstacknode.api.Constants.GRE) COMPLETE(org.onosproject.openstacknode.api.NodeState.COMPLETE) INTEGRATION_BRIDGE(org.onosproject.openstacknode.api.Constants.INTEGRATION_BRIDGE) OpenstackNodeUtil.getConnectedClient(org.onosproject.openstacknode.util.OpenstackNodeUtil.getConnectedClient) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) INTEGRATION_TO_PHYSICAL_PREFIX(org.onosproject.openstacknode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) OpenstackNodeUtil.isOvsdbConnected(org.onosproject.openstacknode.util.OpenstackNodeUtil.isOvsdbConnected) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) BridgeName(org.onosproject.net.behaviour.BridgeName) Collection(java.util.Collection) OpenstackNodeUtil.addOrRemoveSystemInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveSystemInterface) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) DefaultPatchDescription(org.onosproject.net.behaviour.DefaultPatchDescription) Objects(java.util.Objects) List(java.util.List) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) OpenstackNodeUtil.getOvsdbClient(org.onosproject.openstacknode.util.OpenstackNodeUtil.getOvsdbClient) DeviceEvent(org.onosproject.net.device.DeviceEvent) Optional(java.util.Optional) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) AUTO_RECOVERY(org.onosproject.openstacknode.impl.OsgiPropertyConstants.AUTO_RECOVERY) Tools(org.onlab.util.Tools) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) INIT(org.onosproject.openstacknode.api.NodeState.INIT) ComponentContext(org.osgi.service.component.ComponentContext) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) Interface(org.onosproject.ovsdb.rfc.table.Interface) OpenstackNodeAdminService(org.onosproject.openstacknode.api.OpenstackNodeAdminService) INCOMPLETE(org.onosproject.openstacknode.api.NodeState.INCOMPLETE) ControllerNode(org.onosproject.cluster.ControllerNode) CONTROLLER(org.onosproject.openstacknode.api.OpenstackNode.NodeType.CONTROLLER) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) TUNNEL_BRIDGE(org.onosproject.openstacknode.api.Constants.TUNNEL_BRIDGE) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) OVSDB_PORT_NUM_DEFAULT(org.onosproject.openstacknode.impl.OsgiPropertyConstants.OVSDB_PORT_NUM_DEFAULT) Activate(org.osgi.service.component.annotations.Activate) VXLAN_TUNNEL(org.onosproject.openstacknode.api.Constants.VXLAN_TUNNEL) GENEVE_TUNNEL(org.onosproject.openstacknode.api.Constants.GENEVE_TUNNEL) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) PHYSICAL_TO_INTEGRATION_SUFFIX(org.onosproject.openstacknode.api.Constants.PHYSICAL_TO_INTEGRATION_SUFFIX) DEVICE_CREATED(org.onosproject.openstacknode.api.NodeState.DEVICE_CREATED) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DeviceListener(org.onosproject.net.device.DeviceListener) GRE_TUNNEL(org.onosproject.openstacknode.api.Constants.GRE_TUNNEL) OpenstackNodeUtil.addOrRemoveDpdkInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveDpdkInterface) OpenstackNodeUtil.getBooleanProperty(org.onosproject.openstacknode.util.OpenstackNodeUtil.getBooleanProperty) Logger(org.slf4j.Logger) PatchDescription(org.onosproject.net.behaviour.PatchDescription) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) OpenstackNodeHandler(org.onosproject.openstacknode.api.OpenstackNodeHandler) APP_ID(org.onosproject.openstacknode.api.OpenstackNodeService.APP_ID) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TunnelKeys(org.onosproject.net.behaviour.TunnelKeys) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) NETDEV(org.onosproject.openstacknode.api.DpdkConfig.DatapathType.NETDEV) VXLAN(org.onosproject.openstacknode.api.Constants.VXLAN) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) NodeState(org.onosproject.openstacknode.api.NodeState) AUTO_RECOVERY_DEFAULT(org.onosproject.openstacknode.impl.OsgiPropertyConstants.AUTO_RECOVERY_DEFAULT) OvsdbSet(org.onosproject.ovsdb.rfc.notation.OvsdbSet) DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) OpenstackNodeUtil.addOrRemoveDpdkInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveDpdkInterface) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) DpdkInterface(org.onosproject.openstacknode.api.DpdkInterface) OpenstackPhyInterface(org.onosproject.openstacknode.api.OpenstackPhyInterface) OpenstackNodeUtil.addOrRemoveSystemInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveSystemInterface) Interface(org.onosproject.ovsdb.rfc.table.Interface) OpenstackNodeUtil.addOrRemoveDpdkInterface(org.onosproject.openstacknode.util.OpenstackNodeUtil.addOrRemoveDpdkInterface)

Example 2 with OvsdbMap

use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.

the class DefaultOvsdbClient method createQos.

@Override
public boolean createQos(OvsdbQos ovsdbQos) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    Qos qos = (Qos) TableGenerator.createTable(dbSchema, OvsdbTable.QOS);
    OvsdbRowStore rowStore = getRowStore(DATABASENAME, QOS);
    if (rowStore == null) {
        log.debug("The qos uuid is null");
        return false;
    }
    ArrayList<Operation> operations = Lists.newArrayList();
    Set<String> types = Sets.newHashSet();
    Map<Long, Uuid> queues = Maps.newHashMap();
    types.add(ovsdbQos.qosType());
    qos.setOtherConfig(ovsdbQos.otherConfigs());
    qos.setExternalIds(ovsdbQos.externalIds());
    qos.setType(types);
    if (ovsdbQos.qosQueues().isPresent()) {
        for (Map.Entry<Long, String> entry : ovsdbQos.qosQueues().get().entrySet()) {
            OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
            if (queueRowStore != null) {
                ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
                Row queueRow = queueTableRows.values().stream().filter(r -> {
                    OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
                    return entry.getValue().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
                }).findFirst().orElse(null);
                if (queueRow != null) {
                    queues.put(entry.getKey(), queueRow.uuid());
                }
            }
        }
        qos.setQueues(queues);
    }
    Insert qosInsert = new Insert(dbSchema.getTableSchema(QOS), QOS, qos.getRow());
    operations.add(qosInsert);
    try {
        transactConfig(DATABASENAME, operations).get();
    } catch (InterruptedException | ExecutionException e) {
        return false;
    }
    return true;
}
Also used : Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) Insert(org.onosproject.ovsdb.rfc.operations.Insert) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Qos(org.onosproject.ovsdb.rfc.table.Qos) OvsdbQos(org.onosproject.ovsdb.controller.OvsdbQos) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 3 with OvsdbMap

use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.

the class DefaultOvsdbClient method bindQueues.

@Override
public void bindQueues(QosId qosId, Map<Long, QueueDescription> queues) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        log.debug("The qos uuid is null");
        return;
    }
    OvsdbRowStore queueRowStore = getRowStore(DATABASENAME, QUEUE);
    if (queueRowStore == null) {
        log.debug("The queue uuid is null");
        return;
    }
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    ConcurrentMap<String, Row> queueTableRows = queueRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosId.name().equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    if (qosRow == null) {
        log.warn("Can't find QoS {}", qosId);
        return;
    }
    Uuid qosUuid = qosRow.uuid();
    Map<Long, Uuid> newQueues = new HashMap<>();
    for (Map.Entry<Long, QueueDescription> entry : queues.entrySet()) {
        Row queueRow = queueTableRows.values().stream().filter(r -> {
            OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
            return entry.getValue().queueId().name().equals(ovsdbMap.map().get(QUEUE_EXTERNAL_ID_KEY));
        }).findFirst().orElse(null);
        if (queueRow != null) {
            newQueues.put(entry.getKey(), queueRow.uuid());
        }
    }
    // update the qos table
    ArrayList<Operation> operations = Lists.newArrayList();
    Condition condition = ConditionUtil.isEqual(UUID, qosUuid);
    Mutation mutation = MutationUtil.insert(QUEUES, newQueues);
    List<Condition> conditions = Collections.singletonList(condition);
    List<Mutation> mutations = Collections.singletonList(mutation);
    operations.add(new Mutate(dbSchema.getTableSchema(QOS), conditions, mutations));
    transactConfig(DATABASENAME, operations);
}
Also used : Condition(org.onosproject.ovsdb.rfc.notation.Condition) HashMap(java.util.HashMap) Mutate(org.onosproject.ovsdb.rfc.operations.Mutate) Operation(org.onosproject.ovsdb.rfc.operations.Operation) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) QueueDescription(org.onosproject.net.behaviour.QueueDescription) Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) Mutation(org.onosproject.ovsdb.rfc.notation.Mutation) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 4 with OvsdbMap

use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.

the class DefaultOvsdbClient method applyQos.

@Override
public void applyQos(PortNumber portNumber, String qosName) {
    DatabaseSchema dbSchema = schema.get(DATABASENAME);
    OvsdbRowStore portRowStore = getRowStore(DATABASENAME, PORT);
    if (portRowStore == null) {
        log.debug("The port uuid is null");
        return;
    }
    OvsdbRowStore qosRowStore = getRowStore(DATABASENAME, QOS);
    if (qosRowStore == null) {
        log.debug("The qos uuid is null");
        return;
    }
    // Due to Qos Table doesn't have a unique identifier except uuid, unlike
    // Bridge or Port Table has a name column,in order to make the api more
    // general, put qos name in external_ids column of Qos Table if this qos
    // created by onos.
    ConcurrentMap<String, Row> qosTableRows = qosRowStore.getRowStore();
    ConcurrentMap<String, Row> portTableRows = portRowStore.getRowStore();
    Row qosRow = qosTableRows.values().stream().filter(r -> {
        OvsdbMap ovsdbMap = (OvsdbMap) (r.getColumn(EXTERNAL_ID).data());
        return qosName.equals(ovsdbMap.map().get(QOS_EXTERNAL_ID_KEY));
    }).findFirst().orElse(null);
    Row portRow = portTableRows.values().stream().filter(r -> r.getColumn("name").data().equals(portNumber.name())).findFirst().orElse(null);
    if (portRow != null && qosRow != null) {
        String qosId = qosRow.uuid().value();
        Uuid portUuid = portRow.uuid();
        Map<String, Column> columns = new HashMap<>();
        Row newPortRow = new Row(PORT, portUuid, columns);
        Port newport = new Port(dbSchema, newPortRow);
        columns.put(Port.PortColumn.QOS.columnName(), newport.getQosColumn());
        newport.setQos(Uuid.uuid(qosId));
        updateConfig(PORT, UUID, portUuid.value(), newport.getRow());
    }
}
Also used : Uuid(org.onosproject.ovsdb.rfc.notation.Uuid) Column(org.onosproject.ovsdb.rfc.notation.Column) HashMap(java.util.HashMap) OvsdbPort(org.onosproject.ovsdb.controller.OvsdbPort) Port(org.onosproject.ovsdb.rfc.table.Port) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Row(org.onosproject.ovsdb.rfc.notation.Row) OvsdbRowStore(org.onosproject.ovsdb.controller.OvsdbRowStore) DatabaseSchema(org.onosproject.ovsdb.rfc.schema.DatabaseSchema)

Example 5 with OvsdbMap

use of org.onosproject.ovsdb.rfc.notation.OvsdbMap in project onos by opennetworkinglab.

the class TransValueUtil method getValueFromKvType.

/**
 * Convert KeyValuedColumnType JsonNode into OvsdbMap value.
 * @param json KeyValuedColumnType JsonNode
 * @param kvType KeyValuedColumnType entity
 * @return Object OvsdbMap
 */
private static Object getValueFromKvType(JsonNode json, KeyValuedColumnType kvType) {
    if (json.isArray()) {
        if (json.size() == 2) {
            if (json.get(0).isTextual() && "map".equals(json.get(0).asText())) {
                Map map = Maps.newHashMap();
                for (JsonNode pairNode : json.get(1)) {
                    if (pairNode.isArray() && json.size() == 2) {
                        Object key = transToValue(pairNode.get(0), kvType.keyType());
                        Object value = transToValue(pairNode.get(1), kvType.valueType());
                        map.put(key, value);
                    }
                }
                return OvsdbMap.ovsdbMap(map);
            }
        }
    }
    return null;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) OvsdbMap(org.onosproject.ovsdb.rfc.notation.OvsdbMap) Map(java.util.Map)

Aggregations

OvsdbMap (org.onosproject.ovsdb.rfc.notation.OvsdbMap)12 OvsdbRowStore (org.onosproject.ovsdb.controller.OvsdbRowStore)7 Row (org.onosproject.ovsdb.rfc.notation.Row)7 Uuid (org.onosproject.ovsdb.rfc.notation.Uuid)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 DatabaseSchema (org.onosproject.ovsdb.rfc.schema.DatabaseSchema)5 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 Operation (org.onosproject.ovsdb.rfc.operations.Operation)3 Set (java.util.Set)2 OvsdbPort (org.onosproject.ovsdb.controller.OvsdbPort)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1