Search in sources :

Example 51 with PathSegment

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

the class BaseResourceAllocationActionTest method updateAvailableBandwidthNoOverProvisionTest.

@Test()
public void updateAvailableBandwidthNoOverProvisionTest() 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 52 with PathSegment

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

the class SwitchFlowEntriesBuilder method getSwitchFlowEntries.

/**
 * Construct a list of {@link SwitchFlowEntries} that corresponds to the builder's flow.
 */
public List<SwitchFlowEntries> getSwitchFlowEntries(int forwardTransitEncapId, int reverseTransitEncapId, Integer forwardProtectedTransitEncapId, Integer reverseProtectedTransitEncapId) {
    List<SwitchFlowEntries> switchEntries = new ArrayList<>();
    boolean isVxlan = flow.getEncapsulationType() == FlowEncapsulationType.VXLAN;
    FlowPath forwardPath = flow.getForwardPath();
    FlowPath reversePath = flow.getReversePath();
    long forwardCookie = forwardPath.getCookie().getValue();
    long reverseCookie = reversePath.getCookie().getValue();
    Optional<FlowPath> protectedForwardPath = Optional.ofNullable(flow.getProtectedForwardPath());
    Optional<FlowPath> protectedReversePath = Optional.ofNullable(flow.getProtectedReversePath());
    Long protectedForwardCookie = protectedForwardPath.map(FlowPath::getCookie).map(Cookie::getValue).orElse(null);
    Long protectedReverseCookie = protectedReversePath.map(FlowPath::getCookie).map(Cookie::getValue).orElse(null);
    List<PathSegment> forwardSegments = forwardPath.getSegments();
    if (forwardSegments.isEmpty()) {
        throw new IllegalArgumentException("One-switch flows are unsupported");
    }
    PathSegment firstSegment = forwardSegments.get(0);
    switchEntries.add(buildSwitchFlowEntries(flow.getSrcSwitchId(), getFlowEntry(forwardCookie, flow.getSrcPort(), flow.getSrcVlan(), null, firstSegment.getSrcPort(), isVxlan ? null : forwardTransitEncapId, isVxlan ? forwardTransitEncapId : null, forwardPath.getMeterId().getValue()), getFlowEntry(reverseCookie, firstSegment.getSrcPort(), isVxlan ? null : reverseTransitEncapId, isVxlan ? reverseTransitEncapId : null, flow.getSrcPort(), flow.getSrcVlan(), null, null)));
    if (protectedForwardPath.isPresent()) {
        List<PathSegment> protectedForwardSegments = protectedForwardPath.get().getSegments();
        PathSegment firstProtectedSegment = protectedForwardSegments.get(0);
        switchEntries.add(buildSwitchFlowEntries(flow.getSrcSwitchId(), getFlowEntry(protectedReverseCookie, firstProtectedSegment.getSrcPort(), isVxlan ? null : reverseProtectedTransitEncapId, isVxlan ? reverseProtectedTransitEncapId : null, flow.getSrcPort(), flow.getSrcVlan(), null, null)));
    }
    for (int i = 0; i < forwardSegments.size() - 1; i++) {
        PathSegment nsegment = forwardSegments.get(i);
        PathSegment n1segment = forwardSegments.get(i + 1);
        switchEntries.add(buildSwitchFlowEntries(nsegment.getDestSwitchId(), getFlowEntry(forwardCookie, nsegment.getDestPort(), isVxlan ? null : forwardTransitEncapId, isVxlan ? forwardTransitEncapId : null, n1segment.getSrcPort(), null, null, null), getFlowEntry(reverseCookie, n1segment.getSrcPort(), isVxlan ? null : reverseTransitEncapId, isVxlan ? reverseTransitEncapId : null, nsegment.getDestPort(), null, null, null)));
    }
    if (protectedForwardPath.isPresent()) {
        List<PathSegment> forwardProtectedSegments = protectedForwardPath.get().getSegments();
        for (int i = 0; i < forwardProtectedSegments.size() - 1; i++) {
            PathSegment nsegment = forwardProtectedSegments.get(i);
            PathSegment n1segment = forwardProtectedSegments.get(i + 1);
            switchEntries.add(buildSwitchFlowEntries(nsegment.getDestSwitchId(), getFlowEntry(protectedForwardCookie, nsegment.getDestPort(), isVxlan ? null : forwardProtectedTransitEncapId, isVxlan ? forwardProtectedTransitEncapId : null, n1segment.getSrcPort(), null, null, null), getFlowEntry(protectedReverseCookie, n1segment.getSrcPort(), isVxlan ? null : reverseProtectedTransitEncapId, isVxlan ? reverseProtectedTransitEncapId : null, nsegment.getDestPort(), null, null, null)));
        }
    }
    PathSegment lastSegment = forwardSegments.get(forwardSegments.size() - 1);
    switchEntries.add(buildSwitchFlowEntries(flow.getDestSwitchId(), getFlowEntry(forwardCookie, lastSegment.getDestPort(), isVxlan ? null : forwardTransitEncapId, isVxlan ? forwardTransitEncapId : null, flow.getDestPort(), flow.getDestVlan(), null, null), getFlowEntry(reverseCookie, flow.getDestPort(), flow.getDestVlan(), null, lastSegment.getDestPort(), isVxlan ? null : reverseTransitEncapId, isVxlan ? reverseTransitEncapId : null, reversePath.getMeterId().getValue())));
    if (protectedForwardPath.isPresent()) {
        List<PathSegment> forwardProtectedSegments = protectedForwardPath.get().getSegments();
        PathSegment lastProtectedSegment = forwardProtectedSegments.get(forwardProtectedSegments.size() - 1);
        switchEntries.add(buildSwitchFlowEntries(flow.getDestSwitchId(), getFlowEntry(protectedForwardCookie, lastProtectedSegment.getDestPort(), isVxlan ? null : forwardProtectedTransitEncapId, isVxlan ? forwardProtectedTransitEncapId : null, flow.getDestPort(), flow.getDestVlan(), null, null)));
    }
    return switchEntries;
}
Also used : SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) ArrayList(java.util.ArrayList) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath)

