use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method testHashedOutput.
/**
* Test program ecmp output group for Hashed table.
*/
@Test
public void testHashedOutput() throws Exception {
PiAction piAction1 = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_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, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.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(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();
// 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(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).addGroup(expectedGroup).build();
assertEquals(expectedTranslation, actualTranslation);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method testSimpleOutputWithMacTranslation.
/**
* Test program set mac and output rule for Simple table.
*/
@Test
public void testSimpleOutputWithMacTranslation() throws FabricPipelinerException {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(HOST_MAC).setOutput(PORT_1).build();
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
testSimple(treatment, piAction);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method setup.
@Before
public void setup() {
super.doSetup();
translatorHashed = new NextObjectiveTranslator(DEVICE_ID, capabilitiesHashed);
translatorSimple = new NextObjectiveTranslator(DEVICE_ID, capabilitiesSimple);
PiCriterion nextIdCriterion = PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build();
TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(nextIdCriterion).build();
PiAction piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_VLAN).withParameter(new PiActionParam(FabricConstants.VLAN_ID, VLAN_100.toShort())).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(piAction).build();
vlanMetaFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
piAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_MPLS_LABEL).withParameter(new PiActionParam(FabricConstants.LABEL, MPLS_10.toInt())).build();
treatment = DefaultTrafficTreatment.builder().piTableAction(piAction).build();
mplsFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(FabricConstants.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 onos by opennetworkinglab.
the class NextObjectiveTranslatorTest method testRouteAndPushNextObjective.
/**
* Test Route and Push Next Objective (set mac, set double vlan and output port).
*/
@Test
public void testRouteAndPushNextObjective() throws FabricPipelinerException {
TrafficTreatment routeAndPushTreatment = DefaultTrafficTreatment.builder().setEthSrc(ROUTER_MAC).setEthDst(HOST_MAC).setOutput(PORT_1).setVlanId(VLAN_100).pushVlan().setVlanId(VLAN_200).build();
NextObjective nextObjective = DefaultNextObjective.builder().withId(NEXT_ID_1).withPriority(PRIORITY).addTreatment(routeAndPushTreatment).withType(NextObjective.Type.SIMPLE).makePermanent().fromApp(APP_ID).add();
ObjectiveTranslation actualTranslation = translatorSimple.translate(nextObjective);
PiAction piActionRouting = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_SIMPLE).withParameter(new PiActionParam(FabricConstants.SMAC, ROUTER_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.DMAC, HOST_MAC.toBytes())).withParameter(new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong())).build();
PiAction piActionPush = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_DOUBLE_VLAN).withParameter(new PiActionParam(FabricConstants.INNER_VLAN_ID, VLAN_100.toShort())).withParameter(new PiActionParam(FabricConstants.OUTER_VLAN_ID, VLAN_200.toShort())).build();
TrafficSelector nextIdSelector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(FabricConstants.HDR_NEXT_ID, NEXT_ID_1).build()).build();
FlowRule expectedFlowRuleRouting = DefaultFlowRule.builder().forDevice(DEVICE_ID).fromApp(APP_ID).makePermanent().withPriority(0).forTable(FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE).withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionRouting).build()).build();
FlowRule expectedFlowRuleDoublePush = DefaultFlowRule.builder().withSelector(nextIdSelector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piActionPush).build()).forTable(FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN).makePermanent().withPriority(0).forDevice(DEVICE_ID).fromApp(APP_ID).build();
ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder().addFlowRule(expectedFlowRuleDoublePush).addFlowRule(expectedFlowRuleRouting).build();
assertEquals(expectedTranslation, actualTranslation);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class IntProgrammableImpl method init.
@Override
public boolean init() {
if (!setupBehaviour()) {
return false;
}
PiActionParam transitIdParam = new PiActionParam(IntConstants.SWITCH_ID, ImmutableByteSequence.copyFrom(Integer.parseInt(deviceId.toString().substring(deviceId.toString().length() - 2))));
TrafficSelector selector = DefaultTrafficSelector.builder().matchPi(PiCriterion.builder().matchExact(IntConstants.HDR_INT_IS_VALID, (byte) 0x01).build()).build();
PiAction transitAction = PiAction.builder().withId(IntConstants.EGRESS_PROCESS_INT_TRANSIT_INIT_METADATA).withParameter(transitIdParam).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(transitAction).build();
FlowRule transitFlowRule = DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(IntConstants.EGRESS_PROCESS_INT_TRANSIT_TB_INT_INSERT).build();
flowRuleService.applyFlowRules(transitFlowRule);
return true;
}
Aggregations