mirror_frr/lib/northbound_cli.h
Rajasekar Raja 6f132af67b lib: Fix to optimize the time taken while batching huge configs
Issue: When the incoming config has say 30K entries of a prefix-lists,
current implementation is to schedule the configs to be batched and
only after batching the entire config, the processing of the configs
take place. As part of batching this config, we perform string
concatenation to save all the configs in the buffer which over time
results in taking longer time.

Ex: Imagine each line of config is 50 chars. With a delimiter of ‘- ‘ we end
up adding 52 chars to buffer for each command i.e. 52*30000 = 156K of chars.
Strlcat is an expensive operation and every time we strlcat, we have to
traverse at end of string to append new char.
Because of this, we end up adding extra 6-8 secs for accepting the config.

Fix: The idea here is to bring back something similar to the backoff
count implemented as part of 20e9a402 (lib: introduce configuration
back-off timer for YANG-modeled commands).

Essentially we keep a cap of 5000 per batch. So once 5000k config
commands are batched, we process them, clear the buffer, set the count
to 0 and then continue processing the rest of the config.

option1 file has 30K entries of prefix-list
Without Fix:
root@mlx-3700-20:mgmt:/var/log/raja/frr# time sudo vtysh -f option1
<SNIP>..............
Waiting for children to finish applying config...
[25191|staticd] done
[25189|watchfrr] done
[25178|ospfd] done
[25190|pbrd] done
[25181|bgpd] done
[25175|zebra] done

real    0m20.123s
user    0m9.384s
sys     0m2.403s

With Fix:
root@mlx-3700-20:mgmt:/var/log/raja/frr# time sudo vtysh -f option1
<SNIP>..............
Waiting for children to finish applying config...
[19887|staticd] done
[19885|watchfrr] done
[19886|pbrd] done
[19874|ospfd] done
[19877|bgpd] done
[19871|zebra] done

real	0m12.168s
user	0m7.511s
sys	0m1.981s

Issue: 3589101

Ticket# 3589101

Signed-off-by: Rajasekar Raja <rajasekarr@nvidia.com>
2024-12-18 11:53:06 -08:00

163 lines
4.2 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2018 NetDEF, Inc.
* Renato Westphal
*/
#ifndef _FRR_NORTHBOUND_CLI_H_
#define _FRR_NORTHBOUND_CLI_H_
#include "northbound.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Possible formats in which a configuration can be displayed. */
enum nb_cfg_format {
NB_CFG_FMT_CMDS = 0,
NB_CFG_FMT_JSON,
NB_CFG_FMT_XML,
};
/* Maximum config commands in a batch*/
#define NB_CMD_BATCH_SIZE 5000
extern struct nb_config *vty_shared_candidate_config;
/*
* Enqueue change to be applied in the candidate configuration.
*
* vty
* The vty context.
*
* xpath
* XPath (absolute or relative) of the configuration option being edited.
*
* operation
* Operation to apply (either NB_OP_CREATE, NB_OP_MODIFY or NB_OP_DESTROY).
*
* value
* New value of the configuration option. Should be NULL for typeless YANG
* data (e.g. presence-containers). For convenience, NULL can also be used
* to restore a leaf to its default value.
*/
extern void nb_cli_enqueue_change(struct vty *vty, const char *xpath,
enum nb_operation operation,
const char *value);
/*
* Apply enqueued changes to the candidate configuration, do not batch,
* and apply any pending commits along with the currently enqueued.
*
* vty
* The vty context.
*
* xpath_base_fmt
* Prepend the given XPath (absolute or relative) to all enqueued
* configuration changes. This is an optional parameter.
*
* Returns:
* CMD_SUCCESS on success, CMD_WARNING_CONFIG_FAILED otherwise.
*/
extern int nb_cli_apply_changes_clear_pending(struct vty *vty,
const char *xpath_base_fmt, ...)
PRINTFRR(2, 3);
/*
* Apply enqueued changes to the candidate configuration, this function
* may not immediately apply the changes, instead adding them to a pending
* queue.
*
* vty
* The vty context.
*
* xpath_base_fmt
* Prepend the given XPath (absolute or relative) to all enqueued
* configuration changes. This is an optional parameter.
*
* Returns:
* CMD_SUCCESS on success, CMD_WARNING_CONFIG_FAILED otherwise.
*/
extern int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt,
...) PRINTFRR(2, 3);
/*
* Add an input child node for an RPC or an action.
*
* vty
* The vty context.
*
* xpath
* XPath of the child being added, relative to the input container.
*
* value
* Value of the child being added. Can be NULL for containers and leafs of
* type 'empty'.
*/
extern int nb_cli_rpc_enqueue(struct vty *vty, const char *xpath,
const char *value);
/*
* Execute a YANG RPC or Action using the enqueued input parameters.
*
* vty
* The vty terminal to dump any error.
*
* xpath
* XPath of the YANG RPC or Action node.
*
* output_p
* A pointer to the libyang data node that will hold the output data tree.
* It can be set to NULL if the caller is not interested in processing the
* output. The caller is responsible for freeing the output data tree.
*
* Returns:
* CMD_SUCCESS on success, CMD_WARNING otherwise.
*/
extern int nb_cli_rpc(struct vty *vty, const char *xpath,
struct lyd_node **output_p);
/*
* Show CLI commands associated to the given YANG data node.
*
* vty
* The vty terminal to dump the configuration to.
*
* dnode
* libyang data node that should be shown in the form of CLI commands.
*
* show_defaults
* Specify whether to display default configuration values or not.
*/
extern void nb_cli_show_dnode_cmds(struct vty *vty,
const struct lyd_node *dnode,
bool show_defaults);
/*
* Perform pending commit, if any.
*
* vty
* The vty context.
*
* Returns
* CMD_SUCCESS on success (or no pending), CMD_WARNING_CONFIG_FAILED
* otherwise.
*/
extern int nb_cli_pending_commit_check(struct vty *vty);
/* Prototypes of internal functions. */
extern void nb_cli_show_config_prepare(struct nb_config *config,
bool with_defaults);
extern void nb_cli_confirmed_commit_clean(struct vty *vty);
extern int nb_cli_confirmed_commit_rollback(struct vty *vty);
extern void nb_cli_install_default(int node);
extern void nb_cli_init(struct event_loop *tm);
extern void nb_cli_terminate(void);
#ifdef __cplusplus
}
#endif
#endif /* _FRR_NORTHBOUND_CLI_H_ */