Search in sources :

Example 46 with ForwardingObjective

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

the class ForwardingObjectiveTranslatorTest method testAclDrop.

/**
 * Test versatile flag of forwarding objective with acl drop.
 */
@Test
public void testAclDrop() {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().wipeDeferred().build();
    // ACL 8-tuples like
    TrafficSelector selector = DefaultTrafficSelector.builder().matchIPDst(IPV4_UNICAST_ADDR).build();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withTreatment(treatment).add();
    ObjectiveTranslation result = translator.translate(fwd);
    List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
    List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
    assertEquals(1, flowRulesInstalled.size());
    assertTrue(groupsInstalled.isEmpty());
    FlowRule actualFlowRule = flowRulesInstalled.get(0);
    PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_DROP).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
    assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 47 with ForwardingObjective

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

the class ForwardingObjectiveTranslatorTest method testAclArp.

/**
 * Test versatile flag of forwarding objective with ARP match.
 */
@Test
public void testAclArp() {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
    // ARP
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).build();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withTreatment(treatment).add();
    ObjectiveTranslation result = translator.translate(fwd);
    List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
    List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
    assertEquals(1, flowRulesInstalled.size());
    assertEquals(1, groupsInstalled.size());
    FlowRule actualFlowRule = flowRulesInstalled.get(0);
    PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_CLONE_SESSION_ID).withParameter(new PiActionParam(FabricConstants.CLONE_ID, ForwardingObjectiveTranslator.CLONE_TO_CPU_ID)).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
    GroupDescription actualCloneGroup = groupsInstalled.get(0);
    TrafficTreatment cloneGroupTreatment = DefaultTrafficTreatment.builder().setOutput(PortNumber.CONTROLLER).build();
    List<GroupBucket> cloneBuckets = ImmutableList.of(DefaultGroupBucket.createCloneGroupBucket(cloneGroupTreatment));
    GroupBuckets cloneGroupBuckets = new GroupBuckets(cloneBuckets);
    GroupKey cloneGroupKey = new DefaultGroupKey(FabricPipeliner.KRYO.serialize(ForwardingObjectiveTranslator.CLONE_TO_CPU_ID));
    GroupDescription expectedCloneGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.CLONE, cloneGroupBuckets, cloneGroupKey, ForwardingObjectiveTranslator.CLONE_TO_CPU_ID, APP_ID);
    assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
    assertTrue(expectedCloneGroup.equals(actualCloneGroup));
}
Also used : GroupKey(org.onosproject.net.group.GroupKey) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) 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) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) GroupBucket(org.onosproject.net.group.GroupBucket) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) Test(org.junit.Test)

Example 48 with ForwardingObjective

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

the class ForwardingObjectiveTranslatorTest method testAclNextWithPortType.

/**
 * Test versatile flag of forwarding objective with next step and port type.
 */
@Test
public void testAclNextWithPortType() {
    // ACL 8-tuples
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).build();
    TrafficSelector metaSelector = DefaultTrafficSelector.builder().matchMetadata(EDGE_PORT).build();
    ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).withMeta(metaSelector).add();
    ObjectiveTranslation result = translator.translate(fwd);
    List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
    List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
    assertEquals(1, flowRulesInstalled.size());
    assertTrue(groupsInstalled.isEmpty());
    FlowRule actualFlowRule = flowRulesInstalled.get(0);
    PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_ACL_SET_NEXT_ID_ACL).withParameter(new PiActionParam(FabricConstants.NEXT_ID, NEXT_ID_1)).build();
    TrafficSelector expectedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_PORT_TYPE, PORT_TYPE_EDGE, PORT_TYPE_MASK).build()).build();
    FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(expectedSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
    assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
    metaSelector = DefaultTrafficSelector.builder().matchMetadata(INFRA_PORT).build();
    fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).nextStep(NEXT_ID_1).withMeta(metaSelector).add();
    result = translator.translate(fwd);
    flowRulesInstalled = (List<FlowRule>) result.flowRules();
    groupsInstalled = (List<GroupDescription>) result.groups();
    assertEquals(1, flowRulesInstalled.size());
    assertTrue(groupsInstalled.isEmpty());
    actualFlowRule = flowRulesInstalled.get(0);
    expectedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).matchPi(PiCriterion.builder().matchTernary(FabricConstants.HDR_PORT_TYPE, PORT_TYPE_INFRA, PORT_TYPE_MASK).build()).build();
    expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(FabricConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(expectedSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
    assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
Also used : DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 49 with ForwardingObjective

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

the class FabricUtils method isValidSrMetadata.

/**
 * Check metadata passed from SegmentRouting app.
 *
 * @param obj the objective containing the metadata
 * @return true if the objective contains valid metadata, false otherwise
 */
public static boolean isValidSrMetadata(Objective obj) {
    long meta = 0;
    if (obj instanceof FilteringObjective) {
        FilteringObjective filtObj = (FilteringObjective) obj;
        if (filtObj.meta() == null) {
            return true;
        }
        Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
        if (metaIns == null) {
            return true;
        }
        meta = metaIns.metadata() & metaIns.metadataMask();
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjective fwdObj = (ForwardingObjective) obj;
        if (fwdObj.meta() == null) {
            return true;
        }
        MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
        if (metaCrit == null) {
            return true;
        }
        meta = metaCrit.metadata();
    }
    return meta != 0 && ((meta ^ METADATA_MASK) <= METADATA_MASK);
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instructions(org.onosproject.net.flow.instructions.Instructions) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Example 50 with ForwardingObjective

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

the class FabricUtils method isSrMetadataSet.

/**
 * Verify if a given flag has been set into the metadata.
 *
 * @param obj the objective containing the metadata
 * @param flag the flag to verify
 * @return true if the flag is set, false otherwise
 */
public static boolean isSrMetadataSet(Objective obj, long flag) {
    long meta = 0;
    if (obj instanceof FilteringObjective) {
        FilteringObjective filtObj = (FilteringObjective) obj;
        if (filtObj.meta() == null) {
            return false;
        }
        Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
        if (metaIns == null) {
            return false;
        }
        meta = metaIns.metadata() & metaIns.metadataMask();
    } else if (obj instanceof ForwardingObjective) {
        ForwardingObjective fwdObj = (ForwardingObjective) obj;
        if (fwdObj.meta() == null) {
            return false;
        }
        MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
        if (metaCrit == null) {
            return false;
        }
        meta = metaCrit.metadata();
    }
    return (meta & flag) == flag;
}
Also used : MetadataCriterion(org.onosproject.net.flow.criteria.MetadataCriterion) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Instructions(org.onosproject.net.flow.instructions.Instructions) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective)

Aggregations

ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)88 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)37 Test (org.junit.Test)33 NextObjective (org.onosproject.net.flowobjective.NextObjective)32 Objective (org.onosproject.net.flowobjective.Objective)32 FilteringObjective (org.onosproject.net.flowobjective.FilteringObjective)28 List (java.util.List)24 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)20 FlowRule (org.onosproject.net.flow.FlowRule)20 DeviceId (org.onosproject.net.DeviceId)18 ObjectiveContext (org.onosproject.net.flowobjective.ObjectiveContext)18 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)16 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)15 GroupDescription (org.onosproject.net.group.GroupDescription)15 PiAction (org.onosproject.net.pi.runtime.PiAction)14 ArrayList (java.util.ArrayList)13