Revert "fix(jobspec): Delete ipsec nfv density tests"
[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, route_prefix=32):
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         :param route_prefix: Route prefix to configure.
33         :type count: int
34         :type pfs: int
35         :type route_prefix: int
36         """
37         topology = BuiltIn().get_variable_value("&{topology_info}")
38         dut = topology["duts"][-1]
39         ifl = BuiltIn().get_variable_value("${int}")
40
41         for l, i in zip(range(pfs // 2), range(1, pfs, 2)):
42             dut1_int1 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i}}}[0]")
43             dut1_int2 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i+1}}}[0]")
44             dut_int1 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i}}}[0]")
45             dut_int2 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i+1}}}[0]")
46
47             IPUtil.vpp_add_ip_neighbor(
48                 topology["DUT1"], dut1_int1, f"1.{l}.1.1",
49                 topology[f"TG_pf{i}_mac"][0]
50             )
51             if dut == "DUT2":
52                 dut_mac1 = BuiltIn().get_variable_value(
53                     f"${{{dut}_{ifl}{i}_mac}}[0]"
54                 )
55                 IPUtil.vpp_add_ip_neighbor(
56                     topology["DUT1"], dut1_int2, f"3.{l}.3.2", dut_mac1
57                 )
58                 dut_mac2 = BuiltIn().get_variable_value(
59                     f"${{DUT1_{ifl}{i+1}_mac}}[0]"
60                 )
61                 IPUtil.vpp_add_ip_neighbor(
62                     topology["DUT2"], dut_int1, f"3.{l}.3.1", dut_mac2
63                 )
64             IPUtil.vpp_add_ip_neighbor(
65                 topology[dut], dut_int2, f"2.{l}.2.1",
66                 topology[f"TG_pf{i+1}_mac"][0]
67             )
68
69             IPUtil.vpp_interface_set_ip_address(
70                 topology["DUT1"], dut1_int1, f"1.{l}.1.2", 30
71             )
72             if dut == "DUT2":
73                 IPUtil.vpp_interface_set_ip_address(
74                     topology["DUT1"], dut1_int2, f"3.{l}.3.1", 30
75                 )
76                 IPUtil.vpp_interface_set_ip_address(
77                     topology["DUT2"], dut_int1, f"3.{l}.3.2", 30
78                 )
79             IPUtil.vpp_interface_set_ip_address(
80                 topology[dut], dut_int2, f"2.{l}.2.2", 30
81             )
82
83             IPUtil.vpp_route_add(
84                 topology["DUT1"], f"{i}0.0.0.0", route_prefix,
85                 gateway=f"1.{l}.1.1", interface=dut1_int1, count=count
86             )
87             if dut == "DUT2":
88                 IPUtil.vpp_route_add(
89                     topology["DUT1"], f"{i+1}0.0.0.0", route_prefix,
90                     gateway=f"3.{l}.3.2", interface=dut1_int2, count=count
91                 )
92                 IPUtil.vpp_route_add(
93                     topology["DUT2"], f"{i}0.0.0.0", route_prefix,
94                     gateway=f"3.{l}.3.1", interface=dut_int1, count=count
95                 )
96             IPUtil.vpp_route_add(
97                 topology[dut], f"{i+1}0.0.0.0", route_prefix,
98                 gateway=f"2.{l}.2.1", interface=dut_int2, count=count
99             )
100
101
102     @staticmethod
103     def initialize_ipv6_forwarding(count=1, pfs=2, route_prefix=128):
104         """
105         Custom setup of IPv6 forwarding with scalability of IP routes on all
106         DUT nodes in 2-node / 3-node circular topology.
107
108         :param count: Number of routes to configure.
109         :param pfs: Number of physical interfaces to configure.
110         :param route_prefix: Route prefix to configure.
111         :type count: int
112         :type pfs: int
113         :type route_prefix: int
114         """
115         topology = BuiltIn().get_variable_value("&{topology_info}")
116         dut = topology["duts"][-1]
117         ifl = BuiltIn().get_variable_value("${int}")
118
119         for l, i in zip(range(pfs // 2), range(1, pfs, 2)):
120             dut1_int1 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i}}}[0]")
121             dut1_int2 = BuiltIn().get_variable_value(f"${{DUT1_{ifl}{i+1}}}[0]")
122             dut_int1 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i}}}[0]")
123             dut_int2 = BuiltIn().get_variable_value(f"${{{dut}_{ifl}{i+1}}}[0]")
124
125             IPUtil.vpp_add_ip_neighbor(
126                 topology["DUT1"], dut1_int1, f"2001:{l}::1",
127                 topology[f"TG_pf{i}_mac"][0]
128             )
129             if dut == "DUT2":
130                 dut_mac1 = BuiltIn().get_variable_value(
131                     f"${{{dut}_{ifl}{i}_mac}}[0]"
132                 )
133                 IPUtil.vpp_add_ip_neighbor(
134                     topology["DUT1"], dut1_int2, f"2003:{l}::2", dut_mac1
135                 )
136                 dut_mac2 = BuiltIn().get_variable_value(
137                     f"${{DUT1_{ifl}{i+1}_mac}}[0]"
138                 )
139                 IPUtil.vpp_add_ip_neighbor(
140                     topology["DUT2"], dut_int1, f"2003:{l}::1", dut_mac2
141                 )
142             IPUtil.vpp_add_ip_neighbor(
143                 topology[dut], dut_int2, f"2002:{l}::1",
144                 topology[f"TG_pf{i+1}_mac"][0]
145             )
146
147             IPUtil.vpp_interface_set_ip_address(
148                 topology["DUT1"], dut1_int1, f"2001:{l}::2", 64
149             )
150             if dut == "DUT2":
151                 IPUtil.vpp_interface_set_ip_address(
152                     topology["DUT1"], dut1_int2, f"2003:{l}::1", 64
153                 )
154                 IPUtil.vpp_interface_set_ip_address(
155                     topology["DUT2"], dut_int1, f"2003:{l}::2", 64
156                 )
157             IPUtil.vpp_interface_set_ip_address(
158                 topology[dut], dut_int2, f"2002:{l}::2", 64
159             )
160
161             IPUtil.vpp_route_add(
162                 topology["DUT1"], f"2{i}00::0", route_prefix,
163                 gateway=f"2001:{l}::1", interface=dut1_int1, count=count
164             )
165             if dut == "DUT2":
166                 IPUtil.vpp_route_add(
167                     topology["DUT1"], f"2{i+1}00::0", route_prefix,
168                     gateway=f"2003:{l}::2", interface=dut1_int2, count=count
169                 )
170                 IPUtil.vpp_route_add(
171                     topology["DUT2"], f"2{i}00::0", route_prefix,
172                     gateway=f"2003:{l}::1", interface=dut_int1, count=count
173                 )
174             IPUtil.vpp_route_add(
175                 topology[dut], f"2{i+1}00::0", route_prefix,
176                 gateway=f"2002:{l}::1", interface=dut_int2, count=count
177             )