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);
}
}
}
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);
}
}
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);
}
}
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()));
}
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()));
}
Aggregations