Search in sources :

Example 21 with FlowPath

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

the class YFlowReadService method getYFlowPaths.

/**
 * Gets y-flow paths.
 */
public YFlowPathsResponse getYFlowPaths(@NonNull String yFlowId) throws FlowNotFoundException {
    return transactionManager.doInTransaction(getReadOperationRetryPolicy(), () -> {
        Set<YSubFlow> subFlows = yFlowRepository.findById(yFlowId).orElseThrow(() -> new FlowNotFoundException(yFlowId)).getSubFlows();
        Set<FlowPath> mainPaths = new HashSet<>();
        Set<FlowPath> protectedPaths = new HashSet<>();
        for (YSubFlow subFlow : subFlows) {
            Flow flow = subFlow.getFlow();
            mainPaths.add(flow.getForwardPath());
            if (flow.isAllocateProtectedPath() && flow.getProtectedForwardPath() != null) {
                protectedPaths.add(flow.getProtectedForwardPath());
            }
        }
        List<PathSegment> sharedPathSegments = IntersectionComputer.calculatePathIntersectionFromSource(mainPaths);
        PathInfoData sharedPath = FlowPathMapper.INSTANCE.map(sharedPathSegments);
        PathInfoData sharedProtectedPath;
        // At least 2 paths required to calculate Y-point.
        if (protectedPaths.size() < 2) {
            sharedProtectedPath = new PathInfoData();
        } else {
            List<PathSegment> pathSegments = IntersectionComputer.calculatePathIntersectionFromSource(protectedPaths);
            sharedProtectedPath = FlowPathMapper.INSTANCE.map(pathSegments);
        }
        List<SubFlowPathDto> subFlowPathDtos = mainPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        List<SubFlowPathDto> subFlowProtectedPathDtos = protectedPaths.stream().map(flowPath -> new SubFlowPathDto(flowPath.getFlowId(), FlowPathMapper.INSTANCE.map(flowPath))).collect(Collectors.toList());
        return new YFlowPathsResponse(sharedPath, subFlowPathDtos, sharedProtectedPath, subFlowProtectedPathDtos);
    });
}
Also used : TransactionManager(org.openkilda.persistence.tx.TransactionManager) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) SubFlowDto(org.openkilda.messaging.command.yflow.SubFlowDto) YFlowResponse(org.openkilda.messaging.command.yflow.YFlowResponse) FlowPathMapper(org.openkilda.wfm.share.mappers.FlowPathMapper) YFlowDto(org.openkilda.messaging.command.yflow.YFlowDto) PathInfoData(org.openkilda.messaging.info.event.PathInfoData) HashSet(java.util.HashSet) Flow(org.openkilda.model.Flow) IntersectionComputer(org.openkilda.wfm.share.service.IntersectionComputer) Duration(java.time.Duration) SubFlowsResponse(org.openkilda.messaging.command.yflow.SubFlowsResponse) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) PersistenceManager(org.openkilda.persistence.PersistenceManager) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) YSubFlow(org.openkilda.model.YSubFlow) ErrorType(org.openkilda.messaging.error.ErrorType) NonNull(lombok.NonNull) Collection(java.util.Collection) Set(java.util.Set) RetryPolicy(net.jodah.failsafe.RetryPolicy) PersistenceException(org.openkilda.persistence.exceptions.PersistenceException) Collectors(java.util.stream.Collectors) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) YFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.YFlowMapper) Objects(java.util.Objects) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) Collections(java.util.Collections) FlowNotFoundException(org.openkilda.wfm.error.FlowNotFoundException) 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) FlowPath(org.openkilda.model.FlowPath) HashSet(java.util.HashSet) SubFlowPathDto(org.openkilda.messaging.command.yflow.SubFlowPathDto) YFlowPathsResponse(org.openkilda.messaging.command.yflow.YFlowPathsResponse)

Example 22 with FlowPath

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

the class YFlowValidationService method buildSimpleSwitchRules.

