|
4 | 4 | import binascii
|
5 | 5 | import netaddr
|
6 | 6 | import struct
|
| 7 | +import math |
7 | 8 |
|
8 | 9 | from tests.common.helpers.assertions import pytest_require, pytest_assert
|
9 | 10 |
|
@@ -214,16 +215,16 @@ def setup(rand_selected_dut, rand_unselected_dut, tbinfo, vlan_name, topo_scenar
|
214 | 215 | scale_dest_ips[ipv4_rule_name] = ipv4_address
|
215 | 216 | scale_dest_ips[ipv6_rule_name] = ipv6_address
|
216 | 217 |
|
217 |
| - vlan_ips = {} |
218 |
| - |
219 |
| - for vlan_interface_info_dict in mg_facts['minigraph_vlan_interfaces']: |
220 |
| - if netaddr.IPAddress(str(vlan_interface_info_dict['addr'])).version == 6: |
221 |
| - vlan_ips["V6"] = vlan_interface_info_dict['addr'] |
222 |
| - elif netaddr.IPAddress(str(vlan_interface_info_dict['addr'])).version == 4: |
223 |
| - vlan_ips["V4"] = vlan_interface_info_dict['addr'] |
224 |
| - |
225 | 218 | config_facts = rand_selected_dut.config_facts(host=rand_selected_dut.hostname, source="running")['ansible_facts']
|
226 | 219 |
|
| 220 | + vlan_ips = {} |
| 221 | + for vlan_ip_address in config_facts['VLAN_INTERFACE'][vlan_name].keys(): |
| 222 | + ip_address = vlan_ip_address.split("/")[0] |
| 223 | + if netaddr.IPAddress(str(ip_address)).version == 6: |
| 224 | + vlan_ips["V6"] = ip_address |
| 225 | + elif netaddr.IPAddress(str(ip_address)).version == 4: |
| 226 | + vlan_ips["V4"] = ip_address |
| 227 | + |
227 | 228 | vlans = config_facts['VLAN']
|
228 | 229 | topology = tbinfo['topo']['name']
|
229 | 230 | dut_mac = ''
|
@@ -381,14 +382,25 @@ def prepare_ptf_intf_and_ip(request, rand_selected_dut, config_facts, intfs_for_
|
381 | 382 | except ValueError:
|
382 | 383 | continue
|
383 | 384 |
|
| 385 | + vlan_num = len(config_facts['VLAN_INTERFACE']) |
| 386 | + logging.info("It has {} vlan.".format(config_facts['VLAN_INTERFACE'].keys())) |
| 387 | + # by default, if it's 2 vlan config, ipv4 range for vlan1000 is 192.168.0.1/25 |
| 388 | + # and ipv4 range for vlan2000 192.168.0.129/25, so set increment to 65, |
| 389 | + # ptf_intf_ipv4_addr will be in the first VLAN's IP range. |
| 390 | + # otherwise, incrementing by 129 will cause ptf_intf_ipv4_addr overlap within the second VLAN's IP range |
| 391 | + |
| 392 | + # For 1 vlan, increment is 129 |
| 393 | + # for 2 vlans, increment is 65 |
| 394 | + increment = math.ceil(129 / vlan_num) |
| 395 | + |
384 | 396 | # Increment address by 3 to offset it from the intf on which the address may be learned
|
385 | 397 | if intf_ipv4_addr is not None:
|
386 |
| - ptf_intf_ipv4_addr = increment_ipv4_addr(intf_ipv4_addr.network_address, incr=129) |
| 398 | + ptf_intf_ipv4_addr = increment_ipv4_addr(intf_ipv4_addr.network_address, incr=increment) |
387 | 399 | else:
|
388 | 400 | ptf_intf_ipv4_addr = None
|
389 | 401 |
|
390 | 402 | if intf_ipv6_addr is not None:
|
391 |
| - ptf_intf_ipv6_addr = increment_ipv6_addr(intf_ipv6_addr.network_address, incr=129) |
| 403 | + ptf_intf_ipv6_addr = increment_ipv6_addr(intf_ipv6_addr.network_address, incr=increment) |
392 | 404 | else:
|
393 | 405 | ptf_intf_ipv6_addr = None
|
394 | 406 |
|
|
0 commit comments