Commit graph

49 commits

Author SHA1 Message Date
Igor Ryzhov 58a8ebc1fc lib: rework northbound RPC callback
Change input/output arguments of the RPC callback from lists of
(xpath/value) tuples to YANG data trees.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-04-22 16:36:22 +03:00
Christian Hopps ad1ccb6e62 lib: northbound: add yielding and batching to oper-state queries
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:52:57 +00:00
Donald Sharp 24a58196dd *: Convert event.h to frrevent.h
We should probably prevent any type of namespace collision
with something else.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp cd9d053741 *: Convert struct event_master to struct event_loop
Let's find a better name for it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e16d030c65 *: Convert THREAD_XXX macros to EVENT_XXX macros
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 2453d15dbf *: Convert struct thread_master to struct event_master and it's ilk
Convert the `struct thread_master` to `struct event_master`
across the code base.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp 907a2395f4 *: Convert thread_add_XXX functions to event_add_XXX
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp e6685141aa *: Rename struct thread to struct event
Effectively a massive search and replace of
`struct thread` to `struct event`.  Using the
term `thread` gives people the thought that
this event system is a pthread when it is not

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:17 -04:00
Donald Sharp cb37cb336a *: Rename thread.[ch] to event.[ch]
This is a first in a series of commits, whose goal is to rename
the thread system in FRR to an event system.  There is a continual
problem where people are confusing `struct thread` with a true
pthread.  In reality, our entire thread.c is an event system.

In this commit rename the thread.[ch] files to event.[ch].

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24 08:32:16 -04:00
Christian Hopps 7d65b7b7f4 mgmtd: Add MGMT Backend Interface Framework
This commit introduces the MGMT Backend Interface which can be used
by back-end management client daemons like BGPd, Staticd, Zebra to
connect with new FRR Management daemon (MGMTd) and utilize the new
FRR Management Framework to let any Frontend clients to retrieve any
operational data or manipulate any configuration data owned by the
individual Backend daemon component.

This commit includes the following functionalities in the changeset:
1. Add new Backend server for Backend daemons connect to.
2. Add a C-based Backend client library which can be used by daemons
   to communicate with MGMTd via the Backend interface.
3. Maintain a backend adapter for each connection from an appropriate
   Backend client to facilitate client requests and track one or more
   transactions initiated from Frontend client sessions that involves
   the backend client component.
4. Add the following commands to inspect various Backend client
   related information
	a. show mgmt backend-adapter all
	b. show mgmt backend-yang-xpath-registry
        c. show mgmt yang-xpath-subscription

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
Christian Hopps 41ef7327e3 lib: fix init. use of nb_context to be by value not by reference
Pass context argument by value on initialization to be clear that the
value is used/saved but not a pointer to the value. Previously the
northbound code was incorrectly holding a pointer to stack allocated
context structs.

However, the structure definition also had some musings (ifdef'd out
code) and a comment that might be taken to imply that user data could
follow the structure and thus be maintained by the code; it won't; so it
can't; so get rid of the disabled misleading code/text from the
structure definition.

The common use case worked b/c the transaction which cached the pointer
was created and freed inside a single function
call (`nb_condidate_commit`) that executed below the stack allocation.

All other use cases (grpc, confd, sysrepo, and -- coming soon -- mgmtd)
were bugs.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-02-23 20:59:17 -05:00
David Lamparter 47a3a82770 *: manual SPDX License ID conversions
The files converted in this commit either had some random misspelling or
formatting weirdness that made them escape automated replacement, or
have a particularly "weird" licensing setup (e.g. dual-licensed.)

This also marks a bunch of "public domain" files as SPDX License "NONE".

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:07 +01:00
Donald Sharp b8551584ee lib, vrrpd: Use THREAD_ARG
Don't auto set the thread->arg pointer.  It is private
and should be only accessed through the THREAD_ARG pointer.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-07-21 08:30:50 -04:00
Christian Hopps ad6bd53692
lib: grpc: fix covevrity warnings
One uninit warning and one missing lock warning, both were OK but
let's make the tool happy.

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-16 11:31:50 -04:00
Christian Hopps 48c93061f5 lib: grpc: rework RPC handlers improve code clarity
- split NewRpcState object into 2, a Unary and a Streaming variant, which
  then allows for the next.
- move all state machine details inside these new state objects
  - use a template arg to allow for Streaming state tracking object
    creation and deletion w/o requiring this in each specific RPC
    hander.
- Code is more rugged by design now.

