From bcd03b782118434b83b1cd17c2ab2ed01b33d539 Mon Sep 17 00:00:00 2001 From: selldinesh Date: Fri, 2 Jul 2021 22:57:25 +0000 Subject: [PATCH] v6 support --- tests/common/snappi/common_helpers.py | 24 +++++++++ tests/common/snappi/snappi_fixtures.py | 73 ++++++++++++++++++-------- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/tests/common/snappi/common_helpers.py b/tests/common/snappi/common_helpers.py index 4f47e913b72..5cbb8dc771b 100644 --- a/tests/common/snappi/common_helpers.py +++ b/tests/common/snappi/common_helpers.py @@ -13,6 +13,8 @@ import ipaddr from netaddr import IPNetwork +from ipaddress import IPv6Network, IPv6Address +from random import getrandbits from tests.common.mellanox_data import is_mellanox_device as isMellanoxDevice def increment_ip_address(ip, incr=1) : @@ -119,6 +121,28 @@ def get_addrs_in_subnet(subnet, number_of_ip): return ip_addrs[:number_of_ip] +def get_ipv6_addrs_in_subnet(subnet, number_of_ip): + """ + Get N IPv6 addresses in a subnet. + Args: + subnet (str): IPv6 subnet, e.g., '2001::1/64' + number_of_ip (int): Number of IP addresses to get + Return: + Return n IPv6 addresses in this subnet in a list. + """ + + subnet = str(IPNetwork(subnet).network) + "/" + str(subnet.split("/")[1]) + subnet = unicode(subnet, "utf-8") + ipv6_list = [] + for i in range(number_of_ip): + network = IPv6Network(subnet) + address = IPv6Address( + network.network_address + getrandbits( + network.max_prefixlen - network.prefixlen)) + ipv6_list.append(str(address)) + + return ipv6_list + def get_peer_snappi_chassis(conn_data, dut_hostname): """ Get the IXIA chassis connected to the DUT diff --git a/tests/common/snappi/snappi_fixtures.py b/tests/common/snappi/snappi_fixtures.py index d80b029b536..420b95116a2 100644 --- a/tests/common/snappi/snappi_fixtures.py +++ b/tests/common/snappi/snappi_fixtures.py @@ -7,7 +7,7 @@ from tests.common.fixtures.conn_graph_facts import ( conn_graph_facts, fanout_graph_facts) from tests.common.snappi.common_helpers import ( - get_addrs_in_subnet,get_peer_snappi_chassis) + get_addrs_in_subnet,get_ipv6_addrs_in_subnet,get_peer_snappi_chassis) from tests.common.snappi.snappi_helpers import SnappiFanoutManager, get_snappi_port_location @pytest.fixture(scope="module") @@ -40,8 +40,11 @@ def snappi_api_serv_port(duthosts, rand_one_dut_hostname): ['snappi_api_server']['rest_port']) -@pytest.fixture(scope="function") -def tgen_ports(duthost,conn_graph_facts,fanout_graph_facts): +@pytest.fixture(scope="module") +def tgen_ports(duthost, + conn_graph_facts, + fanout_graph_facts): + """ Populate tgen ports info of T0 testbed and returns as a list Args: @@ -49,54 +52,78 @@ def tgen_ports(duthost,conn_graph_facts,fanout_graph_facts): conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph Return: - [{'card_id': '1', - 'ip': '21.1.1.2', + [{'card_id': '1', + 'ip': '22.1.1.2', + 'ipv6': '3001::2', + 'ipv6_prefix': u'64', 'location': '10.36.78.238;1;2', - 'prefix': u'24', - 'peer_ip': u'21.1.1.1', - 'peer_device': 'example-s6100-dut-1', - 'peer_port': 'Ethernet0', + 'peer_device': 'sonic-s6100-dut', + 'peer_ip': u'22.1.1.1', + 'peer_ipv6': u'3001::1', + 'peer_port': 'Ethernet8', 'port_id': '2', - 'speed': '400000'}, + 'prefix': u'24', + 'speed': 'speed_400_gbps'}, {'card_id': '1', - 'ip': '22.1.1.2', + 'ip': '21.1.1.2', + 'ipv6': '2001::2', + 'ipv6_prefix': u'64', 'location': '10.36.78.238;1;1', - 'prefix': u'24', - 'peer_ip': u'22.1.1.1', - 'peer_device': 'example-s6100-dut-1', - 'peer_port': 'Ethernet8', + 'peer_device': 'sonic-s6100-dut', + 'peer_ip': u'21.1.1.1', + 'peer_ipv6': u'2001::1', + 'peer_port': 'Ethernet0', 'port_id': '1', - 'speed': '400000'}] + 'prefix': u'24', + 'speed': 'speed_400_gbps'}] """ + speed_type = {'50000': 'speed_50_gbps', '100000': 'speed_100_gbps', '200000': 'speed_200_gbps', '400000': 'speed_400_gbps'} - snappi_fanout = get_peer_snappi_chassis(conn_data=conn_graph_facts,dut_hostname=duthost.hostname) + + snappi_fanout = get_peer_snappi_chassis(conn_data=conn_graph_facts, + dut_hostname=duthost.hostname) snappi_fanout_id = list(fanout_graph_facts.keys()).index(snappi_fanout) snappi_fanout_list = SnappiFanoutManager(fanout_graph_facts) snappi_fanout_list.get_fanout_device_details(device_number=snappi_fanout_id) snappi_ports = snappi_fanout_list.get_ports(peer_device=duthost.hostname) port_speed = None + for i in range(len(snappi_ports)): if port_speed is None: port_speed = int(snappi_ports[i]['speed']) + elif port_speed != int(snappi_ports[i]['speed']): """ All the ports should have the same bandwidth """ return None - config_facts = duthost.config_facts(host=duthost.hostname,source="running")['ansible_facts'] + + config_facts = duthost.config_facts(host=duthost.hostname, + source="running")['ansible_facts'] + for port in snappi_ports: port['location'] = get_snappi_port_location(port) port['speed'] = speed_type[port['speed']] + for port in snappi_ports: peer_port = port['peer_port'] - subnet = config_facts['INTERFACE'][peer_port].keys()[0] - if not subnet: - raise Exception("IP is not configured on the interface {}".format(peer_port)) - port['peer_ip'], port['prefix'] = subnet.split("/") - port['ip'] = get_addrs_in_subnet(subnet, 1)[0] + int_addrs = config_facts['INTERFACE'][peer_port].keys() + ipv4_subnet = [ele for ele in int_addrs if "." in ele][0] + if not ipv4_subnet: + raise Exception("IPv4 is not configured on the interface {}" + .format(peer_port)) + port['peer_ip'], port['prefix'] = ipv4_subnet.split("/") + port['ip'] = get_addrs_in_subnet(ipv4_subnet, 1)[0] + ipv6_subnet = [ele for ele in int_addrs if ":" in ele][0] + if not ipv6_subnet: + raise Exception("IPv6 is not configured on the interface {}" + .format(peer_port)) + port['peer_ipv6'], port['ipv6_prefix'] = ipv6_subnet.split("/") + port['ipv6'] = get_ipv6_addrs_in_subnet(ipv6_subnet, 1)[0] return snappi_ports + @pytest.fixture(scope='module') def cvg_api(snappi_api_serv_ip, snappi_api_serv_port):