Search in sources :

Example 6 with KildaFeatureToggles

use of org.openkilda.model.KildaFeatureToggles in project open-kilda by telstra.

the class FeatureTogglesService method createOrUpdateFeatureToggles.

/**
 * Create or update feature toggles.
 * @param featureToggles feature toggles.
 * @return updated feature toggles.
 */
public KildaFeatureToggles createOrUpdateFeatureToggles(KildaFeatureToggles featureToggles) {
    log.info("Process feature-toggles update - toggles:{}", featureToggles);
    KildaFeatureToggles before = featureTogglesRepository.getOrDefault();
    KildaFeatureToggles after = transactionManager.doInTransaction(() -> {
        Optional<KildaFeatureToggles> foundCurrent = featureTogglesRepository.find();
        KildaFeatureToggles current;
        if (foundCurrent.isPresent()) {
            current = foundCurrent.get();
            FeatureTogglesCloner.INSTANCE.copyNonNull(featureToggles, current);
        } else {
            current = featureToggles;
            featureTogglesRepository.add(current);
        }
        featureTogglesRepository.detach(current);
        FeatureTogglesCloner.INSTANCE.replaceNullProperties(KildaFeatureToggles.DEFAULTS, current);
        return current;
    });
    if (!before.equals(after)) {
        log.info("Emit feature-toggles update notification - toggles:{}", after);
        carrier.featureTogglesUpdateNotification(after);
        if (before.getServer42FlowRtt() != after.getServer42FlowRtt() || before.getServer42IslRtt() != after.getServer42IslRtt()) {
            Collection<Switch> switches = switchRepository.findActive();
            for (Switch sw : switches) {
                log.info("Emit switch {} sync command", sw.getSwitchId());
                carrier.requestSwitchSync(sw.getSwitchId());
            }
        }
    }
    return after;
}
Also used : Switch(org.openkilda.model.Switch) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles)

Example 7 with KildaFeatureToggles

use of org.openkilda.model.KildaFeatureToggles in project open-kilda by telstra.

the class NetworkIslServiceTest method setUp.

@Before
public void setUp() {
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
    when(repositoryFactory.createIslRepository()).thenReturn(islRepository);
    when(repositoryFactory.createLinkPropsRepository()).thenReturn(linkPropsRepository);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createFeatureTogglesRepository()).thenReturn(featureTogglesRepository);
    when(repositoryFactory.createSwitchPropertiesRepository()).thenReturn(switchPropertiesRepository);
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setFlowsRerouteOnIslDiscoveryEnabled(true);
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    when(transactionManager.getDefaultRetryPolicy()).thenReturn(new RetryPolicy<>().withMaxRetries(2));
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult<?> tr = invocation.getArgument(0);
        tr.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(Mockito.any(TransactionCallbackWithoutResult.class));
    doAnswer(invocation -> {
        RetryPolicy<?> retryPolicy = invocation.getArgument(0);
        TransactionCallbackWithoutResult<?> tr = invocation.getArgument(1);
        Failsafe.with(retryPolicy).run(tr::doInTransaction);
        return null;
    }).when(transactionManager).doInTransaction(Mockito.any(RetryPolicy.class), Mockito.any(TransactionCallbackWithoutResult.class));
    NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder = mock(NetworkTopologyDashboardLogger.Builder.class);
    when(dashboardLoggerBuilder.build(any())).thenReturn(dashboardLogger);
    service = new NetworkIslService(carrier, persistenceManager, options, dashboardLoggerBuilder, clock);
}
Also used : KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) NetworkTopologyDashboardLogger(org.openkilda.wfm.topology.network.NetworkTopologyDashboardLogger) RetryPolicy(net.jodah.failsafe.RetryPolicy) TransactionCallbackWithoutResult(org.openkilda.persistence.tx.TransactionCallbackWithoutResult) Before(org.junit.Before)

Example 8 with KildaFeatureToggles

use of org.openkilda.model.KildaFeatureToggles in project open-kilda by telstra.

the class RuleManagerImpl method getServiceRuleGenerators.