Thanks to Rafael Zalamena <rzalamena@opensourcerouting.org> for the cleanup
ideas/motivation.

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-14 15:54:25 -04:00
Christian Hopps d3074a5207 lib: grpc: use candiate ID to delete rather than pointer to candiate
- also be consistent in candidate IDs being uint64_t

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-14 11:14:12 -04:00
Rafael Zalamena 79c681952e lib: call protobuf clean up on exit
Let's clean up the valgrind output even more by calling the protobuf
shutdown function that deallocates all library used memory.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-03-14 11:14:12 -04:00
Donald Sharp db0a45d0d6
Merge pull request #10741 from LabNConsulting/chopps/critfixgrpc
critical fixes for grpc
2022-03-07 11:49:48 -05:00
Christian Hopps fe095adc24 lib: grpc: fix handling of "empty" yang type
- rather than coerce `const char *` to std:string&, just pass the
C ptr, as that's what is used anyway.

fixes #10578

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-06 12:00:22 -05:00
Christian Hopps 83f6fce7d2 lib: grpc: fix shutdown code
fixes #9732

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-06 12:00:17 -05:00
Christian Hopps c85ecd6405 lib: grpc: initialize uninitialized member variables
fixes #9732, fixes #10578

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-06 07:39:58 -05:00
Christian Hopps 96d434f853 lib: grpc: do not remove candidate entry too soon
Fix from Rafael Zalamena <rzalamena@opensourcerouting.org>

Signed-off-by: Christian Hopps <chopps@labn.net>
2022-03-06 07:37:52 -05:00
Rafael Zalamena 673e440770 lib: tweak northbound gRPC default timeout
Don't let open sockets hang for too long. This will fix an issue where a
improperly coded client (e.g. socat) could exaust the amount of open
file descriptors.

Documentation:
https://grpc.github.io/grpc/cpp/md_doc_keepalive.html

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2022-03-06 07:37:52 -05:00
Donald Sharp cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
Rafael Zalamena 0f538858c2 lib: prevent gRPC assert on missing YANG node
`yang_dnode_get` will `assert` if no YANG node/model exist, so lets test for
its existence first before trying to access it.

This `assert` is only acceptable for internal FRR usage otherwise we
might miss typos or unmatching YANG models nodes/leaves. For gRPC usage
we should let users attempt to use non existing models without
`assert`ing.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-10-05 10:22:27 -03:00
Mark Stapp de800c10af lib: cleanup and stop grpc pthread
At shutdown, try to stop the grpc module and its
dedicated pthread cleanly.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-06-15 11:08:19 -04:00
Christian Hopps b680134e11 lib: fix threading bug in GRPC code
The code that actually calls FRR northbound functions needs to be running in the
master thread. The previous code was running on a GRPC pthread. While fixing
moved to more functional vs OOP to make this easier to see.

Also fix ly merge to merge siblings not throw the originals away.

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-06-01 15:27:54 +00:00
Christian Hopps af1b88e990 lib: libyang2 add missed conversion
Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-17 22:13:59 -04:00
Christian Hopps 3bb513c399 lib: adapt to version 2 of libyang
Compile with v2.0.0 tag of `libyang2` branch of:
https://github.com/CESNET/libyang

staticd init load time of 10k routes now 6s vs ly1 time of 150s

