Search in sources :

Example 31 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method processEgress.

/**
 * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
 * egress tables.
 * @param fwd  the forwarding objective of type 'egress'
 * @return     a collection of flow rules to be sent to the switch. An empty
 *             collection may be returned if there is a problem in processing
 *             the flow rule
 */
@Override
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
    log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
    List<FlowRule> rules = new ArrayList<>();
    // Build selector
    TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
    if (vlanIdCriterion == null) {
        log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof Instructions.OutputInstruction).findFirst();
    if (!outInstr.isPresent()) {
        log.error("Egress forwarding objective:{} must include output port", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    PortNumber portNumber = ((Instructions.OutputInstruction) outInstr.get()).port();
    sb.matchVlanId(vlanIdCriterion.vlanId());
    OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
    sb.extension(actsetOutput, deviceId);
    // Build a flow rule for Egress VLAN Flow table
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    tb.transition(UNICAST_ROUTING_TABLE_1);
    if (fwd.treatment() != null) {
        for (Instruction instr : fwd.treatment().allInstructions()) {
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
                tb.immediate().add(instr);
            }
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
                EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
                tb.immediate().pushVlan(ethType);
            }
        }
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE_IN_INGRESS);
    rules.add(ruleBuilder.build());
    return rules;
}
Also used : MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) NONE(org.onlab.packet.MacAddress.NONE) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ImmutableSet(com.google.common.collect.ImmutableSet) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) VLAN_VID(org.onosproject.net.flow.criteria.Criterion.Type.VLAN_VID) Collection(java.util.Collection) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) Optional(java.util.Optional) Queue(java.util.Queue) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) BROADCAST(org.onlab.packet.MacAddress.BROADCAST) Host(org.onosproject.net.Host) GroupBucket(org.onosproject.net.group.GroupBucket) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Deque(java.util.Deque) HostService(org.onosproject.net.host.HostService) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) OfdpaGroupHandlerUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) ReentrantLock(java.util.concurrent.locks.ReentrantLock) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) TimeUnit(java.util.concurrent.TimeUnit) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) GroupId(org.onosproject.core.GroupId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) PacketPriority(org.onosproject.net.packet.PacketPriority) Collections(java.util.Collections) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ArrayList(java.util.ArrayList) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 32 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class OvsOfdpaPipeline method processDoubleVlanIdFilter.

/**
 * Internal implementation of processDoubleVlanIdFilter.
 *
 * @param portCriterion       port on device for which this filter is programmed
 * @param innerVidCriterion   inner vlan
 * @param outerVidCriterion   outer vlan
 * @param popVlan             true if outer vlan header needs to be removed
 * @param applicationId       for application programming this filter
 * @return flow rules for port-vlan filters
 */
