Search in sources :

Example 86 with PiAction

use of org.onosproject.net.pi.runtime.PiAction 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 87 with PiAction

use of org.onosproject.net.pi.runtime.PiAction 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 88 with PiAction

use of org.onosproject.net.pi.runtime.PiAction 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)

Example 89 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class InstructionCodecTest method piInstructionDecodingTest.

/**
 * Tests the decoding of protocol-independent instructions.
 */
@Test
public void piInstructionDecodingTest() throws IOException {
    Instruction actionInstruction = getInstruction("PiActionInstruction.json");
    Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT));
    PiTableAction action = ((PiInstruction) actionInstruction).action();
    Assert.assertThat(action.type(), is(PiTableAction.Type.ACTION));
    Assert.assertThat(((PiAction) action).id().id(), is("set_egress_port"));
    Assert.assertThat(((PiAction) action).parameters().size(), is(1));
    Collection<PiActionParam> actionParams = ((PiAction) action).parameters();
    PiActionParam actionParam = actionParams.iterator().next();
    Assert.assertThat(actionParam.id().id(), is("port"));
    Assert.assertThat(actionParam.value(), is(copyFrom((byte) 0x1)));
    Instruction actionGroupIdInstruction = getInstruction("PiActionProfileGroupIdInstruction.json");
    Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT));
    PiTableAction actionGroupId = ((PiInstruction) actionGroupIdInstruction).action();
    Assert.assertThat(actionGroupId.type(), is(PiTableAction.Type.ACTION_PROFILE_GROUP_ID));
    Assert.assertThat(((PiActionProfileGroupId) actionGroupId).id(), is(100));
    Instruction actionMemberIdInstruction = getInstruction("PiActionProfileMemberIdInstruction.json");
    Assert.assertThat(actionInstruction.type(), is(Instruction.Type.PROTOCOL_INDEPENDENT));
    PiTableAction actionMemberId = ((PiInstruction) actionMemberIdInstruction).action();
    Assert.assertThat(actionMemberId.type(), is(PiTableAction.Type.ACTION_PROFILE_MEMBER_ID));
    Assert.assertThat(((PiActionProfileMemberId) actionMemberId).id(), is(100));
}
Also used : PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) InstructionJsonMatcher.matchesInstruction(org.onosproject.codec.impl.InstructionJsonMatcher.matchesInstruction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) PiAction(org.onosproject.net.pi.runtime.PiAction) Test(org.junit.Test)

Example 90 with PiAction

use of org.onosproject.net.pi.runtime.PiAction in project onos by opennetworkinglab.

the class InstructionJsonMatcher method matchPiInstruction.

/**
 * Matches the contents of a protocol-independent instruction.
 *
 * @param instructionJson JSON instruction to match
 * @param description Description object used for recording errors
 * @return true if contents match, false otherwise
 */
private boolean matchPiInstruction(JsonNode instructionJson, Description description) {
    PiInstruction instructionToMatch = (PiInstruction) instruction;
    final String jsonSubtype = instructionJson.get("subtype").textValue();
    if (!instructionToMatch.action().type().name().equals(jsonSubtype)) {
        description.appendText("subtype was " + jsonSubtype);
        return false;
    }
    final String jsonType = instructionJson.get("type").textValue();
    if (!instructionToMatch.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    switch(instructionToMatch.action().type()) {
        case ACTION:
            if (!Objects.equals(instructionJson.get("actionId").textValue(), ((PiAction) instructionToMatch.action()).id().id())) {
                description.appendText("action was " + ((PiAction) instructionToMatch.action()).id().id());
                return false;
            }
            Collection<PiActionParam> piActionParams = ((PiAction) instructionToMatch.action()).parameters();
            JsonNode jsonParams = instructionJson.get("actionParams");
            for (PiActionParam actionParam : piActionParams) {
                if (!Objects.equals(copyFrom(HexString.fromHexString(jsonParams.get(actionParam.id().id()).textValue(), null)), actionParam.value())) {
                    description.appendText("action param value was " + actionParam.value());
                    return false;
                }
            }
            break;
        case ACTION_PROFILE_GROUP_ID:
            if (!Objects.equals(instructionJson.get("groupId").asInt(), ((PiActionProfileGroupId) instructionToMatch.action()).id())) {
                description.appendText("action profile group id was " + ((PiActionProfileGroupId) instructionToMatch.action()).id());
                return false;
            }
            break;
        case ACTION_PROFILE_MEMBER_ID:
            if (!Objects.equals(instructionJson.get("memberId").asInt(), ((PiActionProfileMemberId) instructionToMatch.action()).id())) {
                description.appendText("action profile member id was " + ((PiActionProfileMemberId) instructionToMatch.action()).id());
                return false;
            }
            break;
        default:
            description.appendText("type was " + jsonType);
            return false;
    }
    return true;
}
Also used : PiActionProfileMemberId(org.onosproject.net.pi.runtime.PiActionProfileMemberId) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) 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) PiAction(org.onosproject.net.pi.runtime.PiAction)

Aggregations

PiAction (org.onosproject.net.pi.runtime.PiAction)117 PiActionParam (org.onosproject.net.pi.runtime.PiActionParam)74 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)69 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)68 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)57 TrafficSelector (org.onosproject.net.flow.TrafficSelector)57 Test (org.junit.Test)44 PiCriterion (org.onosproject.net.flow.criteria.PiCriterion)44 FlowRule (org.onosproject.net.flow.FlowRule)39 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)33 GroupDescription (org.onosproject.net.group.GroupDescription)22 List (java.util.List)15 ForwardingObjective (org.onosproject.net.flowobjective.ForwardingObjective)14 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)14 DefaultForwardingObjective (org.onosproject.net.flowobjective.DefaultForwardingObjective)13 PortNumber (org.onosproject.net.PortNumber)9 NextObjective (org.onosproject.net.flowobjective.NextObjective)9 GroupBucket (org.onosproject.net.group.GroupBucket)9 PiActionId (org.onosproject.net.pi.model.PiActionId)9 PiTableAction (org.onosproject.net.pi.runtime.PiTableAction)9