Search in sources :

Example 66 with YFlow

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

the class YFlowValidationHubServiceTest method shouldValidateAndFailIfSubFlowHasMissingRule.

@Test
public void shouldValidateAndFailIfSubFlowHasMissingRule() throws DuplicateKeyException {
    // given
    String yFlowId = "test_y_flow_1";
    YFlow yFlow = createYFlowViaTransit(yFlowId);
    YSubFlow failedSubFlow = yFlow.getSubFlows().stream().findFirst().orElseThrow(IllegalStateException::new);
    Flow failedFlow = failedSubFlow.getFlow();
    YFlowSwitchFlowEntriesBuilder flowEntriesBuilder = new YFlowSwitchFlowEntriesBuilder(yFlow, persistenceManager.getRepositoryFactory().createTransitVlanRepository(), persistenceManager.getRepositoryFactory().createVxlanRepository());
    Map<SwitchId, Collection<FlowEntry>> flowEntries = flowEntriesBuilder.getFlowEntries();
    flowEntries.forEach((s, f) -> f.removeIf(entry -> entry.getCookie() == failedFlow.getForwardPath().getCookie().getValue()));
    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
    YFlowValidationResponse response = getNorthboundResponse(yFlowValidationHubCarrier);
    assertFalse(response.isAsExpected());
    assertFalse(response.getYFlowValidationResult().isAsExpected());
    response.getSubFlowValidationResults().forEach(result -> assertTrue(result.getFlowId().equals(failedFlow.getFlowId()) || result.getAsExpected()));
    assertEquals(1, response.getSubFlowValidationResults().stream().filter(r -> !r.getAsExpected()).count());
}
Also used : YFlow(org.openkilda.model.YFlow) InfoMessage(org.openkilda.messaging.info.InfoMessage) Flow(org.openkilda.model.Flow) Pair(org.apache.commons.lang3.tuple.Pair) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) FlowValidationHubCarrier(org.openkilda.wfm.topology.flowhs.service.FlowValidationHubCarrier) Assert.fail(org.junit.Assert.fail) SwitchFlowEntries(org.openkilda.messaging.info.rule.SwitchFlowEntries) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) SwitchGroupEntries(org.openkilda.messaging.info.rule.SwitchGroupEntries) YFlowSwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowSwitchFlowEntriesBuilder) YSubFlow(org.openkilda.model.YSubFlow) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) InfoData(org.openkilda.messaging.info.InfoData) CommandContext(org.openkilda.wfm.CommandContext) GroupEntry(org.openkilda.messaging.info.rule.GroupEntry) SwitchMeterEntries(org.openkilda.messaging.info.meter.SwitchMeterEntries) BURST_COEFFICIENT(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder.BURST_COEFFICIENT) Assert.assertFalse(org.junit.Assert.assertFalse) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) CommandData(org.openkilda.messaging.command.CommandData) Message(org.openkilda.messaging.Message) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) MeterEntry(org.openkilda.messaging.info.meter.MeterEntry) ArrayList(java.util.ArrayList) DumpMetersForFlowHsRequest(org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest) ArgumentCaptor(org.mockito.ArgumentCaptor) YFlow(org.openkilda.model.YFlow) Before(org.junit.Before) Collections.emptyMap(java.util.Collections.emptyMap) DumpGroupsForFlowHsRequest(org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest) DuplicateKeyException(org.openkilda.wfm.topology.flowhs.exception.DuplicateKeyException) Assert.assertNotNull(org.junit.Assert.assertNotNull) ErrorType(org.openkilda.messaging.error.ErrorType) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) FlowValidationHubService(org.openkilda.wfm.topology.flowhs.service.FlowValidationHubService) DumpRulesForFlowHsRequest(org.openkilda.messaging.command.switches.DumpRulesForFlowHsRequest) SwitchId(org.openkilda.model.SwitchId) MIN_BURST_SIZE_IN_KBITS(org.openkilda.wfm.topology.flowhs.fsm.validation.SwitchFlowEntriesBuilder.MIN_BURST_SIZE_IN_KBITS) YFlowValidationService(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowValidationService) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest) Assert.assertEquals(org.junit.Assert.assertEquals) YFlowValidationResponse(org.openkilda.messaging.command.yflow.YFlowValidationResponse) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) YSubFlow(org.openkilda.model.YSubFlow) Flow(org.openkilda.model.Flow) YSubFlow(org.openkilda.model.YSubFlow) YFlow(org.openkilda.model.YFlow) Collection(java.util.Collection) YFlowSwitchFlowEntriesBuilder(org.openkilda.wfm.topology.flowhs.fsm.yflow.validation.YFlowSwitchFlowEntriesBuilder) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 67 with YFlow

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

the class YFlowUpdateServiceTest method shouldFailIfNoResourcesAvailable.

