Search in sources :

Example 41 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.

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(P4InfoConstants.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(P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED).withSelector(nextIdSelector).withTreatment(treatment).build();
    // First egress rule - port1
    PortNumber outPort = outputPort(treatment1);
    PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(P4InfoConstants.HDR_EG_PORT, outPort.toLong()).build();
    TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    PiAction piActionForEgressVlan = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
    TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
    FlowRule expectedEgressVlanPopRule1 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(P4InfoConstants.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(P4InfoConstants.HDR_EG_PORT, outPort.toLong()).build();
    selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
    FlowRule expectedEgressVlanPopRule2 = DefaultFlowRule.builder().withSelector(selectorForEgressVlan).withTreatment(treatmentForEgressVlan).forTable(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_EGRESS_VLAN).makePermanent().withPriority(nextObjective.priority()).forDevice(DEVICE_ID).fromApp(APP_ID).build();
    // Expected group
    PiAction piAction1 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, SPINE1_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.PORT_NUM, PORT_1.toLong())).build();
    PiAction piAction2 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, SPINE2_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.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(P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED, P4InfoConstants.FABRIC_INGRESS_NEXT_HASHED_PROFILE, 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 42 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.

the class FabricIntProgrammableTest method buildWatchlistRule.

private FlowRule buildWatchlistRule(IpPrefix ipPrefix, Criterion.Type criterionType) {
    // Flow rule that we expected.
    TrafficSelector.Builder expectedSelector = DefaultTrafficSelector.builder();
    PiCriterion.Builder expectedPiCriterion = PiCriterion.builder().matchExact(P4InfoConstants.HDR_IPV4_VALID, 1);
    if (ipPrefix != null && criterionType == Criterion.Type.IPV4_DST) {
        expectedSelector.matchIPDst(ipPrefix);
    } else if (ipPrefix != null && criterionType == Criterion.Type.IPV4_SRC) {
        expectedSelector.matchIPSrc(ipPrefix);
    }
    expectedSelector.matchPi(expectedPiCriterion.build());
    PiAction expectedPiAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_INT_WATCHLIST_MARK_TO_REPORT).build();
    TrafficTreatment expectedTreatment = DefaultTrafficTreatment.builder().piTableAction(expectedPiAction).build();
    return DefaultFlowRule.builder().forDevice(LEAF_DEVICE_ID).withSelector(expectedSelector.build()).withTreatment(expectedTreatment).fromApp(APP_ID).withPriority(DEFAULT_PRIORITY).forTable(P4InfoConstants.FABRIC_INGRESS_INT_WATCHLIST_WATCHLIST).makePermanent().build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 43 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.

the class FabricIntProgrammableTest method buildCollectorWatchlistRule.

private FlowRule buildCollectorWatchlistRule(DeviceId deviceId) {
    final PiAction watchlistAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_INT_WATCHLIST_NO_REPORT_COLLECTOR).build();
    final TrafficTreatment watchlistTreatment = DefaultTrafficTreatment.builder().piTableAction(watchlistAction).build();
    final PiCriterion piCriterion = PiCriterion.builder().matchExact(P4InfoConstants.HDR_IPV4_VALID, 1).matchRange(P4InfoConstants.HDR_L4_DPORT, COLLECTOR_PORT.toInt(), COLLECTOR_PORT.toInt()).build();
    final TrafficSelector watchlistSelector = DefaultTrafficSelector.builder().matchIPDst(COLLECTOR_IP.toIpPrefix()).matchIPProtocol(IPv4.PROTOCOL_UDP).matchPi(piCriterion).build();
    return DefaultFlowRule.builder().forDevice(deviceId).withSelector(watchlistSelector).withTreatment(watchlistTreatment).withPriority(DEFAULT_PRIORITY + 10).forTable(P4InfoConstants.FABRIC_INGRESS_INT_WATCHLIST_WATCHLIST).fromApp(APP_ID).makePermanent().build();
}
Also used : PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 44 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.

the class FabricInterpreterTest method testAclTreatmentWipeDeferred.

/**
 * Map wipeDeferred treatment to DROP for ACL table.
 */
@Test
public void testAclTreatmentWipeDeferred() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().wipeDeferred().build();
    PiAction mappedAction = interpreter.mapTreatment(treatment, P4InfoConstants.FABRIC_INGRESS_ACL_ACL);
    PiAction expectedAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_ACL_DROP).build();
    assertEquals(expectedAction, mappedAction);
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 45 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.

the class FabricInterpreterTest method testAclTreatmentEmpty.

/**
 * Map empty treatment to NOP for ACL table.
 */
@Test
public void testAclTreatmentEmpty() throws Exception {
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
    PiAction mappedAction = interpreter.mapTreatment(treatment, P4InfoConstants.FABRIC_INGRESS_ACL_ACL);
    PiAction expectedAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_ACL_NOP_ACL).build();
    assertEquals(expectedAction, mappedAction);
}
Also used : DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Aggregations

PiAction (org.onosproject.net.pi.runtime.PiAction)117 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)74 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)69 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)68 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)57 Test (org.junit.Test)44 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)44 FlowRule (org.onosproject.net.flow.FlowRule)39 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)33 GroupDescription (org.onosproject.net.group.GroupDescription)22 List (java.util.List)15 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)14 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)14 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)13 PortNumber (org.onosproject.net.PortNumber)9 NextObjective (org.onosproject.net.flowobjective.NextObjective)9 GroupBucket (org.onosproject.net.group.GroupBucket)9 PiActionId (org.onosproject.net.pi.model.PiActionId)9 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)9