Example 53 with PathSegment

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

the class SpeakerFlowSegmentRequestBuilderTest method setSegmentsWithoutTransitSwitches.

private void setSegmentsWithoutTransitSwitches(FlowPath forward, FlowPath reverse) {
    PathSegment switch1ToSwitch2 = PathSegment.builder().pathId(forward.getPathId()).srcSwitch(forward.getSrcSwitch()).srcPort(12).destSwitch(forward.getDestSwitch()).destPort(22).build();
    forward.setSegments(ImmutableList.of(switch1ToSwitch2));
    PathSegment switch2ToSwitch1 = PathSegment.builder().pathId(reverse.getPathId()).srcSwitch(reverse.getSrcSwitch()).srcPort(22).destSwitch(reverse.getDestSwitch()).destPort(12).build();
    reverse.setSegments(ImmutableList.of(switch2ToSwitch1));
}
Also used : PathSegment(org.openkilda.model.PathSegment)

Example 54 with PathSegment

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

the class SimpleSwitchRuleConverterTest method buildFlow.

private Flow buildFlow(FlowEncapsulationType flowEncapsulationType, boolean checkWithGroup) {
    Switch switchA = Switch.builder().switchId(TEST_SWITCH_ID_A).description("").build();
    Switch switchB = Switch.builder().switchId(TEST_SWITCH_ID_B).description("").build();
    Switch switchC = Switch.builder().switchId(TEST_SWITCH_ID_C).description("").build();
    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_VALUE)).meterId(new MeterId(FLOW_A_FORWARD_METER_ID)).srcSwitch(switchA).destSwitch(switchC).status(FlowPathStatus.ACTIVE).bandwidth(FLOW_A_BANDWIDTH).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));
    if (checkWithGroup) {
        FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(switchA).mirrorGroup(MirrorGroup.builder().switchId(TEST_SWITCH_ID_A).groupId(new GroupId(FLOW_GROUP_ID_A)).pathId(FLOW_A_FORWARD_PATH_ID).flowId(TEST_FLOW_ID_A).mirrorGroupType(MirrorGroupType.TRAFFIC_INTEGRITY).mirrorDirection(MirrorDirection.INGRESS).build()).build();
        FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(new PathId("mirror_path")).mirrorSwitch(switchA).egressSwitch(switchA).egressPort(FLOW_GROUP_ID_A_OUT_PORT).egressOuterVlan(FLOW_GROUP_ID_A_OUT_VLAN).build();
        flowMirrorPoints.addPaths(flowMirrorPath);
        forwardFlowPath.addFlowMirrorPoints(flowMirrorPoints);
    }
    return flow;
}
Also used : PathId(org.openkilda.model.PathId) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) Switch(org.openkilda.model.Switch) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow) MeterId(org.openkilda.model.MeterId) GroupId(org.openkilda.model.GroupId)

Example 55 with PathSegment

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

the class IntersectionComputerTest method shouldCalculateSharedPathAsFullPath.

@Test
public void shouldCalculateSharedPathAsFullPath() {
    FlowPath firstPath = FlowPath.builder().pathId(PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_C)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_C, 2, 2))).build();
    FlowPath secondPath = FlowPath.builder().pathId(NEW_PATH_ID).srcSwitch(makeSwitch(SWITCH_ID_A)).destSwitch(makeSwitch(SWITCH_ID_D)).segments(Lists.newArrayList(buildPathSegment(NEW_PATH_ID, SWITCH_ID_A, SWITCH_ID_B, 1, 1), buildPathSegment(NEW_PATH_ID, SWITCH_ID_B, SWITCH_ID_C, 2, 2), buildPathSegment(NEW_PATH_ID, SWITCH_ID_C, SWITCH_ID_D, 3, 3))).build();
    List<PathSegment> sharedPath = IntersectionComputer.calculatePathIntersectionFromSource(asList(firstPath, secondPath));
    assertEquals(2, sharedPath.size());
    assertEquals(SWITCH_ID_A, sharedPath.get(0).getSrcSwitchId());
    assertEquals(SWITCH_ID_B, sharedPath.get(0).getDestSwitchId());
    assertEquals(SWITCH_ID_B, sharedPath.get(1).getSrcSwitchId());
    assertEquals(SWITCH_ID_C, sharedPath.get(1).getDestSwitchId());
}
Also used : PathSegment(org.openkilda.model.PathSegment) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

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