Search in sources :

Example 1 with ActionProfileMember

use of p4.v1.P4RuntimeOuterClass.ActionProfileMember 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 2 with ActionProfileMember

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

the class P4RuntimeGroupTest method testInsertPiActionMembers.

@Test
public void testInsertPiActionMembers() throws Exception {
    CompletableFuture<Void> complete = p4RuntimeServerImpl.expectRequests(1);
    assertTrue(client.write(P4_DEVICE_ID, PIPECONF).insert(GROUP_MEMBER_INSTANCES).submitSync().isSuccess());
    complete.get(DEFAULT_TIMEOUT_TIME, TimeUnit.SECONDS);
    WriteRequest result = p4RuntimeServerImpl.getWriteReqs().get(0);
    assertEquals(1, result.getDeviceId());
    assertEquals(3, result.getUpdatesCount());
    assertEquals(DEFAULT_ELECTION_ID, result.getElectionId());
    List<Update> updates = result.getUpdatesList();
    for (Update update : updates) {
        assertEquals(Update.Type.INSERT, update.getType());
        Entity entity = update.getEntity();
        ActionProfileMember member = entity.getActionProfileMember();
        assertNotNull(member);
        assertEquals(P4_INFO_ACT_PROF_ID, member.getActionProfileId());
        assertTrue(MEMBER_IDS.contains(member.getMemberId()));
        Action action = member.getAction();
        assertEquals(SET_EGRESS_PORT_ID, action.getActionId());
        assertEquals(1, action.getParamsCount());
        Action.Param param = action.getParamsList().get(0);
        assertEquals(1, param.getParamId());
        byte outPort = (byte) (member.getMemberId() - BASE_MEM_ID);
        ByteString bs = ByteString.copyFrom(new byte[] { 0, outPort });
        assertEquals(bs, param.getValue());
    }
}
Also used : Entity(p4.v1.P4RuntimeOuterClass.Entity) Action(p4.v1.P4RuntimeOuterClass.Action) PiAction(org.onosproject.net.pi.runtime.PiAction) WriteRequest(p4.v1.P4RuntimeOuterClass.WriteRequest) ByteString(com.google.protobuf.ByteString) Update(p4.v1.P4RuntimeOuterClass.Update) ActionProfileMember(p4.v1.P4RuntimeOuterClass.ActionProfileMember) PiActionProfileMember(org.onosproject.net.pi.runtime.PiActionProfileMember) Test(org.junit.Test)

Aggregations

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