]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/zebra_nht_resolution/test_verify_nh_resolution.py
Merge pull request #12818 from imzyxwvu/fix/other-table-inactive
[mirror_frr.git] / tests / topotests / zebra_nht_resolution / test_verify_nh_resolution.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # Copyright (c) 2022 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
8 #
9
10 """
11 Test is indended for validating zebra NH resolution logic
12 """
13
14 import os
15 import sys
16 import pytest
17
18 from lib.common_config import (
19 start_topology,
20 verify_rib,
21 verify_ip_nht,
22 step,
23 create_static_routes,
24 )
25
26 # pylint: disable=C0413
27 from lib import topotest
28 from lib.topogen import Topogen, TopoRouter, get_topogen
29 from lib.topolog import logger
30
31 CWD = os.path.dirname(os.path.realpath(__file__))
32 sys.path.append(os.path.join(CWD, "../"))
33
34 pytestmark = [pytest.mark.sharpd]
35
36 #GLOBAL VARIABLES
37 NH1 = "2.2.2.32"
38
39 def build_topo(tgen):
40 tgen.add_router("r1")
41
42 switch = tgen.add_switch("sw1")
43 switch.add_link(tgen.gears["r1"])
44
45 def setup_module(mod):
46 tgen = Topogen(build_topo, mod.__name__)
47 tgen.start_topology()
48 router_list = tgen.routers()
49 for rname, router in tgen.routers().items():
50 router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)))
51 router.load_config(
52 TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
53 )
54 tgen.start_router()
55
56 def teardown_module(_mod):
57 tgen = get_topogen()
58 tgen.stop_topology()
59
60 def test_verify_zebra_nh_resolution(request):
61 tgen = get_topogen()
62 tc_name = request.node.name
63 if tgen.routers_have_failure():
64 pytest.skip(tgen.errors)
65 logger.info("Starting Zebra NH resolution testcase")
66 r1 = tgen.gears["r1"]
67
68 step("Configure static route")
69 input_dict_1 = {
70 "r1": {
71 "static_routes": [
72 {"network": "2.2.2.0/24", "next_hop": "r1-eth0"}
73 ]
74 }
75 }
76
77 result = create_static_routes(tgen, input_dict_1)
78 assert result is True, "Testcase {} : Failed \n Error: {}".format(
79 tc_name, result
80 )
81
82 step("Verify static routes in RIB of R1")
83 input_dict_2 = {
84 "r1": {
85 "static_routes": [
86 {"network": "2.2.2.0/24"}
87 ]
88 }
89 }
90
91 dut = "r1"
92 result = verify_rib(tgen, "ipv4", dut, input_dict_2)
93 assert result is True, "Testcase {} :Failed \n Error: {}".format(
94 tc_name, result)
95
96 step("Set the connected flag on the NH tracking entry")
97 r1.vtysh_cmd("sharp watch nexthop 2.2.2.32 connected")
98
99 step("Verify that NH 2.2.2.32 gets resolved over static route")
100 input_dict_nh = {
101 "r1": {
102 NH1: {
103 "Address": "2.2.2.0/24",
104 "resolvedVia": "static",
105 "nexthops": {"nexthop1": {"Interfcae": "r1-eth0"}},
106 }
107 }
108 }
109 result = verify_ip_nht(tgen, input_dict_nh)
110 assert result is True, "Testcase {} : Failed \n"
111 "Error: Nexthop is missing in RIB".format(
112 tc_name, result)
113
114 step("Add a .32/32 route with the NH as itself")
115 r1.vtysh_cmd("sharp install routes 2.2.2.32 nexthop 2.2.2.32 1")
116
117 step("Verify that the installation of .32/32 has no effect on the NHT")
118 input_dict_nh = {
119 "r1": {
120 NH1: {
121 "Address": "2.2.2.0/24",
122 "resolvedVia": "static",
123 "nexthops": {"nexthop1": {"Interface": "r1-eth0"}},
124 }
125 }
126 }
127 result = verify_ip_nht(tgen, input_dict_nh)
128 assert result is True, "Testcase {} : Failed \n"
129 "Error: Nexthop became unresolved".format(
130 tc_name, result)
131
132 step("Add a .31/32 route with the NH as 2.2.2.32"
133 "to verify the NH Resolution behaviour")
134 r1.vtysh_cmd("sharp install routes 2.2.2.31 nexthop 2.2.2.32 1")
135
136 step("Verify that NH 2.2.2.2/32 doesn't become unresolved")
137 input_dict_nh = {
138 "r1": {
139 NH1: {
140 "Address": "2.2.2.0/24",
141 "resolvedVia": "static",
142 "nexthops": {"nexthop1": {"Interface": "r1-eth0"}},
143 }
144 }
145 }
146 result = verify_ip_nht(tgen, input_dict_nh)
147 assert result is True, "Testcase {} : Failed \n"
148 "Error: Nexthop became unresolved".format(
149 tc_name, result)
150
151 if __name__ == "__main__":
152 args = ["-s"] + sys.argv[1:]
153 sys.exit(pytest.main(args))