Search in sources :

Example 6 with PathSegment

use of org.openkilda.model.PathSegment 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 7 with PathSegment

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

the class BaseResourceAllocationActionTest method updateAvailableBandwidthFailsOnOverProvisionTest.

@Test(expected = ResourceAllocationException.class)
public void updateAvailableBandwidthFailsOnOverProvisionTest() throws ResourceAllocationException {
    islRepositorySpy = spy(persistenceManager.getRepositoryFactory().createIslRepository());
    when(repositoryFactory.createIslRepository()).thenReturn(islRepositorySpy);
    doReturn(-1L).when(islRepositorySpy).updateAvailableBandwidth(any(), anyInt(), any(), anyInt());
    BaseResourceAllocationAction action = mock(BaseResourceAllocationAction.class, Mockito.withSettings().useConstructor(persistenceManager, 3, 3, 3, pathComputer, resourcesManager, dashboardLogger).defaultAnswer(Mockito.CALLS_REAL_METHODS));
    PathSegment segment = PathSegment.builder().pathId(new PathId("")).srcSwitch(Switch.builder().switchId(new SwitchId(1)).build()).srcPort(1).destSwitch(Switch.builder().switchId(new SwitchId(2)).build()).destPort(2).build();
    action.createPathSegments(singletonList(segment), Suppliers.ofInstance(emptyMap()));
}
Also used : PathId(org.openkilda.model.PathId) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Example 8 with PathSegment

use of org.openkilda.model.PathSegment 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)

Example 9 with PathSegment

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

the class FlowRerouteServiceTest method extractIslEndpoint.

private IslEndpoint extractIslEndpoint(Flow flow) {
    FlowPath forwardPath = flow.getForwardPath();
    assertNotNull(forwardPath);
    List<PathSegment> forwardSegments = forwardPath.getSegments();
    assertFalse(forwardSegments.isEmpty());
    PathSegment firstSegment = forwardSegments.get(0);
    return new IslEndpoint(firstSegment.getSrcSwitchId(), firstSegment.getSrcPort());
}
Also used : IslEndpoint(org.openkilda.model.IslEndpoint) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath)

Example 10 with PathSegment

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

the class InMemoryPathComputer method convertFlowPathsToSwitchLists.

@VisibleForTesting
List<LinkedList<SwitchId>> convertFlowPathsToSwitchLists(SwitchId sharedSwitchId, FlowPath... flowPaths) {
    List<LinkedList<SwitchId>> paths = new ArrayList<>();
    for (FlowPath flowPath : flowPaths) {
        List<PathSegment> pathSegments = flowPath.getSegments();
        if (pathSegments == null || pathSegments.isEmpty()) {
            throw new IllegalArgumentException(format("The path '%s' has no path segments", flowPath.getPathId()));
        }
        LinkedList<SwitchId> path = new LinkedList<>();
        path.add(pathSegments.get(0).getSrcSwitchId());
        for (PathSegment pathSegment : pathSegments) {
            path.add(pathSegment.getDestSwitchId());
        }
        if (sharedSwitchId.equals(path.getLast())) {
            Collections.reverse(path);
        } else if (!sharedSwitchId.equals(path.getFirst())) {
            throw new IllegalArgumentException(format("Shared switch '%s' is not an endpoint switch for path '%s'", sharedSwitchId, flowPath.getPathId()));
        }
        paths.add(path);
    }
    return paths;
}
Also used : ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) LinkedList(java.util.LinkedList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

PathSegment (org.openkilda.model.PathSegment)73 FlowPath (org.openkilda.model.FlowPath)40 ArrayList (java.util.ArrayList)28 Flow (org.openkilda.model.Flow)26 PathId (org.openkilda.model.PathId)24 SwitchId (org.openkilda.model.SwitchId)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)17 FlowEndpoint (org.openkilda.model.FlowEndpoint)12 Test (org.junit.Test)11 List (java.util.List)9 MeterId (org.openkilda.model.MeterId)9 Switch (org.openkilda.model.Switch)9 YFlow (org.openkilda.model.YFlow)8 PersistenceManager (org.openkilda.persistence.PersistenceManager)7 Optional (java.util.Optional)6 Slf4j (lombok.extern.slf4j.Slf4j)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 PathInfoData (org.openkilda.messaging.info.event.PathInfoData)5