frr/mgmtd/mgmt.h
Christian Hopps ef43a6329b mgmtd: Add MGMT Frontend Interface Framework
This commit introduces the Frontend Interface which can be used
by front-end management clients like Netconf server, Restconf
Server and CLI to interact with new FRR Management daemon (MGMTd)
to access and sometimes modify FRR management data.

This commit includes the following functionalities in the changeset:
1. Add new Frontend server for clients connect to.
2. Add a C-based Frontend client library which can be used by Frontend
   clients to communicate with MGMTd via the Frontend interface.
3. Maintain a frontend adapter for each connection from an appropriate
   Frontend client to facilitate client requests and track one or more
   client sessions across it.
4. Define the protobuf message format for messages to be exchanged
   between MGMTd Frontend module and the Frontend client.
5. This changeset also introduces an instance of MGMT Frontend client
   embedded within the lib/vty module that can be leveraged by any FRR
   daemon to connect to MGMTd's Frontend interface. The same has been
   integrated with and initialized within the MGMTd daemon's process
   context to implement a bunch of 'set-config', 'commit-apply',
   'get-config' and 'get-data' commands via VTYSH

Co-authored-by: Pushpasis Sarkar <pushpasis@gmail.com>
Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com>
Co-authored-by: Ujwal P <ujwalp@vmware.com>
Signed-off-by: Yash Ranjan <ranjany@vmware.com>
2023-03-21 22:08:32 -04:00

103 lines
2.1 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* MGMTD message definition header.
*
* Copyright (C) 2021 Vmware, Inc.
* Pushpasis Sarkar <spushpasis@vmware.com>
*/
#ifndef _FRR_MGMTD_H
#define _FRR_MGMTD_H
#include "vrf.h"
#include "defaults.h"
#include "stream.h"
#include "mgmtd/mgmt_memory.h"
#include "mgmtd/mgmt_ds.h"
#define MGMTD_VTY_PORT 2622
#define MGMTD_SOCKET_BUF_SIZE 65535
extern bool mgmt_debug_be;
extern bool mgmt_debug_fe;
extern bool mgmt_debug_ds;
extern bool mgmt_debug_txn;
/*
* MGMTD master for system wide configurations and variables.
*/
struct mgmt_master {
struct thread_master *master;
/* How big should we set the socket buffer size */
uint32_t socket_buffer;
/* Datastores */
struct mgmt_ds_ctx *running_ds;
struct mgmt_ds_ctx *candidate_ds;
struct mgmt_ds_ctx *oper_ds;
bool terminating; /* global flag that sigint terminate seen */
bool perf_stats_en; /* to enable performance stats measurement */
};
extern struct mgmt_master *mm;
/* Inline functions */
static inline unsigned long timeval_elapsed(struct timeval a, struct timeval b)
{
return (((a.tv_sec - b.tv_sec) * TIMER_SECOND_MICRO)
+ (a.tv_usec - b.tv_usec));
}
/*
* Remove trailing separator from a string.
*
* str
* A null terminated string.
*
* sep
* Trailing character that needs to be removed.
*/
static inline void mgmt_remove_trailing_separator(char *str, char sep)
{
size_t len;
len = strlen(str);
if (len && str[len - 1] == sep)
str[len - 1] = '\0';
}
/* Prototypes. */
extern void mgmt_terminate(void);
extern void mgmt_reset(void);
extern time_t mgmt_clock(void);
extern int mgmt_config_write(struct vty *vty);
extern void mgmt_master_init(struct thread_master *master,
const int buffer_size);
extern void mgmt_init(void);
extern void mgmt_vty_init(void);
static inline char *mgmt_realtime_to_string(struct timeval *tv, char *buf,
size_t sz)
{
char tmp[50];
struct tm *lm;
lm = localtime((const time_t *)&tv->tv_sec);
if (lm) {
strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", lm);
snprintf(buf, sz, "%s.%06lu", tmp,
(unsigned long int)tv->tv_usec);
}
return buf;
}
#endif /* _FRR_MGMTD_H */