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;
}
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);
}
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;
}
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();
}
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);
}
Aggregations