@VisibleForTesting
List<RuleGenerator> getServiceRuleGenerators(SwitchId switchId, DataAdapter adapter) {
    List<RuleGenerator> generators = new ArrayList<>();
    generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(DROP_RULE_COOKIE), OfTable.INPUT));
    generators.add(serviceRulesFactory.getUniCastDiscoveryRuleGenerator());
    generators.add(serviceRulesFactory.getBroadCastDiscoveryRuleGenerator());
    generators.add(serviceRulesFactory.getDropDiscoveryLoopRuleGenerator());
    generators.add(serviceRulesFactory.getBfdCatchRuleGenerator());
    generators.add(serviceRulesFactory.getRoundTripLatencyRuleGenerator());
    generators.add(serviceRulesFactory.getUnicastVerificationVxlanRuleGenerator());
    SwitchProperties switchProperties = adapter.getSwitchProperties(switchId);
    if (switchProperties.isMultiTable()) {
        generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_INGRESS_DROP_COOKIE), OfTable.INGRESS));
        generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_TRANSIT_DROP_COOKIE), OfTable.TRANSIT));
        generators.add(serviceRulesFactory.getTableDefaultRuleGenerator(new Cookie(MULTITABLE_POST_INGRESS_DROP_COOKIE), OfTable.POST_INGRESS));
        generators.add(serviceRulesFactory.getTablePassThroughDefaultRuleGenerator(new Cookie(MULTITABLE_EGRESS_PASS_THROUGH_COOKIE), OfTable.TRANSIT, OfTable.EGRESS));
        generators.add(serviceRulesFactory.getTablePassThroughDefaultRuleGenerator(new Cookie(MULTITABLE_PRE_INGRESS_PASS_THROUGH_COOKIE), OfTable.INGRESS, OfTable.PRE_INGRESS));
        generators.add(serviceRulesFactory.getLldpPostIngressRuleGenerator());
        generators.add(serviceRulesFactory.getLldpPostIngressVxlanRuleGenerator());
        generators.add(serviceRulesFactory.getLldpPostIngressOneSwitchRuleGenerator());
        generators.add(serviceRulesFactory.getArpPostIngressRuleGenerator());
        generators.add(serviceRulesFactory.getArpPostIngressVxlanRuleGenerator());
        generators.add(serviceRulesFactory.getArpPostIngressOneSwitchRuleGenerator());
        if (switchProperties.isSwitchLldp()) {
            generators.add(serviceRulesFactory.getLldpTransitRuleGenerator());
            generators.add(serviceRulesFactory.getLldpInputPreDropRuleGenerator());
            generators.add(serviceRulesFactory.getLldpIngressRuleGenerator());
        }
        if (switchProperties.isSwitchArp()) {
            generators.add(serviceRulesFactory.getArpTransitRuleGenerator());
            generators.add(serviceRulesFactory.getArpInputPreDropRuleGenerator());
            generators.add(serviceRulesFactory.getArpIngressRuleGenerator());
        }
        Set<Integer> islPorts = adapter.getSwitchIslPorts(switchId);
        islPorts.forEach(islPort -> {
            generators.add(serviceRulesFactory.getEgressIslVxlanRuleGenerator(islPort));
            generators.add(serviceRulesFactory.getEgressIslVlanRuleGenerator(islPort));
            generators.add(serviceRulesFactory.getTransitIslVxlanRuleGenerator(islPort));
        });
    }
    Integer server42Port = switchProperties.getServer42Port();
    Integer server42Vlan = switchProperties.getServer42Vlan();
    MacAddress server42MacAddress = switchProperties.getServer42MacAddress();
    KildaFeatureToggles featureToggles = adapter.getFeatureToggles();
    if (featureToggles.getServer42FlowRtt()) {
        generators.add(serviceRulesFactory.getServer42FlowRttTurningRuleGenerator());
        generators.add(serviceRulesFactory.getServer42FlowRttVxlanTurningRuleGenerator());
        if (switchProperties.isServer42FlowRtt()) {
            generators.add(serviceRulesFactory.getServer42FlowRttOutputVlanRuleGenerator(server42Port, server42Vlan, server42MacAddress));
            generators.add(serviceRulesFactory.getServer42FlowRttOutputVxlanRuleGenerator(server42Port, server42Vlan, server42MacAddress));
        }
    }
    if (featureToggles.getServer42IslRtt() && switchProperties.hasServer42IslRttEnabled()) {
        generators.add(serviceRulesFactory.getServer42IslRttTurningRuleGenerator());
        generators.add(serviceRulesFactory.getServer42IslRttOutputRuleGenerator(server42Port, server42Vlan, server42MacAddress));
        for (Integer islPort : adapter.getSwitchIslPorts(switchId)) {
            generators.add(serviceRulesFactory.getServer42IslRttInputRuleGenerator(server42Port, islPort));
        }
    }
    return generators;
}
Also used : Cookie(org.openkilda.model.cookie.Cookie) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) ArrayList(java.util.ArrayList) MacAddress(org.openkilda.model.MacAddress) RuleGenerator(org.openkilda.rulemanager.factory.RuleGenerator) SwitchProperties(org.openkilda.model.SwitchProperties) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with KildaFeatureToggles

use of org.openkilda.model.KildaFeatureToggles in project open-kilda by telstra.

the class SpeakerStatsRequesterBoltTest method doNotRequestGrpcStatsIfToggleIsFalseTest.

@Test
public void doNotRequestGrpcStatsIfToggleIsFalseTest() {
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setCollectGrpcStats(false);
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    runDoNotRequestGrpcStatsTest();
    verify(switchRepository, never()).findActive();
}
Also used : KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) Test(org.junit.Test)

Example 10 with KildaFeatureToggles

use of org.openkilda.model.KildaFeatureToggles in project open-kilda by telstra.

the class SwitchRuleServiceImpl method installRules.