private List<SimpleSwitchRule> buildSimpleSwitchRules(Flow subFlow, SwitchId sharedEndpoint, MeterId sharedMeterId, PathId forwardId, PathId reverseId, SwitchId yPoint, MeterId yMeterId) {
    EncapsulationId encapsulationId = flowResourcesManager.getEncapsulationResources(forwardId, reverseId, subFlow.getEncapsulationType()).map(EncapsulationResources::getEncapsulation).orElseThrow(() -> new IllegalStateException(String.format("Encapsulation id was not found, pathId: %s", forwardId)));
    FlowPath forward = subFlow.getPath(forwardId).orElseThrow(() -> new IllegalStateException(String.format("Path was not found, pathId: %s", forwardId)));
    FlowPath reverse = subFlow.getPath(reverseId).orElseThrow(() -> new IllegalStateException(String.format("Path was not found, pathId: %s", reverseId)));
    if (reverse.getSrcSwitchId().equals(sharedEndpoint)) {
        FlowPath tmp = reverse;
        reverse = forward;
        forward = tmp;
    }
    Collection<SimpleSwitchRule> ingressRules = simpleSwitchRuleConverter.buildIngressSimpleSwitchRules(subFlow, forward, encapsulationId, flowMeterMinBurstSizeInKbits, flowMeterBurstCoefficient);
    // TODO: apply shared endpoint y-flow cookie flags & sharedMeterId
    List<SimpleSwitchRule> result = new ArrayList<>(ingressRules);
    List<PathSegment> orderedSegments = reverse.getSegments().stream().sorted(Comparator.comparingInt(PathSegment::getSeqId)).collect(Collectors.toList());
    for (int i = 1; i < orderedSegments.size(); i++) {
        PathSegment srcPathSegment = orderedSegments.get(i - 1);
        PathSegment dstPathSegment = orderedSegments.get(i);
        if (dstPathSegment.getSrcSwitch().equals(yPoint)) {
            SimpleSwitchRule yPointTransitRules = simpleSwitchRuleConverter.buildTransitSimpleSwitchRule(subFlow, reverse, srcPathSegment, dstPathSegment, encapsulationId);
            // TODO: apply shared endpoint y-flow cookie flags & yMeterId
            result.add(yPointTransitRules);
            break;
        }
    }
    return result;
}
Also used : SimpleSwitchRule(org.openkilda.wfm.share.utils.rule.validation.SimpleSwitchRule) EncapsulationId(org.openkilda.model.EncapsulationId) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath)

Example 23 with FlowPath

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

the class SwitchFlowEntriesBuilder method getSwitchMeterEntries.

/**
 * Construct a list of {@link SwitchMeterEntries} that corresponds to the builder's flow.
 */
