use of org.onosproject.net.pi.runtime.PiAction 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.PiAction 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;
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class IntProgrammableImpl method setSinkPort.
@Override
public boolean setSinkPort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
// process_set_source_sink.tb_set_sink
PiCriterion egressCriterion = PiCriterion.builder().matchExact(IntConstants.HDR_STANDARD_METADATA_EGRESS_SPEC, port.toLong()).build();
TrafficSelector sinkSelector = DefaultTrafficSelector.builder().matchPi(egressCriterion).build();
PiAction setSinkAct = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_INT_SET_SINK).build();
TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder().piTableAction(setSinkAct).build();
FlowRule sinkFlowRule = DefaultFlowRule.builder().withSelector(sinkSelector).withTreatment(sinkTreatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SINK).build();
flowRuleService.applyFlowRules(sinkFlowRule);
return true;
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class IntProgrammableImpl method setSourcePort.
@Override
public boolean setSourcePort(PortNumber port) {
if (!setupBehaviour()) {
return false;
}
// process_int_source_sink.tb_set_source for each host-facing port
PiCriterion ingressCriterion = PiCriterion.builder().matchExact(IntConstants.HDR_STANDARD_METADATA_INGRESS_PORT, port.toLong()).build();
TrafficSelector srcSelector = DefaultTrafficSelector.builder().matchPi(ingressCriterion).build();
PiAction setSourceAct = PiAction.builder().withId(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_INT_SET_SOURCE).build();
TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder().piTableAction(setSourceAct).build();
FlowRule srcFlowRule = DefaultFlowRule.builder().withSelector(srcSelector).withTreatment(srcTreatment).fromApp(appId).withPriority(DEFAULT_PRIORITY).makePermanent().forDevice(deviceId).forTable(IntConstants.INGRESS_PROCESS_INT_SOURCE_SINK_TB_SET_SOURCE).build();
flowRuleService.applyFlowRules(srcFlowRule);
return true;
}
use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.
the class P4RuntimeGroupTest method testInvalidPiActionProfileMember.
@Test
public void testInvalidPiActionProfileMember() {
PiActionParam param = new PiActionParam(PORT_PARAM_ID, "invalidString");
PiAction piAction = PiAction.builder().withId(EGRESS_PORT_ACTION_ID).withParameter(param).build();
PiActionProfileMember actionProfileMember = PiActionProfileMember.builder().forActionProfile(ACT_PROF_ID).withAction(piAction).withId(PiActionProfileMemberId.of(BASE_MEM_ID + 1)).build();
P4RuntimeWriteClient.WriteRequest writeRequest = client.write(P4_DEVICE_ID, PIPECONF);
writeRequest.insert(actionProfileMember);
P4RuntimeWriteClient.WriteResponse response = writeRequest.submitSync();
assertEquals(false, response.isSuccess());
assertEquals(1, response.all().size());
assertEquals("Wrong size for param 'port' of action 'set_egress_port', " + "expected no more than 2 bytes, but found 13", response.all().iterator().next().explanation());
}
Aggregations