Search in sources :

Example 41 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompiler method buildFilteringObjective.

private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, TrafficSelector selector, DeviceId deviceId, PortNumber inPort) {
    FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
    builder.fromApp(appId).permit().makePermanent().withPriority(intent.priority());
    Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
    if (inPortCriterion != null) {
        builder.withKey(inPortCriterion);
    }
    FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream().filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))).filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())).findFirst().orElse(null);
    AtomicBoolean emptyCondition = new AtomicBoolean(true);
    if (ingressPoint != null) {
        // ingress point, use criterion of it
        ingressPoint.trafficSelector().criteria().forEach(criterion -> {
            builder.addCondition(criterion);
            emptyCondition.set(false);
        });
        if (emptyCondition.get()) {
            return null;
        }
        return builder.add();
    }
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    if (encapConstraint.isPresent() && !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
        // encapsulation enabled, use encapsulation label and tag.
        EncapsulationConstraint encap = encapConstraint.get();
        switch(encap.encapType()) {
            case VLAN:
                builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
                emptyCondition.set(false);
                break;
            case MPLS:
                builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
                emptyCondition.set(false);
                break;
            default:
                log.warn("No filtering rule found because of unknown encapsulation type.");
                break;
        }
    } else {
        // encapsulation not enabled, check if the treatment applied to the ingress or not
        if (intent.applyTreatmentOnEgress()) {
            // filtering criterion will be changed on egress point, use
            // criterion of ingress point
            ingressPoint = intent.filteredIngressPoints().stream().findFirst().orElse(null);
            if (ingressPoint == null) {
                log.warn("No filtering rule found because no ingress point in the Intent");
            } else {
                ingressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
                    builder.addCondition(criterion);
                    emptyCondition.set(false);
                });
            }
        } else {
            // filtering criterion will be changed on ingress point, use
            // criterion of egress point
            FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream().findFirst().orElse(null);
            if (egressPoint == null) {
                log.warn("No filtering rule found because no egress point in the Intent");
            } else {
                egressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
                    builder.addCondition(criterion);
                    emptyCondition.set(false);
                });
            }
        }
    }
    if (emptyCondition.get()) {
        return null;
    }
    return builder.add();
}
Also used : CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) Deactivate(org.osgi.service.component.annotations.Deactivate) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Sets(com.google.common.collect.Sets) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DomainService(org.onosproject.net.domain.DomainService) Intent(org.onosproject.net.intent.Intent) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) Activate(org.osgi.service.component.annotations.Activate) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Instruction(org.onosproject.net.flow.instructions.Instruction) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) SetMultimap(com.google.common.collect.SetMultimap) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Reference(org.osgi.service.component.annotations.Reference) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 42 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method createProtectedIntent.

// FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
    log.trace("createProtectedIntent");
    DisjointPath path = getDisjointPath(intent, ingressPoint.deviceId(), egressPoint.deviceId());
    List<Intent> reusableIntents = null;
    if (installable != null) {
        reusableIntents = filterInvalidSubIntents(installable, intent);
        if (reusableIntents.size() == installable.size()) {
            // all old paths are still viable
            return installable;
        }
    }
    List<Intent> intentList = new ArrayList<>();
    // primary path intent
    List<Link> links = new ArrayList<>();
    links.addAll(path.links());
    links.add(createEdgeLink(egressPoint, false));
    // backup path intent
    List<Link> backupLinks = new ArrayList<>();
    backupLinks.addAll(path.backup().links());
    backupLinks.add(createEdgeLink(egressPoint, false));
    /*
         * One of the old paths is still entirely intact. This old path has
         * already been made primary, so we must add a backup path intent
         * and modify the failover group treatment accordingly.
         */
    if (reusableIntents != null && reusableIntents.size() > 1) {
        /*
             * Ensures that the egress port on source device is different than
             * that of existing path so that failover group will be useful
             * (would not be useful if both output ports in group bucket were
             * the same). Does not necessarily ensure that the new backup path
             * is entirely disjoint from the old path.
             */
        PortNumber primaryPort = getPrimaryPort(intent);
        if (primaryPort != null && !links.get(0).src().port().equals(primaryPort)) {
            reusableIntents.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.BACKUP));
            updateFailoverGroup(intent, links);
            return reusableIntents;
        } else {
            reusableIntents.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
            updateFailoverGroup(intent, backupLinks);
            return reusableIntents;
        }
    }
    intentList.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
    intentList.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
    // add contents appropriately.
    if (groupService.getGroup(ingressPoint.deviceId(), makeGroupKey(intent.id())) == null) {
        // manufactured fast failover flow rule intent
        createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
        FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(), intent.key(), createFailoverFlowRules(intent), asList(ingressPoint.deviceId()), PathIntent.ProtectionType.FAILOVER, intent.resourceGroup());
        intentList.add(frIntent);
    } else {
        updateFailoverGroup(intent, links);
        updateFailoverGroup(intent, backupLinks);
    }
    return intentList;
}
Also used : ArrayList(java.util.ArrayList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultPath(org.onosproject.net.DefaultPath) PortNumber(org.onosproject.net.PortNumber) DisjointPath(org.onosproject.net.DisjointPath) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) EdgeLink(org.onosproject.net.EdgeLink) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 43 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class DeviceInjectionConfigMonitor method injectDevice.

