use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class UpdateRequestAction method sendUpdateCommand.
private void sendUpdateCommand(Flow flow, RequestedFlow targetFlow, String anotherFlowId, FlowSwapEndpointsFsm stateMachine) {
FlowRequest flowRequest = RequestedFlowMapper.INSTANCE.toFlowRequest(flow);
flowRequest.setSource(new FlowEndpoint(targetFlow.getSrcSwitch(), targetFlow.getSrcPort(), targetFlow.getSrcVlan()));
flowRequest.setDestination(new FlowEndpoint(targetFlow.getDestSwitch(), targetFlow.getDestPort(), targetFlow.getDestVlan()));
if (flow.getLoopSwitchId() != null) {
boolean flowLoopedOnSrc = flow.getLoopSwitchId().equals(flow.getSrcSwitchId());
flowRequest.setLoopSwitchId(flowLoopedOnSrc ? flowRequest.getSource().getSwitchId() : flowRequest.getDestination().getSwitchId());
}
flowRequest.setBulkUpdateFlowIds(Sets.newHashSet(anotherFlowId));
flowRequest.setType(Type.UPDATE);
stateMachine.sendFlowUpdateRequest(flowRequest);
stateMachine.saveFlowActionToHistory(flow.getFlowId(), "Command for update flow has been sent");
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class OnSubFlowAllocatedAction method performWithResponse.
@Override
protected Optional<Message> performWithResponse(State from, State to, Event event, YFlowCreateContext context, YFlowCreateFsm stateMachine) {
String subFlowId = context.getSubFlowId();
if (!stateMachine.isCreatingSubFlow(subFlowId)) {
throw new IllegalStateException("Received an event for non-pending sub-flow " + subFlowId);
}
String yFlowId = stateMachine.getYFlowId();
stateMachine.saveActionToHistory("Creating a sub-flow", format("Allocated resources for sub-flow %s of y-flow %s", subFlowId, yFlowId));
stateMachine.addAllocatedSubFlow(subFlowId);
SubFlowDto subFlowDto = stateMachine.getTargetFlow().getSubFlows().stream().filter(f -> f.getFlowId().equals(subFlowId)).findAny().orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Can't find definition of created sub-flow %s", subFlowId)));
SubFlowSharedEndpointEncapsulation sharedEndpoint = subFlowDto.getSharedEndpoint();
FlowEndpoint endpoint = subFlowDto.getEndpoint();
log.debug("Start creating sub-flow references from {} to y-flow {}", subFlowId, stateMachine.getYFlowId());
YFlow result = transactionManager.doInTransaction(() -> {
YFlow yFlow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Y-flow %s not found", yFlowId)));
Flow flow = flowRepository.findById(subFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.INTERNAL_ERROR, format("Flow %s not found", subFlowId)));
YSubFlow subFlow = YSubFlow.builder().yFlow(yFlow).flow(flow).sharedEndpointVlan(sharedEndpoint.getVlanId()).sharedEndpointInnerVlan(sharedEndpoint.getInnerVlanId()).endpointSwitchId(endpoint.getSwitchId()).endpointPort(endpoint.getPortNumber()).endpointVlan(endpoint.getOuterVlanId()).endpointInnerVlan(endpoint.getInnerVlanId()).build();
yFlow.addSubFlow(subFlow);
return yFlow;
});
if (subFlowId.equals(stateMachine.getMainAffinityFlowId())) {
stateMachine.getRequestedFlows().forEach(requestedFlow -> {
String requestedFlowId = requestedFlow.getFlowId();
if (!requestedFlowId.equals(subFlowId)) {
stateMachine.addSubFlow(requestedFlowId);
stateMachine.addCreatingSubFlow(requestedFlowId);
stateMachine.notifyEventListeners(listener -> listener.onSubFlowProcessingStart(yFlowId, requestedFlowId));
CommandContext flowContext = stateMachine.getCommandContext().fork(requestedFlowId);
requestedFlow.setAffinityFlowId(stateMachine.getMainAffinityFlowId());
flowCreateService.startFlowCreation(flowContext, requestedFlow, yFlowId);
}
});
}
if (stateMachine.getAllocatedSubFlows().size() == stateMachine.getSubFlows().size()) {
return Optional.of(buildResponseMessage(result, stateMachine.getCommandContext()));
} else {
return Optional.empty();
}
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class FlowOperationsService method addChangedFields.
private FlowRequest addChangedFields(FlowRequest flowRequest, FlowPatch flowPatch) {
boolean trackSrcLldp = flowRequest.getSource().isTrackLldpConnectedDevices();
boolean trackSrcArp = flowRequest.getSource().isTrackArpConnectedDevices();
PatchEndpoint source = flowPatch.getSource();
if (source != null) {
SwitchId switchId = Optional.ofNullable(source.getSwitchId()).orElse(flowRequest.getSource().getSwitchId());
int port = Optional.ofNullable(source.getPortNumber()).orElse(flowRequest.getSource().getPortNumber());
int vlan = Optional.ofNullable(source.getVlanId()).orElse(flowRequest.getSource().getOuterVlanId());
int innerVlan = Optional.ofNullable(source.getInnerVlanId()).orElse(flowRequest.getSource().getInnerVlanId());
trackSrcLldp = Optional.ofNullable(source.getTrackLldpConnectedDevices()).orElse(flowRequest.getSource().isTrackLldpConnectedDevices());
trackSrcArp = Optional.ofNullable(source.getTrackArpConnectedDevices()).orElse(flowRequest.getSource().isTrackArpConnectedDevices());
flowRequest.setSource(new FlowEndpoint(switchId, port, vlan, innerVlan));
}
boolean trackDstLldp = flowRequest.getDestination().isTrackLldpConnectedDevices();
boolean trackDstArp = flowRequest.getDestination().isTrackArpConnectedDevices();
PatchEndpoint destination = flowPatch.getDestination();
if (destination != null) {
SwitchId switchId = Optional.ofNullable(destination.getSwitchId()).orElse(flowRequest.getDestination().getSwitchId());
int port = Optional.ofNullable(destination.getPortNumber()).orElse(flowRequest.getDestination().getPortNumber());
int vlan = Optional.ofNullable(destination.getVlanId()).orElse(flowRequest.getDestination().getOuterVlanId());
int innerVlan = Optional.ofNullable(destination.getInnerVlanId()).orElse(flowRequest.getDestination().getInnerVlanId());
trackDstLldp = Optional.ofNullable(destination.getTrackLldpConnectedDevices()).orElse(flowRequest.getDestination().isTrackLldpConnectedDevices());
trackDstArp = Optional.ofNullable(destination.getTrackArpConnectedDevices()).orElse(flowRequest.getDestination().isTrackArpConnectedDevices());
flowRequest.setDestination(new FlowEndpoint(switchId, port, vlan, innerVlan));
}
flowRequest.setDetectConnectedDevices(new DetectConnectedDevicesDto(trackSrcLldp, trackSrcArp, trackDstLldp, trackDstArp));
Optional.ofNullable(flowPatch.getBandwidth()).ifPresent(flowRequest::setBandwidth);
Optional.ofNullable(flowPatch.getIgnoreBandwidth()).ifPresent(flowRequest::setIgnoreBandwidth);
Optional.ofNullable(flowPatch.getAllocateProtectedPath()).ifPresent(flowRequest::setAllocateProtectedPath);
Optional.ofNullable(flowPatch.getEncapsulationType()).map(FlowMapper.INSTANCE::map).ifPresent(flowRequest::setEncapsulationType);
Optional.ofNullable(flowPatch.getPathComputationStrategy()).map(PathComputationStrategy::toString).ifPresent(flowRequest::setPathComputationStrategy);
Optional.ofNullable(flowPatch.getDiverseFlowId()).ifPresent(flowRequest::setDiverseFlowId);
return flowRequest;
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class SingleTableIngressRuleGenerator method buildTransformActions.
@VisibleForTesting
List<Action> buildTransformActions(int outerVlan, Set<SwitchFeature> features) {
List<Integer> currentStack = makeVlanStack(outerVlan);
List<Integer> targetStack;
if (flowPath.isOneSwitchFlow()) {
FlowEndpoint egressEndpoint = FlowSideAdapter.makeEgressAdapter(flow, flowPath).getEndpoint();
targetStack = makeVlanStack(egressEndpoint.getOuterVlanId());
} else if (encapsulation.getType() == TRANSIT_VLAN) {
targetStack = makeVlanStack(encapsulation.getId());
} else {
targetStack = new ArrayList<>();
}
// TODO do something with groups
List<Action> transformActions = new ArrayList<>(Utils.makeVlanReplaceActions(currentStack, targetStack));
if (!flowPath.isOneSwitchFlow() && encapsulation.getType() == VXLAN) {
transformActions.add(buildPushVxlan(encapsulation.getId(), flowPath.getSrcSwitchId(), flowPath.getDestSwitchId(), VXLAN_UDP_SRC, features));
}
return transformActions;
}
use of org.openkilda.model.FlowEndpoint in project open-kilda by telstra.
the class SingleTableIngressRuleGenerator method generateCommands.
@Override
public List<SpeakerData> generateCommands(Switch sw) {
List<SpeakerData> result = new ArrayList<>();
FlowEndpoint ingressEndpoint = FlowSideAdapter.makeIngressAdapter(flow, flowPath).getEndpoint();
FlowSpeakerData command = buildFlowIngressCommand(sw, ingressEndpoint);
if (command == null) {
return Collections.emptyList();
}
result.add(command);
SpeakerData meterCommand = buildMeter(flowPath, config, flowPath.getMeterId(), sw);
if (meterCommand != null) {
addMeterToInstructions(flowPath.getMeterId(), sw, command.getInstructions());
result.add(meterCommand);
command.getDependsOn().add(meterCommand.getUuid());
}
return result;
}
Aggregations