Search in sources :

Example 6 with GroupEntry

use of org.openkilda.messaging.info.rule.GroupEntry 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)

Aggregations

GroupEntry (org.openkilda.messaging.info.rule.GroupEntry)6 SwitchId (org.openkilda.model.SwitchId)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Test (org.junit.Test)2 OfFlowStatsMapper (org.openkilda.floodlight.converter.OfFlowStatsMapper)2 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)2 CommandData (org.openkilda.messaging.command.CommandData)2 DumpGroupsForFlowHsRequest (org.openkilda.messaging.command.switches.DumpGroupsForFlowHsRequest)2 DumpMetersForFlowHsRequest (org.openkilda.messaging.command.switches.DumpMetersForFlowHsRequest)2 OFGroupDescStatsEntry (org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry)2 Collections.emptyList (java.util.Collections.emptyList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors.toList (java.util.stream.Collectors.toList)1 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)1