Search in sources :

Example 66 with PiActionParam

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());
}
Also used : P4RuntimeWriteClient(org.onosproject.p4runtime.api.P4RuntimeWriteClient) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 67 with PiActionParam

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();
}
Also used : PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 68 with PiActionParam

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();
}
Also used : PiAction(org.onosproject.net.pi.runtime.PiAction) ByteString(com.google.protobuf.ByteString) PiAction(org.onosproject.net.pi.runtime.PiAction) P4InfoOuterClass(p4.config.v1.P4InfoOuterClass) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) P4InfoBrowser(org.onosproject.p4runtime.ctl.utils.P4InfoBrowser) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 69 with PiActionParam

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");
}
Also used : PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiActionId(org.onosproject.net.pi.model.PiActionId) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Map(java.util.Map) PiAction(org.onosproject.net.pi.runtime.PiAction)

Example 70 with PiActionParam

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());
    }
}
Also used : PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)102 PiAction (org.onosproject.net.pi.runtime.PiAction)90 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)50 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)50 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)39 TrafficSelector (org.onosproject.net.flow.TrafficSelector)39 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)39 Test (org.junit.Test)30 FlowRule (org.onosproject.net.flow.FlowRule)27 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)21 GroupDescription (org.onosproject.net.group.GroupDescription)11 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)10 DefaultNextObjective (org.onosproject.net.flowobjective.DefaultNextObjective)8 NextObjective (org.onosproject.net.flowobjective.NextObjective)8 PortNumber (org.onosproject.net.PortNumber)7 DefaultGroupBucket (org.onosproject.net.group.DefaultGroupBucket)7 GroupBucket (org.onosproject.net.group.GroupBucket)7 GroupBuckets (org.onosproject.net.group.GroupBuckets)7 PiActionProfileGroupId (org.onosproject.net.pi.runtime.PiActionProfileGroupId)7 PiGroupKey (org.onosproject.net.pi.runtime.PiGroupKey)6