Search in sources :

Example 6 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class FabricPipeliner method getBucketToFlowMapping.

private Map<GroupBucket, FlowRule> getBucketToFlowMapping(NextObjective nextObjective) {
    Map<GroupBucket, FlowRule> mapping = Maps.newHashMap();
    NextObjective newNextObjective;
    ObjectiveTranslation result;
    FlowRule dummyFlow = getDummyFlow(nextObjective);
    FlowRule egFlow;
    GroupBucket groupBucket;
    GroupDescription group;
    for (NextTreatment nextTreatment : nextObjective.nextTreatments()) {
        newNextObjective = DefaultNextObjective.builder().withId(nextObjective.id()).withType(nextObjective.type()).fromApp(nextObjective.appId()).withMeta(nextObjective.meta()).addTreatment(nextTreatment).verify();
        result = nextTranslator.translate(newNextObjective);
        if ((result.groups().isEmpty() && result.flowRules().isEmpty()) || result.groups().size() > 1) {
            return Collections.emptyMap();
        }
        group = result.groups().iterator().next();
        egFlow = result.flowRules().stream().filter(flowRule -> flowRule.table().equals(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN)).findFirst().orElse(null);
        if (group.buckets().buckets().isEmpty() || group.buckets().buckets().size() > 1) {
            return Collections.emptyMap();
        }
        groupBucket = group.buckets().buckets().iterator().next();
        if (egFlow == null) {
            mapping.put(groupBucket, dummyFlow);
        } else {
            mapping.put(groupBucket, egFlow);
        }
    }
    return mapping;
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) GroupDescription(org.onosproject.net.group.GroupDescription) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) FlowRuleService(org.onosproject.net.flow.FlowRuleService) SharedExecutors(org.onlab.util.SharedExecutors) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Collection(java.util.Collection) PORT_TYPE_INTERNAL(org.onosproject.pipelines.fabric.impl.behaviour.Constants.PORT_TYPE_INTERNAL) Set(java.util.Set) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) ONE(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ONE) Pipeliner(org.onosproject.net.behaviour.Pipeliner) FWD_IPV4_ROUTING(org.onosproject.pipelines.fabric.impl.behaviour.Constants.FWD_IPV4_ROUTING) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultGroup(org.onosproject.net.group.DefaultGroup) GroupBucket(org.onosproject.net.group.GroupBucket) KryoNamespace(org.onlab.util.KryoNamespace) NextGroup(org.onosproject.net.behaviour.NextGroup) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ZERO(org.onosproject.pipelines.fabric.impl.behaviour.FabricInterpreter.ZERO) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) SIMPLE(org.onosproject.net.flowobjective.NextObjective.Type.SIMPLE) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) Maps(com.google.common.collect.Maps) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) FabricPipeconfLoader(org.onosproject.pipelines.fabric.impl.FabricPipeconfLoader) AbstractFabricHandlerBehavior(org.onosproject.pipelines.fabric.impl.behaviour.AbstractFabricHandlerBehavior) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) IdNextTreatment(org.onosproject.net.flowobjective.IdNextTreatment)

Example 7 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class NextObjectiveTranslatorTest method testXconnectOutput.

/**
 * Test XConnect NextObjective.
 *
 * @throws FabricPipelinerException
 */
@Test
public void testXconnectOutput() throws FabricPipelinerException {
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().setOutput(PORT_2).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(treatment1).addTreatment(treatment2).withType(NextObjective.Type.BROADCAST).makePermanent().fromApp(XCONNECT_APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
    // Should generate 2 flows for the xconnect table.
    // Expected multicast table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector xcSelector1 = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).matchInPort(PORT_1).build();
    TrafficTreatment xcTreatment1 = DefaultTrafficTreatment.builder().piTableAction(PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_XCONNECT).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_2.toLong())).build()).build();
    TrafficSelector xcSelector2 = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).matchInPort(PORT_2).build();
    TrafficTreatment xcTreatment2 = DefaultTrafficTreatment.builder().piTableAction(PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_XCONNECT).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build()).build();
    FlowRule expectedXcFlowRule1 = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(XCONNECT_APP_ID).makePermanent().withPriority(nextObjective.priority()).forTable(FabricConstants.FABRIC_INGRESS_NEXT_XCONNECT).withSelector(xcSelector1).withTreatment(xcTreatment1).build();
    FlowRule expectedXcFlowRule2 = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(XCONNECT_APP_ID).makePermanent().withPriority(nextObjective.priority()).forTable(FabricConstants.FABRIC_INGRESS_NEXT_XCONNECT).withSelector(xcSelector2).withTreatment(xcTreatment2).build();
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedXcFlowRule1).addFlowRule(expectedXcFlowRule2).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Test(org.junit.Test)

Example 8 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class NextObjectiveTranslatorTest method testSimple.

