use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.
the class InstallRulesAction method emitInstallRequests.
protected void emitInstallRequests(FlowCreateFsm stateMachine, List<FlowSegmentRequestFactory> factories) {
Map<UUID, SpeakerCommandObserver> pendingRequests = stateMachine.getPendingCommands();
List<FlowSegmentRequestFactory> sentCommands = stateMachine.getSentCommands();
for (FlowSegmentRequestFactory factory : factories) {
FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, request);
commandObserver.start();
sentCommands.add(factory);
// TODO ensure no conflicts
pendingRequests.put(request.getCommandId(), commandObserver);
}
}
use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.
the class EmitIngressRulesVerifyRequestsAction method perform.
@Override
public void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getIngressCommands();
List<FlowSegmentRequestFactory> requestFactories = new ArrayList<>(requestsStorage.values());
requestsStorage.clear();
stateMachine.clearPendingAndRetriedAndFailedCommands();
for (FlowSegmentRequestFactory factory : requestFactories) {
FlowSegmentRequest request = factory.makeVerifyRequest(commandIdGenerator.generate());
// TODO ensure no conflicts
requestsStorage.put(request.getCommandId(), factory);
stateMachine.getCarrier().sendSpeakerRequest(request);
}
requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
stateMachine.saveActionToHistory("Started validation of installed ingress rules");
}
use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.
the class InstallIngressRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
// Detach the entity to avoid propagation to the database.
flowRepository.detach(flow);
if (stateMachine.getNewEncapsulationType() != null) {
// This is for commandBuilder.buildIngressOnly() to use proper (updated) encapsulation type.
flow.setEncapsulationType(stateMachine.getNewEncapsulationType());
}
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
Collection<FlowSegmentRequestFactory> requestFactories = new ArrayList<>();
if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
FlowPath newForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
FlowPath newReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
SpeakerRequestBuildContext speakerContext = buildBaseSpeakerContextForInstall(newForward.getSrcSwitchId(), newReverse.getSrcSwitchId());
requestFactories.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, newForward, newReverse, speakerContext));
}
// Installation of ingress rules for protected paths is skipped. These paths are activated on swap.
stateMachine.clearPendingAndRetriedAndFailedCommands();
if (requestFactories.isEmpty()) {
stateMachine.saveActionToHistory("No need to install ingress rules");
stateMachine.fire(Event.INGRESS_IS_SKIPPED);
} else {
Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getIngressCommands();
for (FlowSegmentRequestFactory factory : requestFactories) {
FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
requestsStorage.put(request.getCommandId(), factory);
stateMachine.getCarrier().sendSpeakerRequest(request);
}
requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
stateMachine.saveActionToHistory("Commands for installing ingress rules have been sent");
}
}
use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.
the class InstallNonIngressRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
// Detach the entity to avoid propagation to the database.
flowRepository.detach(flow);
if (stateMachine.getNewEncapsulationType() != null) {
// This is for commandBuilder.buildAllExceptIngress() to use proper (updated) encapsulation type.
flow.setEncapsulationType(stateMachine.getNewEncapsulationType());
}
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
Collection<FlowSegmentRequestFactory> requestFactories = new ArrayList<>();
if (stateMachine.getNewPrimaryForwardPath() != null && stateMachine.getNewPrimaryReversePath() != null) {
FlowPath newForward = getFlowPath(flow, stateMachine.getNewPrimaryForwardPath());
FlowPath newReverse = getFlowPath(flow, stateMachine.getNewPrimaryReversePath());
requestFactories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, newForward, newReverse));
}
if (stateMachine.getNewProtectedForwardPath() != null && stateMachine.getNewProtectedReversePath() != null) {
FlowPath newForward = getFlowPath(flow, stateMachine.getNewProtectedForwardPath());
FlowPath newReverse = getFlowPath(flow, stateMachine.getNewProtectedReversePath());
requestFactories.addAll(commandBuilder.buildAllExceptIngress(stateMachine.getCommandContext(), flow, newForward, newReverse));
}
stateMachine.clearPendingAndRetriedAndFailedCommands();
if (requestFactories.isEmpty()) {
stateMachine.saveActionToHistory("No need to install non ingress rules");
stateMachine.fire(Event.RULES_INSTALLED);
} else {
Map<UUID, FlowSegmentRequestFactory> requestsStorage = stateMachine.getNonIngressCommands();
for (FlowSegmentRequestFactory factory : requestFactories) {
FlowSegmentRequest request = factory.makeInstallRequest(commandIdGenerator.generate());
// TODO ensure no conflicts
requestsStorage.put(request.getCommandId(), factory);
stateMachine.getCarrier().sendSpeakerRequest(request);
}
requestsStorage.forEach((key, value) -> stateMachine.addPendingCommand(key, value.getSwitchId()));
stateMachine.saveActionToHistory("Commands for installing non ingress rules have been sent");
}
}
use of org.openkilda.floodlight.api.request.FlowSegmentRequest in project open-kilda by telstra.
the class SpeakerWorkerService method handleTimeout.
/**
* Handles operation timeout.
* @param key operation identifier.
*/
public void handleTimeout(@NonNull String key) throws PipelineException {
SpeakerRequest failedRequest = keyToRequest.remove(key);
if (failedRequest instanceof FlowSegmentRequest) {
FlowSegmentRequest flowSegmentRequest = (FlowSegmentRequest) failedRequest;
SpeakerFlowSegmentResponse response = FlowErrorResponse.errorBuilder().commandId(flowSegmentRequest.getCommandId()).switchId(flowSegmentRequest.getSwitchId()).metadata(flowSegmentRequest.getMetadata()).errorCode(ErrorCode.OPERATION_TIMED_OUT).messageContext(flowSegmentRequest.getMessageContext()).build();
carrier.sendResponse(key, response);
} else if (failedRequest instanceof BaseSpeakerCommandsRequest) {
BaseSpeakerCommandsRequest speakerCommandsRequest = (BaseSpeakerCommandsRequest) failedRequest;
SpeakerCommandResponse response = SpeakerCommandResponse.builder().commandId(speakerCommandsRequest.getCommandId()).switchId(speakerCommandsRequest.getSwitchId()).messageContext(speakerCommandsRequest.getMessageContext()).success(false).failedCommandIds(speakerCommandsRequest.getCommands().stream().map(command -> {
if (command instanceof FlowCommand) {
return ((FlowCommand) command).getData();
}
if (command instanceof MeterCommand) {
return ((MeterCommand) command).getData();
}
return ((GroupCommand) command).getData();
}).collect(Collectors.toMap(SpeakerData::getUuid, error -> "Operation is timed out"))).build();
carrier.sendResponse(key, response);
}
}
Aggregations