Search in sources :

Example 1 with FlowMirrorPoints

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);
    }
}
Also used : PathId(org.openkilda.model.PathId) SpeakerRequestEmitter(org.openkilda.wfm.topology.flowhs.utils.SpeakerRequestEmitter) FlowSegmentRequestFactory(org.openkilda.floodlight.api.request.factory.FlowSegmentRequestFactory) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId) Flow(org.openkilda.model.Flow)

Example 2 with FlowMirrorPoints

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;
}
Also used : MirrorGroup(org.openkilda.model.MirrorGroup) Switch(org.openkilda.model.Switch) FlowProcessingException(org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) MirrorDirection(org.openkilda.model.MirrorDirection)

Example 3 with 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));
    }
}
Also used : PathId(org.openkilda.model.PathId) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) SwitchId(org.openkilda.model.SwitchId)

Example 4 with 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, 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()));
    }
}
Also used : PathId(org.openkilda.model.PathId) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowPath(org.openkilda.model.FlowPath) Flow(org.openkilda.model.Flow)

Example 5 with FlowMirrorPoints

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));
}
Also used : FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) InMemoryGraphBasedTest(org.openkilda.persistence.inmemory.InMemoryGraphBasedTest) Test(org.junit.Test)

Aggregations

FlowMirrorPoints (org.openkilda.model.FlowMirrorPoints)26 Flow (org.openkilda.model.Flow)11 PathId (org.openkilda.model.PathId)10 FlowMirrorPath (org.openkilda.model.FlowMirrorPath)7 FlowPath (org.openkilda.model.FlowPath)7 SwitchId (org.openkilda.model.SwitchId)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Switch (org.openkilda.model.Switch)6 InMemoryGraphBasedTest (org.openkilda.persistence.inmemory.InMemoryGraphBasedTest)6 FlowEndpoint (org.openkilda.model.FlowEndpoint)5 PathSegment (org.openkilda.model.PathSegment)5 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 MirrorGroup (org.openkilda.model.MirrorGroup)4 Collections (java.util.Collections)3 Iterator (java.util.Iterator)3 FlowSideAdapter (org.openkilda.adapter.FlowSideAdapter)3 GroupId (org.openkilda.model.GroupId)3