Search in sources :

Example 1 with Builder

use of org.openkilda.server42.control.messaging.Control.CommandPacket.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");
}
Also used : FlowRttStatsData(org.openkilda.messaging.info.stats.FlowRttStatsData) InfoMessage(org.openkilda.messaging.info.InfoMessage) Builder(org.openkilda.server42.stats.messaging.Statistics.LatencyPacketBucket.Builder) FlowLatencyPacket(org.openkilda.server42.stats.messaging.Statistics.FlowLatencyPacket) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Builder

use of org.openkilda.server42.control.messaging.Control.CommandPacket.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);
    }
}
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 3 with Builder

use of org.openkilda.server42.control.messaging.Control.CommandPacket.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);
    }
}
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)

Example 4 with Builder

use of org.openkilda.server42.control.messaging.Control.CommandPacket.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();
}
Also used : Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) SwitchId(org.openkilda.model.SwitchId) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl)

Example 5 with Builder

use of org.openkilda.server42.control.messaging.Control.CommandPacket.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);
    }
}
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)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)11 Builder (org.openkilda.server42.control.messaging.Control.CommandPacket.Builder)10 IslRttControl (org.openkilda.server42.control.messaging.islrtt.IslRttControl)8 FlowRttControl (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl)7 KafkaHandler (org.springframework.kafka.annotation.KafkaHandler)7 SwitchId (org.openkilda.model.SwitchId)6 CommandPacket (org.openkilda.server42.control.messaging.Control.CommandPacket)6 IslEndpoint (org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint)6 Any (com.google.protobuf.Any)5 CommandPacketResponse (org.openkilda.server42.control.messaging.Control.CommandPacketResponse)5 Flow (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow)5 AddFlow (org.openkilda.server42.control.messaging.flowrtt.AddFlow)4 RemoveFlow (org.openkilda.server42.control.messaging.flowrtt.RemoveFlow)4 List (java.util.List)3 Test (org.junit.Test)3 Control (org.openkilda.server42.control.messaging.Control)3 Builder (org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder)3 ListIslsResponse (org.openkilda.server42.control.messaging.islrtt.ListIslsResponse)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Value (org.springframework.beans.factory.annotation.Value)3