use of org.openkilda.model.cookie.FlowSegmentCookie 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.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FermaFlowPathRepositoryTest method createTestFlowPathWithIntermediate.
private FlowPath createTestFlowPathWithIntermediate(Switch intSwitch, int intPort) {
FlowPath flowPath = FlowPath.builder().pathId(new PathId(flow.getFlowId() + "_forward_path")).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1L)).meterId(new MeterId(1)).srcSwitch(switchA).destSwitch(switchB).status(FlowPathStatus.ACTIVE).build();
PathSegment segment1 = PathSegment.builder().pathId(flowPath.getPathId()).srcSwitch(switchA).srcPort(1).destSwitch(intSwitch).destPort(intPort).build();
PathSegment segment2 = PathSegment.builder().pathId(flowPath.getPathId()).srcSwitch(intSwitch).srcPort(intPort + 100).destSwitch(switchB).destPort(2).build();
flowPath.setSegments(asList(segment1, segment2));
flowPathRepository.add(flowPath);
return flowPath;
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FermaFlowRepositoryTest method createTestFlow.
private Flow createTestFlow(String flowId, Switch srcSwitch, int srcPort, int srcVlan, Switch destSwitch, int destPort, int destVlan, boolean multiTable) {
Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcPort(srcPort).srcVlan(srcVlan).destSwitch(destSwitch).destPort(destPort).destVlan(destVlan).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).status(FlowStatus.UP).build();
flowRepository.add(flow);
FlowPath forwardFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_forward_path")).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1L)).meterId(new MeterId(1)).srcSwitch(srcSwitch).destSwitch(destSwitch).status(FlowPathStatus.ACTIVE).srcWithMultiTable(multiTable).destWithMultiTable(multiTable).build();
PathSegment forwardSegment = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(destSwitch).destPort(destPort).build();
forwardFlowPath.setSegments(Collections.singletonList(forwardSegment));
flowPathRepository.add(forwardFlowPath);
flow.setForwardPath(forwardFlowPath);
FlowPath reverseFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_reverse_path")).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 1L)).meterId(new MeterId(2)).srcSwitch(destSwitch).destSwitch(srcSwitch).status(FlowPathStatus.ACTIVE).srcWithMultiTable(multiTable).destWithMultiTable(multiTable).build();
PathSegment reverseSegment = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(destSwitch).srcPort(destPort).destSwitch(srcSwitch).destPort(srcPort).build();
reverseFlowPath.setSegments(Collections.singletonList(reverseSegment));
flowPathRepository.add(reverseFlowPath);
flow.setReversePath(reverseFlowPath);
return flow;
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FermaFlowRepositoryTest method createTestFlowWithIntermediate.
private Flow createTestFlowWithIntermediate(String flowId, Switch srcSwitch, Switch intSwitch, int intPort, Switch destSwitch) {
Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcPort(PORT_1).destSwitch(destSwitch).destPort(PORT_2).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).status(FlowStatus.UP).build();
flowRepository.add(flow);
FlowPath forwardFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_forward_path")).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1L)).meterId(new MeterId(1)).srcSwitch(srcSwitch).destSwitch(destSwitch).status(FlowPathStatus.ACTIVE).build();
flowPathRepository.add(forwardFlowPath);
flow.setForwardPath(forwardFlowPath);
PathSegment forwardSegment = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(srcSwitch).srcPort(1).destSwitch(intSwitch).destPort(intPort).build();
forwardFlowPath.setSegments(Collections.singletonList(forwardSegment));
FlowPath reverseFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_reverse_path")).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 1L)).meterId(new MeterId(2)).srcSwitch(destSwitch).destSwitch(srcSwitch).status(FlowPathStatus.ACTIVE).build();
flowPathRepository.add(reverseFlowPath);
flow.setReversePath(reverseFlowPath);
PathSegment reverseSegment = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(intSwitch).srcPort(100).destSwitch(srcSwitch).destPort(1).build();
reverseFlowPath.setSegments(Collections.singletonList(reverseSegment));
return flow;
}
use of org.openkilda.model.cookie.FlowSegmentCookie in project open-kilda by telstra.
the class FermaYFlowRepositoryTest method createTestFlow.
private Flow createTestFlow(String flowId, Switch srcSwitch, int srcPort, int srcVlan, Switch destSwitch, int destPort, int destVlan) {
Flow flow = Flow.builder().flowId(flowId).srcSwitch(srcSwitch).srcPort(srcPort).srcVlan(srcVlan).destSwitch(destSwitch).destPort(destPort).destVlan(destVlan).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).status(FlowStatus.UP).build();
flowRepository.add(flow);
FlowPath forwardFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_forward_path")).cookie(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1L)).meterId(new MeterId(1)).srcSwitch(srcSwitch).destSwitch(destSwitch).status(FlowPathStatus.ACTIVE).build();
PathSegment forwardSegment = PathSegment.builder().pathId(forwardFlowPath.getPathId()).srcSwitch(srcSwitch).srcPort(srcPort).destSwitch(destSwitch).destPort(destPort).build();
forwardFlowPath.setSegments(Collections.singletonList(forwardSegment));
flowPathRepository.add(forwardFlowPath);
flow.setForwardPath(forwardFlowPath);
FlowPath reverseFlowPath = FlowPath.builder().pathId(new PathId(flowId + "_reverse_path")).cookie(new FlowSegmentCookie(FlowPathDirection.REVERSE, 1L)).meterId(new MeterId(2)).srcSwitch(destSwitch).destSwitch(srcSwitch).status(FlowPathStatus.ACTIVE).build();
PathSegment reverseSegment = PathSegment.builder().pathId(reverseFlowPath.getPathId()).srcSwitch(destSwitch).srcPort(destPort).destSwitch(srcSwitch).destPort(srcPort).build();
reverseFlowPath.setSegments(Collections.singletonList(reverseSegment));
flowPathRepository.add(reverseFlowPath);
flow.setReversePath(reverseFlowPath);
return flow;
}
Aggregations