use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.
the class SpeakerFlowSegmentRequestBuilder method makeLoopRequests.
private List<FlowSegmentRequestFactory> makeLoopRequests(CommandContext context, FlowPath path, FlowTransitEncapsulation encapsulation, FlowSideAdapter ingressSide, FlowSideAdapter egressSide, PathSegment segment) {
List<FlowSegmentRequestFactory> result = new ArrayList<>(2);
PathSegmentSide segmentSide = makePathSegmentSourceSide(segment);
UUID commandId = commandIdGenerator.generate();
MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
FlowSegmentCookie cookie = path.getCookie().toBuilder().looped(true).build();
result.add(IngressFlowLoopSegmentRequestFactory.builder().messageContext(messageContext).metadata(makeMetadata(path.getFlow().getFlowId(), cookie, segmentSide.isMultiTable())).endpoint(ingressSide.getEndpoint()).build());
FlowPathDirection reverse = cookie.getDirection() == FlowPathDirection.FORWARD ? FlowPathDirection.REVERSE : FlowPathDirection.FORWARD;
Cookie transitCookie = path.getCookie().toBuilder().looped(true).direction(reverse).build();
result.add(TransitFlowLoopSegmentRequestFactory.builder().messageContext(messageContext).switchId(segment.getSrcSwitch().getSwitchId()).egressSwitchId(egressSide.getEndpoint().getSwitchId()).metadata(makeMetadata(path.getFlow().getFlowId(), transitCookie, segmentSide.isMultiTable())).port(segment.getSrcPort()).encapsulation(encapsulation).build());
return result;
}
use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.
the class SpeakerFlowSegmentRequestBuilder method makeIngressSegmentRequests.
private List<FlowSegmentRequestFactory> makeIngressSegmentRequests(CommandContext context, FlowPath path, FlowTransitEncapsulation encapsulation, FlowSideAdapter flowSide, PathSegment segment, FlowSideAdapter egressFlowSide, RulesContext rulesContext, MirrorContext mirrorContext) {
PathSegmentSide segmentSide = makePathSegmentSourceSide(segment);
UUID commandId = commandIdGenerator.generate();
MessageContext messageContext = new MessageContext(commandId.toString(), context.getCorrelationId());
FlowSegmentMetadata metadata = makeMetadata(path, ensureEqualMultiTableFlag(path.isSrcWithMultiTable(), segmentSide.isMultiTable(), String.format("First flow(id:%s, path:%s) segment and flow path level multi-table flag values " + "are incompatible to each other - flow path(%s) != segment(%s)", path.getFlow().getFlowId(), path.getPathId(), path.isSrcWithMultiTable(), segmentSide.isMultiTable())));
List<FlowSegmentRequestFactory> ingressFactories = new ArrayList<>();
if (!mirrorContext.isBuildMirrorFactoryOnly()) {
ingressFactories.add(IngressFlowSegmentRequestFactory.builder().messageContext(messageContext).metadata(metadata).endpoint(flowSide.getEndpoint()).meterConfig(getMeterConfig(path)).egressSwitchId(egressFlowSide.getEndpoint().getSwitchId()).islPort(segmentSide.getEndpoint().getPortNumber()).encapsulation(encapsulation).rulesContext(rulesContext).build());
}
Optional<MirrorConfig> mirrorConfig = makeMirrorConfig(path, segmentSide.getEndpoint(), mirrorContext);
if (mirrorConfig.isPresent() || mirrorContext.isRemoveFlowOperation()) {
FlowSegmentCookie mirrorCookie = path.getCookie().toBuilder().mirror(true).build();
ingressFactories.add(IngressMirrorFlowSegmentRequestFactory.builder().messageContext(new MessageContext(commandIdGenerator.generate().toString(), context.getCorrelationId())).metadata(makeMetadata(metadata.getFlowId(), mirrorCookie, metadata.isMultiTable())).endpoint(flowSide.getEndpoint()).meterConfig(getMeterConfig(path)).egressSwitchId(egressFlowSide.getEndpoint().getSwitchId()).islPort(segmentSide.getEndpoint().getPortNumber()).encapsulation(encapsulation).rulesContext(rulesContext.toBuilder().updateMeter(false).installServer42IngressRule(false).installServer42InputRule(false).installServer42OuterVlanMatchSharedRule(false).build()).mirrorConfig(mirrorConfig.orElse(null)).build());
}
return ingressFactories;
}
use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.
the class ResourcesAllocationAction method createSpeakerRequestFactories.
private void createSpeakerRequestFactories(FlowCreateFsm stateMachine, Flow flow) {
final FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
final CommandContext commandContext = stateMachine.getCommandContext();
List<FlowSegmentRequestFactory> requestFactories;
// ingress
requestFactories = stateMachine.getIngressCommands();
SpeakerRequestBuildContext buildContext = buildBaseSpeakerContextForInstall(flow.getSrcSwitchId(), flow.getDestSwitchId());
requestFactories.addAll(commandBuilder.buildIngressOnly(stateMachine.getCommandContext(), flow, buildContext));
// non ingress
requestFactories = stateMachine.getNonIngressCommands();
requestFactories.addAll(commandBuilder.buildAllExceptIngress(commandContext, flow));
if (flow.isAllocateProtectedPath()) {
requestFactories.addAll(commandBuilder.buildAllExceptIngress(commandContext, flow, flow.getProtectedForwardPath(), flow.getProtectedReversePath()));
}
}
use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.
the class RollbackInstalledRulesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowCreateContext context, FlowCreateFsm stateMachine) {
stateMachine.getPendingCommands().clear();
stateMachine.getFailedCommands().clear();
Map<UUID, SpeakerCommandObserver> pendingRequests = stateMachine.getPendingCommands();
for (FlowSegmentRequestFactory factory : stateMachine.getSentCommands()) {
FlowSegmentRequest request = factory.makeRemoveRequest(commandIdGenerator.generate());
SpeakerCommandObserver commandObserver = new SpeakerCommandObserver(speakerCommandFsmBuilder, request);
commandObserver.start();
// TODO ensure no conflicts
pendingRequests.put(request.getCommandId(), commandObserver);
}
stateMachine.saveActionToHistory(String.format("Commands to rollback installed rules have been sent. Total amount: %s", pendingRequests.size()));
}
use of org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory in project open-kilda by telstra.
the class HandleNotCompletedCommandsAction method perform.
@Override
public void perform(State from, State to, Event event, FlowDeleteContext context, FlowDeleteFsm stateMachine) {
for (UUID commandId : stateMachine.getPendingCommands()) {
FlowSegmentRequestFactory notCompletedCommand = stateMachine.getRemoveCommands().get(commandId);
if (notCompletedCommand != null) {
stateMachine.saveErrorToHistory("Command is not finished yet", format("Completing the removal operation although the command may not be finished yet: " + "commandId %s, switch %s, cookie %s", commandId, notCompletedCommand.getSwitchId(), notCompletedCommand.getCookie()));
}
}
log.debug("Abandoning all pending commands: {}", stateMachine.getPendingCommands());
stateMachine.clearPendingCommands();
}
Aggregations