Search in sources :

Example 6 with SwitchSyncResponse

use of org.openkilda.messaging.info.switches.SwitchSyncResponse in project open-kilda by telstra.

the class NetworkSwitchServiceTest method switchMustStayOnlineIfItReceivePeriodicDumps.

@Test
public void switchMustStayOnlineIfItReceivePeriodicDumps() {
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    SpeakerSwitchView dump = getSpeakerSwitchView();
    service.switchBecomeManaged(dump, "A-0");
    ArgumentCaptor<String> syncKeyCaptor = ArgumentCaptor.forClass(String.class);
    verify(carrier).sendSwitchSynchronizeRequest(syncKeyCaptor.capture(), eq(dump.getDatapath()));
    verifyNoMoreInteractions(carrier);
    String syncKey = syncKeyCaptor.getValue();
    SwitchSyncResponse response = makeSuccessSwitchSyncResponse(dump.getDatapath());
    service.switchManagerResponse(response, syncKey);
    verify(carrier).sendSwitchStateChanged(dump.getDatapath(), SwitchStatus.ACTIVE);
    verify(carrier).sendAffectedFlowRerouteRequest(dump.getDatapath());
    verifyNoMoreInteractions(carrier);
    // +10 to be sure to cover +-1 mismatches
    for (int i = 0; i < options.getSwitchOfflineGenerationLag() + 10; i++) {
        service.switchBecomeManaged(dump, String.format("dump#%d", i));
        verifyNoMoreInteractions(carrier);
    }
}
Also used : SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) Endpoint(org.openkilda.wfm.share.model.Endpoint) Test(org.junit.Test)

Example 7 with SwitchSyncResponse

use of org.openkilda.messaging.info.switches.SwitchSyncResponse in project open-kilda by telstra.

the class NetworkSwitchServiceTest method newSwitchWithWrongSynchronizationResponse.

@Test
public void newSwitchWithWrongSynchronizationResponse() {
    List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews();
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(ports).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchEvent(switchAddEvent);
    RulesSyncEntry rulesSyncEntry = new RulesSyncEntry(singletonList(new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue()), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    MetersSyncEntry metersSyncEntry = new MetersSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    GroupSyncEntry groupSyncEntry = new GroupSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    SwitchSyncResponse response = new SwitchSyncResponse(alphaDatapath, rulesSyncEntry, metersSyncEntry, groupSyncEntry, LogicalPortsSyncEntry.builder().build());
    // for a randomly generated key in SwitchFsm
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(carrier).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerResponse(response, captor.getValue());
    verify(carrier, times(SYNC_ATTEMPTS)).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerResponse(response, captor.getValue());
    verifyNewSwitchAfterSwitchSync(ports);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    verifyNoMoreInteractions(carrier);
}
Also used : RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) MetersSyncEntry(org.openkilda.messaging.info.switches.MetersSyncEntry) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) GroupSyncEntry(org.openkilda.messaging.info.switches.GroupSyncEntry) Test(org.junit.Test)

Example 8 with SwitchSyncResponse

use of org.openkilda.messaging.info.switches.SwitchSyncResponse in project open-kilda by telstra.

the class NetworkSwitchServiceTest method newSwitchWithSynchronizationSuccessAfterError.

@Test
public void newSwitchWithSynchronizationSuccessAfterError() {
    List<SpeakerSwitchPortView> ports = getSpeakerSwitchPortViews();
    SpeakerSwitchView speakerSwitchView = getSpeakerSwitchView().toBuilder().ports(ports).build();
    SwitchInfoData switchAddEvent = new SwitchInfoData(alphaDatapath, SwitchChangeType.ACTIVATED, alphaInetAddress.toString(), alphaDescription, speakerInetAddress.toString(), false, speakerSwitchView);
    NetworkSwitchService service = new NetworkSwitchService(carrier, persistenceManager, options);
    service.switchEvent(switchAddEvent);
    // for a randomly generated key in SwitchFsm
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(carrier).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    SwitchSyncErrorData errorData = new SwitchSyncErrorData(alphaDatapath, null, null, null);
    service.switchManagerErrorResponse(errorData, captor.getValue());
    RulesSyncEntry rulesSyncEntry = new RulesSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    MetersSyncEntry metersSyncEntry = new MetersSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    GroupSyncEntry groupSyncEntry = new GroupSyncEntry(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), emptyList());
    SwitchSyncResponse response = new SwitchSyncResponse(alphaDatapath, rulesSyncEntry, metersSyncEntry, groupSyncEntry, LogicalPortsSyncEntry.builder().build());
    verify(carrier, times(SYNC_ATTEMPTS)).sendSwitchSynchronizeRequest(captor.capture(), eq(alphaDatapath));
    service.switchManagerResponse(response, captor.getValue());
    verifyNewSwitchAfterSwitchSync(ports);
    verify(carrier).sendSwitchStateChanged(alphaDatapath, SwitchStatus.ACTIVE);
    verifyNoMoreInteractions(carrier);
}
Also used : SwitchSyncErrorData(org.openkilda.messaging.error.rule.SwitchSyncErrorData) RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) SpeakerSwitchPortView(org.openkilda.messaging.model.SpeakerSwitchPortView) SpeakerSwitchView(org.openkilda.messaging.model.SpeakerSwitchView) MetersSyncEntry(org.openkilda.messaging.info.switches.MetersSyncEntry) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) GroupSyncEntry(org.openkilda.messaging.info.switches.GroupSyncEntry) Test(org.junit.Test)

