Skip to content

Commit 4b6e0ba

Browse files
authored
Merge pull request FRRouting#18349 from donaldsharp/more_yang_state
More yang state
2 parents fe809f4 + 5070852 commit 4b6e0ba

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

tests/topotests/zebra_operational_data/test_zebra_operational.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,51 @@ def test_zebra_operationalr(tgen):
5656
logger.info("Ensuring that the max-multipath value is returned")
5757
assert "max-multipath" in output["frr-zebra:zebra"].keys()
5858

59+
logger.info("Checking IP forwarding states")
60+
state = output["frr-zebra:zebra"]["state"]
61+
assert "ip-forwarding" in state.keys(), "IPv4 forwarding state not found"
62+
assert "ipv6-forwarding" in state.keys(), "IPv6 forwarding state not found"
63+
assert "mpls-forwarding" in state.keys(), "MPLS forwarding state not found"
64+
65+
# Verify the values are boolean
66+
assert isinstance(
67+
state["ip-forwarding"], bool
68+
), "IPv4 forwarding state should be boolean"
69+
assert isinstance(
70+
state["ipv6-forwarding"], bool
71+
), "IPv6 forwarding state should be boolean"
72+
assert isinstance(
73+
state["mpls-forwarding"], bool
74+
), "MPLS forwarding state should be boolean"
75+
76+
# Test IPv6 forwarding state change
77+
logger.info("Testing IPv6 forwarding state change")
78+
# Store initial state
79+
initial_ipv6_state = state["ipv6-forwarding"]
80+
81+
# Turn off IPv6 forwarding
82+
r1.vtysh_cmd("configure terminal\nno ipv6 forwarding\nexit")
83+
84+
# Get updated state
85+
output = json.loads(r1.vtysh_cmd("show mgmt get-data /frr-zebra:zebra"))
86+
new_state = output["frr-zebra:zebra"]["state"]
87+
88+
# Verify IPv6 forwarding is now off
89+
assert (
90+
new_state["ipv6-forwarding"] is False
91+
), "IPv6 forwarding should be False after disabling"
92+
93+
# Restore original state if it was enabled
94+
if initial_ipv6_state:
95+
r1.vtysh_cmd("configure terminal\nipv6 forwarding\nexit")
96+
97+
# Verify state is restored
98+
output = json.loads(r1.vtysh_cmd("show mgmt get-data /frr-zebra:zebra"))
99+
final_state = output["frr-zebra:zebra"]["state"]
100+
assert (
101+
final_state["ipv6-forwarding"] is True
102+
), "IPv6 forwarding should be restored to True"
103+
59104

60105
if __name__ == "__main__":
61106
# To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli

yang/frr-zebra.yang

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,11 @@ module frr-zebra {
29612961
type boolean;
29622962
description
29632963
"IPv6 forwarding status.";
2964+
}
2965+
leaf mpls-forwarding {
2966+
type boolean;
2967+
description
2968+
"MPLS forwarding status.";
29642969
}
29652970
}
29662971
// End of operational / state container

zebra/zebra_nb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ const struct frr_yang_module_info frr_zebra_info = {
5757
.get_elem = zebra_ipv6_forwarding_get_elem,
5858
}
5959
},
60+
{
61+
.xpath = "/frr-zebra:zebra/state/mpls-forwarding",
62+
.cbs = {
63+
.get_elem = zebra_state_mpls_forwarding_get_elem,
64+
}
65+
},
6066
{
6167
.xpath = "/frr-zebra:zebra/workqueue-hold-timer",
6268
.cbs = {

zebra/zebra_nb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ int zebra_ipv6_forwarding_modify(struct nb_cb_modify_args *args);
3737
int zebra_ipv6_forwarding_destroy(struct nb_cb_destroy_args *args);
3838
int zebra_workqueue_hold_timer_modify(struct nb_cb_modify_args *args);
3939
struct yang_data *zebra_ipv6_forwarding_get_elem(struct nb_cb_get_elem_args *args);
40+
struct yang_data *zebra_state_mpls_forwarding_get_elem(struct nb_cb_get_elem_args *args);
4041
int zebra_zapi_packets_modify(struct nb_cb_modify_args *args);
4142
int zebra_import_kernel_table_table_id_modify(struct nb_cb_modify_args *args);
4243
int zebra_import_kernel_table_table_id_destroy(struct nb_cb_destroy_args *args);

zebra/zebra_nb_state.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "zebra/zebra_vxlan.h"
1616
#include "zebra/zebra_vxlan_if.h"
1717
#include "zebra/ipforward.h"
18+
#include "zebra/zebra_mpls.h"
1819

1920
/*
2021
* 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
11891190
{
11901191
return yang_data_new_bool(args->xpath, ipforward_ipv6());
11911192
}
1193+
1194+
/*
1195+
* XPath: /frr-zebra:zebra/state/mpls-forwarding
1196+
*/
1197+
struct yang_data *zebra_state_mpls_forwarding_get_elem(struct nb_cb_get_elem_args *args)
1198+
{
1199+
return yang_data_new_bool(args->xpath, mpls_enabled);
1200+
}

0 commit comments

Comments
 (0)