]>
Commit | Line | Data |
---|---|---|
531c92b8 | 1 | #!/usr/bin/env python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
531c92b8 JU |
3 | |
4 | # | |
5 | # test_zebra_netlink.py | |
6 | # | |
7 | # Copyright (c) 2020 by | |
8 | # | |
531c92b8 JU |
9 | |
10 | """ | |
11 | test_zebra_netlink.py: Test some basic interactions with kernel using Netlink | |
12 | ||
13 | """ | |
1375385a CH |
14 | # pylint: disable=C0413 |
15 | import ipaddress | |
531c92b8 | 16 | import json |
1375385a | 17 | import sys |
531c92b8 JU |
18 | from functools import partial |
19 | ||
1375385a | 20 | import pytest |
531c92b8 | 21 | from lib import topotest |
1375385a | 22 | from lib.topogen import Topogen, TopoRouter |
531c92b8 | 23 | from lib.topolog import logger |
531c92b8 | 24 | |
531c92b8 | 25 | |
9a47e7b2 DS |
26 | pytestmark = [pytest.mark.sharpd] |
27 | ||
28 | ||
531c92b8 JU |
29 | ##################################################### |
30 | ## | |
31 | ## Tests starting | |
32 | ## | |
33 | ##################################################### | |
34 | ||
35 | ||
1375385a CH |
36 | @pytest.fixture(scope="module") |
37 | def tgen(request): | |
531c92b8 | 38 | "Sets up the pytest environment" |
8db751b8 | 39 | |
a53c08bc | 40 | topodef = {"s1": ("r1")} |
1375385a | 41 | tgen = Topogen(topodef, request.module.__name__) |
531c92b8 JU |
42 | tgen.start_topology() |
43 | ||
1375385a | 44 | # Initialize all routers. |
531c92b8 | 45 | router_list = tgen.routers() |
e5f0ed14 | 46 | for rname, router in router_list.items(): |
1375385a CH |
47 | router.load_config(TopoRouter.RD_ZEBRA, "zebra.conf") |
48 | router.load_config(TopoRouter.RD_SHARP) | |
531c92b8 | 49 | |
531c92b8 | 50 | tgen.start_router() |
1375385a CH |
51 | yield tgen |
52 | tgen.stop_topology() | |
531c92b8 JU |
53 | |
54 | ||
1375385a CH |
55 | @pytest.fixture(autouse=True) |
56 | def skip_on_failure(tgen): | |
57 | if tgen.routers_have_failure(): | |
58 | pytest.skip("skipped because of previous test failure") | |
531c92b8 JU |
59 | |
60 | ||
1375385a | 61 | def test_zebra_netlink_batching(tgen): |
531c92b8 JU |
62 | "Test the situation where dataplane fills netlink send buffer entirely." |
63 | logger.info( | |
64 | "Test the situation where dataplane fills netlink send buffer entirely." | |
65 | ) | |
531c92b8 JU |
66 | r1 = tgen.gears["r1"] |
67 | ||
68 | # Reduce the size of the buffer to hit the limit. | |
69 | r1.vtysh_cmd("conf t\nzebra kernel netlink batch-tx-buf 256 256") | |
70 | ||
1375385a CH |
71 | count = 100 |
72 | r1.vtysh_cmd("sharp install routes 2.1.3.7 nexthop 192.168.1.1 " + str(count)) | |
73 | ||
74 | # Generate expected results | |
75 | entry = { | |
76 | "protocol": "sharp", | |
77 | "distance": 150, | |
78 | "metric": 0, | |
79 | "installed": True, | |
80 | "table": 254, | |
81 | "nexthops": [ | |
82 | { | |
83 | "fib": True, | |
84 | "ip": "192.168.1.1", | |
85 | "afi": "ipv4", | |
86 | "interfaceName": "r1-eth0", | |
87 | "active": True, | |
88 | "weight": 1, | |
89 | } | |
90 | ], | |
91 | } | |
92 | ||
93 | match = {} | |
94 | base = int(ipaddress.ip_address(u"2.1.3.7")) | |
95 | for i in range(base, base + count): | |
96 | pfx = str(ipaddress.ip_network((i, 32))) | |
97 | match[pfx] = [dict(entry, prefix=pfx)] | |
98 | ||
a6782fba | 99 | ok = topotest.router_json_cmp_retry(r1, "show ip route json", match, False, 30) |
1375385a CH |
100 | assert ok, '"r1" JSON output mismatches' |
101 | ||
102 | r1.vtysh_cmd("sharp remove routes 2.1.3.7 " + str(count)) | |
531c92b8 JU |
103 | |
104 | ||
105 | if __name__ == "__main__": | |
106 | args = ["-s"] + sys.argv[1:] | |
107 | sys.exit(pytest.main(args)) |