Search in sources :

Example 1 with SpeakerRequestEmitter

use of org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter in project open-kilda by telstra.

the class EmitUpdateRulesRequestsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
    stateMachine.getCommands().clear();
    stateMachine.getPendingCommands().clear();
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    Collection<FlowSegmentRequestFactory> commands = buildCommands(stateMachine, flow);
    // emitting
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
    SpeakerRequestEmitter requestEmitter;
    if (mirrorPoints != null && mirrorPoints.getMirrorPaths().isEmpty()) {
        requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
    } else {
        requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
    }
    requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
    stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to update rules");
    } else {
        stateMachine.saveActionToHistory("Commands for updating rules have been sent");
        stateMachine.setRulesInstalled(true);
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 2 with SpeakerRequestEmitter

use of org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter in project open-kilda by telstra.

the class EmitCommandRequestsAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
    String flowId = stateMachine.getFlowId();
    Flow flow = getFlow(flowId);
    PathId flowPathId = stateMachine.getFlowPathId();
    SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
    FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror points for flow path %s and mirror switch id %s not found", flowPathId, mirrorSwitchId)));
    FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
    Collection<FlowSegmentRequestFactory> commands = buildCommands(commandBuilder, stateMachine, flow, mirrorPoints);
    // emitting
    SpeakerRequestEmitter requestEmitter;
    if (mirrorPoints.getMirrorPaths().isEmpty()) {
        requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
    } else {
        requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
    }
    requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
    stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
    if (commands.isEmpty()) {
        stateMachine.saveActionToHistory("No need to remove group");
    } else {
        stateMachine.saveActionToHistory("Commands for removing group have been sent");
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowCommandBuilder(org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Aggregations

FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)2 Flow (org.openkilda.model.Flow)2 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)2 PathId (org.openkilda.model.PathId)2 SwitchId (org.openkilda.model.SwitchId)2 SpeakerRequestEmitter (org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter)2 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)1 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)1