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);
}
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();
}
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();
}
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);
}
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);
}
Aggregations