private void testSimple(TrafficTreatment treatment, PiAction piAction) throws FabricPipelinerException {
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).withMeta(VLAN_META).addTreatment(treatment).withType(NextObjective.Type.SIMPLE).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);
    // Simple table
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE).withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).build();
    // Expected egress VLAN_PUSH flow rule.
    final PortNumber outPort = outputPort(treatment);
    PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
    TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    PiAction piActionForEgressVlan = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_PUSH_VLAN).build();
    TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
    FlowRule expectedEgressVlanPushRule = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(vlanMetaFlowRule).addFlowRule(expectedFlowRule).addFlowRule(expectedEgressVlanPushRule).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) 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) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 9 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class NextObjectiveTranslatorTest method testMplsHashedOutput.

/**
 * Test program mpls ecmp output group for Hashed table.
 */
@Test
public void testMplsHashedOutput() throws Exception {
    TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(SPINE1_MAC).pushMpls().copyTtlOut().setMpls(MPLS_10).popVlan().setOutput(PORT_1).build();
    TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(SPINE2_MAC).pushMpls().copyTtlOut().setMpls(MPLS_10).popVlan().setOutput(PORT_2).build();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).withMeta(VLAN_META).addTreatment(treatment1).addTreatment(treatment2).withType(NextObjective.Type.HASHED).makePermanent().fromApp(APP_ID).add();
    ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
    // Expected hashed table flow rule.
    PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
    TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
    PiActionProfileGroupId actionGroupId = PiActionProfileGroupId.of(NEXT_ID_1);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(actionGroupId).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
    // First egress rule - port1
    PortNumber outPort = outputPort(treatment1);
    PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
    TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    PiAction piActionForEgressVlan = PiAction.builder().withId(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
    TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
    FlowRule expectedEgressVlanPopRule1 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Second egress rule - port2
    outPort = outputPort(treatment2);
    egressVlanTableMatch = PiCriterion.builder().matchExact(FabricConstants.HDR_EG_PORT, outPort.toLong()).build();
    selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    FlowRule expectedEgressVlanPopRule2 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(FabricConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Expected group
    PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, SPINE1_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piAction2 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, SPINE2_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_2.toLong())).build();
    treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
    treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).build();
    List<TrafficTreatment> treatments = ImmutableList.of(treatment1, treatment2);
    List<GroupBucket> buckets = treatments.stream().map(DefaultGroupBucket::createSelectGroupBucket).collect(Collectors.toList());
    GroupBuckets groupBuckets = new GroupBuckets(buckets);
    PiGroupKey groupKey = new PiGroupKey(FabricConstants.FABRIC_INGRESS_NEXT_HASHED, FabricConstants.FABRIC_INGRESS_NEXT_HASHED_SELECTOR, NEXT_ID_1);
    GroupDescription expectedGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.SELECT, groupBuckets, groupKey, NEXT_ID_1, APP_ID);
    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRule).addFlowRule(vlanMetaFlowRule).addFlowRule(mplsFlowRule).addGroup(expectedGroup).addFlowRule(expectedEgressVlanPopRule1).addFlowRule(expectedEgressVlanPopRule2).build();
    assertEquals(expectedTranslation, actualTranslation);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) GroupBuckets(org.onosproject.net.group.GroupBuckets) PiAction(org.onosproject.net.pi.runtime.PiAction) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Test(org.junit.Test)

Example 10 with NextObjective

use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.

the class VirtualNetworkFlowObjectiveManagerTest method nextObjective.

/**
 * Tests adding a next objective.
 */
@Test
public void nextObjective() {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    NextObjective nextObjective = DefaultNextObjective.builder().withId(service1.allocateNextId()).fromApp(NetTestTools.APP_ID).addTreatment(treatment).withType(NextObjective.Type.BROADCAST).makePermanent().add(new ObjectiveContext() {

        @Override
        public void onSuccess(Objective objective) {
            assertEquals("1 next map entry expected", 1, service1.getNextMappings().size());
            assertEquals("0 next map entry expected", 0, service2.getNextMappings().size());
        }
    });
    service1.next(VDID1, nextObjective);
}
Also used : DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) NextObjective(org.onosproject.net.flowobjective.NextObjective) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Objective(org.onosproject.net.flowobjective.Objective) ObjectiveContext(org.onosproject.net.flowobjective.ObjectiveContext) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Test(org.junit.Test)

Aggregations

NextObjective (org.onosproject.net.flowobjective.NextObjective)83 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)57 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)56 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)55 TrafficSelector (org.onosproject.net.flow.TrafficSelector)51 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)47 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)36 Objective (org.onosproject.net.flowobjective.Objective)31 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)30 DeviceId (org.onosproject.net.DeviceId)29 PortNumber (org.onosproject.net.PortNumber)24 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)24 DefaultObjectiveContext (org.onosproject.net.flowobjective.DefaultObjectiveContext)23 Set (java.util.Set)22 Test (org.junit.Test)22 List (java.util.List)21 Collectors (java.util.stream.Collectors)20 GroupBucket (org.onosproject.net.group.GroupBucket)19 GroupBuckets (org.onosproject.net.group.GroupBuckets)19 Lists (com.google.common.collect.Lists)18