Search in sources :

Example 96 with PathId

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

the class RuleManagerImpl method buildFlowRulesForSwitch.

/**
 * Builds command data only for switches present in the map. Silently skips all others.
 */
private List<SpeakerData> buildFlowRulesForSwitch(SwitchId switchId, FlowPath flowPath, DataAdapter adapter) {
    List<SpeakerData> result = new ArrayList<>();
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Switch sw = adapter.getSwitch(switchId);
    PathId oppositePathId = flow.getOppositePathId(flowPath.getPathId()).orElse(null);
    FlowTransitEncapsulation encapsulation = adapter.getTransitEncapsulation(flowPath.getPathId(), oppositePathId);
    if (switchId.equals(flowPath.getSrcSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
        // TODO filter out equal shared rules from the result list
        result.addAll(buildIngressCommands(sw, flowPath, flow, encapsulation, new HashSet<>(), adapter.getSwitchProperties(switchId), adapter.getFeatureToggles()));
    }
    if (!flowPath.isOneSwitchFlow()) {
        if (switchId.equals(flowPath.getDestSwitchId())) {
            result.addAll(buildEgressCommands(sw, flowPath, flow, encapsulation));
        }
        for (int i = 1; i < flowPath.getSegments().size(); i++) {
            PathSegment firstSegment = flowPath.getSegments().get(i - 1);
            PathSegment secondSegment = flowPath.getSegments().get(i);
            if (switchId.equals(firstSegment.getDestSwitchId()) && switchId.equals(secondSegment.getSrcSwitchId())) {
                result.addAll(buildTransitCommands(sw, flowPath, encapsulation, firstSegment, secondSegment));
                break;
            }
        }
        if (flow.isLooped() && sw.getSwitchId().equals(flow.getLoopSwitchId()) && !flow.isProtectedPath(flowPath.getPathId())) {
            result.addAll(buildTransitLoopCommands(sw, flowPath, flow, encapsulation));
        }
    }
    return result;
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) ArrayList(java.util.ArrayList) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) PathSegment(org.openkilda.model.PathSegment) FlowEndpoint(org.openkilda.model.FlowEndpoint) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) HashSet(java.util.HashSet)

Example 97 with PathId

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

the class TransitVlanPoolTest method gotSameVlanForOppositePath.

@Test
public void gotSameVlanForOppositePath() {
    Flow flow = Flow.builder().flowId("flow_1").srcSwitch(SWITCH_A).destSwitch(SWITCH_B).build();
    final PathId forwardPathId = new PathId("forward");
    final PathId reversePathId = new PathId("reverse");
    transactionManager.doInTransaction(() -> {
        TransitVlan forward = transitVlanPool.allocate(flow, forwardPathId, reversePathId).getTransitVlan();
        TransitVlan reverse = transitVlanPool.allocate(flow, reversePathId, forwardPathId).getTransitVlan();
        Assert.assertEquals(forward, reverse);
    });
}
Also used : PathId(org.openkilda.model.PathId) TransitVlan(org.openkilda.model.TransitVlan) Flow(org.openkilda.model.Flow) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 98 with PathId

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

the class FlowMapper method buildPath.

private FlowPath buildPath(FlowDto flowDto) {
    Switch srcSwitch = Switch.builder().switchId(flowDto.getSourceSwitch()).build();
    Switch destSwitch = Switch.builder().switchId(flowDto.getDestinationSwitch()).build();
    return FlowPath.builder().srcSwitch(srcSwitch).destSwitch(destSwitch).cookie(new FlowSegmentCookie(flowDto.getCookie())).bandwidth(flowDto.getBandwidth()).ignoreBandwidth(flowDto.isIgnoreBandwidth()).pathId(new PathId(UUID.randomUUID().toString())).meterId(flowDto.getMeterId() != null ? new MeterId(flowDto.getMeterId()) : null).build();
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) MeterId(org.openkilda.model.MeterId)

