Search in sources :

Example 21 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class AbstractYFlowTest method createYFlowViaTransit.

protected YFlow createYFlowViaTransit(String yFlowId) {
    // Create sub-flows
    Flow firstFlow = dummyFactory.makeMainAffinityFlow(firstSharedEndpoint, firstEndpoint, islSharedToTransit, islTransitToFirst);
    Flow secondFlow = dummyFactory.makeFlow(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), islSharedToTransit, islTransitToSecond);
    SwitchId yPoint = SWITCH_TRANSIT;
    FlowMeter yPointMeter = dummyFactory.makeFlowMeter(yPoint, yFlowId, null);
    FlowMeter sharedEndpointMeter = dummyFactory.makeFlowMeter(firstSharedEndpoint.getSwitchId(), yFlowId, null);
    YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).sharedEndpointMeterId(sharedEndpointMeter.getMeterId()).yPoint(yPoint).meterId(yPointMeter.getMeterId()).status(FlowStatus.UP).build();
    yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
    YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
    yFlowRepository.add(yFlow);
    return yFlow;
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) SwitchId(org.openkilda.model.SwitchId) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) FlowMeter(org.openkilda.model.FlowMeter) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Example 22 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class AbstractYFlowTest method createYFlowWithProtected.

protected YFlow createYFlowWithProtected(String yFlowId) {
    dummyFactory.getFlowDefaults().setAllocateProtectedPath(true);
    // Create sub-flows
    Flow firstFlow = dummyFactory.makeMainAffinityFlowWithProtectedPath(firstSharedEndpoint, firstEndpoint, asList(islSharedToTransit, islTransitToFirst), asList(islSharedToAltTransit, islAltTransitToFirst));
    Flow secondFlow = dummyFactory.makeFlowWithProtectedPath(secondSharedEndpoint, secondEndpoint, firstFlow.getAffinityGroupId(), asList(islSharedToTransit, islTransitToSecond), asList(islSharedToAltTransit, islAltTransitToSecond));
    YFlow yFlow = YFlow.builder().yFlowId(yFlowId).sharedEndpoint(new SharedEndpoint(firstSharedEndpoint.getSwitchId(), firstSharedEndpoint.getPortNumber())).allocateProtectedPath(true).status(FlowStatus.UP).build();
    yFlow.setSubFlows(Stream.of(firstFlow, secondFlow).map(flow -> YSubFlow.builder().sharedEndpointVlan(flow.getSrcVlan()).sharedEndpointInnerVlan(flow.getSrcInnerVlan()).endpointSwitchId(flow.getDestSwitchId()).endpointPort(flow.getDestPort()).endpointVlan(flow.getDestVlan()).endpointInnerVlan(flow.getDestInnerVlan()).flow(flow).yFlow(yFlow).build()).collect(Collectors.toSet()));
    YFlowRepository yFlowRepository = persistenceManager.getRepositoryFactory().createYFlowRepository();
    yFlowRepository.add(yFlow);
    return yFlow;
}
Also used : YFlow(org.openkilda.model.YFlow) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) SharedEndpoint(org.openkilda.model.YFlow.SharedEndpoint) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow)

Example 23 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class FlowValidator method checkDiverseFlow.

@VisibleForTesting
void checkDiverseFlow(RequestedFlow targetFlow) throws InvalidFlowException {
    if (targetFlow.getSrcSwitch().equals(targetFlow.getDestSwitch())) {
        throw new InvalidFlowException("Couldn't add one-switch flow into diverse group", ErrorType.PARAMETERS_INVALID);
    }
    Flow diverseFlow = flowRepository.findById(targetFlow.getDiverseFlowId()).orElse(null);
    if (diverseFlow == null) {
        YFlow diverseYFlow = yFlowRepository.findById(targetFlow.getDiverseFlowId()).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", targetFlow.getDiverseFlowId()), ErrorType.PARAMETERS_INVALID));
        diverseFlow = diverseYFlow.getSubFlows().stream().map(YSubFlow::getFlow).filter(flow -> flow.getFlowId().equals(flow.getAffinityGroupId())).findFirst().orElseThrow(() -> new InvalidFlowException(format("Failed to find main affinity flow for diverse y-flow id %s", targetFlow.getDiverseFlowId()), ErrorType.INTERNAL_ERROR));
    }
    if (StringUtils.isNotBlank(diverseFlow.getAffinityGroupId())) {
        String diverseFlowId = diverseFlow.getAffinityGroupId();
        diverseFlow = flowRepository.findById(diverseFlowId).orElseThrow(() -> new InvalidFlowException(format("Failed to find diverse flow id %s", diverseFlowId), ErrorType.PARAMETERS_INVALID));
        Collection<String> affinityFlowIds = flowRepository.findFlowsIdByAffinityGroupId(diverseFlow.getAffinityGroupId()).stream().filter(Objects::nonNull).collect(Collectors.toSet());
        if (affinityFlowIds.contains(targetFlow.getAffinityFlowId())) {
            throw new InvalidFlowException("Couldn't create diverse group with flow in the same affinity group", ErrorType.PARAMETERS_INVALID);
        }
    }
    if (diverseFlow.isOneSwitchFlow()) {
        throw new InvalidFlowException("Couldn't create diverse group with one-switch flow", ErrorType.PARAMETERS_INVALID);
    }
}
Also used : YFlow(org.openkilda.model.YFlow) Getter(lombok.Getter) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AccessLevel(lombok.AccessLevel) Flow(org.openkilda.model.Flow) IslRepository(org.openkilda.persistence.repositories.IslRepository) FlowSourceAdapter(org.openkilda.adapter.FlowSourceAdapter) YFlow(org.openkilda.model.YFlow) FlowRepository(org.openkilda.persistence.repositories.FlowRepository) FlowDestAdapter(org.openkilda.adapter.FlowDestAdapter) PersistenceManager(org.openkilda.persistence.PersistenceManager) SwitchProperties(org.openkilda.model.SwitchProperties) FlowEncapsulationType(org.openkilda.model.FlowEncapsulationType) FlowEndpoint(org.openkilda.model.FlowEndpoint) Switch(org.openkilda.model.Switch) FlowMirrorPointsRepository(org.openkilda.persistence.repositories.FlowMirrorPointsRepository) YSubFlow(org.openkilda.model.YSubFlow) PhysicalPortRepository(org.openkilda.persistence.repositories.PhysicalPortRepository) RequestedFlowMirrorPoint(org.openkilda.wfm.topology.flowhs.model.RequestedFlowMirrorPoint) ErrorType(org.openkilda.messaging.error.ErrorType) FlowMirrorPoints(org.openkilda.model.FlowMirrorPoints) Collection(java.util.Collection) Set(java.util.Set) FlowMirrorPathRepository(org.openkilda.persistence.repositories.FlowMirrorPathRepository) RequestedFlowMapper(org.openkilda.wfm.topology.flowhs.mapper.RequestedFlowMapper) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) YFlowRepository(org.openkilda.persistence.repositories.YFlowRepository) Objects(java.util.Objects) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) FlowMirrorPath(org.openkilda.model.FlowMirrorPath) Optional(java.util.Optional) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AllArgsConstructor(lombok.AllArgsConstructor) PhysicalPort(org.openkilda.model.PhysicalPort) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) YSubFlow(org.openkilda.model.YSubFlow) RequestedFlow(org.openkilda.wfm.topology.flowhs.model.RequestedFlow) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 24 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class YFlowRerouteServiceTest method verifyYFlowStatus.