public List<SwitchMeterEntries> getSwitchMeterEntries() {
    List<SwitchMeterEntries> switchMeterEntries = new ArrayList<>();
    FlowPath forwardPath = flow.getForwardPath();
    switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getSrcSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(forwardPath.getMeterId().getValue()).rate(forwardPath.getBandwidth()).burstSize(Meter.calculateBurstSize(forwardPath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
    FlowPath reversePath = flow.getReversePath();
    switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getDestSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(reversePath.getMeterId().getValue()).rate(reversePath.getBandwidth()).burstSize(Meter.calculateBurstSize(reversePath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
    FlowPath protectedForwardPath = flow.getProtectedForwardPath();
    if (protectedForwardPath != null) {
        switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getSrcSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(protectedForwardPath.getMeterId().getValue()).rate(protectedForwardPath.getBandwidth()).burstSize(Meter.calculateBurstSize(protectedForwardPath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
    }
    FlowPath protectedReversePath = flow.getProtectedReversePath();
    if (protectedReversePath != null) {
        switchMeterEntries.add(SwitchMeterEntries.builder().switchId(flow.getDestSwitchId()).meterEntries(Collections.singletonList(MeterEntry.builder().meterId(protectedReversePath.getMeterId().getValue()).rate(protectedReversePath.getBandwidth()).burstSize(Meter.calculateBurstSize(protectedReversePath.getBandwidth(), MIN_BURST_SIZE_IN_KBITS, BURST_COEFFICIENT, "")).flags(Meter.getMeterKbpsFlags()).build())).build());
    }
    return switchMeterEntries;
}
Also used : SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) ArrayList(java.util.ArrayList) FlowPath(org.openkilda.model.FlowPath)

Example 24 with FlowPath

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

the class FlowDeleteServiceTest method shouldCompleteDeleteOnErrorDuringResourceDeallocation.

@Test
public void shouldCompleteDeleteOnErrorDuringResourceDeallocation() throws DuplicateKeyException, UnknownKeyException {
    Flow target = makeFlow();
    FlowPath forwardPath = target.getForwardPath();
    Assert.assertNotNull(forwardPath);
    doThrow(new RuntimeException(injectedErrorMessage)).when(flowResourcesManager).deallocatePathResources(MockitoHamcrest.argThat(Matchers.hasProperty("forward", Matchers.<PathResources>hasProperty("pathId", is(forwardPath.getPathId())))));
    FlowDeleteService service = makeService();
    service.handleRequest(dummyRequestKey, commandContext, target.getFlowId());
    verifyFlowStatus(target.getFlowId(), FlowStatus.IN_PROGRESS);
    verifyNorthboundSuccessResponse(carrier);
    produceSpeakerResponses(service);
    // 4 flow rules + 4 mirror rules
    verify(carrier, times(8)).sendSpeakerRequest(any());
    verifyFlowIsMissing(target);
}
Also used : FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) Test(org.junit.Test)

Example 25 with FlowPath

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

the class FlowValidationTestBase method buildFlow.

protected void buildFlow(FlowEncapsulationType flowEncapsulationType, String endpointSwitchManufacturer) {
    Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
    switchRepository.add(switchA);
    switchA.setOfDescriptionManufacturer(endpointSwitchManufacturer);
    Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
    switchRepository.add(switchB);
    Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
    switchRepository.add(switchC);
    Switch switchE = Switch.builder().switchId(TEST_SWITCH_ID_E).description("").build();
    switchRepository.add(switchE);
    Flow flow = Flow.builder().flowId(TEST_FLOW_ID_A).srcSwitch(switchA).srcPort(FLOW_A_SRC_PORT).srcVlan(FLOW_A_SRC_VLAN).destSwitch(switchC).destPort(FLOW_A_DST_PORT).destVlan(FLOW_A_DST_VLAN).allocateProtectedPath(true).encapsulationType(flowEncapsulationType).bandwidth(FLOW_A_BANDWIDTH).status(FlowStatus.UP).build();
    FlowPath forwardFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setForwardPath(forwardFlowPath);
    PathSegment forwardSegmentA = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_A_DST_PORT).build();
    PathSegment forwardSegmentB = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_B_SRC_PORT).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT).build();
    forwardFlowPath.setSegments(Lists.newArrayList(forwardSegmentA, forwardSegmentB));
    FlowPath forwardProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_FORWARD_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_FORWARD_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID_PROTECTED)).srcSwitch(switchA).destSwitch(switchC).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedForwardPath(forwardProtectedFlowPath);
    PathSegment forwardProtectedSegmentA = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchA).srcPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).build();
    PathSegment forwardProtectedSegmentB = PathSegment.builder().pathId(forwardProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).destSwitch(switchC).destPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).build();
    forwardProtectedFlowPath.setSegments(Lists.newArrayList(forwardProtectedSegmentA, forwardProtectedSegmentB));
    FlowPath reverseFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setReversePath(reverseFlowPath);
    PathSegment reverseSegmentA = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT).destSwitch(switchB).destPort(FLOW_A_SEGMENT_B_SRC_PORT).build();
    PathSegment reverseSegmentB = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(switchB).srcPort(FLOW_A_SEGMENT_A_DST_PORT).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT).build();
    reverseFlowPath.setSegments(Lists.newArrayList(reverseSegmentA, reverseSegmentB));
    FlowPath reverseProtectedFlowPath = FlowPath.builder().pathId(FLOW_A_REVERSE_PATH_ID_PROTECTED).cookie(new FlowSegmentCookie(FLOW_A_REVERSE_COOKIE_PROTECTED)).meterId(new MeterId(FLOW_A_REVERSE_METER_ID_PROTECTED)).srcSwitch(switchC).destSwitch(switchA).bandwidth(FLOW_A_BANDWIDTH).status(FlowPathStatus.ACTIVE).build();
    flow.setProtectedReversePath(reverseProtectedFlowPath);
    PathSegment reverseProtectedSegmentA = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchC).srcPort(FLOW_A_SEGMENT_B_DST_PORT_PROTECTED).destSwitch(switchE).destPort(FLOW_A_SEGMENT_B_SRC_PORT_PROTECTED).build();
    PathSegment reverseProtectedSegmentB = PathSegment.builder().pathId(reverseProtectedFlowPath.getPathId()).srcSwitch(switchE).srcPort(FLOW_A_SEGMENT_A_DST_PORT_PROTECTED).destSwitch(switchA).destPort(FLOW_A_SEGMENT_A_SRC_PORT_PROTECTED).build();
    reverseProtectedFlowPath.setSegments(Lists.newArrayList(reverseProtectedSegmentA, reverseProtectedSegmentB));
    flowRepository.add(flow);
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId)

Aggregations

FlowPath (org.openkilda.model.FlowPath)229 Flow (org.openkilda.model.Flow)128 Test (org.junit.Test)108 PathId (org.openkilda.model.PathId)65 PathSegment (org.openkilda.model.PathSegment)42 SwitchId (org.openkilda.model.SwitchId)40 ArrayList (java.util.ArrayList)39 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)33 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)29 Switch (org.openkilda.model.Switch)28 FlowSpeakerData (org.openkilda.rulemanager.FlowSpeakerData)27 SpeakerData (org.openkilda.rulemanager.SpeakerData)27 Action (org.openkilda.rulemanager.action.Action)26 PopVlanAction (org.openkilda.rulemanager.action.PopVlanAction)26 PopVxlanAction (org.openkilda.rulemanager.action.PopVxlanAction)26 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)26 PushVlanAction (org.openkilda.rulemanager.action.PushVlanAction)26 SetFieldAction (org.openkilda.rulemanager.action.SetFieldAction)26 MeterId (org.openkilda.model.MeterId)20 YFlow (org.openkilda.model.YFlow)19