Search in sources :

Example 1 with ReadResponse

use of p4.v1.P4RuntimeOuterClass.ReadResponse in project onos by opennetworkinglab.

the class P4RuntimeGroupTest method testReadGroups.

@Test
public void testReadGroups() throws Exception {
    ActionProfileGroup.Builder group = ActionProfileGroup.newBuilder().setGroupId(GROUP_ID.id()).setActionProfileId(P4_INFO_ACT_PROF_ID);
    MEMBER_IDS.forEach(id -> {
        ActionProfileGroup.Member member = ActionProfileGroup.Member.newBuilder().setMemberId(id).setWeight(DEFAULT_MEMBER_WEIGHT).build();
        group.addMembers(member);
    });
    List<ReadResponse> responses = Lists.newArrayList();
    responses.add(ReadResponse.newBuilder().addEntities(Entity.newBuilder().setActionProfileGroup(group)).build());
    p4RuntimeServerImpl.willReturnReadResult(responses);
    CompletableFuture<Void> complete = p4RuntimeServerImpl.expectRequests(1);
    Collection<PiActionProfileGroup> groups = client.read(P4_DEVICE_ID, PIPECONF).actionProfileGroups(ACT_PROF_ID).submitSync().all(PiActionProfileGroup.class);
    complete.get(DEFAULT_TIMEOUT_TIME, TimeUnit.SECONDS);
    assertEquals(1, groups.size());
    PiActionProfileGroup piActionGroup = groups.iterator().next();
    assertEquals(ACT_PROF_ID, piActionGroup.actionProfile());
    assertEquals(GROUP_ID, piActionGroup.id());
    assertEquals(3, piActionGroup.members().size());
    assertTrue(GROUP_WEIGHTED_MEMBERS.containsAll(piActionGroup.members()));
    assertTrue(piActionGroup.members().containsAll(GROUP_WEIGHTED_MEMBERS));
}
Also used : ReadResponse(p4.v1.P4RuntimeOuterClass.ReadResponse) ActionProfileGroup(p4.v1.P4RuntimeOuterClass.ActionProfileGroup) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) PiActionProfileGroup(org.onosproject.net.pi.runtime.PiActionProfileGroup) Test(org.junit.Test)

Example 2 with ReadResponse

use of p4.v1.P4RuntimeOuterClass.ReadResponse in project onos by opennetworkinglab.

the class P4RuntimeGroupTest method testReadMembers.

@Test
public void testReadMembers() throws Exception {
    List<ActionProfileMember> members = Lists.newArrayList();
    MEMBER_IDS.forEach(id -> {
        byte outPort = (byte) (id - BASE_MEM_ID);
        ByteString bs = ByteString.copyFrom(new byte[] { 0, outPort });
        Action.Param param = Action.Param.newBuilder().setParamId(1).setValue(bs).build();
        Action action = Action.newBuilder().setActionId(SET_EGRESS_PORT_ID).addParams(param).build();
        ActionProfileMember actProfMember = ActionProfileMember.newBuilder().setActionProfileId(P4_INFO_ACT_PROF_ID).setMemberId(id).setAction(action).build();
        members.add(actProfMember);
    });
    List<ReadResponse> responses = Lists.newArrayList();
    responses.add(ReadResponse.newBuilder().addAllEntities(members.stream().map(m -> Entity.newBuilder().setActionProfileMember(m).build()).collect(Collectors.toList())).build());
    p4RuntimeServerImpl.willReturnReadResult(responses);
    CompletableFuture<Void> complete = p4RuntimeServerImpl.expectRequests(1);
    Collection<PiActionProfileMember> piMembers = client.read(P4_DEVICE_ID, PIPECONF).actionProfileMembers(ACT_PROF_ID).submitSync().all(PiActionProfileMember.class);
    complete.get(DEFAULT_TIMEOUT_TIME, TimeUnit.SECONDS);
    assertEquals(3, piMembers.size());
    assertTrue(GROUP_MEMBER_INSTANCES.containsAll(piMembers));
    assertTrue(piMembers.containsAll(GROUP_MEMBER_INSTANCES));
}
Also used : Action(p4.v1.P4RuntimeOuterClass.Action) PiAction(org.onosproject.net.pi.runtime.PiAction) ReadResponse(p4.v1.P4RuntimeOuterClass.ReadResponse) ByteString(com.google.protobuf.ByteString) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) ActionProfileMember(p4.v1.P4RuntimeOuterClass.ActionProfileMember) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) Test(org.junit.Test)

Example 3 with ReadResponse

use of p4.v1.P4RuntimeOuterClass.ReadResponse in project onos by opennetworkinglab.

the class MockP4RuntimeServer method read.

@Override
public void read(ReadRequest request, StreamObserver<ReadResponse> responseObserver) {
    readReqs.add(request);
    if (readResps != null && !readResps.isEmpty()) {
        // get first response
        ReadResponse readResp = readResps.remove(0);
        responseObserver.onNext(readResp);
        responseObserver.onCompleted();
    }
    complete();
}
Also used : ReadResponse(p4.v1.P4RuntimeOuterClass.ReadResponse)

Aggregations

ReadResponse (p4.v1.P4RuntimeOuterClass.ReadResponse)3 Test (org.junit.Test)2 ByteString (com.google.protobuf.ByteString)1 PiAction (org.onosproject.net.pi.runtime.PiAction)1 PiActionProfileGroup (org.onosproject.net.pi.runtime.PiActionProfileGroup)1 PiActionProfileMember (org.onosproject.net.pi.runtime.PiActionProfileMember)1 Action (p4.v1.P4RuntimeOuterClass.Action)1 ActionProfileGroup (p4.v1.P4RuntimeOuterClass.ActionProfileGroup)1 ActionProfileMember (p4.v1.P4RuntimeOuterClass.ActionProfileMember)1