Signed-off-by: Christian Hopps <chopps@labn.net>
2021-05-13 16:24:48 -04:00
David Lamparter 09781197b6 build: make builddir include path consistent
... by referencing all autogenerated headers relative to the root
directory.  (90% of the changes here is `version.h`.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-21 15:42:33 +02:00
David Lamparter 80413c2073 *: require semicolon after FRR_DAEMON_INFO & co.
... again ...

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17 06:18:39 +01:00
Chirag Shah f63f5f1947 *: add errmsg to nb rpc
Display human readable error message in northbound rpc
transaction failure. In case of vtysh nb client, the error
message will be displayed to user.

Testing:

bharat# clear evpn dup-addr vni 1002 ip 11.11.11.11
Error type: generic error
Error description: Requested IP's associated MAC aa:aa:aa:aa:aa:aa is still
in duplicate state

Signed-off-by: Chirag Shah <chirag@nvidia.com>
2020-10-05 13:15:59 -07:00
Renato Westphal 0d206e9d85
Merge pull request #6945 from qlyoung/nb-more-messages
More gRPC logging + errmsg for no changes
2020-08-19 20:14:05 -03:00
Quentin Young 5bfb669b37 lib: fill nb errmsg when no changes during prep
During the prep phase to apply a northbound commit, if no changes were
detected make sure we fill the error message buffer to explain this.

Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-08-19 14:24:32 -04:00
Quentin Young 1058646261 lib: add better zlogging to gRPC Commit RPC
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
2020-08-18 16:31:03 -04:00
Renato Westphal 0fe5b904b7 lib: don't ignore error messages generated during the commit apply phase
While a configuration transaction can't be rejected once it reaches
the APPLY phase, we should allow NB callbacks to generate error
or warning messages when a configuration change is being applied.
That should be useful, for example, to return warnings back to
the user informing that the applied configuration has some kind of
inconsistency or is missing something in order to be effectively
activated. The infrastructure for this was already present, but the
northbound layer was ignoring all errors/warnings generated during
the apply/abort phases instead of returning them to the user. This
commit changes that.

In the gRPC plugin, extend the Commit() RPC adding a new
"error_message" field to the response type. This is necessary to
allow errors/warnings to be returned even when the commit operation
succeeds (since grpc::Status::OK doesn't support error messages
like the other status codes).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-08-14 21:37:14 -03:00
Renato Westphal 0e10aeeb18 lib: fix issue were a few gRPC RPCs were being logged twice
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-05-28 19:22:54 -03:00
Renato Westphal df5eda3d87 lib: return human-readable error messages to the northbound clients
Instead of returning only error codes (e.g. NB_ERR_VALIDATION)
to the northbound clients, do better than that and also return
a human-readable error message. This should make FRR more
automation-friendly since operators won't need to dig into system
logs to find out what went wrong in the case of an error.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-05-28 19:22:54 -03:00
Renato Westphal 13d6b9c134 lib: introduce the northbound context structure
The new northbound context structure contains information about
the client performing a configuration transaction. This information
will be made available to all configuration callbacks through the
args->context parameter.

The usefulness of this structure comes from the fact that it can be
used as a communication channel (both input and output) between the
northbound callbacks and the northbound clients. This can be done
through its "client_data" field which contains client-specific data.

This should cover some very specific scenarios where a northbound
callback should perform an action only if the configuration change
is coming from a given client. An example would be sending a PCEP
response to a PCE when an SR-TE policy is created or modified
through the PCEP northbound client (for that to happen, the
northbound callbacks need to have access to the PCEP request ID,
which needs to be available).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-05-28 19:22:54 -03:00
Quentin Young f6239dc799 lib: remove unnecessary rpc request in grpc
Bit of leftover copypaste code there.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-05-11 12:52:17 -04:00
Renato Westphal 69ec583289 lib: fix undue warning during gRPC module initialization
This warning only shows up when a daemon is started with --log=stdout.
Fix it.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-05-09 00:50:45 -03:00
Quentin Young ecf9fb30b7 lib: convert GRPC plugin to async
Synchronous GRPC services are called from arbitrary threads. This makes
access to anything outside the GRPC module unsafe. We need to convert
the plugin to use the async model that allows us to control our own
threads.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-05-08 15:50:11 -04:00
Chirag Shah 0edcb505a3 lib: use frr_pthread to spawn grpc pthread
start grpc thread with frr_pthread library
callbacks to integrate with rcu infrastructure.

If a thread is created using native pthread callbacks
and if zlog is used then it leads to crash.

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2020-05-08 15:50:11 -04:00
Renato Westphal 97cd849362 lib: create a wrapper function for all northbound callbacks
The intention here is to keep the code more organized. These wrappers
should be used by the northbound clients only, and never directly
by any YANG backend code.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-04-23 01:21:46 -03:00
Quentin Young 20b0a2ed3e lib: defer grpc plugin initialization to post fork
When using the GRPC northbound plugin, initialization occurs at the
frr_late_init hook. This is called before fork() when daemonizing (using
-d). Because the GRPC library internally creates threads, this means our
threads go away in the child process, so GRPC doesn't work when used
with -d. Rectify this situation by deferring plugin init to after fork
by scheduling a task on the threadmaster, since those are executed by
the child.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2020-03-30 14:28:10 -04:00
Renato Westphal 07705c8b8a lib: silence compiler warning in the gRPC plugin
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-10-16 17:13:28 -03:00
Quentin Young 63d12a7d77 lib: fix gRPC northbound plugin build
Some issues with our internal vector type being typedef'd as `vector`,
which conflicts with the C++ standard vector class...

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-10-08 19:13:50 +00:00
Renato Westphal 8685be73e0 Revert "lib: introduce a read-write lock for northbound configurations"
Adding a lock to protect the global running configuration doesn't
help much since the FRR daemons are not prepared to process
configuration changes in a pthread that is not the main one (a
whole lot of new protections would be necessary to prevent race
conditions).

This means the lock added by commit 83981138 only adds more
complexity for no benefit. Remove it now to simplify the code.

All northbound clients, including the gRPC one, should either run
in the main pthread or use synchronization primitives to process
configuration transactions in the main pthread.

This reverts commit 83981138fe.
2019-09-18 14:35:10 -03:00
Renato Westphal ec2ac5f28a lib: add new gRPC-based northbound plugin
This is an experimental plugin for now. Full documentation will
come later.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-26 18:15:32 -03:00