Example 99 with PathId

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

the class SwitchValidateFsm method validateEnter.

protected void validateEnter(SwitchValidateState from, SwitchValidateState to, SwitchValidateEvent event, SwitchValidateContext context) {
    SwitchId switchId = getSwitchId();
    Set<PathId> flowPathIds = flowPathRepository.findBySegmentSwitch(switchId).stream().map(FlowPath::getPathId).collect(Collectors.toSet());
    flowPathIds.addAll(flowPathRepository.findByEndpointSwitch(switchId).stream().map(FlowPath::getPathId).collect(Collectors.toSet()));
    PersistenceDataAdapter dataAdapter = PersistenceDataAdapter.builder().persistenceManager(persistenceManager).switchIds(Collections.singleton(switchId)).pathIds(flowPathIds).keepMultitableForFlow(true).build();
    List<SpeakerData> expectedEntities = ruleManager.buildRulesForSwitch(switchId, dataAdapter);
    List<FlowSpeakerData> expectedRules = filterSpeakerData(expectedEntities, FlowSpeakerData.class);
    List<MeterSpeakerData> expectedMeters = filterSpeakerData(expectedEntities, MeterSpeakerData.class);
    List<GroupSpeakerData> expectedGroups = filterSpeakerData(expectedEntities, GroupSpeakerData.class);
    validateRules(expectedRules);
    validateMeters(expectedMeters);
    validateGroups(expectedGroups);
    validateLogicalPorts();
}
Also used : PersistenceDataAdapter(org.openkilda.rulemanager.adapter.PersistenceDataAdapter) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) SwitchId(org.openkilda.model.SwitchId) PathId(org.openkilda.model.PathId) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) FlowPath(org.openkilda.model.FlowPath) SpeakerData(org.openkilda.rulemanager.SpeakerData) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData)

Example 100 with PathId

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

the class AllocateProtectedResourcesAction method allocate.

