Search in sources :

Example 11 with CommandPacket

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

the class GateTest method pushSettingsTest.

@Test
public void pushSettingsTest() throws Exception {
    PushSettings data = PushSettings.builder().packetGenerationIntervalInMs(500).build();
    gate.listen(data);
    CommandPacket commandPacket = getCommandPacket();
    assertThat(commandPacket.getType()).isEqualTo(Type.PUSH_SETTINGS);
    assertThat(commandPacket.getCommandList()).hasSize(1);
    Any command = commandPacket.getCommand(0);
    assertThat(command.is(Control.PushSettings.class)).isTrue();
    Control.PushSettings unpack = command.unpack(Control.PushSettings.class);
    assertThat(unpack.getPacketGenerationIntervalInMs()).isEqualTo(500);
}
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) PushSettings(org.openkilda.server42.control.messaging.flowrtt.PushSettings) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) Any(com.google.protobuf.Any) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with CommandPacket

use of org.openkilda.server42.control.messaging.Control.CommandPacket 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 13 with CommandPacket

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

the class GateTest method testAddIsl.

@Test
public void testAddIsl() throws Exception {
    AddIsl addIsl = AddIsl.builder().switchId(new SwitchId("00:00:1b:45:18:d6:71:5a")).port(42).build();
    gate.listen(addIsl);
    CommandPacket commandPacket = getCommandPacket();
    assertThat(commandPacket.getType()).isEqualTo(Type.ADD_ISL);
    assertThat(commandPacket.getCommandCount()).isEqualTo(1);
    Any command = commandPacket.getCommand(0);
    assertThat(command.is(IslRttControl.AddIsl.class)).isTrue();
    IslRttControl.AddIsl unpack = command.unpack(IslRttControl.AddIsl.class);
    IslRttControl.IslEndpoint endpoint = unpack.getIsl();
    String switchId = addIsl.getSwitchId().toString();
    assertThat(endpoint.getSwitchId()).isEqualTo(switchId);
    assertThat(endpoint.getPort()).isEqualTo(addIsl.getPort());
    assertThat(unpack.getUdpSrcPort()).isEqualTo(islRttUdpSrcPortOffset + addIsl.getPort());
    assertThat(unpack.getSwitchMac()).isSubstringOf(switchId).isNotEqualTo(switchId);
}
Also used : IslEndpoint(org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint) SwitchId(org.openkilda.model.SwitchId) AddIsl(org.openkilda.server42.control.messaging.islrtt.AddIsl) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) Any(com.google.protobuf.Any) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with CommandPacket

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

the class GateTest method testRemoveIsl.

@Test
public void testRemoveIsl() throws Exception {
    RemoveIsl removeIsl = RemoveIsl.builder().switchId(new SwitchId("00:00:1b:45:18:d6:71:5a")).port(42).build();
    gate.listen(removeIsl);
    CommandPacket commandPacket = getCommandPacket();
    assertThat(commandPacket.getType()).isEqualTo(Type.REMOVE_ISL);
    assertThat(commandPacket.getCommandList()).hasSize(1);
    Any command = commandPacket.getCommand(0);
    assertThat(command.is(IslRttControl.RemoveIsl.class)).isTrue();
    IslRttControl.RemoveIsl unpack = command.unpack(IslRttControl.RemoveIsl.class);
    IslRttControl.IslEndpoint endpoint = unpack.getIsl();
    String switchId = removeIsl.getSwitchId().toString();
    assertThat(endpoint.getSwitchId()).isEqualTo(switchId);
    assertThat(endpoint.getPort()).isEqualTo(removeIsl.getPort());
}
Also used : IslEndpoint(org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint) SwitchId(org.openkilda.model.SwitchId) IslRttControl(org.openkilda.server42.control.messaging.islrtt.IslRttControl) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) Any(com.google.protobuf.Any) RemoveIsl(org.openkilda.server42.control.messaging.islrtt.RemoveIsl) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with CommandPacket

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

the class GateTest method clearFlowsTest.

@Test
public void clearFlowsTest() throws Exception {
    Headers headers = Headers.builder().correlationId("some-correlation-id").build();
    ClearFlows clearFlows = ClearFlows.builder().headers(headers).build();
    String dpId = "00:00:1b:45:18:d6:71:5a";
    gate.listen(clearFlows, dpId);
    CommandPacket commandPacket = getCommandPacket();
    assertThat(commandPacket.getType()).isEqualTo(Type.CLEAR_FLOWS);
    assertThat(commandPacket.getCommandList()).hasSize(1);
    Any command = commandPacket.getCommand(0);
    assertThat(command.is(FlowRttControl.ClearFlowsFilter.class)).isTrue();
    FlowRttControl.ClearFlowsFilter unpack = command.unpack(FlowRttControl.ClearFlowsFilter.class);
    String dstMac = "1b:45:18:d6:71:5a";
    assertThat(unpack.getDstMac()).isEqualTo(dstMac);
}
Also used : Headers(org.openkilda.server42.control.messaging.flowrtt.Headers) ClearFlows(org.openkilda.server42.control.messaging.flowrtt.ClearFlows) FlowRttControl(org.openkilda.server42.control.messaging.flowrtt.FlowRttControl) CommandPacket(org.openkilda.server42.control.messaging.Control.CommandPacket) Any(com.google.protobuf.Any) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CommandPacket (org.openkilda.server42.control.messaging.Control.CommandPacket)15 Any (com.google.protobuf.Any)12 FlowRttControl (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl)10 Test (org.junit.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)7 SwitchId (org.openkilda.model.SwitchId)7 Flow (org.openkilda.server42.control.messaging.flowrtt.FlowRttControl.Flow)7 RemoveFlow (org.openkilda.server42.control.messaging.flowrtt.RemoveFlow)7 IslRttControl (org.openkilda.server42.control.messaging.islrtt.IslRttControl)7 AddFlow (org.openkilda.server42.control.messaging.flowrtt.AddFlow)6 CommandPacketResponse (org.openkilda.server42.control.messaging.Control.CommandPacketResponse)5 IslEndpoint (org.openkilda.server42.control.messaging.islrtt.IslRttControl.IslEndpoint)5 List (java.util.List)4 Control (org.openkilda.server42.control.messaging.Control)4 Builder (org.openkilda.server42.control.messaging.Control.CommandPacket.Builder)4 KafkaHandler (org.springframework.kafka.annotation.KafkaHandler)4 Builder (org.openkilda.server42.control.messaging.Control.CommandPacketResponse.Builder)3 ClearFlows (org.openkilda.server42.control.messaging.flowrtt.ClearFlows)3 Headers (org.openkilda.server42.control.messaging.flowrtt.Headers)3