use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder in project open-kilda by telstra.
the class StatsCollectorTest method sendStatsTest.
@Test
public void sendStatsTest() throws Exception {
Builder bucketBuilder = LatencyPacketBucket.newBuilder();
FlowLatencyPacket packet1 = FlowLatencyPacket.newBuilder().setFlowId("some-flow-id-1").setDirection(false).setT0(100).setT1(150).setPacketId(1).build();
FlowLatencyPacket packet2 = FlowLatencyPacket.newBuilder().setDirection(true).setT0(200).setT1(250).setPacketId(2).build();
bucketBuilder.addFlowLatencyPacket(packet1);
bucketBuilder.addFlowLatencyPacket(packet2);
statsCollector.sendStats(bucketBuilder.build());
ArgumentCaptor<InfoMessage> argument = ArgumentCaptor.forClass(InfoMessage.class);
verify(template).send(eq(toStorm), eq(packet1.getFlowId()), argument.capture());
InfoMessage packet1Message = argument.getValue();
FlowRttStatsData statsPacket1 = (FlowRttStatsData) packet1Message.getData();
assertThat(statsPacket1).extracting(FlowRttStatsData::getFlowId, FlowRttStatsData::getT0, FlowRttStatsData::getT1).contains(packet1.getFlowId(), packet1.getT0(), packet1.getT1());
assertThat(statsPacket1).extracting(FlowRttStatsData::getDirection).isEqualTo("forward");
verify(template).send(eq(toStorm), eq(packet2.getFlowId()), argument.capture());
InfoMessage packet2Message = argument.getValue();
FlowRttStatsData statsPacket2 = (FlowRttStatsData) packet2Message.getData();
assertThat(statsPacket2).extracting(FlowRttStatsData::getFlowId, FlowRttStatsData::getT0, FlowRttStatsData::getT1).contains(packet2.getFlowId(), packet2.getT0(), packet2.getT1());
assertThat(statsPacket2).extracting(FlowRttStatsData::getDirection).isEqualTo("reverse");
}
use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(@Payload ListIslPortsOnSwitch 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;
}
for (Any any : serverResponse.getResponseList()) {
IslRttControl.IslEndpoint endpoint = any.unpack(IslRttControl.IslEndpoint.class);
if (!data.getIslPorts().contains(endpoint.getPort())) {
removeIsl(data.getSwitchId(), endpoint.getPort());
}
}
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data, e);
}
}
use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder in project open-kilda by telstra.
the class Gate method removeIsl.
private void removeIsl(SwitchId switchId, int port) {
Builder builder = CommandPacket.newBuilder();
IslEndpoint endpoint = IslEndpoint.newBuilder().setSwitchId(switchId.toString()).setPort(port).build();
IslRttControl.RemoveIsl removeIsl = IslRttControl.RemoveIsl.newBuilder().setIsl(endpoint).build();
builder.setType(Type.REMOVE_ISL);
builder.addCommand(Any.pack(removeIsl));
try {
zeroMqClient.send(builder.build());
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {} / {}", switchId, port, e);
}
}
use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder in project open-kilda by telstra.
the class Gate method getFlowListCommandPacket.
private CommandPacket getFlowListCommandPacket(String switchIdKey) {
SwitchId switchId = new SwitchId(switchIdKey);
Builder builder = CommandPacket.newBuilder();
builder.setType(Type.LIST_FLOWS);
FlowRttControl.ListFlowsFilter listFlowsFilter = FlowRttControl.ListFlowsFilter.newBuilder().setDstMac(switchId.toMacAddress()).build();
builder.addCommand(Any.pack(listFlowsFilter));
return builder.build();
}
use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder 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);
}
}
Aggregations