use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class ResourceAllocationAction method allocate.
@Override
protected void allocate(FlowMirrorPointCreateFsm stateMachine) throws RecoverableException, UnroutableFlowException, ResourceAllocationException {
RequestedFlowMirrorPoint mirrorPoint = stateMachine.getRequestedFlowMirrorPoint();
transactionManager.doInTransaction(() -> {
Flow flow = getFlow(mirrorPoint.getFlowId());
FlowPath flowPath = getFlowPath(mirrorPoint, flow);
stateMachine.setFlowPathId(flowPath.getPathId());
Optional<FlowMirrorPoints> foundFlowMirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPath.getPathId(), mirrorPoint.getMirrorPointSwitchId());
FlowMirrorPoints flowMirrorPoints;
if (foundFlowMirrorPoints.isPresent()) {
flowMirrorPoints = foundFlowMirrorPoints.get();
} else {
flowMirrorPoints = createFlowMirrorPoints(mirrorPoint, flowPath);
stateMachine.setAddNewGroup(true);
}
Switch sinkSwitch = switchRepository.findById(mirrorPoint.getSinkEndpoint().getSwitchId()).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Switch %s not found", mirrorPoint.getSinkEndpoint().getSwitchId())));
stateMachine.setUnmaskedCookie(resourcesManager.getAllocatedCookie(flow.getFlowId()));
FlowSegmentCookie cookie = FlowSegmentCookie.builder().flowEffectiveId(stateMachine.getUnmaskedCookie()).mirror(true).build();
SwitchProperties switchProperties = getSwitchProperties(sinkSwitch.getSwitchId());
boolean dstWithMultiTable = switchProperties != null ? switchProperties.isMultiTable() : kildaConfigurationRepository.getOrDefault().getUseMultiTable();
FlowMirrorPath flowMirrorPath = FlowMirrorPath.builder().pathId(stateMachine.getMirrorPathId()).mirrorSwitch(flowMirrorPoints.getMirrorSwitch()).egressSwitch(sinkSwitch).egressPort(mirrorPoint.getSinkEndpoint().getPortNumber()).egressOuterVlan(mirrorPoint.getSinkEndpoint().getOuterVlanId()).egressInnerVlan(mirrorPoint.getSinkEndpoint().getInnerVlanId()).cookie(cookie).bandwidth(flow.getBandwidth()).ignoreBandwidth(flow.isIgnoreBandwidth()).status(FlowPathStatus.IN_PROGRESS).egressWithMultiTable(dstWithMultiTable).build();
flowMirrorPathRepository.add(flowMirrorPath);
flowMirrorPoints.addPaths(flowMirrorPath);
// TODO: add path allocation in case when src switch is not equal to dst switch
});
stateMachine.saveActionToHistory("New mirror path was created", format("The flow mirror path %s was created (with allocated resources)", stateMachine.getMirrorPathId()));
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class EmitCommandRequestsAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
String flowId = stateMachine.getFlowId();
Flow flow = getFlow(flowId);
PathId flowPathId = stateMachine.getFlowPathId();
SwitchId mirrorSwitchId = stateMachine.getMirrorSwitchId();
FlowMirrorPoints mirrorPoints = flowMirrorPointsRepository.findByPathIdAndSwitchId(flowPathId, mirrorSwitchId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror points for flow path %s and mirror switch id %s not found", flowPathId, mirrorSwitchId)));
FlowCommandBuilder commandBuilder = commandBuilderFactory.getBuilder(flow.getEncapsulationType());
Collection<FlowSegmentRequestFactory> commands = buildCommands(commandBuilder, stateMachine, flow, mirrorPoints);
// emitting
SpeakerRequestEmitter requestEmitter;
if (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 remove group");
} else {
stateMachine.saveActionToHistory("Commands for removing group have been sent");
}
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class DeallocateFlowMirrorPathResourcesAction method perform.
@Override
protected void perform(State from, State to, Event event, FlowMirrorPointDeleteContext context, FlowMirrorPointDeleteFsm stateMachine) {
PathId mirrorPathId = stateMachine.getMirrorPathId();
FlowMirrorPath flowMirrorPath = flowMirrorPathRepository.findById(mirrorPathId).orElseThrow(() -> new FlowProcessingException(ErrorType.NOT_FOUND, format("Flow mirror point %s not found", mirrorPathId)));
FlowMirrorPoints flowMirrorPoints = flowMirrorPath.getFlowMirrorPoints();
stateMachine.setFlowPathId(flowMirrorPoints.getFlowPathId());
stateMachine.setMirrorSwitchId(flowMirrorPoints.getMirrorSwitchId());
resourcesManager.deallocateCookie(flowMirrorPath.getCookie().getFlowEffectiveId());
flowMirrorPathRepository.remove(stateMachine.getMirrorPathId());
stateMachine.saveActionToHistory("Flow mirror path resources were deallocated", format("The flow resources for mirror path %s were deallocated", stateMachine.getMirrorPathId()));
stateMachine.setMirrorPathResourcesDeallocated(true);
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class FermaFlowMirrorPointsRepositoryTest method shouldDeleteFlowPath.
@Test
public void shouldDeleteFlowPath() {
FlowMirrorPoints flowMirrorPoints = createTestFlowMirrorPoints();
transactionManager.doInTransaction(() -> flowMirrorPointsRepository.remove(flowMirrorPoints));
assertEquals(0, flowMirrorPointsRepository.findAll().size());
}
use of org.openkilda.model.FlowMirrorPoints in project open-kilda by telstra.
the class FermaFlowMirrorPointsRepositoryTest method shouldCreateFlowMirrorPaths.
@Test
public void shouldCreateFlowMirrorPaths() {
createTestFlowMirrorPoints();
Collection<FlowMirrorPoints> allPaths = flowMirrorPointsRepository.findAll();
assertThat(allPaths, hasSize(1));
FlowMirrorPoints flowMirrorPoints = flowMirrorPointsRepository.findByGroupId(TEST_GROUP_ID).get();
assertEquals(switchA.getSwitchId(), flowMirrorPoints.getMirrorSwitch().getSwitchId());
}
Aggregations