Search in sources :

Example 1 with ValidateLogicalPortsResult

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

the class ValidationServiceImpl method validateLogicalPorts.

@Override
public ValidateLogicalPortsResult validateLogicalPorts(SwitchId switchId, List<LogicalPort> presentLogicalPorts) {
    Map<Integer, LogicalPortInfoEntry> expectedPorts = lagLogicalPortRepository.findBySwitchId(switchId).stream().map(LogicalPortMapper.INSTANCE::map).peek(port -> Collections.sort(port.getPhysicalPorts())).collect(Collectors.toMap(LogicalPortInfoEntry::getLogicalPortNumber, Function.identity()));
    Map<Integer, LogicalPortInfoEntry> actualPorts = presentLogicalPorts.stream().map(LogicalPortMapper.INSTANCE::map).peek(port -> Collections.sort(port.getPhysicalPorts())).collect(Collectors.toMap(LogicalPortInfoEntry::getLogicalPortNumber, Function.identity()));
    List<LogicalPortInfoEntry> properPorts = new ArrayList<>();
    List<LogicalPortInfoEntry> missingPorts = new ArrayList<>();
    List<LogicalPortInfoEntry> excessPorts = new ArrayList<>();
    List<LogicalPortInfoEntry> misconfiguredPorts = new ArrayList<>();
    for (Entry<Integer, LogicalPortInfoEntry> entry : expectedPorts.entrySet()) {
        int portNumber = entry.getKey();
        LogicalPortInfoEntry expected = entry.getValue();
        if (actualPorts.containsKey(portNumber)) {
            LogicalPortInfoEntry actual = actualPorts.get(portNumber);
            if (actual.equals(expected)) {
                properPorts.add(actual);
            } else {
                misconfiguredPorts.add(calculateMisconfiguredLogicalPort(expected, actual));
            }
        } else {
            missingPorts.add(expected);
        }
    }
    for (Entry<Integer, LogicalPortInfoEntry> entry : actualPorts.entrySet()) {
        if (LogicalPortType.BFD.equals(entry.getValue().getType())) {
            // At this moment we do not validate BFD ports, so Kilda wouldn't include BFD ports into excess list
            continue;
        }
        if (!expectedPorts.containsKey(entry.getKey())) {
            excessPorts.add(entry.getValue());
        }
    }
    return new ValidateLogicalPortsResult(ImmutableList.copyOf(properPorts), ImmutableList.copyOf(missingPorts), ImmutableList.copyOf(excessPorts), ImmutableList.copyOf(misconfiguredPorts));
}
Also used : Arrays(java.util.Arrays) FlowPath(org.openkilda.model.FlowPath) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) Map(java.util.Map) FlowMeterRepository(org.openkilda.persistence.repositories.FlowMeterRepository) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult) ImmutableSet(com.google.common.collect.ImmutableSet) LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortMisconfiguredInfoEntry) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) MeterEntryConverter(org.openkilda.wfm.topology.switchmanager.mappers.MeterEntryConverter) Collection(java.util.Collection) Set(java.util.Set) GroupEntryConverter(org.openkilda.wfm.topology.switchmanager.mappers.GroupEntryConverter) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) MeterInfoEntry(org.openkilda.messaging.info.switches.MeterInfoEntry) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Entry(java.util.Map.Entry) Optional(java.util.Optional) Meter(org.openkilda.model.Meter) GroupInfoEntry(org.openkilda.messaging.info.switches.GroupInfoEntry) MeterMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.MeterMisconfiguredInfoEntry) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) FlowMeter(org.openkilda.model.FlowMeter) LogicalPort(org.openkilda.messaging.model.grpc.LogicalPort) BucketEntry(org.openkilda.messaging.info.switches.GroupInfoEntry.BucketEntry) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchNotFoundException(org.openkilda.wfm.topology.switchmanager.error.SwitchNotFoundException) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ImmutableList(com.google.common.collect.ImmutableList) Cookie(org.openkilda.model.cookie.Cookie) LogicalPortMapper(org.openkilda.wfm.topology.switchmanager.mappers.LogicalPortMapper) PersistenceManager(org.openkilda.persistence.PersistenceManager) ValidateGroupsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult) LogicalPortType(org.openkilda.messaging.info.switches.LogicalPortType) Switch(org.openkilda.model.Switch) MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) Collectors.toList(java.util.stream.Collectors.toList) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchId(org.openkilda.model.SwitchId) GroupSpeakerData(org.openkilda.rulemanager.GroupSpeakerData) LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) ArrayList(java.util.ArrayList) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult)

Example 2 with ValidateLogicalPortsResult

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

the class ValidationServiceImplTest method validateLogicalPorts.

