1 # Copyright (c) 2023 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, parallel_links=1):
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 parallel_links: Number of parallel links to configure.
33 :type parallel_links: int
35 topology = BuiltIn().get_variable_value("&{topology_info}")
36 dut = topology["duts"][-1]
37 ifl = BuiltIn().get_variable_value("${int}")
39 for l, i in zip(range(parallel_links), range(1, parallel_links*2, 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]")
45 IPUtil.vpp_add_ip_neighbor(
46 topology["DUT1"], dut1_int1, f"1.{l}.1.1",
47 topology[f"TG_pf{i}_mac"][0]
50 dut_mac1 = BuiltIn().get_variable_value(
51 f"${{{dut}_{ifl}{i}_mac}}[0]"
53 IPUtil.vpp_add_ip_neighbor(
54 topology["DUT1"], dut1_int2, f"3.{l}.3.2", dut_mac1
56 dut_mac2 = BuiltIn().get_variable_value(
57 f"${{DUT1_{ifl}{i+1}_mac}}[0]"
59 IPUtil.vpp_add_ip_neighbor(
60 topology["DUT2"], dut_int1, f"3.{l}.3.1", dut_mac2
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]
67 IPUtil.vpp_interface_set_ip_address(
68 topology["DUT1"], dut1_int1, f"1.{l}.1.2", 30
71 IPUtil.vpp_interface_set_ip_address(
72 topology["DUT1"], dut1_int2, f"3.{l}.3.1", 30
74 IPUtil.vpp_interface_set_ip_address(
75 topology["DUT2"], dut_int1, f"3.{l}.3.2", 30
77 IPUtil.vpp_interface_set_ip_address(
78 topology[dut], dut_int2, f"2.{l}.2.2", 30
82 topology["DUT1"], f"{i}0.0.0.0", 32, gateway=f"1.{l}.1.1",
83 interface=dut1_int1, count=count
87 topology["DUT1"], f"{i+1}0.0.0.0", 32, gateway=f"3.{l}.3.2",
88 interface=dut1_int2, count=count
91 topology["DUT2"], f"{i}0.0.0.0", 32, gateway=f"3.{l}.3.1",
92 interface=dut_int1, count=count
95 topology[dut], f"{i+1}0.0.0.0", 32, gateway=f"2.{l}.2.1",
96 interface=dut_int2, count=count