@Test
public void shouldFailIfNoResourcesAvailable() throws UnroutableFlowException, RecoverableException, ResourceAllocationException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    doThrow(new ResourceAllocationException(injectedErrorMessage)).when(flowResourcesManager).allocateMeter(eq("test_successful_yflow"), eq(SWITCH_TRANSIT));
    // when
    processUpdateRequestAndSpeakerCommands(request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    // +1 from YFlowCreateFsm
    verify(flowResourcesManager, times(METER_ALLOCATION_RETRIES_LIMIT + 2)).allocateMeter(eq("test_successful_yflow"), eq(SWITCH_TRANSIT));
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) SwitchId(org.openkilda.model.SwitchId) ResourceAllocationException(org.openkilda.wfm.share.flow.resources.ResourceAllocationException) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 68 with YFlow

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

the class YFlowUpdateServiceTest method shouldFailIfNoPathAvailableForSecondSubFlow.

@Test
public void shouldFailIfNoPathAvailableForSecondSubFlow() throws UnroutableFlowException, RecoverableException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    when(pathComputer.getPath(buildFlowIdArgumentMatch("test_flow_2"), any())).thenThrow(new UnroutableFlowException(injectedErrorMessage));
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    // when
    processUpdateRequestAndSpeakerCommands(request, FlowStatus.IN_PROGRESS, FlowStatus.UP, FlowStatus.IN_PROGRESS);
    verifyNorthboundErrorResponse(yFlowUpdateHubCarrier, ErrorType.NOT_FOUND);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) UnroutableFlowException(org.openkilda.pce.exception.UnroutableFlowException) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 69 with YFlow

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

the class YFlowUpdateServiceTest method shouldUpdateFlowWithProtectedPath.

@Test
public void shouldUpdateFlowWithProtectedPath() throws UnroutableFlowException, RecoverableException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlowWithProtectedPath();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildNewFirstSubFlowProtectedPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildNewSecondSubFlowProtectedPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT, SWITCH_TRANSIT);
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_NEW_ALT_TRANSIT, SWITCH_NEW_ALT_TRANSIT);
    // when
    processUpdateRequestAndSpeakerCommands(request);
    verifyNorthboundSuccessResponse(yFlowUpdateHubCarrier, YFlowResponse.class);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    verifyAffinity(request.getYFlowId());
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(2000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) Test(org.junit.Test) AbstractYFlowTest(org.openkilda.wfm.topology.flowhs.service.AbstractYFlowTest)

Example 70 with YFlow

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

the class YFlowUpdateServiceTest method shouldFailOnUnsuccessfulMeterInstallation.

@Test
public void shouldFailOnUnsuccessfulMeterInstallation() throws RecoverableException, UnroutableFlowException, DuplicateKeyException {
    // given
    YFlowRequest request = createYFlow();
    request.setMaximumBandwidth(2000L);
    request.getSubFlows().get(0).setEndpoint(newFirstEndpoint);
    request.getSubFlows().get(1).setEndpoint(newSecondEndpoint);
    preparePathComputationForUpdate("test_flow_1", buildNewFirstSubFlowPathPair(), buildFirstSubFlowPathPair());
    preparePathComputationForUpdate("test_flow_2", buildNewSecondSubFlowPathPair(), buildSecondSubFlowPathPair());
    prepareYPointComputation(SWITCH_SHARED, SWITCH_NEW_FIRST_EP, SWITCH_NEW_SECOND_EP, SWITCH_TRANSIT);
    YFlowUpdateService service = makeYFlowUpdateService(0);
    // when
    service.handleRequest(request.getYFlowId(), new CommandContext(), request);
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.IN_PROGRESS, FlowStatus.IN_PROGRESS, FlowStatus.UP);
    // and
    handleSpeakerCommandsAndFailInstall(service, request.getYFlowId(), "test_successful_yflow");
    // then
    verifyYFlowStatus(request.getYFlowId(), FlowStatus.UP);
    YFlow flow = getYFlow(request.getYFlowId());
    assertEquals(1000L, flow.getMaximumBandwidth());
    Set<SwitchId> expectedEndpointSwitchIds = Stream.of(SWITCH_FIRST_EP, SWITCH_SECOND_EP).collect(Collectors.toSet());
    Set<SwitchId> actualEndpointSwitchIds = flow.getSubFlows().stream().map(YSubFlow::getEndpointSwitchId).collect(Collectors.toSet());
    assertEquals(expectedEndpointSwitchIds, actualEndpointSwitchIds);
}
Also used : YFlow(org.openkilda.model.YFlow) CommandContext(org.openkilda.wfm.CommandContext) SwitchId(org.openkilda.model.SwitchId) YFlowRequest(org.openkilda.messaging.command.yflow.YFlowRequest) 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