Example 9 with SwitchSyncResponse

use of org.openkilda.messaging.info.switches.SwitchSyncResponse in project open-kilda by telstra.

the class SwitchServiceTest method shouldSynchronizeSwitch.

@Test
public void shouldSynchronizeSwitch() throws ExecutionException, InterruptedException {
    String correlationId = "not-sync-rules";
    RequestCorrelationId.create(correlationId);
    Long missingRule = 100L;
    Long misconfiguredRule = 11L;
    Long excessRule = 101L;
    Long properRule = 10L;
    SwitchId switchId = new SwitchId(1L);
    RulesSyncEntry rulesEntry = new RulesSyncEntry(singletonList(missingRule), singletonList(misconfiguredRule), singletonList(properRule), singletonList(excessRule), singletonList(missingRule), singletonList(excessRule));
    InfoData validationResult = new SwitchSyncResponse(switchId, rulesEntry, MetersSyncEntry.builder().proper(singletonList(getMeterInfo(properRule))).build(), GroupSyncEntry.builder().build(), LogicalPortsSyncEntry.builder().build());
    messageExchanger.mockResponse(correlationId, validationResult);
    SwitchSyncResult result = switchService.syncSwitch(switchId, true).get();
    RulesSyncDto rules = result.getRules();
    assertThat(rules.getMissing(), is(singletonList(missingRule)));
    assertThat(rules.getMisconfigured(), is(singletonList(misconfiguredRule)));
    assertThat(rules.getInstalled(), is(singletonList(missingRule)));
    assertThat(rules.getExcess(), is(singletonList(excessRule)));
    assertThat(rules.getInstalled(), is(singletonList(missingRule)));
    assertThat(rules.getRemoved(), is(singletonList(excessRule)));
}
Also used : RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) InfoData(org.openkilda.messaging.info.InfoData) RulesSyncDto(org.openkilda.northbound.dto.v1.switches.RulesSyncDto) SwitchId(org.openkilda.model.SwitchId) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) SwitchSyncResult(org.openkilda.northbound.dto.v1.switches.SwitchSyncResult) Test(org.junit.Test)

Example 10 with SwitchSyncResponse

use of org.openkilda.messaging.info.switches.SwitchSyncResponse in project open-kilda by telstra.

the class SwitchSyncFsm method finished.

