Search in sources :

Example 6 with RequestedFlowMirrorPoint

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint 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()));
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowPath(org.openkilda.model.FlowPath) SwitchProperties(org.openkilda.model.SwitchProperties) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Flow(org.openkilda.model.Flow)

Example 7 with RequestedFlowMirrorPoint

use of org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint in project open-kilda by telstra.

the class RequestedFlowMirrorPointMapperTest method testFlowMirrorPointCreateRequestToRequestedFlowMirrorPoint.

@Test
public void testFlowMirrorPointCreateRequestToRequestedFlowMirrorPoint() {
    FlowMirrorPointCreateRequest request = FlowMirrorPointCreateRequest.builder().flowId(FLOW_ID).mirrorPointId(MIRROR_POINT_ID).mirrorPointDirection(MIRROR_POINT_DIRECTION).mirrorPointSwitchId(MIRROR_POINT_SWITCH_ID).sinkEndpoint(FlowEndpoint.builder().switchId(RECEIVER_POINT_SWITCH_ID).portNumber(RECEIVER_POINT_PORT).outerVlanId(RECEIVER_POINT_OUTER_VLAN).innerVlanId(RECEIVER_POINT_INNER_VLAN).build()).build();
    RequestedFlowMirrorPoint flowMirrorPoint = RequestedFlowMirrorPointMapper.INSTANCE.map(request);
    assertEquals(request.getFlowId(), flowMirrorPoint.getFlowId());
    assertEquals(request.getMirrorPointId(), flowMirrorPoint.getMirrorPointId());
    assertEquals(MIRROR_POINT_DIRECTION, flowMirrorPoint.getMirrorPointDirection());
    assertEquals(request.getMirrorPointSwitchId(), flowMirrorPoint.getMirrorPointSwitchId());
    assertEquals(request.getSinkEndpoint(), flowMirrorPoint.getSinkEndpoint());
}
Also used : RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) FlowMirrorPointCreateRequest(org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest) Test(org.junit.Test)

Aggregations

RequestedFlowMirrorPoint (org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint)7 Flow (org.openkilda.model.Flow)3 FlowPath (org.openkilda.model.FlowPath)3 PathId (org.openkilda.model.PathId)3 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)3 FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 FlowMirrorPointCreateRequest (org.openkilda.messaging.command.flow.FlowMirrorPointCreateRequest)1 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)1 PhysicalPort (org.openkilda.model.PhysicalPort)1 Switch (org.openkilda.model.Switch)1 SwitchProperties (org.openkilda.model.SwitchProperties)1 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)1 CommandContext (org.openkilda.wfm.CommandContext)1 SpeakerRequestBuildContext (org.openkilda.wfm.share.model.SpeakerRequestBuildContext)1 FlowCommandBuilder (org.openkilda.wfm.topology.flowhs.service.FlowCommandBuilder)1 InvalidFlowException (org.openkilda.wfm.topology.flowhs.validation.InvalidFlowException)1 UnavailableFlowEndpointException (org.openkilda.wfm.topology.flowhs.validation.UnavailableFlowEndpointException)1