Search in sources :

Example 76 with PathId

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

the class FlowPathBuilderTest method shouldDetectNotSameSwitchPaths.

@Test
public void shouldDetectNotSameSwitchPaths() {
    SwitchId switchId1 = new SwitchId(1);
    SwitchId switchId2 = new SwitchId(2);
    Switch switch2 = Switch.builder().switchId(switchId2).build();
    Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId1).segments(Collections.emptyList()).build();
    FlowPath flowPath = FlowPath.builder().srcSwitch(switch2).destSwitch(switch2).pathId(new PathId("test_path_id")).build();
    assertFalse(builder.isSamePath(path, flowPath));
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Example 77 with PathId

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

the class FlowPathBuilderTest method shouldDetectSame3SwitchPaths.

@Test
public void shouldDetectSame3SwitchPaths() {
    SwitchId switchId1 = new SwitchId(1);
    Switch switch1 = Switch.builder().switchId(switchId1).build();
    SwitchId switchId2 = new SwitchId(2);
    Switch switch2 = Switch.builder().switchId(switchId2).build();
    SwitchId switchId3 = new SwitchId(3);
    Switch switch3 = Switch.builder().switchId(switchId3).build();
    Path path = Path.builder().srcSwitchId(switchId1).destSwitchId(switchId2).segments(asList(Segment.builder().srcSwitchId(switchId1).srcPort(1).destSwitchId(switchId3).destPort(2).build(), Segment.builder().srcSwitchId(switchId3).srcPort(1).destSwitchId(switchId2).destPort(2).build())).build();
    PathId flowPathId = new PathId("test_path_id");
    FlowPath flowPath = FlowPath.builder().srcSwitch(switch1).destSwitch(switch2).pathId(flowPathId).segments(asList(PathSegment.builder().pathId(flowPathId).srcSwitch(switch1).srcPort(1).destSwitch(switch3).destPort(2).build(), PathSegment.builder().pathId(flowPathId).srcSwitch(switch3).srcPort(1).destSwitch(switch2).destPort(2).build())).build();
    assertTrue(builder.isSamePath(path, flowPath));
}
Also used : FlowPath(org.openkilda.model.FlowPath) Path(org.openkilda.pce.Path) PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) SwitchId(org.openkilda.model.SwitchId) FlowPath(org.openkilda.model.FlowPath) Test(org.junit.Test)

Example 78 with PathId

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

the class PacketServiceTest method createFlow.

private void createFlow(String flowId, int srcVlan, int dstVlan, Integer transitVlan, boolean oneSwitchFlow, boolean onePort) {
    if (transitVlan != null) {
        transitVlanRepository.add(new TransitVlan(flowId, new PathId(PATH_ID), transitVlan));
    }
    Switch srcSwitch = switchRepository.findById(SWITCH_ID_1).get();
    Switch dstSwitch = oneSwitchFlow ? srcSwitch : switchRepository.findById(SWITCH_ID_2).get();
    Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcVlan(srcVlan).srcPort(PORT_NUMBER_1).destSwitch(dstSwitch).destVlan(dstVlan).destPort(onePort ? PORT_NUMBER_1 : PORT_NUMBER_2).build();
    flowRepository.add(flow);
}
Also used : PathId(org.openkilda.model.PathId) Switch(org.openkilda.model.Switch) TransitVlan(org.openkilda.model.TransitVlan) Flow(org.openkilda.model.Flow)

Example 79 with PathId

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