private void injectDevice(DeviceId did) {
    Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
    Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
    if (discovery.isPresent()) {
        providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
        providerService.updatePorts(did, discovery.get().discoverPortDetails());
    } else {
        String unk = "UNKNOWN";
        DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
        providerService.deviceConnected(did, desc);
        Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
        String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
        int numPorts = Integer.parseInt(ports);
        List<PortDescription> portDescs = new ArrayList<>(numPorts);
        for (int i = 1; i <= numPorts; ++i) {
            // TODO inject port details if something like BasicPortConfig was created
            PortNumber number = portNumber(i);
            boolean isEnabled = true;
            portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
        }
        providerService.updatePorts(did, portDescs);
    }
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) PortNumber.portNumber(org.onosproject.net.PortNumber.portNumber) PortNumber(org.onosproject.net.PortNumber) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) DeviceProviderRegistry(org.onosproject.net.device.DeviceProviderRegistry) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData) DriverService(org.onosproject.net.driver.DriverService) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) DEVICE_SUBJECT_FACTORY(org.onosproject.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) DeviceProvider(org.onosproject.net.device.DeviceProvider) PortDescription(org.onosproject.net.device.PortDescription) DeviceProviderService(org.onosproject.net.device.DeviceProviderService) Activate(org.osgi.service.component.annotations.Activate) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) EnumSet(java.util.EnumSet) ExecutorService(java.util.concurrent.ExecutorService) Type(org.onosproject.net.Device.Type) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) MastershipRole(org.onosproject.net.MastershipRole) Deactivate(org.osgi.service.component.annotations.Deactivate) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Beta(com.google.common.annotations.Beta) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) ConfigFactory(org.onosproject.net.config.ConfigFactory) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) List(java.util.List) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) ChassisId(org.onlab.packet.ChassisId) ChassisId(org.onlab.packet.ChassisId) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) ArrayList(java.util.ArrayList) DeviceInjectionConfig(org.onosproject.net.config.inject.DeviceInjectionConfig) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) DeviceDescriptionDiscovery(org.onosproject.net.device.DeviceDescriptionDiscovery) DefaultDeviceDescription(org.onosproject.net.device.DefaultDeviceDescription) PortNumber(org.onosproject.net.PortNumber) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 44 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class OplinkOpticalDeviceDescription method parsePort.

private PortDescription parsePort(HierarchicalConfiguration cfg) {
    PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
    HierarchicalConfiguration portInfo = cfg.configurationAt(KEY_PORT);
    DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portInfo.getString(KEY_PORTNAME)).set(PORT_DIRECTION, portInfo.getString(KEY_PORTDIRECT)).build();
    return omsPortDescription(portNumber, true, START_CENTER_FREQ, STOP_CENTER_FREQ, CHANNEL_SPACING.frequency(), annotations);
}
Also used : DefaultAnnotations(org.onosproject.net.DefaultAnnotations) PortNumber(org.onosproject.net.PortNumber) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration)

Example 45 with PortNumber

use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.

the class OplinkOpticalProtectionSwitchConfig method buildProtectedTransportEndpointState.

private ProtectedTransportEndpointState buildProtectedTransportEndpointState() {
    // First, get active port from device.
    PortNumber activePort = acquireActivePort();
    // Build all endpoint state with port working attribute.
    List<TransportEndpointState> states = new ArrayList<>();
    states.add(buildTransportEndpointState(data().deviceId(), PORT_PRIMARY, activePort));
    states.add(buildTransportEndpointState(data().deviceId(), PORT_SECONDARY, activePort));
    return ProtectedTransportEndpointState.builder().withPathStates(states).withDescription(buildProtectedTransportEndpointDescription()).withActivePathIndex(getActiveIndex(states, activePort)).build();
}
Also used : ProtectedTransportEndpointState(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointState) TransportEndpointState(org.onosproject.net.behaviour.protection.TransportEndpointState) ArrayList(java.util.ArrayList) PortNumber(org.onosproject.net.PortNumber)

Aggregations

PortNumber (org.onosproject.net.PortNumber)336 DeviceId (org.onosproject.net.DeviceId)136 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)109 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)103 ConnectPoint (org.onosproject.net.ConnectPoint)82 TrafficSelector (org.onosproject.net.flow.TrafficSelector)80 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)74 Port (org.onosproject.net.Port)67 ArrayList (java.util.ArrayList)64 Set (java.util.Set)64 List (java.util.List)59 Logger (org.slf4j.Logger)58 Collectors (java.util.stream.Collectors)51 DeviceService (org.onosproject.net.device.DeviceService)49 VlanId (org.onlab.packet.VlanId)42 MacAddress (org.onlab.packet.MacAddress)41 Device (org.onosproject.net.Device)40 FlowRule (org.onosproject.net.flow.FlowRule)40 Optional (java.util.Optional)39 Sets (com.google.common.collect.Sets)35