use of org.openkilda.messaging.info.switches.MetersSyncEntry in project open-kilda by telstra.
the class NetworkSwitchServiceTest method makeSuccessSwitchSyncResponse.
private SwitchSyncResponse makeSuccessSwitchSyncResponse(SwitchId switchId) {
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());
return new SwitchSyncResponse(switchId, rulesSyncEntry, metersSyncEntry, groupSyncEntry, LogicalPortsSyncEntry.builder().build());
}
use of org.openkilda.messaging.info.switches.MetersSyncEntry in project open-kilda by telstra.
the class SwitchFsm method isSynchronized.
private boolean isSynchronized(SwitchSyncResponse syncResponse) {
RulesSyncEntry rules = syncResponse.getRules();
boolean missingRulesCheck = missingRulesCheck(rules);
boolean misconfiguredRulesCheck = misconfiguredRulesCheck(rules);
boolean excessRulesCheck = excessRulesCheck(rules);
boolean missingMetersCheck = true;
boolean excessMetersCheck = true;
MetersSyncEntry meters = syncResponse.getMeters();
if (meters != null) {
missingMetersCheck = missingMetersCheck(meters);
excessMetersCheck = excessMetersCheck(meters);
}
return missingRulesCheck && misconfiguredRulesCheck && excessRulesCheck && missingMetersCheck && excessMetersCheck;
}
use of org.openkilda.messaging.info.switches.MetersSyncEntry 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);
}
use of org.openkilda.messaging.info.switches.MetersSyncEntry 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);
}
use of org.openkilda.messaging.info.switches.MetersSyncEntry 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);
}
Aggregations