private List<FlowRule> processDoubleVlanIdFilter(PortCriterion portCriterion, VlanIdCriterion innerVidCriterion, VlanIdCriterion outerVidCriterion, boolean popVlan, ApplicationId applicationId) {
    List<FlowRule> rules = new ArrayList<>();
    TrafficSelector.Builder outerSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder outerTreatment = DefaultTrafficTreatment.builder();
    TrafficSelector.Builder innerSelector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder innerTreatment = DefaultTrafficTreatment.builder();
    VlanId outerVlanId = outerVidCriterion.vlanId();
    VlanId innerVlanId = innerVidCriterion.vlanId();
    PortNumber portNumber = portCriterion.port();
    // Check arguments
    if (PortNumber.ALL.equals(portNumber) || outerVlanId.equals(VlanId.NONE) || innerVlanId.equals(VlanId.NONE)) {
        log.warn("Incomplete Filtering Objective. " + "VLAN Table cannot be programmed for {}", deviceId);
        return ImmutableList.of();
    } else {
        outerSelector.matchInPort(portNumber);
        innerSelector.matchInPort(portNumber);
        outerTreatment.transition(VLAN_1_TABLE);
        innerTreatment.transition(TMAC_TABLE);
        outerTreatment.writeMetadata(outerVlanId.toShort(), 0xFFF);
        outerSelector.matchVlanId(outerVlanId);
        innerSelector.matchVlanId(innerVlanId);
        // force recompilation
        // FIXME might be issue due tu /fff mask
        innerSelector.matchMetadata(outerVlanId.toShort());
        if (popVlan) {
            outerTreatment.popVlan();
        }
    }
    // NOTE: for double-tagged packets, restore original outer vlan
    // before sending it to the controller.
    GroupKey groupKey = popVlanPuntGroupKey();
    Group group = groupService.getGroup(deviceId, groupKey);
    if (group != null) {
        // push outer vlan and send to controller
        TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder().matchInPort(portNumber).matchVlanId(innerVlanId);
        Host host = handler().get(HostService.class).getConnectedHosts(ConnectPoint.deviceConnectPoint(deviceId + "/" + portNumber.toLong())).stream().filter(h -> h.vlan().equals(outerVlanId)).findFirst().orElse(null);
        EthType vlanType = EthType.EtherType.VLAN.ethType();
        if (host != null) {
            vlanType = host.tpid();
        }
        TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().pushVlan(vlanType).setVlanId(outerVlanId).punt();
        rules.add(DefaultFlowRule.builder().forDevice(deviceId).withSelector(sbuilder.build()).withTreatment(tbuilder.build()).withPriority(PacketPriority.CONTROL.priorityValue()).fromApp(driverId).makePermanent().forTable(PUNT_TABLE).build());
    } else {
        log.info("popVlanPuntGroup not found in dev:{}", deviceId);
        return Collections.emptyList();
    }
    FlowRule outerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(outerSelector.build()).withTreatment(outerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_TABLE).build();
    FlowRule innerRule = DefaultFlowRule.builder().forDevice(deviceId).withSelector(innerSelector.build()).withTreatment(innerTreatment.build()).withPriority(DEFAULT_PRIORITY).fromApp(applicationId).makePermanent().forTable(VLAN_1_TABLE).build();
    rules.add(outerRule);
    rules.add(innerRule);
    return rules;
}
Also used : NextGroup(org.onosproject.net.behaviour.NextGroup) Group(org.onosproject.net.group.Group) HostService(org.onosproject.net.host.HostService) ArrayList(java.util.ArrayList) GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) Host(org.onosproject.net.Host) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId)

Example 33 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class PathIntentCompiler method compile.

@Override
public List<Intent> compile(PathIntent intent, List<Intent> installable) {
    List<FlowRule> rules = new LinkedList<>();
    List<DeviceId> devices = new LinkedList<>();
    compile(this, intent, rules, devices);
    return ImmutableList.of(new FlowRuleIntent(appId, intent.key(), rules, intent.resources(), intent.type(), intent.resourceGroup()));
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) LinkedList(java.util.LinkedList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 34 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method createFailoverFlowRules.

/**
 * Manufactures flow rule with treatment that is defined by failover
 * group and traffic selector determined by ingress port of the intent.
 *
 * @param intent intent which is being compiled (for appId)
 * @return       a list of a singular flow rule with fast failover
 *               outport traffic treatment
 */
private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) {
    List<FlowRule> flowRules = new ArrayList<>();
    ConnectPoint ingress = intent.filteredIngressPoint().connectPoint();
    DeviceId deviceId = ingress.deviceId();
    // flow rule with failover traffic treatment
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector()).matchInPort(ingress.port()).build();
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRules.add(flowRuleBuilder.withSelector(trafficSelector).withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id()))).fromApp(intent.appId()).makePermanent().forDevice(deviceId).withPriority(PRIORITY).build());
    return flowRules;
}
Also used : DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 35 with FlowRule

use of org.onosproject.net.flow.FlowRule in project onos by opennetworkinglab.

the class FlowRuleIntentInstaller method prepareReallocation.

/**
 * This method prepares the {@link FlowRule} required for every reallocation stage.
 *     <p>Stage 1: the FlowRules of the new path are installed,
 *     with a lower priority only on the devices shared with the old path;</p>
 *     <p>Stage 2: the FlowRules of the old path are removed from the ingress to the egress points,
 *     only in the shared devices;</p>
 *     <p>Stage 3: the FlowRules with a lower priority are restored to the original one;</p>
 *     <p>Stage 4: the remaining FlowRules of the old path are deleted.</p>
 *
 * @param uninstallIntents the previous FlowRuleIntent
 * @param installIntents the new FlowRuleIntent to be installed
 * @param firstStageBuilder the first stage operation builder
 * @param secondStageFlowRules the second stage FlowRules
 * @param thirdStageBuilder the third stage operation builder
 * @param finalStageBuilder the last stage operation builder
 */
