use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.
the class NextObjectiveTranslatorTest method testBroadcastOutput.
/**
* Test program output group for Broadcast table.
*/
@Test
public void testBroadcastOutput() throws FabricPipelinerException {
TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().popVlan().setOutput(PORT_2).build();
NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(treatment1).addTreatment(treatment2).withMeta(VLAN_META).withType(NextObjective.Type.BROADCAST).makePermanent().fromApp(APP_ID).add();
ObjectiveTranslation actualTranslation = translatorHashed.doTranslate(nextObjective);
// Should generate 3 flows:
// - Multicast table flow that matches on next-id and set multicast group (1)
// - Egress VLAN pop handling for treatment2 (0)
// - Next VLAN flow (2)
// And 2 groups:
// - Multicast group
// Expected multicast table flow rule.
PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(P4InfoConstants.HDR_NEXT_ID, NEXT_ID_1).build();
TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
PiAction setMcGroupAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_SET_MCAST_GROUP_ID).withParameter(new PiActionParam(P4InfoConstants.GROUP_ID, NEXT_ID_1)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(setMcGroupAction).build();
FlowRule expectedHashedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(nextObjective.priority()).forTable(P4InfoConstants.FABRIC_INGRESS_NEXT_MULTICAST).withSelector(nextIdSelector).withTreatment(treatment).build();
// Expected egress VLAN_PUSH flow rule.
PiCriterion egressVlanTableMatch = PiCriterion.builder().matchExact(P4InfoConstants.HDR_EG_PORT, PORT_1.toLong()).build();
TrafficSelector selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
PiAction piActionForEgressVlan = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_PUSH_VLAN).build();
TrafficTreatment treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
FlowRule expectedEgressVlanPushRule = 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 egress VLAN POP flow rule.
egressVlanTableMatch = PiCriterion.builder().matchExact(P4InfoConstants.HDR_EG_PORT, PORT_2.toLong()).build();
selectorForEgressVlan = DefaultTrafficSelector.builder().matchPi(egressVlanTableMatch).matchVlanId(VLAN_100).build();
piActionForEgressVlan = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_EGRESS_NEXT_POP_VLAN).build();
treatmentForEgressVlan = DefaultTrafficTreatment.builder().piTableAction(piActionForEgressVlan).build();
FlowRule expectedEgressVlanPopRule = 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 ALL group.
TrafficTreatment allGroupTreatment1 = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
TrafficTreatment allGroupTreatment2 = DefaultTrafficTreatment.builder().setOutput(PORT_2).build();
List<TrafficTreatment> allTreatments = ImmutableList.of(allGroupTreatment1, allGroupTreatment2);
List<GroupBucket> allBuckets = allTreatments.stream().map(DefaultGroupBucket::createAllGroupBucket).collect(Collectors.toList());
GroupBuckets allGroupBuckets = new GroupBuckets(allBuckets);
GroupKey allGroupKey = new DefaultGroupKey(FabricUtils.KRYO.serialize(NEXT_ID_1));
GroupDescription expectedAllGroup = new DefaultGroupDescription(DEVICE_ID, GroupDescription.Type.ALL, allGroupBuckets, allGroupKey, NEXT_ID_1, APP_ID);
ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedHashedFlowRule).addFlowRule(vlanMetaFlowRule).addFlowRule(expectedEgressVlanPushRule).addFlowRule(expectedEgressVlanPopRule).addGroup(expectedAllGroup).build();
assertEquals(expectedTranslation, actualTranslation);
}
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);
}
use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.
the class FabricInterpreterTest method testNextMplsTreatment.
/**
* Map treatment to set_mpls action.
*/
@Test
public void testNextMplsTreatment() throws Exception {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(MPLS_10).build();
PiAction mappedAction = interpreter.mapTreatment(treatment, P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS);
PiActionParam mplsParam = new PiActionParam(P4InfoConstants.LABEL, MPLS_10.toInt());
PiAction expectedAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_SET_MPLS_LABEL).withParameter(mplsParam).build();
assertEquals(expectedAction, mappedAction);
}
use of org.onosproject.net.pi.runtime.PiAction in project fabric-tna by stratum.
the class FabricInterpreterTest method testNextVlanTreatment.
/**
* Map treatment to set_vlan_output action.
*/
@Test
public void testNextVlanTreatment() throws Exception {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setVlanId(VLAN_100).build();
PiAction mappedAction = interpreter.mapTreatment(treatment, P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN);
PiActionParam vlanParam = new PiActionParam(P4InfoConstants.VLAN_ID, VLAN_100.toShort());
PiAction expectedAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_SET_VLAN).withParameter(vlanParam).build();
assertEquals(expectedAction, mappedAction);
}
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);
}
Aggregations