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