Skip to content

Commit 9ae6ae2

Browse files
committed
tests: Add basic test for route notifier.
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 Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ales Musil <amusil@redhat.com>
1 parent 5ec13ae commit 9ae6ae2

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

tests/system-common-macros.at

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ m4_define([VRF_RESERVE],
400400
]
401401
)
402402

403+
# RTPROT_OVN - the routing protocol number used by OVN.
404+
m4_define([RTPROT_OVN], [84])
405+
403406
# OVN_ROUTE_EQUAL([vrf], [string to compare])
404407
#
405408
# Will dump all v4 routes in the mentioned vrf. Trailing spaces will be removed

tests/system-ovn-netlink.at

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,45 @@ blackhole fd20:100::/64 dev lo proto ovn metric 1024 pref medium
495495
fe80::/64 dev lo-test proto kernel metric 256 pref medium])
496496

497497
AT_CLEANUP
498+
499+
AT_SETUP([sync netlink routes - table notify])
500+
AT_KEYWORDS([netlink-routes])
501+
CHECK_VRF()
502+
503+
table_id=100
504+
505+
check ip link add vrf-$table_id type vrf table $table_id
506+
on_exit 'ip link del vrf-$table_id'
507+
check ip link set dev vrf-$table_id up
508+
509+
check ip link add lo-test type dummy
510+
on_exit 'ip link del lo-test'
511+
check ip link set lo-test master vrf-$table_id
512+
check ip link set lo-test address 00:00:00:00:00:10
513+
check ip addr add 20.0.0.10/24 dev lo-test
514+
check ip addr add fd20::10/64 dev lo-test
515+
check ip link set up lo-test
516+
517+
dnl Should notify if an IPv4 route is added to a table monitored by OVN.
518+
AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \
519+
"ip route add 10.10.10.0/24 via 20.0.0.1 vrf vrf-$table_id"], [0], [dnl
520+
Notification v4 table_id=$table_id
521+
])
522+
523+
dnl Should notify if an IPv6 route is added to a table monitored by OVN.
524+
AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \
525+
"ip -6 route add fd10::/64 via fd20::1 vrf vrf-$table_id"], [0], [dnl
526+
Notification v6 table_id=$table_id
527+
])
528+
529+
dnl Should NOT notify if a route with proto ovn is added.
530+
AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \
531+
"ip route add 10.10.20.0/24 via 20.0.0.1 vrf vrf-$table_id proto RTPROT_OVN"], [0], [dnl
532+
])
533+
534+
dnl Should NOT notify if an IPv6 route with proto ovn is added.
535+
AT_CHECK_UNQUOTED([ovstest test-ovn-netlink route-table-notify \
536+
"ip -6 route add fd20:200::/64 via fd20::1 vrf vrf-$table_id proto RTPROT_OVN"], [0], [dnl
537+
])
538+
539+
AT_CLEANUP

tests/test-ovn-netlink.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,35 @@ test_route_sync(struct ovs_cmdl_context *ctx)
250250
ds_destroy(&msg);
251251
}
252252

253+
static void
254+
test_route_table_notify(struct ovs_cmdl_context *ctx)
255+
{
256+
unsigned int shift = 1;
257+
258+
const char *cmd = test_read_value(ctx, shift++, "shell_command");
259+
if (!cmd) {
260+
return;
261+
}
262+
263+
ovn_netlink_update_notifier(OVN_NL_NOTIFIER_ROUTE_V4, true);
264+
ovn_netlink_update_notifier(OVN_NL_NOTIFIER_ROUTE_V6, true);
265+
run_command_under_notifier(cmd);
266+
267+
uint32_t table_id;
268+
269+
struct vector *msgs = ovn_netlink_get_msgs(OVN_NL_NOTIFIER_ROUTE_V4);
270+
VECTOR_FOR_EACH (msgs, table_id) {
271+
printf("Notification v4 table_id=%"PRIu32"\n", table_id);
272+
}
273+
274+
msgs = ovn_netlink_get_msgs(OVN_NL_NOTIFIER_ROUTE_V6);
275+
VECTOR_FOR_EACH (msgs, table_id) {
276+
printf("Notification v6 table_id=%"PRIu32"\n", table_id);
277+
}
278+
279+
ovn_netlink_notifiers_destroy();
280+
}
281+
253282
static void
254283
test_ovn_netlink(int argc, char *argv[])
255284
{
@@ -260,6 +289,8 @@ test_ovn_netlink(int argc, char *argv[])
260289
test_neighbor_table_notify, OVS_RO},
261290
{"host-if-monitor", NULL, 2, 3, test_host_if_monitor, OVS_RO},
262291
{"route-sync", NULL, 1, INT_MAX, test_route_sync, OVS_RO},
292+
{"route-table-notify", NULL, 1, 1,
293+
test_route_table_notify, OVS_RO},
263294
{NULL, NULL, 0, 0, NULL, OVS_RO},
264295
};
265296
struct ovs_cmdl_context ctx;

0 commit comments

Comments
 (0)