use of org.openkilda.server42.control.messaging.islrtt.ListIslsResponse in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(@Payload ListIslsRequest data) {
Builder builder = CommandPacket.newBuilder();
builder.setType(Type.LIST_ISLS);
IslRttControl.ListIslsFilter listIslsFilter = IslRttControl.ListIslsFilter.newBuilder().setSwitchId(data.getSwitchId().toString()).build();
builder.addCommand(Any.pack(listIslsFilter));
try {
CommandPacketResponse serverResponse = zeroMqClient.send(builder.build());
if (serverResponse == null) {
log.error("No response from server on {}", data.getHeaders().getCorrelationId());
return;
}
HashSet<Integer> portList = new HashSet<>();
for (Any any : serverResponse.getResponseList()) {
portList.add(any.unpack(IslEndpoint.class).getPort());
}
ListIslsResponse response = ListIslsResponse.builder().headers(data.getHeaders()).switchId(data.getSwitchId()).ports(portList).build();
template.send(toStorm, response);
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data, e);
}
}
use of org.openkilda.server42.control.messaging.islrtt.ListIslsResponse in project open-kilda by telstra.
the class GateTest method listIslsTest.
@Test
public void listIslsTest() throws Exception {
Builder commandPacketResponseBuilded = CommandPacketResponse.newBuilder();
String switchId = "00:00:1b:45:18:d6:71:5a";
IslEndpoint port1 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(1).build();
IslEndpoint port2 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(2).build();
IslEndpoint port3 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(3).build();
IslEndpoint port4 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(4).build();
commandPacketResponseBuilded.addResponse(Any.pack(port1));
commandPacketResponseBuilded.addResponse(Any.pack(port2));
commandPacketResponseBuilded.addResponse(Any.pack(port3));
commandPacketResponseBuilded.addResponse(Any.pack(port4));
CommandPacketResponse commandPacketResponse = commandPacketResponseBuilded.build();
when(zeroMqClient.send(argThat(commandPacket -> commandPacket.getType() == Type.LIST_ISLS))).thenReturn(commandPacketResponse);
gate.listen(ListIslsRequest.builder().switchId(new SwitchId(switchId)).build());
ArgumentCaptor<ListIslsResponse> argument = ArgumentCaptor.forClass(ListIslsResponse.class);
verify(template).send(eq(toStorm), argument.capture());
ListIslsResponse response = argument.getValue();
assertThat(response.getPorts()).contains(port1.getPort(), port2.getPort(), port3.getPort(), port4.getPort());
}
Aggregations