Search in sources :

Example 11 with Builder

use of org.openkilda.server42.control.messaging.Control.CommandPacket.Builder in project open-kilda by telstra.

the class GateTest method listIslsTest.

@Test
public void listIslsTest() throws Exception {
    Builder commandPacketResponseBuilded = CommandPacketResponse.newBuilder();
    String switchId = "00:00:1b:45:18:d6:71:5a";
    IslEndpoint port1 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(1).build();
    IslEndpoint port2 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(2).build();
    IslEndpoint port3 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(3).build();
    IslEndpoint port4 = IslEndpoint.newBuilder().setSwitchId(switchId).setPort(4).build();
    commandPacketResponseBuilded.addResponse(Any.pack(port1));
    commandPacketResponseBuilded.addResponse(Any.pack(port2));
    commandPacketResponseBuilded.addResponse(Any.pack(port3));
    commandPacketResponseBuilded.addResponse(Any.pack(port4));
    CommandPacketResponse commandPacketResponse = commandPacketResponseBuilded.build();
    when(zeroMqClient.send(argThat(commandPacket -> commandPacket.getType() == Type.LIST_ISLS))).thenReturn(commandPacketResponse);
    gate.listen(ListIslsRequest.builder().switchId(new SwitchId(switchId)).build());
    ArgumentCaptor<ListIslsResponse> argument = ArgumentCaptor.forClass(ListIslsResponse.class);
    verify(template).send(eq(toStorm), argument.capture());
    ListIslsResponse response = argument.getValue();
    assertThat(response.getPorts()).contains(port1.getPort(), port2.getPort(), port3.getPort(), port4.getPort());
}
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) IslEndpoint(org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint) Builder(org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder) SwitchId(org.openkilda.model.SwitchId) CommandPacketResponse(org.openkilda.server42.control.messaging.Control.CommandPacketResponse) ListIslsResponse(org.openkilda.server42.control.messaging.islrtt.ListIslsResponse) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 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 AddIsl data) {
    Builder builder = CommandPacket.newBuilder();
    builder.setType(Type.ADD_ISL);
    SwitchId switchId = data.getSwitchId();
    String switchIdKey = switchId.toString();
    IslEndpoint endpoint = IslEndpoint.newBuilder().setSwitchId(switchIdKey).setPort(data.getPort()).build();
    IslRttControl.AddIsl addIsl = IslRttControl.AddIsl.newBuilder().setIsl(endpoint).setSwitchMac(switchId.toMacAddress()).setUdpSrcPort(islRttUdpSrcPortOffset + data.getPort()).setTransitEncapsulationType(IslRttControl.AddIsl.EncapsulationType.VLAN).setTransitTunnelId(switchToVlanMap.get(switchIdKey)).setHashCode(data.hashCode()).build();
    builder.addCommand(Any.pack(addIsl));
    try {
        zeroMqClient.send(builder.build());
    } 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) SwitchId(org.openkilda.model.SwitchId) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 13 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(PushSettings data) {
    Builder builder = CommandPacket.newBuilder();
    Control.PushSettings pushSettings = Control.PushSettings.newBuilder().setPacketGenerationIntervalInMs(data.getPacketGenerationIntervalInMs()).build();
    builder.setType(Type.PUSH_SETTINGS);
    builder.addCommand(Any.pack(pushSettings));
    CommandPacket packet = builder.build();
    try {
        zeroMqClient.send(packet);
    } catch (InvalidProtocolBufferException e) {
        log.error("Marshalling error on {}", data);
    }
}
Also used : Control(org.openkilda.server42.control.messaging.Control) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) Builder(org.openkilda.server42.control.messaging.Control.CommandPacket.Builder) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) KafkaHandler(org.springframework.kafka.annotation.KafkaHandler)

Example 14 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 ClearIsls data) {
    Builder builder = CommandPacket.newBuilder();
    builder.setType(Type.CLEAR_ISLS);
    IslRttControl.ClearIslsFilter clearIslsFilter = IslRttControl.ClearIslsFilter.newBuilder().setSwitchId(data.getSwitchId().toString()).build();
    builder.addCommand(Any.pack(clearIslsFilter));
    try {
        zeroMqClient.send(builder.build());
    } 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) 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