Add basic test for route notifier in very similar fashion to what we already have for neighbor notifications.
Assisted-by: Claude, with model: claude-opus-4-6 Signed-off-by: Ales Musil <[email protected]> --- tests/system-common-macros.at | 3 +++ tests/system-ovn-netlink.at | 42 +++++++++++++++++++++++++++++++++++ tests/test-ovn-netlink.c | 31 ++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/tests/system-common-macros.at b/tests/system-common-macros.at index 5062f02b0..5243b3f1b 100644 --- a/tests/system-common-macros.at +++ b/tests/system-common-macros.at @@ -400,6 +400,9 @@ m4_define([VRF_RESERVE], ] ) +# RTPROT_OVN - the routing protocol number used by OVN. +m4_define([RTPROT_OVN], [84]) + # OVN_ROUTE_EQUAL([vrf], [string to compare]) # # Will dump all v4 routes in the mentioned vrf. Trailing spaces will be removed diff --git a/tests/system-ovn-netlink.at b/tests/system-ovn-netlink.at index 8bf1055d1..26382f087 100644 --- a/tests/system-ovn-netlink.at +++ b/tests/system-ovn-netlink.at @@ -495,3 +495,45 @@ blackhole fd20:100::/64 dev lo proto ovn metric 1024 pref medium fe80::/64 dev lo-test proto kernel metric 256 pref medium]) AT_CLEANUP + +AT_SETUP([sync netlink routes - table notify]) +AT_KEYWORDS([netlink-routes]) +CHECK_VRF() + +table_id=100 + +check ip link add vrf-$table_id type vrf table $table_id +on_exit 'ip link del vrf-$table_id' +check ip link set dev vrf-$table_id up + +check ip link add lo-test type dummy +on_exit 'ip link del lo-test' +check ip link set lo-test master vrf-$table_id +check ip link set lo-test address 00:00:00:00:00:10 +check ip addr add 20.0.0.10/24 dev lo-test +check ip addr add fd20::10/64 dev lo-test +check ip link set up lo-test + +dnl Should notify if an IPv4 route is added to a table monitored by OVN. +AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \ + "ip route add 10.10.10.0/24 via 20.0.0.1 vrf vrf-$table_id"], [0], [dnl +Notification v4 table_id=$table_id +]) + +dnl Should notify if an IPv6 route is added to a table monitored by OVN. +AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \ + "ip -6 route add fd10::/64 via fd20::1 vrf vrf-$table_id"], [0], [dnl +Notification v6 table_id=$table_id +]) + +dnl Should NOT notify if a route with proto ovn is added. +AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \ + "ip route add 10.10.20.0/24 via 20.0.0.1 vrf vrf-$table_id proto RTPROT_OVN"], [0], [dnl +]) + +dnl Should NOT notify if an IPv6 route with proto ovn is added. +AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \ + "ip -6 route add fd20:200::/64 via fd20::1 vrf vrf-$table_id proto RTPROT_OVN"], [0], [dnl +]) + +AT_CLEANUP diff --git a/tests/test-ovn-netlink.c b/tests/test-ovn-netlink.c index efc3c9e5e..555b2df99 100644 --- a/tests/test-ovn-netlink.c +++ b/tests/test-ovn-netlink.c @@ -250,6 +250,35 @@ done: ds_destroy(&msg); } +static void +test_route_table_notify(struct ovs_cmdl_context *ctx) +{ + unsigned int shift = 1; + + const char *cmd = test_read_value(ctx, shift++, "shell_command"); + if (!cmd) { + return; + } + + ovn_netlink_update_notifier(OVN_NL_NOTIFIER_ROUTE_V4, true); + ovn_netlink_update_notifier(OVN_NL_NOTIFIER_ROUTE_V6, true); + run_command_under_notifier(cmd); + + uint32_t table_id; + + struct vector *msgs = ovn_netlink_get_msgs(OVN_NL_NOTIFIER_ROUTE_V4); + VECTOR_FOR_EACH (msgs, table_id) { + printf("Notification v4 table_id=%"PRIu32"\n", table_id); + } + + msgs = ovn_netlink_get_msgs(OVN_NL_NOTIFIER_ROUTE_V6); + VECTOR_FOR_EACH (msgs, table_id) { + printf("Notification v6 table_id=%"PRIu32"\n", table_id); + } + + ovn_netlink_notifiers_destroy(); +} + static void test_ovn_netlink(int argc, char *argv[]) { @@ -260,6 +289,8 @@ test_ovn_netlink(int argc, char *argv[]) test_neighbor_table_notify, OVS_RO}, {"host-if-monitor", NULL, 2, 3, test_host_if_monitor, OVS_RO}, {"route-sync", NULL, 1, INT_MAX, test_route_sync, OVS_RO}, + {"route-table-notify", NULL, 1, 1, + test_route_table_notify, OVS_RO}, {NULL, NULL, 0, 0, NULL, OVS_RO}, }; struct ovs_cmdl_context ctx; -- 2.53.0 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
