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));
}
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));
}
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();
}
Aggregations