@Override
public void installRules(String key, SwitchRulesInstallRequest data) {
    isOperationCompleted = false;
    SwitchId switchId = data.getSwitchId();
    if (!switchRepository.exists(switchId)) {
        ErrorData errorData = new ErrorData(ErrorType.NOT_FOUND, format("Switch %s not found", switchId), "Error when installing switch rules");
        ErrorMessage errorMessage = new ErrorMessage(errorData, System.currentTimeMillis(), key);
        carrier.response(key, errorMessage);
        return;
    }
    Optional<SwitchProperties> switchProperties = switchPropertiesRepository.findBySwitchId(switchId);
    KildaFeatureToggles featureToggles = featureTogglesRepository.getOrDefault();
    boolean server42FlowRttFeatureToggle = featureToggles.getServer42FlowRtt();
    data.setServer42FlowRttFeatureToggle(server42FlowRttFeatureToggle);
    data.setServer42IslRttEnabled(featureToggles.getServer42IslRtt() && switchProperties.map(SwitchProperties::hasServer42IslRttEnabled).orElse(false));
    if (switchProperties.isPresent()) {
        data.setMultiTable(switchProperties.get().isMultiTable());
        data.setSwitchLldp(switchProperties.get().isSwitchLldp());
        data.setSwitchArp(switchProperties.get().isSwitchArp());
        data.setServer42FlowRttSwitchProperty(switchProperties.get().isServer42FlowRtt());
        data.setServer42Port(switchProperties.get().getServer42Port());
        data.setServer42Vlan(switchProperties.get().getServer42Vlan());
        data.setServer42MacAddress(switchProperties.get().getServer42MacAddress());
        Collection<FlowPath> flowPaths = flowPathRepository.findBySrcSwitch(switchId);
        List<Integer> flowPorts = new ArrayList<>();
        Set<Integer> flowLldpPorts = new HashSet<>();
        Set<Integer> flowArpPorts = new HashSet<>();
        Set<Integer> server42FlowPorts = new HashSet<>();
        fillFlowPorts(switchProperties.get(), flowPaths, flowPorts, flowLldpPorts, flowArpPorts, server42FlowPorts, server42FlowRttFeatureToggle && switchProperties.get().isServer42FlowRtt());
        data.setFlowPorts(flowPorts);
        data.setFlowLldpPorts(flowLldpPorts);
        data.setFlowArpPorts(flowArpPorts);
        data.setServer42FlowRttPorts(server42FlowPorts);
        List<Integer> islPorts = islRepository.findBySrcSwitch(switchId).stream().map(isl -> isl.getSrcPort()).collect(Collectors.toList());
        data.setIslPorts(islPorts);
    }
    carrier.sendCommandToSpeaker(key, data);
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) FlowPath(org.openkilda.model.FlowPath) KildaFeatureTogglesRepository(org.openkilda.persistence.repositories.KildaFeatureTogglesRepository) SwitchRulesDeleteRequest(org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest) SwitchRulesInstallRequest(org.openkilda.messaging.command.switches.SwitchRulesInstallRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwitchRuleService(org.openkilda.wfm.topology.switchmanager.service.SwitchRuleService) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) SwitchManagerCarrier(org.openkilda.wfm.topology.switchmanager.service.SwitchManagerCarrier) IslRepository(org.openkilda.persistence.repositories.IslRepository) SwitchProperties(org.openkilda.model.SwitchProperties) ErrorType(org.openkilda.messaging.error.ErrorType) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) SwitchPropertiesRepository(org.openkilda.persistence.repositories.SwitchPropertiesRepository) List(java.util.List) SwitchId(org.openkilda.model.SwitchId) SwitchRulesResponse(org.openkilda.messaging.info.switches.SwitchRulesResponse) Optional(java.util.Optional) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) ArrayList(java.util.ArrayList) SwitchId(org.openkilda.model.SwitchId) KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) FlowPath(org.openkilda.model.FlowPath) ErrorData(org.openkilda.messaging.error.ErrorData) SwitchProperties(org.openkilda.model.SwitchProperties) HashSet(java.util.HashSet)

Aggregations

KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)14 Test (org.junit.Test)6 SwitchId (org.openkilda.model.SwitchId)5 KildaFeatureTogglesRepository (org.openkilda.persistence.repositories.KildaFeatureTogglesRepository)5 ArrayList (java.util.ArrayList)3 Switch (org.openkilda.model.Switch)3 SwitchProperties (org.openkilda.model.SwitchProperties)3 String.format (java.lang.String.format)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Before (org.junit.Before)2 SwitchRulesDeleteRequest (org.openkilda.messaging.command.switches.SwitchRulesDeleteRequest)2 SwitchRulesInstallRequest (org.openkilda.messaging.command.switches.SwitchRulesInstallRequest)2 ErrorData (org.openkilda.messaging.error.ErrorData)2 ErrorMessage (org.openkilda.messaging.error.ErrorMessage)2 ErrorType (org.openkilda.messaging.error.ErrorType)2