Search in sources :

Example 1 with ValidateRulesResult

use of org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult in project open-kilda by telstra.

the class ValidationServiceImplTest method validateRules.

@Test
public void validateRules() {
    ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
    List<FlowSpeakerData> actualFlows = Lists.newArrayList(FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000001L)).priority(1).build(), FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000001L)).priority(2).build(), FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000002L)).priority(1).build(), FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000002L)).priority(2).build(), FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000004L)).priority(1).build());
    List<FlowSpeakerData> expectedFlows = Lists.newArrayList(FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000001L)).priority(1).build(), FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000002L)).priority(3).build(), FlowSpeakerData.builder().cookie(new Cookie(0x8000000000000003L)).priority(1).build());
    ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, actualFlows, expectedFlows);
    assertEquals(ImmutableSet.of(0x8000000000000001L), new HashSet<>(response.getProperRules()));
    assertEquals(ImmutableSet.of(0x8000000000000001L, 0x8000000000000002L), new HashSet<>(response.getMisconfiguredRules()));
    assertEquals(ImmutableSet.of(0x8000000000000003L), new HashSet<>(response.getMissingRules()));
    assertEquals(ImmutableSet.of(0x8000000000000004L), new HashSet<>(response.getExcessRules()));
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) Test(org.junit.Test)

Example 2 with ValidateRulesResult

use of org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult in project open-kilda by telstra.

the class ValidationServiceImplTest method validateRulesEmpty.

@Test
public void validateRulesEmpty() {
    ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
    ValidateRulesResult response = validationService.validateRules(SWITCH_ID_A, emptyList(), emptyList());
    assertTrue(response.getMissingRules().isEmpty());
    assertTrue(response.getProperRules().isEmpty());
    assertTrue(response.getExcessRules().isEmpty());
}
Also used : ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) Test(org.junit.Test)

Example 3 with ValidateRulesResult

use of org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult in project open-kilda by telstra.

the class SwitchValidateFsm method validateRules.

private void validateRules(List<FlowSpeakerData> expectedRules) {
    log.info("Validate rules (switch={}, key={})", getSwitchId(), key);
    ValidateRulesResult results = validationService.validateRules(getSwitchId(), validationContext.getActualOfFlows(), expectedRules);
    validationContext = validationContext.toBuilder().ofFlowsValidationReport(results).build();
}
Also used : ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult)

Example 4 with ValidateRulesResult

use of org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult in project open-kilda by telstra.

the class SwitchValidateServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    SwitchRepository switchRepository = Mockito.mock(SwitchRepository.class);
    when(switchRepository.findById(eq(SWITCH_ID))).thenReturn(Optional.of(SWITCH_1));
    when(switchRepository.findById(eq(SWITCH_ID_MISSING))).thenReturn(Optional.empty());
    LagLogicalPortRepository lagLogicalPortRepository = Mockito.mock(LagLogicalPortRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    service = new SwitchValidateServiceImpl(carrier, persistenceManager, validationService, ruleManager);
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).processMeters(true).build();
    flowSpeakerData = FlowSpeakerData.builder().ofVersion(OfVersion.OF_13).cookie(new Cookie(1L)).table(OfTable.INPUT).priority(10).match(emptySet()).instructions(Instructions.builder().build()).flags(emptySet()).build();
    meterSpeakerData = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    when(validationService.validateRules(any(), any(), any())).thenReturn(new ValidateRulesResult(newHashSet(flowSpeakerData.getCookie().getValue()), emptySet(), emptySet(), emptySet()));
    when(validationService.validateMeters(any(), any(), any())).thenReturn(new ValidateMetersResult(emptyList(), emptyList(), emptyList(), emptyList()));
}
Also used : LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) Cookie(org.openkilda.model.cookie.Cookie) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) MeterId(org.openkilda.model.MeterId) Before(org.junit.Before)

Example 5 with ValidateRulesResult

use of org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult in project open-kilda by telstra.

the class SwitchSyncFsmTest method getModifyDefaultMetersWithMissingRulesTest.

@Test
public void getModifyDefaultMetersWithMissingRulesTest() {
    ValidateRulesResult validateRulesResult = new ValidateRulesResult(newHashSet(COOKIE_1), newHashSet(), newHashSet(), newHashSet(COOKIE_2));
    ArrayList<MeterInfoEntry> misconfiguredMeters = newArrayList(MeterInfoEntry.builder().cookie(COOKIE_1).meterId(METER_ID_1).build(), MeterInfoEntry.builder().cookie(COOKIE_2).meterId(METER_ID_2).build(), MeterInfoEntry.builder().cookie(COOKIE_3).meterId(METER_ID_3).build());
    ValidateMetersResult validateMetersResult = new ValidateMetersResult(newArrayList(), misconfiguredMeters, newArrayList(), newArrayList());
    ValidationResult validationResult = new ValidationResult(new ArrayList<>(), true, validateRulesResult, validateMetersResult, EMPTY_VALIDATE_GROUPS_RESULT, EMPTY_LOGICAL_PORTS_RESULT);
    SwitchSyncFsm fsm = new SwitchSyncFsm(null, null, null, new SwitchValidateRequest(SWITCH_ID, true, true, true), validationResult);
    List<Long> modifyMeters = fsm.getModifyDefaultMeters();
    assertEquals(1, modifyMeters.size());
    assertEquals(METER_ID_3, modifyMeters.get(0).longValue());
}
Also used : ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchValidateRequest(org.openkilda.messaging.command.switches.SwitchValidateRequest) ValidationResult(org.openkilda.wfm.topology.switchmanager.model.ValidationResult) Test(org.junit.Test)

Aggregations

ValidateRulesResult (org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult)6 Test (org.junit.Test)3 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)3 Cookie (org.openkilda.model.cookie.Cookie)2 ValidationService (org.openkilda.wfm.topology.switchmanager.service.ValidationService)2 Before (org.junit.Before)1 SwitchValidateRequest (org.openkilda.messaging.command.switches.SwitchValidateRequest)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 GroupSyncEntry (org.openkilda.messaging.info.switches.GroupSyncEntry)1 LogicalPortsSyncEntry (org.openkilda.messaging.info.switches.LogicalPortsSyncEntry)1 MeterInfoEntry (org.openkilda.messaging.info.switches.MeterInfoEntry)1 MetersSyncEntry (org.openkilda.messaging.info.switches.MetersSyncEntry)1 RulesSyncEntry (org.openkilda.messaging.info.switches.RulesSyncEntry)1 SwitchSyncResponse (org.openkilda.messaging.info.switches.SwitchSyncResponse)1 MeterId (org.openkilda.model.MeterId)1 MirrorConfig (org.openkilda.model.MirrorConfig)1 FlowPathRepository (org.openkilda.persistence.repositories.FlowPathRepository)1 LagLogicalPortRepository (org.openkilda.persistence.repositories.LagLogicalPortRepository)1 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)1 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)1