use of org.onosproject.net.pi.runtime.PiActionParam 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);
}
use of org.onosproject.net.pi.runtime.PiActionParam 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);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method testSimpleOutputWithVlanTranslation.
/**
* Test program set vlan and output rule for Simple table.
*/
@Test
public void testSimpleOutputWithVlanTranslation() throws FabricPipelinerException {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setVlanId(VLAN_100).setOutput(PORT_1).build();
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
testSimple(treatment, piAction);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class FilteringObjectiveTranslatorTest method buildExpectedFwdClassifierRule.
private Collection<FlowRule> buildExpectedFwdClassifierRule(PortNumber inPort, MacAddress dstMac, MacAddress dstMacMask, short ethType, byte fwdClass) {
PiActionParam classParam = new PiActionParam(P4InfoConstants.FWD_TYPE, ImmutableByteSequence.copyFrom(fwdClass));
PiAction fwdClassifierAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_FILTERING_SET_FORWARDING_TYPE).withParameter(classParam).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(fwdClassifierAction).build();
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder().matchInPort(inPort);
if (dstMacMask != null) {
sbuilder.matchEthDstMasked(dstMac, dstMacMask);
} else {
sbuilder.matchEthDstMasked(dstMac, MacAddress.EXACT_MASK);
}
// Special case for MPLS UNICAST forwarding, need to build 2 rules for MPLS+IPv4 and MPLS+IPv6
if (ethType == Ethernet.MPLS_UNICAST) {
return buildExpectedFwdClassifierRulesMpls(fwdClassifierAction, treatment, sbuilder);
}
sbuilder.matchPi(PiCriterion.builder().matchExact(P4InfoConstants.HDR_IP_ETH_TYPE, ethType).build());
TrafficSelector selector = sbuilder.build();
return List.of(DefaultFlowRule.builder().withPriority(PRIORITY).withSelector(selector).withTreatment(treatment).fromApp(APP_ID).forDevice(DEVICE_ID).makePermanent().forTable(P4InfoConstants.FABRIC_INGRESS_FILTERING_FWD_CLASSIFIER).build());
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class FilteringObjectiveTranslatorTest method buildExpectedVlanInPortRule.
private FlowRule buildExpectedVlanInPortRule(PortNumber inPort, VlanId vlanId, VlanId innerVlanId, VlanId internalVlan, byte portType, TableId tableId) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder().matchInPort(inPort);
PiAction piAction;
selector.matchPi(buildPiCriterionVlan(vlanId, innerVlanId));
if (!vlanValid(vlanId)) {
piAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN).withParameter(new PiActionParam(P4InfoConstants.VLAN_ID, internalVlan.toShort())).withParameter(new PiActionParam(P4InfoConstants.PORT_TYPE, portType)).build();
} else {
selector.matchVlanId(vlanId);
if (vlanValid(innerVlanId)) {
selector.matchInnerVlanId(innerVlanId);
}
piAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_FILTERING_PERMIT).withParameter(new PiActionParam(P4InfoConstants.PORT_TYPE, portType)).build();
}
return DefaultFlowRule.builder().withPriority(PRIORITY).withSelector(selector.build()).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).forDevice(DEVICE_ID).makePermanent().forTable(tableId).build();
}
Aggregations