-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Standardize arguments for ZAPI message handlers A lot of the handler functions that are called directly from the ZAPI input processing code take different argument sets where they don't need to. These functions are called from only one place and all have the same fundamental information available to them to do their work. There is no need to specialize what information is passed to them; it is cleaner and easier to understand when they all accept the same base set of information and extract what they need inline. * Eliminate the humongous switch-case in the dispatcher After doing the above work it becomes possible to eliminate the big switch-case statement and turn it into a lookup table keyed by ZAPI message code. Granted the compiler usually optimized switch-case statements into jump tables anyway but it is better to make this a strong guarantee by doing it in the source. * Allow batching ZAPI I/O ZAPI's original I/O loop looks like: zserv_read: - Read one message - Run message handler - Schedule zserv_read This has been changed to: zserv_handle_messages: - For each message on the input queue: - Pop the message - Run message handler zserv_read: - Read as many messages as available into input queue - Schedule zserv_handle_messages - Schedule zserv_read This is more flexible as it allows decoupling I/O from actual state changes inside Zebra. Theoretically it also helps cache churn by grouping the same tasks together instead of alternating between them. * Modify all handlers to stop accessing global client buffers There is no reason for message handlers to look at a global data structure that holds the last message received. Instead we can reduce the amount of global state they need to know about by making them accept a message stream, and not care about where it came from. This is also necessary for the input queue changes above. It also moves us closer to being able to unit test ZAPI message handlers. * Modify all handlers to not return an status code All of the ZAPI message handlers return an integer that means different things to each of them, but nobody ever reads these integers, so this is technical debt that we can just eliminate outright. * Rename some functions to zread_* or zsend_* to clarify action zserv.c functions are roughly organized into three kinds of functions: - Functions that encode Zebra datastructures into ZAPI message equivalents - Functions that build and send whole messages - Functions that process received ZAPI messages These are variously named with prefixes like "zserv", "zebra", "zread", "zsend", etc. Organize them by using consistent naming prefixes; zserv_encode_*, zsend_*, zread_* respectively for the three types given above. * Organize zserv.c into logical sections Group the above functions together by type, and group the plumbing for the I/O code together as well. * Add struct zmsghdr Formalize the ZAPI header by documenting it in code and providing it to message handlers free of charge to reduce complexity. * Clean up zserv_read Just some simplifications of the existing code intended to make it easier to read, understand and debug. Also improved debugging output for ZAPI messages by leveraging zmsghdr and making log messages consistent. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
- Loading branch information
Showing
16 changed files
with
1,103 additions
and
1,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.