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));
}
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));
}
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);
}
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);
}
});
}
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);
}
});
}
Aggregations