the class RevertPathsSwapAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowUpdateContext context, FlowUpdateFsm stateMachine) {
    if (stateMachine.getEndpointUpdate().isPartialUpdate()) {
        stateMachine.saveActionToHistory("Skip paths swap");
        return;
    }
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(stateMachine.getFlowId());
        if (stateMachine.getNewPrimaryForwardPath() != null) {
            PathId oldPrimaryForward = stateMachine.getOldPrimaryForwardPath();
            if (oldPrimaryForward != null) {
                flowPathRepository.findById(oldPrimaryForward).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldPrimaryForwardPathStatus());
                    }
                });
            }
            log.debug("Swapping back the primary forward path {} with {}", flow.getForwardPathId(), oldPrimaryForward != null ? oldPrimaryForward : "no path");
            flow.setForwardPathId(oldPrimaryForward);
            saveHistory(stateMachine, flow.getFlowId(), oldPrimaryForward);
        }
        if (stateMachine.getNewPrimaryReversePath() != null) {
            PathId oldPrimaryReverse = stateMachine.getOldPrimaryReversePath();
            if (oldPrimaryReverse != null) {
                flowPathRepository.findById(oldPrimaryReverse).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldPrimaryReversePathStatus());
                    }
                });
            }
            log.debug("Swapping back the primary reverse path {} with {}", flow.getReversePathId(), oldPrimaryReverse != null ? oldPrimaryReverse : "no path");
            flow.setReversePathId(oldPrimaryReverse);
            saveHistory(stateMachine, flow.getFlowId(), oldPrimaryReverse);
        }
        if (stateMachine.getNewProtectedForwardPath() != null) {
            PathId oldProtectedForward = stateMachine.getOldProtectedForwardPath();
            if (oldProtectedForward != null) {
                flowPathRepository.findById(oldProtectedForward).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldProtectedForwardPathStatus());
                    }
                });
            }
            log.debug("Swapping back the protected forward path {} with {}", flow.getProtectedForwardPathId(), oldProtectedForward != null ? oldProtectedForward : "no path");
            flow.setProtectedForwardPathId(oldProtectedForward);
            saveHistory(stateMachine, flow.getFlowId(), oldProtectedForward);
        }
        if (stateMachine.getNewProtectedReversePath() != null) {
            PathId oldProtectedReverse = stateMachine.getOldProtectedReversePath();
            if (oldProtectedReverse != null) {
                flowPathRepository.findById(oldProtectedReverse).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldProtectedReversePathStatus());
                    }
                });
            }
            log.debug("Swapping back the protected reverse path {} with {}", flow.getProtectedReversePathId(), oldProtectedReverse != null ? oldProtectedReverse : "no path");
            flow.setProtectedReversePathId(oldProtectedReverse);
            saveHistory(stateMachine, flow.getFlowId(), oldProtectedReverse);
        }
    });
}
Also used : PathId(org.openkilda.model.PathId) Flow(org.openkilda.model.Flow)

Example 80 with PathId

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

the class RevertPathsSwapAction method perform.

@Override
protected void perform(State from, State to, Event event, FlowRerouteContext context, FlowRerouteFsm stateMachine) {
    transactionManager.doInTransaction(() -> {
        Flow flow = getFlow(stateMachine.getFlowId());
        if (stateMachine.getNewEncapsulationType() != null) {
            flow.setEncapsulationType(stateMachine.getOriginalEncapsulationType());
        }
        flow.setPathComputationStrategy(stateMachine.getOriginalPathComputationStrategy());
        if (stateMachine.getNewPrimaryForwardPath() != null) {
            PathId oldPrimaryForward = stateMachine.getOldPrimaryForwardPath();
            if (oldPrimaryForward != null) {
                flowPathRepository.findById(oldPrimaryForward).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldPrimaryForwardPathStatus());
                    }
                });
            }
            log.debug("Swapping back the primary forward path {} with {}", flow.getForwardPathId(), oldPrimaryForward != null ? oldPrimaryForward : "no path");
            flow.setForwardPathId(oldPrimaryForward);
            saveHistory(stateMachine, flow.getFlowId(), oldPrimaryForward);
        }
        if (stateMachine.getNewPrimaryReversePath() != null) {
            PathId oldPrimaryReverse = stateMachine.getOldPrimaryReversePath();
            if (oldPrimaryReverse != null) {
                flowPathRepository.findById(oldPrimaryReverse).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldPrimaryReversePathStatus());
                    }
                });
            }
            log.debug("Swapping back the primary reverse path {} with {}", flow.getReversePathId(), oldPrimaryReverse != null ? oldPrimaryReverse : "no path");
            flow.setReversePathId(oldPrimaryReverse);
            saveHistory(stateMachine, flow.getFlowId(), oldPrimaryReverse);
        }
        if (stateMachine.getNewProtectedForwardPath() != null) {
            PathId oldProtectedForward = stateMachine.getOldProtectedForwardPath();
            if (oldProtectedForward != null) {
                flowPathRepository.findById(oldProtectedForward).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldProtectedForwardPathStatus());
                    }
                });
            }
            log.debug("Swapping back the protected forward path {} with {}", flow.getProtectedForwardPathId(), oldProtectedForward != null ? oldProtectedForward : "no path");
            flow.setProtectedForwardPathId(oldProtectedForward);
            saveHistory(stateMachine, flow.getFlowId(), oldProtectedForward);
        }
        if (stateMachine.getNewProtectedReversePath() != null) {
            PathId oldProtectedReverse = stateMachine.getOldProtectedReversePath();
            if (oldProtectedReverse != null) {
                flowPathRepository.findById(oldProtectedReverse).ifPresent(path -> {
                    if (path.getStatus() != FlowPathStatus.ACTIVE) {
                        path.setStatus(stateMachine.getOldProtectedReversePathStatus());
                    }
                });
            }
            log.debug("Swapping back the protected reverse path {} with {}", flow.getProtectedReversePathId(), oldProtectedReverse != null ? oldProtectedReverse : "no path");
            flow.setProtectedReversePathId(oldProtectedReverse);
            saveHistory(stateMachine, flow.getFlowId(), oldProtectedReverse);
        }
    });
}
Also used : PathId(org.openkilda.model.PathId) Flow(org.openkilda.model.Flow)

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