Search in sources :

Example 21 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class OnSubFlowAllocatedAction method buildRerouteResponseMessage.

private Message buildRerouteResponseMessage(YFlowRerouteFsm stateMachine) {
    String yFlowId = stateMachine.getYFlowId();
    List<Long> oldFlowPathCookies = stateMachine.getOldYFlowPathCookies();
    List<FlowPath> flowPaths = transactionManager.doInTransaction(() -> {
        YFlow yflow = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Y-flow %s not found", yFlowId)));
        SwitchId sharedSwitchId = yflow.getSharedEndpoint().getSwitchId();
        List<FlowPath> paths = new ArrayList<>();
        for (YSubFlow subFlow : yflow.getSubFlows()) {
            Flow flow = subFlow.getFlow();
            FlowPath flowPath = flow.getPaths().stream().filter(path -> sharedSwitchId.equals(path.getSrcSwitchId()) && !path.isProtected() && !oldFlowPathCookies.contains(path.getCookie().getValue())).findFirst().orElse(sharedSwitchId.equals(flow.getForwardPath().getSrcSwitchId()) ? flow.getForwardPath() : flow.getReversePath());
            paths.add(flowPath);
        }
        return paths;
    });
    List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(flowPaths);
    PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
    List<SubFlowPathDto> subFlowPathDtos = flowPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).sorted(Comparator.comparing(SubFlowPathDto::getFlowId)).collect(Collectors.toList());
    PathInfoData oldSharedPath = stateMachine.getOldSharedPath();
    List<SubFlowPathDto> oldSubFlowPathDtos = stateMachine.getOldSubFlowPathDtos();
    YFlowRerouteResponse response = new YFlowRerouteResponse(sharedPath, subFlowPathDtos, !(sharedPath.equals(oldSharedPath) && subFlowPathDtos.equals(oldSubFlowPathDtos)));
    CommandContext commandContext = stateMachine.getCommandContext();
    return new InfoMessage(response, commandContext.getCreateTime(), commandContext.getCorrelationId());
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) YFlowRerouteResponse(org.openkilda.messaging.command.yflow.YFlowRerouteResponse) InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPath(org.openkilda.model.FlowPath) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto)

Example 22 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class YFlowSwitchFlowEntriesBuilder method getGroupEntries.

/**
 * Construct a set of {@link GroupEntry} that corresponds to the builder's y-flow.
 */
public Map<SwitchId, Collection<GroupEntry>> getGroupEntries() {
    MultiValuedMap<SwitchId, GroupEntry> groupEntries = new ArrayListValuedHashMap<>();
    yFlow.getSubFlows().forEach(subFlow -> {
        Flow flow = subFlow.getFlow();
        SwitchFlowEntriesBuilder builder = new SwitchFlowEntriesBuilder(flow);
        builder.getSwitchGroupEntries().forEach(entries -> groupEntries.putAll(entries.getSwitchId(), entries.getGroupEntries()));
    });
    return groupEntries.asMap();
}
Also used : GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) SwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder) SwitchId(org.openkilda.model.SwitchId) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow)

Example 23 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class AbstractYFlowTest method createYFlowViaTransit.

protected YFlow createYFlowViaTransit(String yFlowId) {
    // Create sub-flows
    Flow firstFlow = dummyFactory.makeMainAffinityFlow(firstSharedEndpoint, firstEndpoint, islSharedToTransit, islTransitToFirst);
    Flow secondFlow = dummyFactory.makeFlow(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), islSharedToTransit, islTransitToSecond);
    SwitchId yPoint = SWITCH_TRANSIT;
    FlowMeter yPointMeter = dummyFactory.makeFlowMeter(yPoint, yFlowId, null);
    FlowMeter sharedEndpointMeter = dummyFactory.makeFlowMeter(firstSharedEndpoint.getSwitchId(), yFlowId, null);
    YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).sharedEndpointMeterId(sharedEndpointMeter.getMeterId()).yPoint(yPoint).meterId(yPointMeter.getMeterId()).status(FlowStatus.UP).build();
    yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
    YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
    yFlowRepository.add(yFlow);
    return yFlow;
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) SwitchId(org.openkilda.model.SwitchId) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) FlowMeter(org.openkilda.model.FlowMeter) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Example 24 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class FlowValidator method checkSwitchesSupportLldpAndArpIfNeeded.

