feat(tests): IPv6 scale
[csit.git] / resources / libraries / python / IPTopology.py
1 # Copyright (c) 2024 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """IP Topology Library."""
15
16 from robot.libraries.BuiltIn import BuiltIn
17
18 from resources.libraries.python.IPUtil import IPUtil
19
20
21 class IPTopology:
22     """IP Topology Library."""
23
24     @staticmethod
25     def initialize_ipv4_forwarding(count=1, pfs=2):
26         """
27         Custom setup of IPv4 forwarding with scalability of IP routes on all
28         DUT nodes in 2-node / 3-node circular topology.
29
30         :param count: Number of routes to configure.
31         :param pfs: Number of physical interfaces to configure.
32         :type count: int
33         :type pfs: int
34         """
35         topology = BuiltIn().get_variable_value("&{topology_info}")
36         dut = topology["duts"][-1]
37         ifl = BuiltIn().get_variable_value("${int}")
38
39         for l, i in zip(range(pfs // 2), range(1, pfs, 2)):
40             dut1_int1 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i}}}[0]")
41             dut1_int2 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i+1}}}[0]")
42             dut_int1 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i}}}[0]")
43             dut_int2 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i+1}}}[0]")
44
45             IPUtil.vpp_add_ip_neighbor(
46                 topology["DUT1"], dut1_int1, f"1.{l}.1.1",
47                 topology[f"TG_pf{i}_mac"][0]
48             )
49             if dut == "DUT2":
50                 dut_mac1 = BuiltIn().get_variable_value(
51                     f"${{{dut}_{ifl}{i}_mac}}[0]"
52                 )
53                 IPUtil.vpp_add_ip_neighbor(
54                     topology["DUT1"], dut1_int2, f"3.{l}.3.2", dut_mac1
55                 )
56                 dut_mac2 = BuiltIn().get_variable_value(
57                     f"${{DUT1_{ifl}{i+1}_mac}}[0]"
58                 )
59                 IPUtil.vpp_add_ip_neighbor(
60                     topology["DUT2"], dut_int1, f"3.{l}.3.1", dut_mac2
61                 )
62             IPUtil.vpp_add_ip_neighbor(
63                 topology[dut], dut_int2, f"2.{l}.2.1",
64                 topology[f"TG_pf{i+1}_mac"][0]
65             )
66
67             IPUtil.vpp_interface_set_ip_address(
68                 topology["DUT1"], dut1_int1, f"1.{l}.1.2", 30
69             )
70             if dut == "DUT2":
71                 IPUtil.vpp_interface_set_ip_address(
72                     topology["DUT1"], dut1_int2, f"3.{l}.3.1", 30
73                 )
74                 IPUtil.vpp_interface_set_ip_address(
75                     topology["DUT2"], dut_int1, f"3.{l}.3.2", 30
76                 )
77             IPUtil.vpp_interface_set_ip_address(
78                 topology[dut], dut_int2, f"2.{l}.2.2", 30
79             )
80
81             IPUtil.vpp_route_add(
82                 topology["DUT1"], f"{i}0.0.0.0", 32, gateway=f"1.{l}.1.1",
83                 interface=dut1_int1, count=count
84             )
85             if dut == "DUT2":
86                 IPUtil.vpp_route_add(
87                     topology["DUT1"], f"{i+1}0.0.0.0", 32, gateway=f"3.{l}.3.2",
88                     interface=dut1_int2, count=count
89                 )
90                 IPUtil.vpp_route_add(
91                     topology["DUT2"], f"{i}0.0.0.0", 32, gateway=f"3.{l}.3.1",
92                     interface=dut_int1, count=count
93                 )
94             IPUtil.vpp_route_add(
95                 topology[dut], f"{i+1}0.0.0.0", 32, gateway=f"2.{l}.2.1",
96                 interface=dut_int2, count=count
97             )
98
99
100     @staticmethod
101     def initialize_ipv6_forwarding(count=1, pfs=2):
102         """
103         Custom setup of IPv6 forwarding with scalability of IP routes on all
104         DUT nodes in 2-node / 3-node circular topology.
105
106         :param count: Number of routes to configure.
107         :param pfs: Number of physical interfaces to configure.
108         :type count: int
109         :type pfs: int
110         """
111         topology = BuiltIn().get_variable_value("&{topology_info}")
112         dut = topology["duts"][-1]
113         ifl = BuiltIn().get_variable_value("${int}")
114
115         for l, i in zip(range(pfs // 2), range(1, pfs, 2)):
116             dut1_int1 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i}}}[0]")
117             dut1_int2 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i+1}}}[0]")
118             dut_int1 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i}}}[0]")
119             dut_int2 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i+1}}}[0]")
120
121             IPUtil.vpp_add_ip_neighbor(
122                 topology["DUT1"], dut1_int1, f"2001:{l}::1",
123                 topology[f"TG_pf{i}_mac"][0]
124             )
125             if dut == "DUT2":
126                 dut_mac1 = BuiltIn().get_variable_value(
127                     f"${{{dut}_{ifl}{i}_mac}}[0]"
128                 )
129                 IPUtil.vpp_add_ip_neighbor(
130                     topology["DUT1"], dut1_int2, f"2003:{l}::2", dut_mac1
131                 )
132                 dut_mac2 = BuiltIn().get_variable_value(
133                     f"${{DUT1_{ifl}{i+1}_mac}}[0]"
134                 )
135                 IPUtil.vpp_add_ip_neighbor(
136                     topology["DUT2"], dut_int1, f"2003:{l}::1", dut_mac2
137                 )
138             IPUtil.vpp_add_ip_neighbor(
139                 topology[dut], dut_int2, f"2002:{l}::1",
140                 topology[f"TG_pf{i+1}_mac"][0]
141             )
142
143             IPUtil.vpp_interface_set_ip_address(
144                 topology["DUT1"], dut1_int1, f"2001:{l}::2", 64
145             )
146             if dut == "DUT2":
147                 IPUtil.vpp_interface_set_ip_address(
148                     topology["DUT1"], dut1_int2, f"2003:{l}::1", 64
149                 )
150                 IPUtil.vpp_interface_set_ip_address(
151                     topology["DUT2"], dut_int1, f"2003:{l}::2", 64
152                 )
153             IPUtil.vpp_interface_set_ip_address(
154                 topology[dut], dut_int2, f"2002:{l}::2", 64
155             )
156
157             IPUtil.vpp_route_add(
158                 topology["DUT1"], f"2{i}00::0", 64,
159                 gateway=f"2001:{l}::1", interface=dut1_int1, count=count
160             )
161             if dut == "DUT2":
162                 IPUtil.vpp_route_add(
163                     topology["DUT1"], f"2{i+1}00::0", 64,
164                     gateway=f"2003:{l}::2", interface=dut1_int2, count=count
165                 )
166                 IPUtil.vpp_route_add(
167                     topology["DUT2"], f"2{i}00::0", 64,
168                     gateway=f"2003:{l}::1", interface=dut_int1, count=count
169                 )
170             IPUtil.vpp_route_add(
171                 topology[dut], f"2{i+1}00::0", 64,
172                 gateway=f"2002:{l}::1", interface=dut_int2, count=count
173             )