Skip to content

Commit

Permalink
v6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
selldinesh committed Jul 2, 2021
1 parent b05bf49 commit bcd03b7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 23 deletions.
24 changes: 24 additions & 0 deletions tests/common/snappi/common_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down Expand Up @@ -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
Expand Down
73 changes: 50 additions & 23 deletions tests/common/snappi/snappi_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -40,63 +40,90 @@ 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:
duthost (pytest fixture): duthost fixture
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):
Expand Down

0 comments on commit bcd03b7

Please sign in to comment.