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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
14 """IP Topology Library."""
16 from robot.libraries.BuiltIn import BuiltIn
18 from resources.libraries.python.IPUtil import IPUtil
22 """IP Topology Library."""
25 def initialize_ipv4_forwarding(count=1, pfs=2, route_prefix=32):
27 Custom setup of IPv4 forwarding with scalability of IP routes on all
28 DUT nodes in 2-node / 3-node circular topology.
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.
35 :type route_prefix: int
37 topology = BuiltIn().get_variable_value("&{topology_info}")
38 dut = topology["duts"][-1]
39 ifl = BuiltIn().get_variable_value("${int}")
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]")
47 IPUtil.vpp_add_ip_neighbor(
48 topology["DUT1"], dut1_int1, f"1.{l}.1.1",
49 topology[f"TG_pf{i}_mac"][0]
52 dut_mac1 = BuiltIn().get_variable_value(
53 f"${{{dut}_{ifl}{i}_mac}}[0]"
55 IPUtil.vpp_add_ip_neighbor(
56 topology["DUT1"], dut1_int2, f"3.{l}.3.2", dut_mac1
58 dut_mac2 = BuiltIn().get_variable_value(
59 f"${{DUT1_{ifl}{i+1}_mac}}[0]"
61 IPUtil.vpp_add_ip_neighbor(
62 topology["DUT2"], dut_int1, f"3.{l}.3.1", dut_mac2
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]
69 IPUtil.vpp_interface_set_ip_address(
70 topology["DUT1"], dut1_int1, f"1.{l}.1.2", 30
73 IPUtil.vpp_interface_set_ip_address(
74 topology["DUT1"], dut1_int2, f"3.{l}.3.1", 30
76 IPUtil.vpp_interface_set_ip_address(
77 topology["DUT2"], dut_int1, f"3.{l}.3.2", 30
79 IPUtil.vpp_interface_set_ip_address(
80 topology[dut], dut_int2, f"2.{l}.2.2", 30
84 topology["DUT1"], f"{i}0.0.0.0", route_prefix,
85 gateway=f"1.{l}.1.1", interface=dut1_int1, count=count
89 topology["DUT1"], f"{i+1}0.0.0.0", route_prefix,
90 gateway=f"3.{l}.3.2", interface=dut1_int2, count=count
93 topology["DUT2"], f"{i}0.0.0.0", route_prefix,
94 gateway=f"3.{l}.3.1", interface=dut_int1, count=count
97 topology[dut], f"{i+1}0.0.0.0", route_prefix,
98 gateway=f"2.{l}.2.1", interface=dut_int2, count=count
103 def initialize_ipv6_forwarding(count=1, pfs=2, route_prefix=128):
105 Custom setup of IPv6 forwarding with scalability of IP routes on all
106 DUT nodes in 2-node / 3-node circular topology.
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.
113 :type route_prefix: int
115 topology = BuiltIn().get_variable_value("&{topology_info}")
116 dut = topology["duts"][-1]
117 ifl = BuiltIn().get_variable_value("${int}")
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]")
125 IPUtil.vpp_add_ip_neighbor(
126 topology["DUT1"], dut1_int1, f"2001:{l}::1",
127 topology[f"TG_pf{i}_mac"][0]
130 dut_mac1 = BuiltIn().get_variable_value(
131 f"${{{dut}_{ifl}{i}_mac}}[0]"
133 IPUtil.vpp_add_ip_neighbor(
134 topology["DUT1"], dut1_int2, f"2003:{l}::2", dut_mac1
136 dut_mac2 = BuiltIn().get_variable_value(
137 f"${{DUT1_{ifl}{i+1}_mac}}[0]"
139 IPUtil.vpp_add_ip_neighbor(
140 topology["DUT2"], dut_int1, f"2003:{l}::1", dut_mac2
142 IPUtil.vpp_add_ip_neighbor(
143 topology[dut], dut_int2, f"2002:{l}::1",
144 topology[f"TG_pf{i+1}_mac"][0]
147 IPUtil.vpp_interface_set_ip_address(
148 topology["DUT1"], dut1_int1, f"2001:{l}::2", 64
151 IPUtil.vpp_interface_set_ip_address(
152 topology["DUT1"], dut1_int2, f"2003:{l}::1", 64
154 IPUtil.vpp_interface_set_ip_address(
155 topology["DUT2"], dut_int1, f"2003:{l}::2", 64
157 IPUtil.vpp_interface_set_ip_address(
158 topology[dut], dut_int2, f"2002:{l}::2", 64
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
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
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
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