Search in sources :

Example 1 with Headers

use of org.openkilda.server42.control.messaging.flowrtt.Headers 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);
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ListFlowsResponse(org.openkilda.server42.control.messaging.flowrtt.ListFlowsResponse) CommandPacketResponse(org.openkilda.server42.control.messaging.Control.CommandPacketResponse) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) Any(com.google.protobuf.Any) HashSet(java.util.HashSet) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 2 with Headers

use of org.openkilda.server42.control.messaging.flowrtt.Headers 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);
    }
}
Also used : Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) CommandPacketResponse(org.openkilda.server42.control.messaging.Control.CommandPacketResponse) ListIslsResponse(org.openkilda.server42.control.messaging.islrtt.ListIslsResponse) Any(com.google.protobuf.Any) HashSet(java.util.HashSet) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 3 with Headers

use of org.openkilda.server42.control.messaging.flowrtt.Headers 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());
}
Also used : FlowDirection(org.openkilda.server42.messaging.FlowDirection) Control(org.openkilda.server42.control.messaging.Control) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl) ClearIsls(org.openkilda.server42.control.messaging.islrtt.ClearIsls) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) CommandPacketResponse(org.openkilda.server42.control.messaging.Control.CommandPacketResponse) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) AddFlow(org.openkilda.server42.control.messaging.flowrtt.AddFlow) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) Type(org.openkilda.server42.control.messaging.Control.CommandPacket.Type) Value(org.springframework.beans.factory.annotation.Value) ZeroMqClient(org.openkilda.server42.control.zeromq.ZeroMqClient) ListIslsRequest(org.openkilda.server42.control.messaging.islrtt.ListIslsRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) ClearFlows(org.openkilda.server42.control.messaging.flowrtt.ClearFlows) KafkaTemplate(org.springframework.kafka.core.KafkaTemplate) ListFlowsResponse(org.openkilda.server42.control.messaging.flowrtt.ListFlowsResponse) Map(java.util.Map) RemoveIsl(org.openkilda.server42.control.messaging.islrtt.RemoveIsl) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Headers(org.openkilda.server42.control.messaging.flowrtt.Headers) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) Flow(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow) MockBean(org.springframework.boot.test.mock.mockito.MockBean) RemoveFlow(org.openkilda.server42.control.messaging.flowrtt.RemoveFlow) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ListFlowsRequest(org.openkilda.server42.control.messaging.flowrtt.ListFlowsRequest) Test(org.junit.Test) TestPropertySource(org.springframework.test.context.TestPropertySource) Mockito.when(org.mockito.Mockito.when) Builder(org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder) Mockito.verify(org.mockito.Mockito.verify) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) List(java.util.List) AddIsl(org.openkilda.server42.control.messaging.islrtt.AddIsl) SwitchId(org.openkilda.model.SwitchId) SwitchToVlanMapping(org.openkilda.server42.control.config.SwitchToVlanMapping) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) PushSettings(org.openkilda.server42.control.messaging.flowrtt.PushSettings) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Any(com.google.protobuf.Any) IslEndpoint(org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint) ListIslsResponse(org.openkilda.server42.control.messaging.islrtt.ListIslsResponse) Headers(org.openkilda.server42.control.messaging.flowrtt.Headers) Builder(org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder) ListFlowsRequest(org.openkilda.server42.control.messaging.flowrtt.ListFlowsRequest) ListFlowsResponse(org.openkilda.server42.control.messaging.flowrtt.ListFlowsResponse) CommandPacketResponse(org.openkilda.server42.control.messaging.Control.CommandPacketResponse) AddFlow(org.openkilda.server42.control.messaging.flowrtt.AddFlow) Flow(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow) RemoveFlow(org.openkilda.server42.control.messaging.flowrtt.RemoveFlow) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Headers

use of org.openkilda.server42.control.messaging.flowrtt.Headers in project open-kilda by telstra.

the class KafkaController method getFlowList.

@GetMapping(value = "/flow/")
@ResponseBody
private DeferredResult<ResponseEntity<?>> getFlowList(@RequestParam String switchId) throws InterruptedException, ExecutionException, TimeoutException {
    Headers headers = buildHeader();
    String correlationId = headers.getCorrelationId();
    send(switchId, new ListFlowsRequest(headers));
    DeferredResult<ResponseEntity<?>> deferredResult = new DeferredResult<>(500L);
    deferredResult.onTimeout(() -> {
        deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body("Request timeout occurred."));
        deferredResultConcurrentHashMap.remove(correlationId);
    });
    deferredResult.onCompletion(() -> deferredResultConcurrentHashMap.remove(correlationId));
    deferredResult.onError((Throwable throwable) -> {
        deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(throwable));
        deferredResultConcurrentHashMap.remove(correlationId);
    });
    deferredResultConcurrentHashMap.put(correlationId, deferredResult);
    return deferredResult;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Headers(org.openkilda.server42.control.messaging.flowrtt.Headers) ListFlowsRequest(org.openkilda.server42.control.messaging.flowrtt.ListFlowsRequest) DeferredResult(org.springframework.web.context.request.async.DeferredResult) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with Headers

use of org.openkilda.server42.control.messaging.flowrtt.Headers in project open-kilda by telstra.

the class FlowHandler method notifyActivateFlowMonitoring.

@Override
public void notifyActivateFlowMonitoring(String flowId, SwitchId switchId, Integer port, Integer vlan, Integer innerVlan, boolean isForward) {
    AddFlow addFlow = AddFlow.builder().flowId(flowId).port(port).tunnelId(vlan.longValue()).innerTunnelId(innerVlan.longValue()).direction(isForward ? FlowDirection.FORWARD : FlowDirection.REVERSE).headers(buildHeader()).build();
    emit(STREAM_CONTROL_COMMANDS_ID, getCurrentTuple(), new Values(switchId.toString(), addFlow));
}
Also used : AddFlow(org.openkilda.server42.control.messaging.flowrtt.AddFlow) Values(org.apache.storm.tuple.Values)

Aggregations

Values (org.apache.storm.tuple.Values)7 Any (com.google.protobuf.Any)4 Headers (org.openkilda.server42.control.messaging.flowrtt.Headers)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 CommandPacket (org.openkilda.server42.control.messaging.Control.CommandPacket)3 CommandPacketResponse (org.openkilda.server42.control.messaging.Control.CommandPacketResponse)3 ClearFlows (org.openkilda.server42.control.messaging.flowrtt.ClearFlows)3 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 SwitchId (org.openkilda.model.SwitchId)2 AddFlow (org.openkilda.server42.control.messaging.flowrtt.AddFlow)2 FlowRttControl (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl)2 ListFlowsRequest (org.openkilda.server42.control.messaging.flowrtt.ListFlowsRequest)2 ListFlowsResponse (org.openkilda.server42.control.messaging.flowrtt.ListFlowsResponse)2 RemoveFlow (org.openkilda.server42.control.messaging.flowrtt.RemoveFlow)2 AddIsl (org.openkilda.server42.control.messaging.islrtt.AddIsl)2 ClearIsls (org.openkilda.server42.control.messaging.islrtt.ClearIsls)2 IslRttControl (org.openkilda.server42.control.messaging.islrtt.IslRttControl)2 ListIslsResponse (org.openkilda.server42.control.messaging.islrtt.ListIslsResponse)2 KafkaHandler (org.springframework.kafka.annotation.KafkaHandler)2