Search in sources :

Example 26 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class OnErrorResponseAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
    SpeakerFlowSegmentResponse response = context.getSpeakerFlowResponse();
    if (response.isSuccess() || !(response instanceof FlowErrorResponse)) {
        throw new IllegalArgumentException(format("Invoked %s for a success response: %s", this.getClass(), response));
    }
    UUID failedCommandId = response.getCommandId();
    FlowSegmentRequestFactory failedCommand = stateMachine.getRemoveCommands().get(failedCommandId);
    if (!stateMachine.getPendingCommands().contains(failedCommandId) || failedCommand == null) {
        log.info("Received a response for unexpected command: {}", response);
        return;
    }
    FlowErrorResponse errorResponse = (FlowErrorResponse) response;
    int attempt = stateMachine.doRetryForCommand(failedCommandId);
    if (attempt <= speakerCommandRetriesLimit) {
        stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s. Retrying (attempt %d)", failedCommandId, errorResponse.getSwitchId(), response.getCookie(), errorResponse, attempt));
        stateMachine.getCarrier().sendSpeakerRequest(failedCommand.makeRemoveRequest(failedCommandId));
    } else {
        stateMachine.removePendingCommand(failedCommandId);
        stateMachine.saveErrorToHistory("Failed to remove rule", format("Failed to remove the rule: commandId %s, switch %s, cookie %s. Error %s", failedCommandId, errorResponse.getSwitchId(), response.getCookie(), errorResponse));
        stateMachine.addFailedCommand(failedCommandId, errorResponse);
        if (stateMachine.getPendingCommands().isEmpty()) {
            String errorMessage = format("Received error response(s) for %d remove commands", stateMachine.getFailedCommands().size());
            stateMachine.saveErrorToHistory(errorMessage);
            stateMachine.fire(Event.RULES_REMOVED);
        }
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowErrorResponse(org.openkilda.floodlight.flow.response.FlowErrorResponse) SpeakerFlowSegmentResponse(org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse) UUID(java.util.UUID)

Example 27 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class EmitVerifyRulesAction method emitVerifyRequests.

protected void emitVerifyRequests(FlowCreateFsm stateMachine, Collection<FlowSegmentRequestFactory> requestFactories) {
    final Map<UUID, SpeakerCommandObserver> pendingCommands = stateMachine.getPendingCommands();
    for (FlowSegmentRequestFactory factory : requestFactories) {
        FlowSegmentRequest request = factory.makeVerifyRequest(commandIdGenerator.generate());
        SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, Collections.singleton(ErrorCode.MISSING_OF_FLOWS), request);
        commandObserver.start();
        pendingCommands.put(request.getCommandId(), commandObserver);
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest) SpeakerCommandObserver(org.openkilda.wfm.topology.flowhs.service.SpeakerCommandObserver) UUID(java.util.UUID)

Example 28 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class SpeakerRequestEmitter method emitBatch.

/**
 * Emit series of speaker requests produced from proposed series of request factories.
 */
public void emitBatch(FlowGenericCarrier carrier, Collection<FlowSegmentRequestFactory> factories, Map<UUID, FlowSegmentRequestFactory> requestsStorage) {
    for (FlowSegmentRequestFactory factory : factories) {
        FlowSegmentRequest request = makeRequest(factory);
        requestsStorage.put(request.getCommandId(), factory);
        carrier.sendSpeakerRequest(request);
    }
}
Also used : FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowSegmentRequest(org.openkilda.floodlight.api.request.FlowSegmentRequest)

Example 29 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilderTest method shouldCreateOneSwitchFlow.

@Test
public void shouldCreateOneSwitchFlow() {
    Switch sw = Switch.builder().switchId(SWITCH_1).build();
    Flow flow = buildFlow(sw, 1, 10, sw, 2, 12, 1000);
    List<FlowSegmentRequestFactory> commands = target.buildAll(COMMAND_CONTEXT, flow, flow.getForwardPath(), flow.getReversePath(), SpeakerRequestBuildContext.getEmpty());
    assertEquals(2, commands.size());
    verifyForwardOneSwitchRequest(flow, commands.get(0).makeInstallRequest(commandIdGenerator.generate()));
    verifyReverseOneSwitchRequest(flow, commands.get(1).makeInstallRequest(commandIdGenerator.generate()));
}
Also used : IngressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) Switch(org.openkilda.model.Switch) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 30 with FlowSegmentRequestFactory

use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.

the class SpeakerFlowSegmentRequestBuilderTest method shouldCreateNonIngressRequestsWithoutVlans.

@Test
public void shouldCreateNonIngressRequestsWithoutVlans() {
    Switch srcSwitch = Switch.builder().switchId(SWITCH_1).build();
    Switch destSwitch = Switch.builder().switchId(SWITCH_2).build();
    Flow flow = buildFlow(srcSwitch, 1, 0, destSwitch, 2, 0, 0);
    setSegmentsWithoutTransitSwitches(Objects.requireNonNull(flow.getForwardPath()), Objects.requireNonNull(flow.getReversePath()));
    List<FlowSegmentRequestFactory> commands = target.buildAllExceptIngress(COMMAND_CONTEXT, flow);
    assertEquals(2, commands.size());
    verifyForwardEgressRequest(flow, commands.get(0).makeInstallRequest(commandIdGenerator.generate()));
    verifyReverseEgressRequest(flow, commands.get(1).makeInstallRequest(commandIdGenerator.generate()));
}
Also used : IngressFlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) Switch(org.openkilda.model.Switch) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

FlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory)53 UUID (java.util.UUID)33 Flow (org.openkilda.model.Flow)21 ArrayList (java.util.ArrayList)19 FlowErrorResponse (org.openkilda.floodlight.flow.response.FlowErrorResponse)15 SpeakerFlowSegmentResponse (org.openkilda.floodlight.api.response.SpeakerFlowSegmentResponse)14 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)14 FlowPath (org.openkilda.model.FlowPath)12 IngressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressFlowSegmentRequestFactory)11 SpeakerRequestBuildContext (org.openkilda.wfm.share.model.SpeakerRequestBuildContext)11 FlowSegmentRequest (org.openkilda.floodlight.api.request.FlowSegmentRequest)9 EgressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressMirrorFlowSegmentRequestFactory)7 EgressFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.EgressFlowSegmentRequestFactory)6 IngressMirrorFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.IngressMirrorFlowSegmentRequestFactory)6 TransitFlowSegmentRequestFactory (org.openkilda.floodlight.api.request.factory.TransitFlowSegmentRequestFactory)6 Switch (org.openkilda.model.Switch)5 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)5 MirrorContext (org.openkilda.wfm.share.model.MirrorContext)5 Test (org.junit.Test)4 SpeakerResponse (org.openkilda.floodlight.api.response.SpeakerResponse)4