Merge pull request #18349 from donaldsharp/more_yang_state

More yang state
This commit is contained in:
Russ White 2025-03-18 11:02:28 -04:00 committed by GitHub
commit 4b6e0ba1a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 66 additions and 0 deletions

View file

@ -56,6 +56,51 @@ def test_zebra_operationalr(tgen):
logger.info("Ensuring that the max-multipath value is returned")
assert "max-multipath" in output["frr-zebra:zebra"].keys()
logger.info("Checking IP forwarding states")
state = output["frr-zebra:zebra"]["state"]
assert "ip-forwarding" in state.keys(), "IPv4 forwarding state not found"
assert "ipv6-forwarding" in state.keys(), "IPv6 forwarding state not found"
assert "mpls-forwarding" in state.keys(), "MPLS forwarding state not found"
# Verify the values are boolean
assert isinstance(
state["ip-forwarding"], bool
), "IPv4 forwarding state should be boolean"
assert isinstance(
state["ipv6-forwarding"], bool
), "IPv6 forwarding state should be boolean"
assert isinstance(
state["mpls-forwarding"], bool
), "MPLS forwarding state should be boolean"
# Test IPv6 forwarding state change
logger.info("Testing IPv6 forwarding state change")
# Store initial state
initial_ipv6_state = state["ipv6-forwarding"]
# Turn off IPv6 forwarding
r1.vtysh_cmd("configure terminal\nno ipv6 forwarding\nexit")
# Get updated state
output = json.loads(r1.vtysh_cmd("show mgmt get-data /frr-zebra:zebra"))
new_state = output["frr-zebra:zebra"]["state"]
# Verify IPv6 forwarding is now off
assert (
new_state["ipv6-forwarding"] is False
), "IPv6 forwarding should be False after disabling"
# Restore original state if it was enabled
if initial_ipv6_state:
r1.vtysh_cmd("configure terminal\nipv6 forwarding\nexit")
# Verify state is restored
output = json.loads(r1.vtysh_cmd("show mgmt get-data /frr-zebra:zebra"))
final_state = output["frr-zebra:zebra"]["state"]
assert (
final_state["ipv6-forwarding"] is True
), "IPv6 forwarding should be restored to True"
if __name__ == "__main__":
# To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli

View file

@ -2961,6 +2961,11 @@ module frr-zebra {
type boolean;
description
"IPv6 forwarding status.";
}
leaf mpls-forwarding {
type boolean;
description
"MPLS forwarding status.";
}
}
// End of operational / state container

View file

@ -57,6 +57,12 @@ const struct frr_yang_module_info frr_zebra_info = {
.get_elem = zebra_ipv6_forwarding_get_elem,
}
},
{
.xpath = "/frr-zebra:zebra/state/mpls-forwarding",
.cbs = {
.get_elem = zebra_state_mpls_forwarding_get_elem,
}
},
{
.xpath = "/frr-zebra:zebra/workqueue-hold-timer",
.cbs = {

View file

@ -37,6 +37,7 @@ int zebra_ipv6_forwarding_modify(struct nb_cb_modify_args *args);
int zebra_ipv6_forwarding_destroy(struct nb_cb_destroy_args *args);
int zebra_workqueue_hold_timer_modify(struct nb_cb_modify_args *args);
struct yang_data *zebra_ipv6_forwarding_get_elem(struct nb_cb_get_elem_args *args);
struct yang_data *zebra_state_mpls_forwarding_get_elem(struct nb_cb_get_elem_args *args);
int zebra_zapi_packets_modify(struct nb_cb_modify_args *args);
int zebra_import_kernel_table_table_id_modify(struct nb_cb_modify_args *args);
int zebra_import_kernel_table_table_id_destroy(struct nb_cb_destroy_args *args);

View file

@ -15,6 +15,7 @@
#include "zebra/zebra_vxlan.h"
#include "zebra/zebra_vxlan_if.h"
#include "zebra/ipforward.h"
#include "zebra/zebra_mpls.h"
/*
* XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/up-count
@ -1189,3 +1190,11 @@ struct yang_data *zebra_ipv6_forwarding_get_elem(struct nb_cb_get_elem_args *arg
{
return yang_data_new_bool(args->xpath, ipforward_ipv6());
}
/*
* XPath: /frr-zebra:zebra/state/mpls-forwarding
*/
struct yang_data *zebra_state_mpls_forwarding_get_elem(struct nb_cb_get_elem_args *args)
{
return yang_data_new_bool(args->xpath, mpls_enabled);
}