Search in sources :

Example 21 with Flow

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

the class FlowCreateHubBolt method sendActivateFlowMonitoring.

@Override
public void sendActivateFlowMonitoring(@NonNull RequestedFlow flow) {
    ActivateFlowMonitoringInfoData payload = RequestedFlowMapper.INSTANCE.toActivateFlowMonitoringInfoData(flow);
    Message message = new InfoMessage(payload, getCommandContext().getCreateTime(), getCommandContext().getCorrelationId());
    emitWithContext(HUB_TO_SERVER42_CONTROL_TOPOLOGY_SENDER.name(), getCurrentTuple(), new Values(flow.getFlowId(), message));
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) CommandMessage(org.openkilda.messaging.command.CommandMessage) Message(org.openkilda.messaging.Message) InfoMessage(org.openkilda.messaging.info.InfoMessage) Values(org.apache.storm.tuple.Values) ActivateFlowMonitoringInfoData(org.openkilda.server42.control.messaging.flowrtt.ActivateFlowMonitoringInfoData)

Example 22 with Flow

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

the class Router method handleInfoMessage.

private void handleInfoMessage(Tuple input, InfoData payload) throws PipelineException {
    if (payload instanceof ActivateFlowMonitoringInfoData) {
        ActivateFlowMonitoringInfoData data = (ActivateFlowMonitoringInfoData) payload;
        emit(STREAM_FLOW_ID, input, makeTuple(new ActivateFlowMonitoringCommand(data, true)));
        emit(STREAM_FLOW_ID, input, makeTuple(new ActivateFlowMonitoringCommand(data, false)));
    } else if (payload instanceof DeactivateFlowMonitoringInfoData) {
        DeactivateFlowMonitoringInfoData data = (DeactivateFlowMonitoringInfoData) payload;
        for (SwitchId switchId : data.getSwitchIds()) {
            emit(STREAM_FLOW_ID, input, makeTuple(new DeactivateFlowMonitoringCommand(switchId, data.getFlowId(), true)));
            emit(STREAM_FLOW_ID, input, makeTuple(new DeactivateFlowMonitoringCommand(switchId, data.getFlowId(), false)));
        }
    } else if (payload instanceof ActivateFlowMonitoringOnSwitchInfoData) {
        ActivateFlowMonitoringOnSwitchInfoData data = (ActivateFlowMonitoringOnSwitchInfoData) payload;
        activateFlowMonitoringOnSwitch(data.getSwitchId());
    } else if (payload instanceof DeactivateFlowMonitoringOnSwitchInfoData) {
        DeactivateFlowMonitoringOnSwitchInfoData data = (DeactivateFlowMonitoringOnSwitchInfoData) payload;
        deactivateFlowMonitoringOnSwitch(data.getSwitchId());
    } else if (payload instanceof ActivateIslMonitoringOnSwitchInfoData) {
        ActivateIslMonitoringOnSwitchInfoData data = (ActivateIslMonitoringOnSwitchInfoData) payload;
        activateIslMonitoringOnSwitch(data.getSwitchId());
    } else if (payload instanceof DeactivateIslMonitoringOnSwitchInfoData) {
        DeactivateIslMonitoringOnSwitchInfoData data = (DeactivateIslMonitoringOnSwitchInfoData) payload;
        deactivateIslMonitoringOnSwitch(data.getSwitchId());
    } else if (payload instanceof FeatureTogglesUpdate) {
        FeatureTogglesUpdate data = (FeatureTogglesUpdate) payload;
        this.service.handleFlowRttFeatureToggle(data.getToggles().getServer42FlowRtt());
        this.service.handleIslRttFeatureToggle(data.getToggles().getServer42IslRtt());
    } else {
        log.error("Do not proxy flow message - unexpected message payload \"{}\"", payload.getClass());
    }
}
Also used : DeactivateFlowMonitoringCommand(org.openkilda.server42.control.topology.storm.bolt.flow.command.DeactivateFlowMonitoringCommand) ActivateFlowMonitoringCommand(org.openkilda.server42.control.topology.storm.bolt.flow.command.ActivateFlowMonitoringCommand) ActivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.ActivateIslMonitoringOnSwitchInfoData) ActivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.ActivateFlowMonitoringOnSwitchInfoData) FeatureTogglesUpdate(org.openkilda.messaging.info.event.FeatureTogglesUpdate) DeactivateFlowMonitoringInfoData(org.openkilda.server42.control.messaging.flowrtt.DeactivateFlowMonitoringInfoData) DeactivateFlowMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.flowrtt.DeactivateFlowMonitoringOnSwitchInfoData) SwitchId(org.openkilda.model.SwitchId) DeactivateIslMonitoringOnSwitchInfoData(org.openkilda.server42.control.messaging.islrtt.DeactivateIslMonitoringOnSwitchInfoData) ActivateFlowMonitoringInfoData(org.openkilda.server42.control.messaging.flowrtt.ActivateFlowMonitoringInfoData)

Example 23 with Flow

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

the class StatsServer method run.

/**
 * Generate packet statistics.
 */
@Override
public void run() {
    log.info("started");
    try (ZContext context = new ZContext()) {
        Socket server = context.createSocket(ZMQ.PUSH);
        server.bind(bindEndpoint);
        while (!isInterrupted()) {
            LatencyPacketBucket.Builder bucketBuilder = LatencyPacketBucket.newBuilder();
            long seconds = TimeUnit.MILLISECONDS.toSeconds(Instant.now().toEpochMilli());
            long timestamp = seconds << 32;
            synchronized (this) {
                FlowLatencyPacket.Builder flowLatencyPacketBuilder = FlowLatencyPacket.newBuilder();
                for (FlowStats flow : flows.values()) {
                    flowLatencyPacketBuilder.setFlowId(flow.flowId);
                    flowLatencyPacketBuilder.setDirection(flow.direction);
                    flowLatencyPacketBuilder.setT0(timestamp);
                    long generatedLatency = MIN_DELTA_LATENCY + (long) (Math.random() * (MAX_DELTA_LATENCY - MIN_DELTA_LATENCY));
                    flowLatencyPacketBuilder.setT1(timestamp + flow.baseLatency + generatedLatency);
                    bucketBuilder.addFlowLatencyPacket(flowLatencyPacketBuilder.build());
                }
                IslLatencyPacket.Builder islLatencyPacketBuilder = IslLatencyPacket.newBuilder();
                for (Map.Entry<IslKey, Long> isl : isls.entrySet()) {
                    islLatencyPacketBuilder.setSwitchId(isl.getKey().getSwitchId());
                    islLatencyPacketBuilder.setPort(isl.getKey().getPort());
                    islLatencyPacketBuilder.setT0(timestamp);
                    long generatedLatency = MIN_DELTA_LATENCY + (long) (Math.random() * (MAX_DELTA_LATENCY - MIN_DELTA_LATENCY));
                    islLatencyPacketBuilder.setT1(timestamp + isl.getValue() + generatedLatency);
                    bucketBuilder.addIslLatencyPacket(islLatencyPacketBuilder.build());
                }
            }
            server.send(bucketBuilder.build().toByteArray());
            if (flows.isEmpty() && isls.isEmpty()) {
                log.info("send ping");
            } else {
                log.info("send stats");
            }
            try {
                sleep(tickSize);
            } catch (InterruptedException e) {
                log.info("received shutdown, exiting from server loop");
                return;
            }
        }
    }
}
Also used : LatencyPacketBucket(org.openkilda.server42.stats.messaging.Statistics.LatencyPacketBucket) IslLatencyPacket(org.openkilda.server42.stats.messaging.Statistics.IslLatencyPacket) FlowLatencyPacket(org.openkilda.server42.stats.messaging.Statistics.FlowLatencyPacket) ZContext(org.zeromq.ZContext) HashMap(java.util.HashMap) Map(java.util.Map) Socket(org.zeromq.ZMQ.Socket)

Example 24 with Flow

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

the class GateTest method removeFlow.

@Test
public void removeFlow() throws Exception {
    RemoveFlow removeFlow = RemoveFlow.builder().flowId("some-flow-id").build();
    gate.listen(removeFlow);
    CommandPacket commandPacket = getCommandPacket();
    assertThat(commandPacket.getType()).isEqualTo(Type.REMOVE_FLOW);
    assertThat(commandPacket.getCommandList()).hasSize(1);
    Any command = commandPacket.getCommand(0);
    assertThat(command.is(FlowRttControl.RemoveFlow.class)).isTrue();
    FlowRttControl.RemoveFlow unpack = command.unpack(FlowRttControl.RemoveFlow.class);
    assertThat(unpack.getFlow().getFlowId()).isEqualTo(removeFlow.getFlowId());
}
Also used : RemoveFlow(org.openkilda.server42.control.messaging.flowrtt.RemoveFlow) 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)

Example 25 with Flow

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

the class StubApplicationTests method deleteFlow.

@Test
public void deleteFlow() throws Exception {
    pushFlow(testFlowVlan1001);
    pushFlow(testFlowVxlan2002);
    pushFlow(testFlowVxlan3003);
    mockMvc.perform(delete("/kafka/flow/{id}", testFlowVxlan2002.getFlowId()).param("switchId", switchId)).andExpect(status().isOk());
    MvcResult result = mockMvc.perform(get("/kafka/flow/").param("switchId", switchId)).andReturn();
    ListFlowsPayload listFlowsPayload = new ListFlowsPayload();
    listFlowsPayload.getFlowIds().add(testFlowVlan1001.getFlowId());
    listFlowsPayload.getFlowIds().add(testFlowVxlan3003.getFlowId());
    mockMvc.perform(asyncDispatch(result)).andExpect(status().isOk()).andExpect(content().json(objectWriter.writeValueAsString(listFlowsPayload)));
}
Also used : ListFlowsPayload(org.openkilda.server42.control.stormstub.api.ListFlowsPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Test (org.junit.Test)11 SwitchId (org.openkilda.model.SwitchId)10 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 FlowDirection (org.openkilda.server42.messaging.FlowDirection)9 Duration (java.time.Duration)8 Values (org.apache.storm.tuple.Values)8 RunWith (org.junit.runner.RunWith)8 Mockito.verify (org.mockito.Mockito.verify)8 Message (org.openkilda.messaging.Message)8 CommandMessage (org.openkilda.messaging.command.CommandMessage)8 Arrays (java.util.Arrays)7 Assert.assertEquals (org.junit.Assert.assertEquals)7 Assert.assertTrue (org.junit.Assert.assertTrue)7 Before (org.junit.Before)7 Mock (org.mockito.Mock)7 Mockito.times (org.mockito.Mockito.times)7 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)7 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)7 UpdateFlowCommand (org.openkilda.messaging.info.flow.UpdateFlowCommand)7 FlowPathDto (org.openkilda.messaging.model.FlowPathDto)7