use of org.onosproject.net.pi.model.PiActionParamId in project onos by opennetworkinglab.
the class P4InfoParserTest method testParseP4RuntimeTranslationAndOptional.
/**
* Tests parse method with P4Runtime translation fields and optional fields.
* @throws Exception if equality group objects dose not match as expected
*/
@Test
public void testParseP4RuntimeTranslationAndOptional() throws Exception {
PiPipelineModel model = P4InfoParser.parse(p4InfoUrl2);
// Generate a P4Info object from the file
final P4Info p4info;
try {
p4info = getP4InfoMessage(p4InfoUrl2);
} catch (IOException e) {
throw new P4InfoParserException("Unable to parse protobuf " + p4InfoUrl.toString(), e);
}
List<Table> tableMsgs = p4info.getTablesList();
PiTableId table0Id = PiTableId.of(tableMsgs.get(0).getPreamble().getName());
// parse tables
PiTableModel table0Model = model.table(table0Id).orElse(null);
// Check matchFields
List<MatchField> matchFieldList = tableMsgs.get(0).getMatchFieldsList();
List<PiMatchFieldModel> piMatchFieldList = new ArrayList<>();
for (MatchField matchFieldIter : matchFieldList) {
MatchField.MatchType matchType = matchFieldIter.getMatchType();
PiMatchType piMatchType;
switch(matchType) {
case EXACT:
piMatchType = PiMatchType.EXACT;
break;
case LPM:
piMatchType = PiMatchType.LPM;
break;
case TERNARY:
piMatchType = PiMatchType.TERNARY;
break;
case RANGE:
piMatchType = PiMatchType.RANGE;
break;
case OPTIONAL:
piMatchType = PiMatchType.OPTIONAL;
break;
default:
Assert.fail();
return;
}
if (matchFieldIter.getTypeName().getName().equals("mac_addr_t")) {
piMatchFieldList.add(new P4MatchFieldModel(PiMatchFieldId.of(matchFieldIter.getName()), P4MatchFieldModel.BIT_WIDTH_UNDEFINED, piMatchType));
} else {
piMatchFieldList.add(new P4MatchFieldModel(PiMatchFieldId.of(matchFieldIter.getName()), matchFieldIter.getBitwidth(), piMatchType));
}
}
assertThat("Incorrect order for matchFields", table0Model.matchFields(), IsIterableContainingInOrder.contains(piMatchFieldList.get(0), piMatchFieldList.get(1), piMatchFieldList.get(2), piMatchFieldList.get(3)));
// check table0 actionsRefs
List<ActionRef> actionRefList = tableMsgs.get(0).getActionRefsList();
assertThat("Incorrect size for actionRefs", actionRefList.size(), is(equalTo(4)));
// create action instances
// Set egress with string as parameter
PiActionId actionId = PiActionId.of("set_egress_port");
PiActionParamId piActionParamId = PiActionParamId.of("port");
PiActionParamModel actionParamModel = new P4ActionParamModel(piActionParamId, P4ActionParamModel.BIT_WIDTH_UNDEFINED);
ImmutableMap<PiActionParamId, PiActionParamModel> params = new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().put(piActionParamId, actionParamModel).build();
PiActionModel setEgressPortAction = new P4ActionModel(actionId, params);
// Set egress with 32 bit as parameter
actionId = PiActionId.of("set_egress_port2");
piActionParamId = PiActionParamId.of("port");
int bitWitdth = 32;
actionParamModel = new P4ActionParamModel(piActionParamId, bitWitdth);
params = new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().put(piActionParamId, actionParamModel).build();
PiActionModel setEgressPortAction2 = new P4ActionModel(actionId, params);
actionId = PiActionId.of("send_to_cpu");
PiActionModel sendToCpuAction = new P4ActionModel(actionId, new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().build());
actionId = PiActionId.of("drop");
PiActionModel dropAction = new P4ActionModel(actionId, new ImmutableMap.Builder<PiActionParamId, PiActionParamModel>().build());
// check table0 actions
assertThat("action dose not match", table0Model.actions(), IsIterableContainingInAnyOrder.containsInAnyOrder(setEgressPortAction, setEgressPortAction2, sendToCpuAction, dropAction));
}
use of org.onosproject.net.pi.model.PiActionParamId in project onos by opennetworkinglab.
the class PiActionParamIdTest method testConstruction.
/**
* Checks the construction of a PiActionParamId object.
*/
@Test
public void testConstruction() {
final String param = SRC_ADDR;
final PiActionParamId actionParamId = PiActionParamId.of(param);
assertThat(actionParamId, is(notNullValue()));
assertThat(actionParamId.id(), is(param));
}
use of org.onosproject.net.pi.model.PiActionParamId in project onos by opennetworkinglab.
the class PiActionParamTest method testConstruction.
/**
* Checks the construction of a PiActionParam object.
*/
@Test
public void testConstruction() {
ImmutableByteSequence value = copyFrom(0x0b010102);
final PiActionParamId piActionParamId = PiActionParamId.of(SRC_ADDR);
final PiActionParam piActionParam = new PiActionParam(piActionParamId, value);
assertThat(piActionParam, is(notNullValue()));
assertThat(piActionParam.id(), is(piActionParamId));
assertThat(piActionParam.value(), is(value));
}
use of org.onosproject.net.pi.model.PiActionParamId in project onos by opennetworkinglab.
the class MyTunnelApp method insertTunnelForwardRule.
/**
* Generates and insert a flow rule to perform the tunnel FORWARD/EGRESS
* function for the given switch, output port address and tunnel ID.
*
* @param switchId switch ID
* @param outPort output port where to forward tunneled packets
* @param tunId tunnel ID
* @param isEgress if true, perform tunnel egress action, otherwise forward
* packet as is to port
*/
private void insertTunnelForwardRule(DeviceId switchId, PortNumber outPort, int tunId, boolean isEgress) {
PiTableId tunnelForwardTableId = PiTableId.of("c_ingress.t_tunnel_fwd");
// Exact match on tun_id
PiMatchFieldId tunIdMatchFieldId = PiMatchFieldId.of("hdr.my_tunnel.tun_id");
PiCriterion match = PiCriterion.builder().matchExact(tunIdMatchFieldId, tunId).build();
// Action depend on isEgress parameter.
// if true, perform tunnel egress action on the given outPort, otherwise
// simply forward packet as is (set_out_port action).
PiActionParamId portParamId = PiActionParamId.of("port");
PiActionParam portParam = new PiActionParam(portParamId, (short) outPort.toLong());
final PiAction action;
if (isEgress) {
// Tunnel egress action.
// Remove MyTunnel header and forward to outPort.
PiActionId egressActionId = PiActionId.of("c_ingress.my_tunnel_egress");
action = PiAction.builder().withId(egressActionId).withParameter(portParam).build();
} else {
// Tunnel transit action.
// Forward the packet as is to outPort.
/*
* TODO EXERCISE: create action object for the transit case.
* Look at the t_tunnel_fwd table in the P4 program. Which of the 3
* actions can be used to simply set the output port? Get the full
* action name from the P4Info file, and use that when creating the
* PiActionId object. When creating the PiAction object, remember to
* add all action parameters as defined in the P4 program.
*
* Hint: the code will be similar to the case when isEgress is true.
*/
// Replace null with your solution.
action = null;
}
log.info("Inserting {} rule on switch {}: table={}, match={}, action={}", isEgress ? "EGRESS" : "TRANSIT", switchId, tunnelForwardTableId, match, action);
insertPiFlowRule(switchId, tunnelForwardTableId, match, action);
}
use of org.onosproject.net.pi.model.PiActionParamId in project onos by opennetworkinglab.
the class InstructionCodecTest method piInstructionEncodingTest.
/**
* Tests the encoding of protocol-independent instructions.
*/
@Test
public void piInstructionEncodingTest() {
PiActionId actionId = PiActionId.of("set_egress_port");
PiActionParamId actionParamId = PiActionParamId.of("port");
PiActionParam actionParam = new PiActionParam(actionParamId, ImmutableByteSequence.copyFrom(10));
PiTableAction action = PiAction.builder().withId(actionId).withParameter(actionParam).build();
final PiInstruction actionInstruction = Instructions.piTableAction(action);
final ObjectNode actionInstructionJson = instructionCodec.encode(actionInstruction, context);
assertThat(actionInstructionJson, matchesInstruction(actionInstruction));
PiTableAction actionGroupId = PiActionProfileGroupId.of(10);
final PiInstruction actionGroupIdInstruction = Instructions.piTableAction(actionGroupId);
final ObjectNode actionGroupIdInstructionJson = instructionCodec.encode(actionGroupIdInstruction, context);
assertThat(actionGroupIdInstructionJson, matchesInstruction(actionGroupIdInstruction));
PiTableAction actionProfileMemberId = PiActionProfileMemberId.of(10);
final PiInstruction actionProfileMemberIdInstruction = Instructions.piTableAction(actionProfileMemberId);
final ObjectNode actionProfileMemberIdInstructionJson = instructionCodec.encode(actionProfileMemberIdInstruction, context);
assertThat(actionProfileMemberIdInstructionJson, matchesInstruction(actionProfileMemberIdInstruction));
}
Aggregations