/**
 * Ensure switches support LLDP/ARP.
 *
 * @param requestedFlow a flow to be validated.
 */
// TODO: switch to per endpoint based strategy (same as other enpoint related checks)
@VisibleForTesting
void checkSwitchesSupportLldpAndArpIfNeeded(RequestedFlow requestedFlow) throws InvalidFlowException {
    SwitchId sourceId = requestedFlow.getSrcSwitch();
    SwitchId destinationId = requestedFlow.getDestSwitch();
    List<String> errorMessages = new ArrayList<>();
    if (requestedFlow.getDetectConnectedDevices().isSrcLldp() || requestedFlow.getDetectConnectedDevices().isSrcArp()) {
        validateMultiTableProperty(sourceId, errorMessages);
    }
    if (requestedFlow.getDetectConnectedDevices().isDstLldp() || requestedFlow.getDetectConnectedDevices().isDstArp()) {
        validateMultiTableProperty(destinationId, errorMessages);
    }
    if (!errorMessages.isEmpty()) {
        throw new InvalidFlowException(String.join(" ", errorMessages), ErrorType.DATA_INVALID);
    }
}
Also used : ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 25 with SwitchId

use of org.openkilda.model.SwitchId in project open-kilda by telstra.

the class FlowValidator method baseFlowValidate.

private void baseFlowValidate(RequestedFlow flow, Set<String> bulkUpdateFlowIds) throws InvalidFlowException, UnavailableFlowEndpointException {
    final FlowEndpoint source = RequestedFlowMapper.INSTANCE.mapSource(flow);
    final FlowEndpoint destination = RequestedFlowMapper.INSTANCE.mapDest(flow);
    checkOneSwitchFlowConflict(source, destination);
    checkSwitchesExistsAndActive(flow.getSrcSwitch(), flow.getDestSwitch());
    for (EndpointDescriptor descriptor : new EndpointDescriptor[] { EndpointDescriptor.makeSource(source), EndpointDescriptor.makeDestination(destination) }) {
        SwitchId switchId = descriptor.endpoint.getSwitchId();
        SwitchProperties properties = switchPropertiesRepository.findBySwitchId(switchId).orElseThrow(() -> new InvalidFlowException(format("Couldn't get switch properties for %s switch %s.", descriptor.name, switchId), ErrorType.DATA_INVALID));
        // skip encapsulation type check for one switch flow
        if (!source.getSwitchId().equals(destination.getSwitchId())) {
            checkForEncapsulationTypeRequirement(descriptor, properties, flow.getFlowEncapsulationType());
        }
        checkForMultiTableRequirement(descriptor, properties);
        checkFlowForIslConflicts(descriptor);
        checkFlowForFlowConflicts(flow.getFlowId(), descriptor, bulkUpdateFlowIds);
        checkFlowForSinkEndpointConflicts(descriptor);
        checkFlowForMirrorEndpointConflicts(flow.getFlowId(), descriptor);
        checkFlowForServer42Conflicts(descriptor, properties);
    }
}
Also used : FlowEndpoint(org.openkilda.model.FlowEndpoint) SwitchId(org.openkilda.model.SwitchId) SwitchProperties(org.openkilda.model.SwitchProperties)

Aggregations

SwitchId (org.openkilda.model.SwitchId)339 Test (org.junit.Test)149 Flow (org.openkilda.model.Flow)73 Switch (org.openkilda.model.Switch)69 List (java.util.List)59 FlowPath (org.openkilda.model.FlowPath)49 ArrayList (java.util.ArrayList)44 Collectors (java.util.stream.Collectors)37 PathId (org.openkilda.model.PathId)36 PathComputer (org.openkilda.pce.PathComputer)35 Set (java.util.Set)34 YFlow (org.openkilda.model.YFlow)33 Map (java.util.Map)30 GetPathsResult (org.openkilda.pce.GetPathsResult)30 InfoMessage (org.openkilda.messaging.info.InfoMessage)29 String.format (java.lang.String.format)28 HashSet (java.util.HashSet)27 Optional (java.util.Optional)27 Collection (java.util.Collection)26 Collections (java.util.Collections)26