]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/zebra_nht_resolution/test_verify_nh_resolution.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / zebra_nht_resolution / test_verify_nh_resolution.py
1 #!/usr/bin/env python
2
3 #
4 # Copyright (c) 2022 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
7 #
8 # Permission to use, copy, modify, and/or distribute this software
9 # for any purpose with or without fee is hereby granted, provided
10 # that the above copyright notice and this permission notice appear
11 # in all copies.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 # OF THIS SOFTWARE.
21 #
22
23 """
24 Test is indended for validating zebra NH resolution logic
25 """
26
27 import os
28 import sys
29 import pytest
30
31 from lib.common_config import (
32 start_topology,
33 verify_rib,
34 verify_ip_nht,
35 step,
36 create_static_routes,
37 )
38
39 # pylint: disable=C0413
40 from lib import topotest
41 from lib.topogen import Topogen, TopoRouter, get_topogen
42 from lib.topolog import logger
43
44 CWD = os.path.dirname(os.path.realpath(__file__))
45 sys.path.append(os.path.join(CWD, "../"))
46
47 pytestmark = [pytest.mark.sharpd]
48
49 #GLOBAL VARIABLES
50 NH1 = "2.2.2.32"
51
52 def build_topo(tgen):
53 tgen.add_router("r1")
54
55 switch = tgen.add_switch("sw1")
56 switch.add_link(tgen.gears["r1"])
57
58 def setup_module(mod):
59 tgen = Topogen(build_topo, mod.__name__)
60 tgen.start_topology()
61 router_list = tgen.routers()
62 for rname, router in tgen.routers().items():
63 router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)))
64 router.load_config(
65 TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
66 )
67 tgen.start_router()
68
69 def teardown_module(_mod):
70 tgen = get_topogen()
71 tgen.stop_topology()
72
73 def test_verify_zebra_nh_resolution(request):
74 tgen = get_topogen()
75 tc_name = request.node.name
76 if tgen.routers_have_failure():
77 pytest.skip(tgen.errors)
78 logger.info("Starting Zebra NH resolution testcase")
79 r1 = tgen.gears["r1"]
80
81 step("Configure static route")
82 input_dict_1 = {
83 "r1": {
84 "static_routes": [
85 {"network": "2.2.2.0/24", "next_hop": "r1-eth0"}
86 ]
87 }
88 }
89
90 result = create_static_routes(tgen, input_dict_1)
91 assert result is True, "Testcase {} : Failed \n Error: {}".format(
92 tc_name, result
93 )
94
95 step("Verify static routes in RIB of R1")
96 input_dict_2 = {
97 "r1": {
98 "static_routes": [
99 {"network": "2.2.2.0/24"}
100 ]
101 }
102 }
103
104 dut = "r1"
105 result = verify_rib(tgen, "ipv4", dut, input_dict_2)
106 assert result is True, "Testcase {} :Failed \n Error: {}".format(
107 tc_name, result)
108
109 step("Set the connected flag on the NH tracking entry")
110 r1.vtysh_cmd("sharp watch nexthop 2.2.2.32 connected")
111
112 step("Verify that NH 2.2.2.32 gets resolved over static route")
113 input_dict_nh = {
114 "r1": {
115 NH1: {
116 "Address": "2.2.2.0/24",
117 "resolvedVia": "static",
118 "nexthops": {"nexthop1": {"Interfcae": "r1-eth0"}},
119 }
120 }
121 }
122 result = verify_ip_nht(tgen, input_dict_nh)
123 assert result is True, "Testcase {} : Failed \n"
124 "Error: Nexthop is missing in RIB".format(
125 tc_name, result)
126
127 step("Add a .32/32 route with the NH as itself")
128 r1.vtysh_cmd("sharp install routes 2.2.2.32 nexthop 2.2.2.32 1")
129
130 step("Verify that the installation of .32/32 has no effect on the NHT")
131 input_dict_nh = {
132 "r1": {
133 NH1: {
134 "Address": "2.2.2.0/24",
135 "resolvedVia": "static",
136 "nexthops": {"nexthop1": {"Interface": "r1-eth0"}},
137 }
138 }
139 }
140 result = verify_ip_nht(tgen, input_dict_nh)
141 assert result is True, "Testcase {} : Failed \n"
142 "Error: Nexthop became unresolved".format(
143 tc_name, result)
144
145 step("Add a .31/32 route with the NH as 2.2.2.32"
146 "to verify the NH Resolution behaviour")
147 r1.vtysh_cmd("sharp install routes 2.2.2.31 nexthop 2.2.2.32 1")
148
149 step("Verify that NH 2.2.2.2/32 doesn't become unresolved")
150 input_dict_nh = {
151 "r1": {
152 NH1: {
153 "Address": "2.2.2.0/24",
154 "resolvedVia": "static",
155 "nexthops": {"nexthop1": {"Interface": "r1-eth0"}},
156 }
157 }
158 }
159 result = verify_ip_nht(tgen, input_dict_nh)
160 assert result is True, "Testcase {} : Failed \n"
161 "Error: Nexthop became unresolved".format(
162 tc_name, result)
163
164 if __name__ == "__main__":
165 args = ["-s"] + sys.argv[1:]
166 sys.exit(pytest.main(args))