@TimedExecution("fsm.resource_allocation_protected")
@Override
protected void allocate(FlowRerouteFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
    String flowId = stateMachine.getFlowId();
    Flow tmpFlowCopy = getFlow(flowId);
    // Detach the entity to avoid propagation to the database.
    flowRepository.detach(tmpFlowCopy);
    if (stateMachine.getNewEncapsulationType() != null) {
        // This is for PCE to use proper (updated) encapsulation type.
        tmpFlowCopy.setEncapsulationType(stateMachine.getNewEncapsulationType());
    }
    FlowPathPair oldPaths = new FlowPathPair(tmpFlowCopy.getProtectedForwardPath(), tmpFlowCopy.getProtectedReversePath());
    FlowPath primaryForward = tmpFlowCopy.getPath(stateMachine.getNewPrimaryForwardPath()).orElse(tmpFlowCopy.getForwardPath());
    FlowPath primaryReverse = tmpFlowCopy.getPath(stateMachine.getNewPrimaryReversePath()).orElse(tmpFlowCopy.getReversePath());
    Predicate<GetPathsResult> testNonOverlappingPath = path -> (primaryForward == null || !flowPathBuilder.arePathsOverlapped(path.getForward(), primaryForward)) && (primaryReverse == null || !flowPathBuilder.arePathsOverlapped(path.getReverse(), primaryReverse));
    PathId newForwardPathId = resourcesManager.generatePathId(flowId);
    PathId newReversePathId = resourcesManager.generatePathId(flowId);
    List<PathId> pathsToReuse = Lists.newArrayList(tmpFlowCopy.getProtectedForwardPathId(), tmpFlowCopy.getProtectedReversePathId());
    pathsToReuse.addAll(stateMachine.getRejectedPaths());
    log.debug("Finding a new protected path for flow {}", flowId);
    GetPathsResult allocatedPaths = allocatePathPair(tmpFlowCopy, newForwardPathId, newReversePathId, stateMachine.isIgnoreBandwidth(), pathsToReuse, oldPaths, stateMachine.isRecreateIfSamePath(), stateMachine.getSharedBandwidthGroupId(), testNonOverlappingPath);
    if (allocatedPaths != null) {
        stateMachine.setBackUpProtectedPathComputationWayUsed(allocatedPaths.isBackUpPathComputationWayUsed());
        if (!testNonOverlappingPath.test(allocatedPaths)) {
            stateMachine.saveActionToHistory("Couldn't find non overlapping protected path. Skipped creating it");
            stateMachine.fireNoPathFound("Couldn't find non overlapping protected path");
        } else {
            log.debug("New protected paths have been allocated: {}", allocatedPaths);
            stateMachine.setNewProtectedForwardPath(newForwardPathId);
            stateMachine.setNewProtectedReversePath(newReversePathId);
            log.debug("Allocating resources for a new protected path of flow {}", flowId);
            FlowResources flowResources = allocateFlowResources(tmpFlowCopy, newForwardPathId, newReversePathId);
            stateMachine.setNewProtectedResources(flowResources);
            FlowPathPair createdPaths = createFlowPathPair(flowId, flowResources, allocatedPaths, stateMachine.isIgnoreBandwidth(), stateMachine.getSharedBandwidthGroupId());
            log.debug("New protected paths have been created: {}", createdPaths);
            saveAllocationActionWithDumpsToHistory(stateMachine, tmpFlowCopy, "protected", createdPaths);
        }
    } else {
        stateMachine.saveActionToHistory("Found the same protected path. Skipped creating of it");
    }
}
Also used : FlowRerouteContext(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteContext) BaseResourceAllocationAction(org.openkilda.wfm.topology.flowhs.fsm.common.actions.BaseResourceAllocationAction) FlowOperationsDashboardLogger(org.openkilda.wfm.share.logger.FlowOperationsDashboardLogger) FlowPath(org.openkilda.model.FlowPath) ErrorType(org.openkilda.messaging.error.ErrorType) Predicate(java.util.function.Predicate) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) FlowRerouteFsm(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) Event(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.Event) RecoverableException(org.openkilda.pce.exception.RecoverableException) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) State(org.openkilda.wfm.topology.flowhs.fsm.reroute.FlowRerouteFsm.State) Lists(com.google.common.collect.Lists) Flow(org.openkilda.model.Flow) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution) PathComputer(org.openkilda.pce.PathComputer) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) FlowResourcesManager(org.openkilda.wfm.share.flow.resources.FlowResourcesManager) GetPathsResult(org.openkilda.pce.GetPathsResult) PersistenceManager(org.openkilda.persistence.PersistenceManager) PathId(org.openkilda.model.PathId) PathId(org.openkilda.model.PathId) FlowResources(org.openkilda.wfm.share.flow.resources.FlowResources) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) FlowPathPair(org.openkilda.wfm.topology.flow.model.FlowPathPair) GetPathsResult(org.openkilda.pce.GetPathsResult) TimedExecution(org.openkilda.wfm.share.metrics.TimedExecution)

Aggregations

PathId (org.openkilda.model.PathId)124 Flow (org.openkilda.model.Flow)65 FlowPath (org.openkilda.model.FlowPath)65 Test (org.junit.Test)44 Switch (org.openkilda.model.Switch)29 SwitchId (org.openkilda.model.SwitchId)28 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)27 PathSegment (org.openkilda.model.PathSegment)26 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)21 MeterId (org.openkilda.model.MeterId)19 ArrayList (java.util.ArrayList)18 List (java.util.List)13 Slf4j (lombok.extern.slf4j.Slf4j)11 GetPathsResult (org.openkilda.pce.GetPathsResult)11 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)10 Path (org.openkilda.pce.Path)10 Collection (java.util.Collection)9 RecoverableException (org.openkilda.pce.exception.RecoverableException)9 String.format (java.lang.String.format)8 HashMap (java.util.HashMap)8