protected YFlow verifyYFlowStatus(String yFlowId, FlowStatus expectedStatus, FlowStatus expectedFirstSubFlowStatus, FlowStatus expectedSecondSubFlowStatus) {
    YFlow flow = getYFlow(yFlowId);
    assertEquals(expectedStatus, flow.getStatus());
    Set<FlowStatus> expectedSubFlowStatuses = Stream.of(expectedFirstSubFlowStatus, expectedSecondSubFlowStatus).collect(Collectors.toSet());
    Set<FlowStatus> actualSubFlowStatuses = flow.getSubFlows().stream().map(YSubFlow::getFlow).map(Flow::getStatus).collect(Collectors.toSet());
    assertEquals(expectedSubFlowStatuses, actualSubFlowStatuses);
    return flow;
}
Also used : YFlow(org.openkilda.model.YFlow) FlowStatus(org.openkilda.model.FlowStatus) YSubFlow(org.openkilda.model.YSubFlow)

Example 25 with YFlow

use of org.openkilda.model.YFlow in project open-kilda by telstra.

the class YFlowValidationHubServiceTest method shouldValidateYFlowSuccessfully.

@Test
public void shouldValidateYFlowSuccessfully() throws DuplicateKeyException {
    // given
    String yFlowId = "test_y_flow_1";
    YFlow yFlow = createYFlowViaTransit(yFlowId);
    YFlowSwitchFlowEntriesBuilder flowEntriesBuilder = new YFlowSwitchFlowEntriesBuilder(yFlow, persistenceManager.getRepositoryFactory().createTransitVlanRepository(), persistenceManager.getRepositoryFactory().createVxlanRepository());
    Map<SwitchId, Collection<FlowEntry>> flowEntries = flowEntriesBuilder.getFlowEntries();
    Map<SwitchId, Collection<MeterEntry>> meterEntries = flowEntriesBuilder.getMeterEntries();
    Map<SwitchId, Collection<GroupEntry>> groupEntries = flowEntriesBuilder.getGroupEntries();
    YFlowValidationHubService service = makeYFlowValidationHubService();
    service.handleRequest(yFlow.getYFlowId(), new CommandContext(), yFlow.getYFlowId());
    // when
    handleSpeakerRequests(service, yFlowId, flowEntries, meterEntries, groupEntries);
    // then
    verifyNorthboundSuccessResponse(yFlowValidationHubCarrier);
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) Collection(java.util.Collection) YFlowSwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowSwitchFlowEntriesBuilder) SwitchId(org.openkilda.model.SwitchId) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Aggregations

YFlow (org.openkilda.model.YFlow)74 Flow (org.openkilda.model.Flow)30 SwitchId (org.openkilda.model.SwitchId)29 YSubFlow (org.openkilda.model.YSubFlow)26 FlowProcessingException (org.openkilda.wfm.topology.flowhs.exception.FlowProcessingException)19 Test (org.junit.Test)12 YFlowRequest (org.openkilda.messaging.command.yflow.YFlowRequest)12 ArrayList (java.util.ArrayList)11 FlowStatus (org.openkilda.model.FlowStatus)10 CommandContext (org.openkilda.wfm.CommandContext)10 AbstractYFlowTest (org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)10 FlowPath (org.openkilda.model.FlowPath)9 FlowEndpoint (org.openkilda.model.FlowEndpoint)8 InstallSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.InstallSpeakerCommandsRequest)6 Switch (org.openkilda.model.Switch)6 HashSet (java.util.HashSet)5 DeleteSpeakerCommandsRequest (org.openkilda.floodlight.api.request.rulemanager.DeleteSpeakerCommandsRequest)5 SharedEndpoint (org.openkilda.model.YFlow.SharedEndpoint)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4