use of org.onosproject.net.pi.runtime.PiActionParam 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());
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class P4RuntimeGroupTest method outputMember.
private static PiActionProfileMember outputMember(short portNum) {
PiActionParam param = new PiActionParam(PORT_PARAM_ID, ImmutableByteSequence.copyFrom(portNum));
PiAction piAction = PiAction.builder().withId(EGRESS_PORT_ACTION_ID).withParameter(param).build();
return PiActionProfileMember.builder().forActionProfile(ACT_PROF_ID).withAction(piAction).withId(PiActionProfileMemberId.of(BASE_MEM_ID + portNum)).build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class ActionCodec method decode.
@Override
protected PiAction decode(P4RuntimeOuterClass.Action message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException, CodecException {
final P4InfoBrowser.EntityBrowser<P4InfoOuterClass.Action.Param> paramInfo = browser.actionParams(message.getActionId());
final String actionName = browser.actions().getById(message.getActionId()).getPreamble().getName();
final PiAction.Builder builder = PiAction.builder().withId(PiActionId.of(actionName));
for (P4RuntimeOuterClass.Action.Param p : message.getParamsList()) {
final P4InfoOuterClass.Action.Param actionParam = paramInfo.getById(p.getParamId());
final ImmutableByteSequence value;
if (browser.isTypeString(actionParam.getTypeName())) {
value = copyFrom(new String(p.getValue().toByteArray()));
} else {
try {
value = copyAndFit(p.getValue().asReadOnlyByteBuffer(), actionParam.getBitwidth());
} catch (ImmutableByteSequence.ByteSequenceTrimException e) {
throw new CodecException(e.getMessage());
}
}
builder.withParameter(new PiActionParam(PiActionParamId.of(actionParam.getName()), value));
}
return builder.build();
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class DecodeInstructionCodecHelper method decodePi.
/**
* Decodes a protocol-independent instruction.
*
* @return instruction object decoded from the JSON
* @throws IllegalArgumentException if the JSON is invalid
*/
private Instruction decodePi() {
String subType = nullIsIllegal(json.get(InstructionCodec.SUBTYPE), InstructionCodec.SUBTYPE + InstructionCodec.ERROR_MESSAGE).asText();
if (subType.equals(PiTableAction.Type.ACTION.name())) {
PiActionId piActionId = PiActionId.of(nullIsIllegal(json.get(InstructionCodec.PI_ACTION_ID), InstructionCodec.PI_ACTION_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asText());
JsonNode params = json.get(InstructionCodec.PI_ACTION_PARAMS);
PiAction.Builder builder = PiAction.builder();
PiActionParam piActionParam;
PiActionParamId piActionParamId;
if (params != null) {
for (Map.Entry<String, String> param : ((Map<String, String>) (context.mapper().convertValue(params, Map.class))).entrySet()) {
piActionParamId = PiActionParamId.of(param.getKey());
piActionParam = new PiActionParam(piActionParamId, ImmutableByteSequence.copyFrom(HexString.fromHexString(param.getValue(), null)));
builder.withParameter(piActionParam);
}
}
return Instructions.piTableAction(builder.withId(piActionId).build());
} else if (subType.equals(PiTableAction.Type.ACTION_PROFILE_GROUP_ID.name())) {
PiActionProfileGroupId piActionGroupId = PiActionProfileGroupId.of(nullIsIllegal(json.get(InstructionCodec.PI_ACTION_PROFILE_GROUP_ID), InstructionCodec.PI_ACTION_PROFILE_GROUP_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
return Instructions.piTableAction(piActionGroupId);
} else if (subType.equals(PiTableAction.Type.ACTION_PROFILE_MEMBER_ID.name())) {
PiActionProfileMemberId piActionProfileMemberId = PiActionProfileMemberId.of(nullIsIllegal(json.get(InstructionCodec.PI_ACTION_PROFILE_MEMBER_ID), InstructionCodec.PI_ACTION_PROFILE_MEMBER_ID + InstructionCodec.MISSING_MEMBER_MESSAGE).asInt());
return Instructions.piTableAction(piActionProfileMemberId);
}
// TODO: implement JSON decoder for ACTION_SET
throw new IllegalArgumentException("Protocol-independent Instruction subtype " + subType + " is not supported");
}
use of org.onosproject.net.pi.runtime.PiActionParam in project onos by opennetworkinglab.
the class EncodeInstructionCodecHelper method encodePi.
/**
* Encode a protocol-independent instruction.
*
* @param result json node that the instruction attributes are added to
*/
private void encodePi(ObjectNode result) {
PiInstruction piInstruction = (PiInstruction) instruction;
result.put(InstructionCodec.SUBTYPE, piInstruction.action().type().name());
switch(piInstruction.action().type()) {
case ACTION:
final PiAction piAction = (PiAction) piInstruction.action();
result.put(InstructionCodec.PI_ACTION_ID, piAction.id().id());
final ObjectNode jsonActionParams = context.mapper().createObjectNode();
for (PiActionParam actionParam : piAction.parameters()) {
jsonActionParams.put(actionParam.id().id(), HexString.toHexString(actionParam.value().asArray(), null));
}
result.set(InstructionCodec.PI_ACTION_PARAMS, jsonActionParams);
break;
case ACTION_PROFILE_GROUP_ID:
final PiActionProfileGroupId groupId = (PiActionProfileGroupId) piInstruction.action();
result.put(InstructionCodec.PI_ACTION_PROFILE_GROUP_ID, groupId.id());
break;
case ACTION_PROFILE_MEMBER_ID:
final PiActionProfileMemberId memberId = (PiActionProfileMemberId) piInstruction.action();
result.put(InstructionCodec.PI_ACTION_PROFILE_MEMBER_ID, memberId.id());
break;
// TODO: implement JSON encoder for ACTION_SET
default:
throw new IllegalArgumentException("Cannot convert protocol-independent subtype of" + piInstruction.action().type().name());
}
}
Aggregations