Search in sources :

Example 86 with FlowEndpoint

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");
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) FlowRequest(org.openkilda.messaging.command.flow.FlowRequest)

Example 87 with FlowEndpoint

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();
    }
}
Also used : YFlow(org.openkilda.model.YFlow) FlowEndpoint(org.openkilda.model.FlowEndpoint) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) SubFlowSharedEndpointEncapsulation(org.openkilda.messaging.command.yflow.SubFlowSharedEndpointEncapsulation) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow)

Example 88 with FlowEndpoint

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;
}
Also used : RequestedFlowMapper(org.openkilda.wfm.share.mappers.RequestedFlowMapper) FlowMapper(org.openkilda.wfm.share.mappers.FlowMapper) FlowEndpoint(org.openkilda.model.FlowEndpoint) PatchEndpoint(org.openkilda.messaging.model.PatchEndpoint) DetectConnectedDevicesDto(org.openkilda.messaging.model.DetectConnectedDevicesDto) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPoint(org.openkilda.messaging.nbtopology.response.FlowMirrorPointsDumpResponse.FlowMirrorPoint) IslEndpoint(org.openkilda.model.IslEndpoint) PatchEndpoint(org.openkilda.messaging.model.PatchEndpoint) FlowEndpoint(org.openkilda.model.FlowEndpoint)

Example 89 with FlowEndpoint

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;
}
Also used : Action(org.openkilda.rulemanager.action.Action) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) FlowEndpoint(org.openkilda.model.FlowEndpoint) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 90 with FlowEndpoint

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;
}
Also used : FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowEndpoint(org.openkilda.model.FlowEndpoint) ArrayList(java.util.ArrayList) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData)

Aggregations

FlowEndpoint (org.openkilda.model.FlowEndpoint)105 Test (org.junit.Test)26 Flow (org.openkilda.model.Flow)22 ArrayList (java.util.ArrayList)15 RoutingMetadata (org.openkilda.floodlight.utils.metadata.RoutingMetadata)12 YFlow (org.openkilda.model.YFlow)11 FlowPath (org.openkilda.model.FlowPath)10 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)9 SpeakerData (org.openkilda.rulemanager.SpeakerData)9 SwitchId (org.openkilda.model.SwitchId)8 YSubFlow (org.openkilda.model.YSubFlow)8 HashSet (java.util.HashSet)7 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)7 FlowSourceAdapter (org.openkilda.adapter.FlowSourceAdapter)7 IngressFlowSegmentInstallCommand (org.openkilda.floodlight.command.flow.ingress.IngressFlowSegmentInstallCommand)7 EffectiveIds (org.openkilda.floodlight.model.EffectiveIds)7 FlowSegmentWrapperCommand (org.openkilda.floodlight.command.flow.FlowSegmentWrapperCommand)6 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)6 OFFlowAdd (org.projectfloodlight.openflow.protocol.OFFlowAdd)6 MessageContext (org.openkilda.messaging.MessageContext)5