@Test
public void validateLogicalPorts() {
    ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
    LogicalPort proper = buildLogicalPort(LOGICAL_PORT_NUMBER_1, PHYSICAL_PORT_2, PHYSICAL_PORT_1);
    LogicalPort misconfigured = buildLogicalPort(LOGICAL_PORT_NUMBER_2, LogicalPortType.BFD, PHYSICAL_PORT_3);
    LogicalPort excess = buildLogicalPort(LOGICAL_PORT_NUMBER_4, PHYSICAL_PORT_6);
    LogicalPort bfdExcess = buildLogicalPort(LOGICAL_PORT_NUMBER_5, LogicalPortType.BFD, PHYSICAL_PORT_7);
    ValidateLogicalPortsResult result = validationService.validateLogicalPorts(SWITCH_ID_A, Lists.newArrayList(proper, misconfigured, excess, bfdExcess));
    assertEquals(1, result.getProperLogicalPorts().size());
    // bfdExcess port shouldn't be in this list
    assertEquals(1, result.getExcessLogicalPorts().size());
    assertEquals(1, result.getMissingLogicalPorts().size());
    assertEquals(1, result.getMisconfiguredLogicalPorts().size());
    assertEqualLogicalPort(proper, result.getProperLogicalPorts().get(0));
    assertEqualLogicalPort(excess, result.getExcessLogicalPorts().get(0));
    LogicalPortInfoEntry missing = LogicalPortInfoEntry.builder().type(org.openkilda.messaging.info.switches.LogicalPortType.LAG).logicalPortNumber(LOGICAL_PORT_NUMBER_3).physicalPorts(Lists.newArrayList(PHYSICAL_PORT_5, PHYSICAL_PORT_6)).build();
    assertEquals(missing, result.getMissingLogicalPorts().get(0));
    LogicalPortInfoEntry misconfiguredEntry = LogicalPortInfoEntry.builder().type(org.openkilda.messaging.info.switches.LogicalPortType.BFD).logicalPortNumber(LOGICAL_PORT_NUMBER_2).physicalPorts(Lists.newArrayList(PHYSICAL_PORT_3)).actual(new LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortType.BFD, Lists.newArrayList(PHYSICAL_PORT_3))).expected(new LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortType.LAG, Lists.newArrayList(PHYSICAL_PORT_3, PHYSICAL_PORT_4))).build();
    assertEquals(misconfiguredEntry, result.getMisconfiguredLogicalPorts().get(0));
}
Also used : LogicalPort(org.openkilda.messaging.model.grpc.LogicalPort) LagLogicalPort(org.openkilda.model.LagLogicalPort) LogicalPortInfoEntry(org.openkilda.messaging.info.switches.LogicalPortInfoEntry) LogicalPortMisconfiguredInfoEntry(org.openkilda.messaging.info.switches.LogicalPortMisconfiguredInfoEntry) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult) Test(org.junit.Test)

Example 3 with ValidateLogicalPortsResult

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

the class SwitchSyncServiceImplTest method handleSyncWhenNotProcessMeters.

@Test
public void handleSyncWhenNotProcessMeters() {
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).performSync(true).removeExcess(true).build();
    ValidationResult tempResult = makeValidationResult();
    service.handleSwitchSync(KEY, request, new ValidationResult(tempResult.getFlowEntries(), false, tempResult.getValidateRulesResult(), null, new ValidateGroupsResult(emptyList(), emptyList(), emptyList(), emptyList()), new ValidateLogicalPortsResult(emptyList(), emptyList(), emptyList(), emptyList())));
    verify(commandBuilder).buildCommandsToSyncMissingRules(eq(SWITCH_ID), eq(missingRules));
    verify(carrier).sendCommandToSpeaker(eq(KEY), any(CommandData.class));
    service.handleInstallRulesResponse(KEY);
    verify(carrier).cancelTimeoutCallback(eq(KEY));
    ArgumentCaptor<InfoMessage> responseCaptor = ArgumentCaptor.forClass(InfoMessage.class);
    verify(carrier).response(eq(KEY), responseCaptor.capture());
    assertNull(((SwitchSyncResponse) responseCaptor.getValue().getData()).getMeters());
    verifyNoMoreInteractions(commandBuilder);
    verifyNoMoreInteractions(carrier);
}
Also used : ValidateGroupsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult) InfoMessage(org.openkilda.messaging.info.InfoMessage) ValidationResult(org.openkilda.wfm.topology.switchmanager.model.ValidationResult) CommandData(org.openkilda.messaging.command.CommandData) ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult) Test(org.junit.Test)

Example 4 with ValidateLogicalPortsResult

use of org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult 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)

Example 5 with ValidateLogicalPortsResult

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

the class SwitchValidateFsm method validateLogicalPorts.

protected void validateLogicalPorts() {
    if (validationContext.getActualLogicalPortEntries() == null) {
        return;
    }
    log.info("Validate logical ports (switch={}, key={})", getSwitchId(), key);
    ValidateLogicalPortsResult results = validationService.validateLogicalPorts(getSwitchId(), validationContext.getActualLogicalPortEntries());
    validationContext = validationContext.toBuilder().validateLogicalPortResult(results).build();
}
Also used : ValidateLogicalPortsResult(org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult)

Aggregations

ValidateLogicalPortsResult (org.openkilda.wfm.topology.switchmanager.model.ValidateLogicalPortsResult)5 Test (org.junit.Test)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)2 LogicalPortInfoEntry (org.openkilda.messaging.info.switches.LogicalPortInfoEntry)2 LogicalPortMisconfiguredInfoEntry (org.openkilda.messaging.info.switches.LogicalPortMisconfiguredInfoEntry)2 LogicalPort (org.openkilda.messaging.model.grpc.LogicalPort)2 ValidateGroupsResult (org.openkilda.wfm.topology.switchmanager.model.ValidateGroupsResult)2 ValidationService (org.openkilda.wfm.topology.switchmanager.service.ValidationService)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1