protected void finished(SwitchSyncState from, SwitchSyncState to, SwitchSyncEvent event, Object context) {
    ValidateRulesResult validateRulesResult = validationResult.getValidateRulesResult();
    ValidateMetersResult validateMetersResult = validationResult.getValidateMetersResult();
    ValidateGroupsResult validateGroupsResult = validationResult.getValidateGroupsResult();
    ValidateLogicalPortsResult validateLogicalPortsResult = Optional.ofNullable(validationResult.getValidateLogicalPortsResult()).orElse(ValidateLogicalPortsResult.newEmpty());
    RulesSyncEntry rulesEntry = new RulesSyncEntry(new ArrayList<>(validateRulesResult.getMissingRules()), new ArrayList<>(validateRulesResult.getMisconfiguredRules()), new ArrayList<>(validateRulesResult.getProperRules()), new ArrayList<>(validateRulesResult.getExcessRules()), installedRulesCookies, request.isRemoveExcess() ? union(removedFlowRulesCookies, removedDefaultRulesCookies) : removedDefaultRulesCookies);
    MetersSyncEntry metersEntry = null;
    if (validationResult.isProcessMeters()) {
        metersEntry = new MetersSyncEntry(validateMetersResult.getMissingMeters(), validateMetersResult.getMisconfiguredMeters(), validateMetersResult.getProperMeters(), validateMetersResult.getExcessMeters(), validateMetersResult.getMissingMeters(), request.isRemoveExcess() ? validateMetersResult.getExcessMeters() : emptyList());
    }
    List<Integer> installedGroupsIds = missingGroups.stream().map(GroupInstallContext::getMirrorConfig).map(MirrorConfig::getGroupId).map(GroupId::intValue).collect(Collectors.toList());
    List<Integer> modifiedGroupsIds = misconfiguredGroups.stream().map(GroupInstallContext::getMirrorConfig).map(MirrorConfig::getGroupId).map(GroupId::intValue).collect(Collectors.toList());
    GroupSyncEntry groupEntry = GroupSyncEntry.builder().proper(validateGroupsResult.getProperGroups()).misconfigured(validateGroupsResult.getMisconfiguredGroups()).missing(validateGroupsResult.getMissingGroups()).excess(validateGroupsResult.getExcessGroups()).installed(mapToGroupEntryList(installedGroupsIds, validateGroupsResult.getMissingGroups())).modified(mapToGroupEntryList(modifiedGroupsIds, validateGroupsResult.getMisconfiguredGroups())).removed(mapToGroupEntryList(excessGroups, validateGroupsResult.getExcessGroups())).build();
    LogicalPortsSyncEntry logicalPortsEntry = LogicalPortsSyncEntry.builder().proper(validateLogicalPortsResult.getProperLogicalPorts()).misconfigured(validateLogicalPortsResult.getMisconfiguredLogicalPorts()).excess(validateLogicalPortsResult.getExcessLogicalPorts()).missing(validateLogicalPortsResult.getMissingLogicalPorts()).installed(validateLogicalPortsResult.getMissingLogicalPorts()).removed(validateLogicalPortsResult.getExcessLogicalPorts()).build();
    SwitchSyncResponse response = new SwitchSyncResponse(switchId, rulesEntry, metersEntry, groupEntry, logicalPortsEntry);
    InfoMessage message = new InfoMessage(response, System.currentTimeMillis(), key);
    carrier.cancelTimeoutCallback(key);
    carrier.response(key, message);
}
Also used : ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) MetersSyncEntry(org.openkilda.messaging.info.switches.MetersSyncEntry) RulesSyncEntry(org.openkilda.messaging.info.switches.RulesSyncEntry) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) ValidateGroupsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult) MirrorConfig(org.openkilda.model.MirrorConfig) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchSyncResponse(org.openkilda.messaging.info.switches.SwitchSyncResponse) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult) GroupSyncEntry(org.openkilda.messaging.info.switches.GroupSyncEntry) LogicalPortsSyncEntry(org.openkilda.messaging.info.switches.LogicalPortsSyncEntry)

Aggregations

SwitchSyncResponse (org.openkilda.messaging.info.switches.SwitchSyncResponse)10 RulesSyncEntry (org.openkilda.messaging.info.switches.RulesSyncEntry)7 Test (org.junit.Test)6 GroupSyncEntry (org.openkilda.messaging.info.switches.GroupSyncEntry)5 MetersSyncEntry (org.openkilda.messaging.info.switches.MetersSyncEntry)4 SpeakerSwitchView (org.openkilda.messaging.model.SpeakerSwitchView)4 SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)3 SpeakerSwitchPortView (org.openkilda.messaging.model.SpeakerSwitchPortView)3 SwitchId (org.openkilda.model.SwitchId)2 SwitchSyncErrorData (org.openkilda.messaging.error.rule.SwitchSyncErrorData)1 InfoData (org.openkilda.messaging.info.InfoData)1 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 LogicalPortsSyncEntry (org.openkilda.messaging.info.switches.LogicalPortsSyncEntry)1 MirrorConfig (org.openkilda.model.MirrorConfig)1 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)1 RulesSyncDto (org.openkilda.northbound.dto.v1.switches.RulesSyncDto)1 RulesSyncResult (org.openkilda.northbound.dto.v1.switches.RulesSyncResult)1 SwitchSyncResult (org.openkilda.northbound.dto.v1.switches.SwitchSyncResult)1 Endpoint (org.openkilda.wfm.share.model.Endpoint)1 ValidateGroupsResult (org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult)1