Search in sources :

Example 1 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler 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);
    }
}
Also used : IslEndpoint(org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint) 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) Any(com.google.protobuf.Any) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 2 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler 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 3 with KafkaHandler

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

Example 4 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler 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 5 with KafkaHandler

use of org.springframework.kafka.annotation.KafkaHandler in project open-kilda by telstra.

the class Gate method listen.

@KafkaHandler
void listen(@Payload AddFlow data, @Header(KafkaHeaders.RECEIVED_MESSAGE_KEY) String switchIdKey) {
    SwitchId switchId = new SwitchId(switchIdKey);
    Builder builder = CommandPacket.newBuilder();
    Flow flow = Flow.newBuilder().setFlowId(data.getFlowId()).setEncapsulationType(Flow.EncapsulationType.VLAN).setTunnelId(data.getTunnelId()).setTransitEncapsulationType(Flow.EncapsulationType.VLAN).setInnerTunnelId(data.getInnerTunnelId()).setTransitTunnelId(switchToVlanMap.get(switchIdKey)).setDirection(FlowDirection.toBoolean(data.getDirection())).setUdpSrcPort(flowRttUdpSrcPortOffset + data.getPort()).setDstMac(switchId.toMacAddress()).setHashCode(data.hashCode()).build();
    FlowRttControl.AddFlow addFlow = FlowRttControl.AddFlow.newBuilder().setFlow(flow).build();
    builder.setType(Type.ADD_FLOW);
    builder.addCommand(Any.pack(addFlow));
    CommandPacket packet = builder.build();
    try {
        zeroMqClient.send(packet);
    } catch (InvalidProtocolBufferException e) {
        log.error("Marshalling error on {}", data);
    }
}
Also used : Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SwitchId(org.openkilda.model.SwitchId) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) 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) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Aggregations

KafkaHandler (org.springframework.kafka.annotation.KafkaHandler)11 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)9 Builder (org.openkilda.server42.control.messaging.Control.CommandPacket.Builder)7 IslRttControl (org.openkilda.server42.control.messaging.islrtt.IslRttControl)5 Any (com.google.protobuf.Any)4 CommandPacket (org.openkilda.server42.control.messaging.Control.CommandPacket)4 CommandPacketResponse (org.openkilda.server42.control.messaging.Control.CommandPacketResponse)4 SwitchId (org.openkilda.model.SwitchId)3 FlowRttControl (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl)3 HashSet (java.util.HashSet)2 AddFlow (org.openkilda.server42.control.messaging.flowrtt.AddFlow)2 Flow (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow)2 RemoveFlow (org.openkilda.server42.control.messaging.flowrtt.RemoveFlow)2 IslEndpoint (org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint)2 MDCCloseable (org.slf4j.MDC.MDCCloseable)2 Control (org.openkilda.server42.control.messaging.Control)1 ListFlowsResponse (org.openkilda.server42.control.messaging.flowrtt.ListFlowsResponse)1 ListIslsResponse (org.openkilda.server42.control.messaging.islrtt.ListIslsResponse)1