use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
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(P4InfoConstants.FABRIC_INGRESS_ACL_SET_NEXT_ID_ACL).withParameter(new PiActionParam(P4InfoConstants.NEXT_ID, NEXT_ID_1)).build();
TrafficSelector expectedSelector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IPV4_UNICAST_ADDR).matchPi(PiCriterion.builder().matchTernary(P4InfoConstants.HDR_IG_PORT_TYPE, PORT_TYPE_EDGE, PORT_TYPE_MASK).build()).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(P4InfoConstants.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(P4InfoConstants.HDR_IG_PORT_TYPE, PORT_TYPE_INFRA, PORT_TYPE_MASK).build()).build();
expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(P4InfoConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(expectedSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class ForwardingObjectiveTranslatorTest method testSpecificForward.
private void testSpecificForward(PiTableId expectedTableId, TrafficSelector expectedSelector, TrafficSelector selector, Integer nextId) throws FabricPipelinerException {
TrafficTreatment setNextIdTreatment;
if (nextId == null) {
// Ref: RoutingRulePopulator.java->revokeIpRuleForRouter
setNextIdTreatment = DefaultTrafficTreatment.builder().piTableAction(PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_FORWARDING_NOP_ROUTING_V4).build()).build();
} else {
PiActionParam nextIdParam = new PiActionParam(P4InfoConstants.NEXT_ID, nextId);
PiAction.Builder setNextIdAction = PiAction.builder().withParameter(nextIdParam);
if (expectedTableId.equals(P4InfoConstants.FABRIC_INGRESS_FORWARDING_BRIDGING)) {
setNextIdAction.withId(P4InfoConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_BRIDGING);
} else if (expectedTableId.equals(P4InfoConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V4)) {
setNextIdAction.withId(P4InfoConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_ROUTING_V4);
} else if (expectedTableId.equals(P4InfoConstants.FABRIC_INGRESS_FORWARDING_ROUTING_V6)) {
setNextIdAction.withId(P4InfoConstants.FABRIC_INGRESS_FORWARDING_SET_NEXT_ID_ROUTING_V6);
}
setNextIdTreatment = DefaultTrafficTreatment.builder().piTableAction(setNextIdAction.build()).build();
}
testSpecificForward(expectedTableId, expectedSelector, selector, nextId, setNextIdTreatment);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class NextObjectiveTranslatorTest method setup.
@Before
public void setup() {
super.doSetup();
translatorHashed = new NextObjectiveTranslator(DEVICE_ID, capabilitiesHashed);
// TODO: add profile with simple next or remove test
// translatorSimple = new NextObjectiveTranslator(DEVICE_ID, capabilitiesSimple);
PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(P4InfoConstants.HDR_NEXT_ID, NEXT_ID_1).build();
TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
PiAction piAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_SET_VLAN).withParameter(new PiActionParam(P4InfoConstants.VLAN_ID, VLAN_100.toShort())).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(piAction).build();
vlanMetaFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
piAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_SET_MPLS_LABEL).withParameter(new PiActionParam(P4InfoConstants.LABEL, MPLS_10.toInt())).build();
treatment = DefaultTrafficTreatment.builder().piTableAction(piAction).build();
mplsFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class NextObjectiveTranslatorTest method testHashedOutput.
/**
* Test program ecmp output group for Hashed table.
*/
@Test
public void testHashedOutput() throws Exception {
PiAction piAction1 = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(P4InfoConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.DMAC, HOST_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, HOST_MAC.toBytes())).withParameter(new PiActionParam(P4InfoConstants.PORT_NUM, PORT_1.toLong())).build();
TrafficTreatment treatment1 = DefaultTrafficTreatment.builder().piTableAction(piAction1).build();
TrafficTreatment treatment2 = DefaultTrafficTreatment.builder().piTableAction(piAction2).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();
// Expected group
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).addGroup(expectedGroup).build();
assertEquals(expectedTranslation, actualTranslation);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project fabric-tna by stratum.
the class FabricIntProgrammableTest method buildFilterConfigFlow.
private FlowRule buildFilterConfigFlow(DeviceId deviceId) {
final PiActionParam hopLatencyMask = new PiActionParam(P4InfoConstants.HOP_LATENCY_MASK, DEFAULT_QMASK);
final PiActionParam timestampMask = new PiActionParam(P4InfoConstants.TIMESTAMP_MASK, DEFAULT_TIMESTAMP_MASK);
final PiAction quantizeAction = PiAction.builder().withId(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_SET_CONFIG).withParameter(hopLatencyMask).withParameter(timestampMask).build();
final TrafficTreatment quantizeTreatment = DefaultTrafficTreatment.builder().piTableAction(quantizeAction).build();
return DefaultFlowRule.builder().forDevice(deviceId).makePermanent().withPriority(DEFAULT_PRIORITY).withTreatment(quantizeTreatment).fromApp(APP_ID).forTable(P4InfoConstants.FABRIC_EGRESS_INT_EGRESS_CONFIG).build();
}
Aggregations