Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgmtd get-data request expansion #15154

Merged
merged 9 commits into from
Jan 15, 2024
Merged

Conversation

idryzhov
Copy link
Contributor

  • add the ability to request state-only, config-only, or all data in the same request
  • add the ability to request the exact node instead of the whole data tree
  • a couple of fixes for existing yang-related functions
  • tests for the new functionality

@idryzhov idryzhov requested a review from choppsv1 January 13, 2024 22:56
@frrbot frrbot bot added bugfix libfrr mgmt FRR Management Infra tests Topotests, make check, etc vtysh labels Jan 13, 2024
enum mgmt_msg_get_data_content {
GET_CONTENT_STATE,
GET_CONTENT_CONFIG,
GET_CONTENT_ALL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit more natural as flags, so GET_DATA_FLAG_STATE = 0x1, GET_DATA_FLAG_CONFIG = 0x2. This allows for CHECK_FLAGS(content, GET_DATA_FLAG_STATE) for both the STATE and the ALL case, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I changed the "exact" field to a flag as well.

mgmtd/mgmt_txn.c Outdated
@@ -2385,6 +2386,55 @@ int mgmt_txn_send_get_tree_oper(uint64_t txn_id, uint64_t req_id,
get_tree->simple_xpath = simple_xpath;
get_tree->xpath = XSTRDUP(MTYPE_MGMTD_XPATH, xpath);

if (content != GET_CONTENT_STATE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with flags this becomes CHECK_FLAG(content, GET_DATA_FLAG_CONFIG) which is much clearer IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

uint8_t resv2[7];

alignas(8) char xpath[];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just replace mgmt_msg_get_tree with this? Even with the expanded functionality coming in later commits? I don't see any point in having a specialized get-tree message that can be exactly replaced by this one with a couple extra params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is more clear if we have separate messages for the frontend and for the backend. There are new fields in the frontend message and there will be more later (like datastore, with-defaults, etc., to cover the whole NETCONF/RESTCONF functionality). And all these new fields don't make sense on the backend.

We should traverse all top-level siblings, not only the first one.

Signed-off-by: Igor Ryzhov <[email protected]>
/* Flags for get-data request */
#define GET_DATA_FLAG_STATE 0x01 /* get only "config false" data */
#define GET_DATA_FLAG_CONFIG 0x02 /* get only "config true" data */
#define GET_DATA_FLAG_ALL (GET_DATA_FLAG_STATE | GET_DATA_FLAG_CONFIG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I almost put in my earlier comment, ditch ALL, should have... Please get rid of the ALL #define. It's just more clear what's going on in the code when one or both flags are present when need be. You are adding EXACT as a flag which is really incompatible with ALL. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

mgmtd/mgmt_vty.c Outdated
flags = GET_DATA_FLAG_CONFIG;
} else {
flags = GET_DATA_FLAG_STATE;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest:

        uint8_t flags = cont ? GET_DATA_FLAG_CONFIG : GET_DATA_FLAG_STATE;

        if (cont && cont[0] == 'w')
                flags |= GET_DATA_FLAG_STATE;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I used your code.

mgmtd has to know if netns is used as the vrf backend to correctly
process interface names in northbound.

Signed-off-by: Igor Ryzhov <[email protected]>
Currently it's the same as get-tree request for the backend, but it is
going to be expanded in the following commits.

Signed-off-by: Igor Ryzhov <[email protected]>
@idryzhov idryzhov force-pushed the mgmt-get-data branch 2 times, most recently from 7f2cd79 to ddbb292 Compare January 14, 2024 18:42
@mwinter-osr
Copy link
Member

CI:rerun Retest for new ASAN Memory Leaks

LY_ERR err;

err = lyd_find_xpath(config->dnode, xpath, &set);
if (err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set is leaked (never ly_set_free(set, NULL)d)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

Like in RESTCONF GET request and NETCONF get-data request, make it
possible to request state-only, config-only, or all data.

Signed-off-by: Igor Ryzhov <[email protected]>
When creating an initial tree trunk for oper data walk, if the xpath
represents a leaf, the leaf is created with an incorrect empty value.
If it doesn't actually exist in daemon's oper data, its value is not
overwritten later and an empty value is returned in the result.

For example, when requesting
`/frr-interface:lib/interface[name='eth0']/description`, the result is:
```
{
  "frr-interface:lib": {
    "interface": [
      {
        "name": "eth0",
        "description": ""
      }
    ]
  }
}
```
instead of an empty JSON that it should be.

Signed-off-by: Igor Ryzhov <[email protected]>
RESTCONF expects to receive the exact node as a result, not the whole
data tree.

Signed-off-by: Igor Ryzhov <[email protected]>
@choppsv1 choppsv1 merged commit f2bb687 into FRRouting:master Jan 15, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix libfrr master mgmt FRR Management Infra size/L tests Topotests, make check, etc vtysh
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants