use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class FabricInterpreterTest method testNextTreatmentSimpleOutput.
/* Next control block */
/**
* Map treatment to output action.
*/
@Test
public void testNextTreatmentSimpleOutput() throws Exception {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(PORT_1).build();
PiAction mappedAction = interpreter.mapTreatment(treatment, FabricConstants.FABRIC_INGRESS_NEXT_SIMPLE);
PiActionParam param = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong());
PiAction expectedAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_OUTPUT_SIMPLE).withParameter(param).build();
assertEquals(expectedAction, mappedAction);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class FabricInterpreterTest method testNextVlanTreatment.
/**
* Map treatment to set_vlan_output action.
*/
@Test
public void testNextVlanTreatment() throws Exception {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setVlanId(VLAN_100).build();
PiAction mappedAction = interpreter.mapTreatment(treatment, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN);
PiActionParam vlanParam = new PiActionParam(FabricConstants.VLAN_ID, VLAN_100.toShort());
PiAction expectedAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_PRE_NEXT_SET_VLAN).withParameter(vlanParam).build();
assertEquals(expectedAction, mappedAction);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class FabricInterpreterTest method testNextTreatmentHashedRoutingV4.
/**
* Map treatment for hashed table to routing v4 action.
*/
@Test
public void testNextTreatmentHashedRoutingV4() throws Exception {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthSrc(SRC_MAC).setEthDst(DST_MAC).setOutput(PORT_1).build();
PiAction mappedAction = interpreter.mapTreatment(treatment, FabricConstants.FABRIC_INGRESS_NEXT_HASHED);
PiActionParam ethSrcParam = new PiActionParam(FabricConstants.SMAC, SRC_MAC.toBytes());
PiActionParam ethDstParam = new PiActionParam(FabricConstants.DMAC, DST_MAC.toBytes());
PiActionParam portParam = new PiActionParam(FabricConstants.PORT_NUM, PORT_1.toLong());
PiAction expectedAction = PiAction.builder().withId(FabricConstants.FABRIC_INGRESS_NEXT_ROUTING_HASHED).withParameters(ImmutableList.of(ethSrcParam, ethDstParam, portParam)).build();
assertEquals(expectedAction, mappedAction);
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class PiFlowRuleTranslatorImpl method checkPiAction.
private static PiTableAction checkPiAction(PiAction piAction, PiTableModel table) throws PiTranslationException {
// Table supports this action?
PiActionModel actionModel = table.action(piAction.id()).orElseThrow(() -> new PiTranslationException(format("Not such action '%s' for table '%s'", piAction.id(), table.id())));
// Is the number of runtime parameters correct?
if (actionModel.params().size() != piAction.parameters().size()) {
throw new PiTranslationException(format("Wrong number of runtime parameters for action '%s', expected %d but found %d", actionModel.id(), actionModel.params().size(), piAction.parameters().size()));
}
// Forge a new action instance with well-sized parameters.
// The same comment as in typeCheckFieldMatch() about duplicating field match instances applies here.
PiAction.Builder newActionBuilder = PiAction.builder().withId(piAction.id());
for (PiActionParam param : piAction.parameters()) {
PiActionParamModel paramModel = actionModel.param(param.id()).orElseThrow(() -> new PiTranslationException(format("Not such parameter '%s' for action '%s'", param.id(), actionModel)));
try {
newActionBuilder.withParameter(new PiActionParam(param.id(), paramModel.hasBitWidth() ? param.value().fit(paramModel.bitWidth()) : param.value()));
} catch (ByteSequenceTrimException e) {
throw new PiTranslationException(format("Size mismatch for parameter '%s' of action '%s': %s", param.id(), piAction.id(), e.getMessage()));
}
}
return newActionBuilder.build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class FabricPipeliner method ingressVlanRule.
public FlowRule ingressVlanRule(long port, boolean vlanValid, int vlanId) {
final TrafficSelector selector = DefaultTrafficSelector.builder().add(Criteria.matchInPort(PortNumber.portNumber(port))).add(PiCriterion.builder().matchExact(FabricConstants.HDR_VLAN_IS_VALID, vlanValid ? ONE : ZERO).build()).build();
final TrafficTreatment treatment = DefaultTrafficTreatment.builder().piTableAction(PiAction.builder().withId(vlanValid ? FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT : FabricConstants.FABRIC_INGRESS_FILTERING_PERMIT_WITH_INTERNAL_VLAN).withParameter(new PiActionParam(FabricConstants.VLAN_ID, vlanId)).withParameter(new PiActionParam(FabricConstants.PORT_TYPE, PORT_TYPE_INTERNAL)).build()).build();
return DefaultFlowRule.builder().withSelector(selector).withTreatment(treatment).forTable(FabricConstants.FABRIC_INGRESS_FILTERING_INGRESS_PORT_VLAN).makePermanent().withPriority(DEFAULT_FLOW_PRIORITY).forDevice(deviceId).fromApp(appId).build();
}
Aggregations