use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class EmitUpdateRulesRequestsAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
stateMachine.getCommands().clear();
stateMachine.getPendingCommands().clear();
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
Collection<FlowSegmentRequestFactory> commands = buildCommands(stateMachine, flow);
// emitting
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
SpeakerRequestEmitter requestEmitter;
if (mirrorPoints != null && mirrorPoints.getMirrorPaths().isEmpty()) {
requestEmitter = SpeakerRemoveSegmentEmitter.INSTANCE;
} else {
requestEmitter = SpeakerInstallSegmentEmitter.INSTANCE;
}
requestEmitter.emitBatch(stateMachine.getCarrier(), commands, stateMachine.getCommands());
stateMachine.getCommands().forEach((key, value) -> stateMachine.getPendingCommands().put(key, value.getSwitchId()));
if (commands.isEmpty()) {
stateMachine.saveActionToHistory("No need to update rules");
} else {
stateMachine.saveActionToHistory("Commands for updating rules have been sent");
stateMachine.setRulesInstalled(true);
}
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class ResourceAllocationAction method createFlowMirrorPoints.
private FlowMirrorPoints createFlowMirrorPoints(RequestedFlowMirrorPoint mirrorPoint, FlowPath flowPath) throws ResourceAllocationException {
Switch mirrorSwitch = switchRepository.findById(mirrorPoint.getMirrorPointSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getMirrorPointSwitchId())));
MirrorDirection direction = mirrorPoint.getMirrorPointSwitchId().equals(flowPath.getSrcSwitchId()) ? MirrorDirection.INGRESS : MirrorDirection.EGRESS;
MirrorGroup mirrorGroup = resourcesManager.getAllocatedMirrorGroup(mirrorPoint.getMirrorPointSwitchId(), mirrorPoint.getFlowId(), flowPath.getPathId(), MirrorGroupType.TRAFFIC_INTEGRITY, direction);
FlowMirrorPoints flowMirrorPoints = FlowMirrorPoints.builder().mirrorSwitch(mirrorSwitch).mirrorGroup(mirrorGroup).build();
flowMirrorPointsRepository.add(flowMirrorPoints);
flowPath.addFlowMirrorPoints(flowMirrorPoints);
return flowMirrorPoints;
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class PostFlowMirrorPathDeallocationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
boolean mirrorPointsWereDeallocated = transactionManager.doInTransaction(() -> {
FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElse(null);
if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
flowMirrorPointsRepository.remove(flowMirrorPoints);
resourcesManager.deallocateMirrorGroup(flowPathId, mirrorSwitchId);
return true;
}
return false;
});
if (mirrorPointsWereDeallocated) {
stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorSwitchId));
}
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class PostFlowMirrorPathDeallocationAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointCreateContext context, FlowMirrorPointCreateFsm stateMachine) {
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
PathId flowPathId = transactionManager.doInTransaction(() -> {
Flow flow = getFlow(mirrorPoint.getFlowId());
FlowPath flowPath = getFlowPath(mirrorPoint, flow);
FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId()).orElse(null);
if (flowMirrorPoints != null && flowMirrorPoints.getMirrorPaths().isEmpty()) {
flowMirrorPointsRepository.remove(flowMirrorPoints);
resourcesManager.deallocateMirrorGroup(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
return flowPath.getPathId();
}
return null;
});
if (flowPathId != null) {
stateMachine.saveActionToHistory("Flow mirror group was deallocated", format("The flow mirror group for flow path %s and switch id %s was deallocated", flowPathId, mirrorPoint.getMirrorPointSwitchId()));
}
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class FermaFlowMirrorPathRepositoryTest method shouldCreateFlowMirrorPaths.
@Test
public void shouldCreateFlowMirrorPaths() {
createTestFlowPaths();
Collection<FlowMirrorPath> allPaths = flowMirrorPathRepository.findAll();
assertThat(allPaths, hasSize(2));
FlowMirrorPath foundPath = flowMirrorPathRepository.findById(TEST_MIRROR_PATH_ID_1).get();
assertEquals(switchA.getSwitchId(), foundPath.getMirrorSwitchId());
assertEquals(switchB.getSwitchId(), foundPath.getEgressSwitchId());
FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByGroupId(TEST_GROUP_ID).get();
assertThat(flowMirrorPoints.getMirrorPaths(), hasSize(2));
}
Aggregations