private void prepareReallocation(List<FlowRuleIntent> uninstallIntents, List<FlowRuleIntent> installIntents, FlowRuleOperations.Builder firstStageBuilder, List<FlowRule> secondStageFlowRules, FlowRuleOperations.Builder thirdStageBuilder, FlowRuleOperations.Builder finalStageBuilder) {
    // Filter out same intents and intents with same flow rules
    installIntents.forEach(installIntent -> {
        uninstallIntents.forEach(uninstallIntent -> {
            List<FlowRule> uninstallFlowRules = Lists.newArrayList(uninstallIntent.flowRules());
            List<FlowRule> installFlowRules = Lists.newArrayList(installIntent.flowRules());
            List<FlowRule> secondStageRules = Lists.newArrayList();
            List<FlowRule> thirdStageRules = Lists.newArrayList();
            List<DeviceId> orderedDeviceList = createIngressToEgressDeviceList(installIntent.resources());
            uninstallIntent.flowRules().forEach(flowRuleToUnistall -> {
                installIntent.flowRules().forEach(flowRuleToInstall -> {
                    if (flowRuleToInstall.exactMatch(flowRuleToUnistall)) {
                        // The FlowRules are in common (i.e., we are sharing the path)
                        uninstallFlowRules.remove(flowRuleToInstall);
                        installFlowRules.remove(flowRuleToInstall);
                    } else if (flowRuleToInstall.deviceId().equals(flowRuleToUnistall.deviceId())) {
                        // FlowRules that have a device in common but
                        // different treatment/selector (i.e., overlapping path)
                        FlowRule flowRuleWithLowerPriority = DefaultFlowRule.builder().withPriority(flowRuleToInstall.priority() - 1).withSelector(flowRuleToInstall.selector()).forDevice(flowRuleToInstall.deviceId()).makePermanent().withTreatment(flowRuleToInstall.treatment()).fromApp(new DefaultApplicationId(flowRuleToInstall.appId(), "org.onosproject.net.intent")).build();
                        // Update the FlowRule to be installed with one with a lower priority
                        installFlowRules.remove(flowRuleToInstall);
                        installFlowRules.add(flowRuleWithLowerPriority);
                        // Add the FlowRule to be uninstalled to the second stage of non-disruptive update
                        secondStageRules.add(flowRuleToUnistall);
                        uninstallFlowRules.remove(flowRuleToUnistall);
                        thirdStageRules.add(flowRuleToInstall);
                        uninstallFlowRules.add(flowRuleWithLowerPriority);
                    }
                });
            });
            firstStageBuilder.newStage();
            installFlowRules.forEach(firstStageBuilder::add);
            Collections.sort(secondStageRules, new SecondStageComparator(orderedDeviceList));
            secondStageFlowRules.addAll(secondStageRules);
            thirdStageBuilder.newStage();
            thirdStageRules.forEach(thirdStageBuilder::add);
            finalStageBuilder.newStage();
            uninstallFlowRules.forEach(finalStageBuilder::remove);
        });
    });
}
Also used : DeviceId(org.onosproject.net.DeviceId) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultApplicationId(org.onosproject.core.DefaultApplicationId)

Aggregations

FlowRule (org.onosproject.net.flow.FlowRule)432 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)279 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)226 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)225 TrafficSelector (org.onosproject.net.flow.TrafficSelector)193 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)189 Test (org.junit.Test)173 List (java.util.List)101 DeviceId (org.onosproject.net.DeviceId)101 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)90 Intent (org.onosproject.net.intent.Intent)88 Collection (java.util.Collection)75 Collectors (java.util.stream.Collectors)75 CoreService (org.onosproject.core.CoreService)72 Collections (java.util.Collections)70 VlanId (org.onlab.packet.VlanId)65 FlowEntry (org.onosproject.net.flow.FlowEntry)63 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)61 PortNumber (org.onosproject.net.PortNumber)57 ArrayList (java.util.ArrayList)56