Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions tests/acl/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ptf.testutils as testutils
import ptf.mask as mask
import ptf.packet as packet
import re

from abc import ABCMeta, abstractmethod
from collections import defaultdict
Expand All @@ -21,8 +22,9 @@
from tests.common.fixtures.ptfhost_utils import copy_arp_responder_py, run_garp_service, change_mac_addresses # noqa F401
from tests.common.dualtor.dual_tor_mock import mock_server_base_ip_addr # noqa F401
from tests.common.helpers.constants import DEFAULT_NAMESPACE
from tests.common.utilities import wait_until, get_upstream_neigh_type, get_downstream_neigh_type, check_msg_in_syslog
from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa F401
from tests.common.utilities import wait_until, check_msg_in_syslog
from tests.common.utilities import get_all_upstream_neigh_type, get_downstream_neigh_type
from tests.common.fixtures.conn_graph_facts import conn_graph_facts # noqa: F401
from tests.common.platform.processes_utils import wait_critical_processes
from tests.common.platform.interface_utils import check_all_interface_information
from tests.common.utilities import get_iface_ip
Expand Down Expand Up @@ -346,9 +348,9 @@ def setup(duthosts, ptfhost, rand_selected_dut, rand_unselected_dut, tbinfo, ptf
downstream_port_id_to_router_mac_map = t2_info['downstream_port_id_to_router_mac_map']
upstream_port_id_to_router_mac_map = t2_info['upstream_port_id_to_router_mac_map']
else:
upstream_neigh_type = get_upstream_neigh_type(topo)
upstream_neigh_types = get_all_upstream_neigh_type(topo)
downstream_neigh_type = get_downstream_neigh_type(topo)
pytest_require(upstream_neigh_type is not None and downstream_neigh_type is not None,
pytest_require(len(upstream_neigh_types) > 0 and downstream_neigh_type is not None,
"Cannot get neighbor type for unsupported topo: {}".format(topo))
mg_vlans = mg_facts["minigraph_vlans"]
for interface, neighbor in list(mg_facts["minigraph_neighbors"].items()):
Expand All @@ -361,10 +363,11 @@ def setup(duthosts, ptfhost, rand_selected_dut, rand_unselected_dut, tbinfo, ptf
downstream_ports[neighbor['namespace']].append(interface)
downstream_port_ids.append(port_id)
downstream_port_id_to_router_mac_map[port_id] = downlink_dst_mac
elif upstream_neigh_type in neighbor["name"].upper():
upstream_ports[neighbor['namespace']].append(interface)
upstream_port_ids.append(port_id)
upstream_port_id_to_router_mac_map[port_id] = rand_selected_dut.facts["router_mac"]
for neigh_type in upstream_neigh_types:
if neigh_type in neighbor["name"].upper():
upstream_ports[neighbor['namespace']].append(interface)
upstream_port_ids.append(port_id)
upstream_port_id_to_router_mac_map[port_id] = rand_selected_dut.facts["router_mac"]

# stop garp service for single tor
if 'dualtor' not in tbinfo['topo']['name']:
Expand Down Expand Up @@ -397,9 +400,18 @@ def setup(duthosts, ptfhost, rand_selected_dut, rand_unselected_dut, tbinfo, ptf
# In multi-asic we need config both in host and namespace.
if namespace:
acl_table_ports[''] += port

if topo in ["t0", "m0_vlan", "m0_l3"] or tbinfo["topo"]["name"] in ("t1-lag", "t1-64-lag", "t1-64-lag-clet",
"t1-56-lag", "t1-28-lag", "t1-32-lag"):
if (
len(port_channels)
and (
topo in ["t0", "m0_vlan", "m0_l3"]
or tbinfo["topo"]["name"] in (
"t1-lag", "t1-64-lag", "t1-64-lag-clet",
"t1-56-lag", "t1-28-lag", "t1-32-lag"
)
or 't1-isolated' in tbinfo["topo"]["name"]
)
and not re.match(r"t0-.*s\d+", tbinfo["topo"]["name"])
):
for k, v in list(port_channels.items()):
acl_table_ports[v['namespace']].append(k)
# In multi-asic we need config both in host and namespace.
Expand Down
3 changes: 2 additions & 1 deletion tests/acl/test_stress_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def prepare_test_port(rand_selected_dut, tbinfo):
upstream_port_ids = []
for interface, neighbor in list(mg_facts["minigraph_neighbors"].items()):
port_id = mg_facts["minigraph_ptf_indices"][interface]
if (topo == "t1" and "T2" in neighbor["name"]) or (topo == "t0" and "T1" in neighbor["name"]) or \
if (topo == "t1" and "T2" in neighbor["name"]) or \
(topo == "t0" and ("T1" in neighbor["name"] or "PT0" in neighbor["name"])) or \
(topo == "m0" and "M1" in neighbor["name"]) or (topo == "mx" and "M0" in neighbor["name"]):
upstream_ports[neighbor['namespace']].append(interface)
upstream_port_ids.append(port_id)
Expand Down
25 changes: 25 additions & 0 deletions tests/common/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@
"m0_vlan": "m1",
"m0_l3": "m1"
}

# Describe ALL upstream neighbor of dut in different topos
UPSTREAM_ALL_NEIGHBOR_MAP = {
"t0": ["t1", "pt0"],
"t1": ["t2"],
"m1": ["ma", "mb"],
"m0": ["m1"],
"mx": ["m0"],
"t2": ["t3"],
"m0_vlan": ["m1"],
"m0_l3": ["m1"],
}

# Describe downstream neighbor of dut in different topos
DOWNSTREAM_NEIGHBOR_MAP = {
"t0": "server",
Expand All @@ -29,3 +42,15 @@
"m0_vlan": "server",
"m0_l3": "mx"
}

# Describe downstream neighbor of dut in different topos
DOWNSTREAM_ALL_NEIGHBOR_MAP = {
"t0": ["server"],
"t1": ["t0"],
"m1": ["m0", "c0"],
"m0": ["mx", "server"],
"mx": ["server"],
"t2": ["t1"],
"m0_vlan": ["mx", "server"],
"m0_l3": ["mx", "server"],
}
2 changes: 1 addition & 1 deletion tests/common/helpers/ptf_tests_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def upstream_links(rand_selected_dut, tbinfo, nbrhosts):
duthost = rand_selected_dut

def filter(interface, neighbor, mg_facts, tbinfo):
if ((tbinfo["topo"]["type"] == "t0" and "T1" in neighbor["name"])
if ((tbinfo["topo"]["type"] == "t0" and ("T1" in neighbor["name"] or "PT0" in neighbor["name"]))
or (tbinfo["topo"]["type"] == "t1" and "T2" in neighbor["name"])):
for item in mg_facts["minigraph_bgp"]:
if item["name"] == neighbor["name"]:
Expand Down
29 changes: 28 additions & 1 deletion tests/common/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from tests.common import constants
from tests.common.cache import cached
from tests.common.cache import FactsCache
from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, DOWNSTREAM_NEIGHBOR_MAP
from tests.common.helpers.constants import UPSTREAM_NEIGHBOR_MAP, UPSTREAM_ALL_NEIGHBOR_MAP
from tests.common.helpers.constants import DOWNSTREAM_NEIGHBOR_MAP, DOWNSTREAM_ALL_NEIGHBOR_MAP
from tests.common.helpers.assertions import pytest_assert
from netaddr import valid_ipv6

Expand Down Expand Up @@ -878,6 +879,19 @@ def get_upstream_neigh_type(topo_type, is_upper=True):
return None


def get_all_upstream_neigh_type(topo_type, is_upper=True):
"""
@summary: Get ALL upstream neighbor type by topo type
@param topo_type: topo type
@param is_upper: if is_upper is True, return uppercase str, else return lowercase str
@return a list
Sample output: ["ma", "mb"]
"""
if is_upper:
return [neigh.upper() for neigh in UPSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, [])]
return UPSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, [])


def get_downstream_neigh_type(topo_type, is_upper=True):
"""
@summary: Get neighbor type by topo type
Expand All @@ -892,6 +906,19 @@ def get_downstream_neigh_type(topo_type, is_upper=True):
return None


def get_all_downstream_neigh_type(topo_type, is_upper=True):
"""
@summary: Get ALL downstream neighbor type by topo type
@param topo_type: topo type
@param is_upper: if is_upper is True, return uppercase str, else return lowercase str
@return a list
Sample output: ["m0", "c0"]
"""
if is_upper:
return [neigh.upper() for neigh in DOWNSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, [])]
return DOWNSTREAM_ALL_NEIGHBOR_MAP.get(topo_type, [])


def run_until(interval, delay, retry, condition, function, *args, **kwargs):
"""
@summary: Execute function until condition or retry number met.
Expand Down
Loading