use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse 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 in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(ListFlowsRequest data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
CommandPacket commandPacket = getFlowListCommandPacket(switchIdKey);
try {
CommandPacketResponse serverResponse = zeroMqClient.send(commandPacket);
if (serverResponse == null) {
log.error("No response from server on {}", data.getHeaders().getCorrelationId());
return;
}
HashSet<String> flowList = new HashSet<>();
for (Any any : serverResponse.getResponseList()) {
flowList.add(any.unpack(Flow.class).getFlowId());
}
ListFlowsResponse response = ListFlowsResponse.builder().headers(data.getHeaders()).flowIds(flowList).build();
template.send(toStorm, response);
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data);
}
}
use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse in project open-kilda by telstra.
the class Gate method listen.
@KafkaHandler
void listen(ListFlowsOnSwitch data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
CommandPacket commandPacket = getFlowListCommandPacket(switchIdKey);
try {
CommandPacketResponse serverResponse = zeroMqClient.send(commandPacket);
if (serverResponse == null) {
log.error("No response from server on {}", data.getHeaders().getCorrelationId());
return;
}
for (Any any : serverResponse.getResponseList()) {
String flowId = any.unpack(Flow.class).getFlowId();
if (!data.getFlowIds().contains(flowId)) {
removeFlow(flowId, FlowDirection.FORWARD);
removeFlow(flowId, FlowDirection.REVERSE);
}
}
} catch (InvalidProtocolBufferException e) {
log.error("Marshalling error on {}", data);
}
}
use of org.openkilda.server42.control.messaging.Control.CommandPacketResponse 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.Control.CommandPacketResponse in project open-kilda by telstra.
the class GateTest method listFlowsTest.
@Test
public void listFlowsTest() throws Exception {
Builder commandPacketResponseBuilded = CommandPacketResponse.newBuilder();
Flow flow1 = Flow.newBuilder().setFlowId("some-flow-id-01").build();
Flow flow2 = Flow.newBuilder().setFlowId("some-flow-id-02").build();
commandPacketResponseBuilded.addResponse(Any.pack(flow1));
commandPacketResponseBuilded.addResponse(Any.pack(flow2));
CommandPacketResponse commandPacketResponse = commandPacketResponseBuilded.build();
when(zeroMqClient.send(argThat(commandPacket -> commandPacket.getType() == Type.LIST_FLOWS))).thenReturn(commandPacketResponse);
String switchId = "00:00:1b:45:18:d6:71:5a";
Headers headers = Headers.builder().correlationId("some-correlation-id").build();
gate.listen(new ListFlowsRequest(headers), switchId);
ArgumentCaptor<ListFlowsResponse> argument = ArgumentCaptor.forClass(ListFlowsResponse.class);
verify(template).send(eq(toStorm), argument.capture());
ListFlowsResponse response = argument.getValue();
assertThat(response.getFlowIds()).contains(flow1.getFlowId(), flow2.getFlowId());
}
Aggregations