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
20 changes: 19 additions & 1 deletion tests/bgp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from bgp_helpers import DUMP_FILE, CUSTOM_DUMP_SCRIPT, CUSTOM_DUMP_SCRIPT_DEST, BGPMON_TEMPLATE_FILE, BGPMON_CONFIG_FILE, BGP_MONITOR_NAME, BGP_MONITOR_PORT
from tests.common.helpers.constants import DEFAULT_NAMESPACE
from tests.common.dualtor.dual_tor_utils import mux_cable_server_ip
from tests.common import constants


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -274,10 +275,13 @@ def _setup_interfaces_dualtor(mg_facts, peer_count):
def _setup_interfaces_t0(mg_facts, peer_count):
try:
connections = []
is_backend_topo = "backend" in tbinfo["topo"]["name"]
vlan_intf = _find_vlan_intferface(mg_facts)
vlan_intf_name = vlan_intf["attachto"]
vlan_intf_addr = "%s/%s" % (vlan_intf["addr"], vlan_intf["prefixlen"])
vlan_members = mg_facts["minigraph_vlans"][vlan_intf_name]["members"]
is_vlan_tagged = mg_facts["minigraph_vlans"][vlan_intf_name].get("type", "").lower() == "tagged"
vlan_id = mg_facts["minigraph_vlans"][vlan_intf_name]["vlanid"]
local_interfaces = random.sample(vlan_members, peer_count)
neighbor_addresses = generate_ips(
peer_count,
Expand All @@ -299,6 +303,8 @@ def _setup_interfaces_t0(mg_facts, peer_count):
conn["local_addr"] = vlan_intf_addr
conn["neighbor_addr"] = neighbor_addr
conn["neighbor_intf"] = "eth%s" % mg_facts["minigraph_port_indices"][local_intf]
if is_backend_topo and is_vlan_tagged:
conn["neighbor_intf"] += (constants.VLAN_SUB_INTERFACE_SEPARATOR + vlan_id)
conn["loopback_ip"] = loopback_ip
connections.append(conn)

Expand All @@ -318,6 +324,7 @@ def _setup_interfaces_t0(mg_facts, peer_count):
def _setup_interfaces_t1(mg_facts, peer_count):
try:
connections = []
is_backend_topo = "backend" in tbinfo["topo"]["name"]
ipv4_interfaces = []
used_subnets = set()
if mg_facts["minigraph_interfaces"]:
Expand All @@ -337,6 +344,13 @@ def _setup_interfaces_t1(mg_facts, peer_count):
ipv4_lag_interfaces.append(pt["attachto"])
used_subnets.add(ipaddress.ip_network(pt["subnet"]))

vlan_sub_interfaces = []
if is_backend_topo:
for intf in mg_facts.get("minigraph_vlan_sub_interfaces"):
if _is_ipv4_address(intf["addr"]):
vlan_sub_interfaces.append(intf["attachto"])
used_subnets.add(ipaddress.ip_network(intf["subnet"]))

subnet_prefixlen = list(used_subnets)[0].prefixlen
_subnets = ipaddress.ip_network(u"10.0.0.0/24").subnets(new_prefix=subnet_prefixlen)
subnets = (_ for _ in _subnets if _ not in used_subnets)
Expand All @@ -349,7 +363,7 @@ def _setup_interfaces_t1(mg_facts, peer_count):
if not loopback_ip:
pytest.fail("ipv4 lo interface not found")

for intf, subnet in zip(random.sample(ipv4_interfaces + ipv4_lag_interfaces, peer_count), subnets):
for intf, subnet in zip(random.sample(ipv4_interfaces + ipv4_lag_interfaces + vlan_sub_interfaces, peer_count), subnets):
conn = {}
local_addr, neighbor_addr = [_ for _ in subnet][:2]
conn["local_intf"] = "%s" % intf
Expand All @@ -361,6 +375,10 @@ def _setup_interfaces_t1(mg_facts, peer_count):
member_intf = mg_facts["minigraph_portchannels"][intf]["members"][0]
conn["neighbor_intf"] = "eth%s" % mg_facts["minigraph_port_indices"][member_intf]
conn["namespace"] = mg_facts["minigraph_portchannels"][intf]["namespace"]
elif constants.VLAN_SUB_INTERFACE_SEPARATOR in intf:
orig_intf, vlan_id = intf.split(constants.VLAN_SUB_INTERFACE_SEPARATOR)
ptf_port_index = str(mg_facts["minigraph_port_indices"][orig_intf])
conn["neighbor_intf"] = "eth" + ptf_port_index + constants.VLAN_SUB_INTERFACE_SEPARATOR + vlan_id
else:
conn["neighbor_intf"] = "eth%s" % mg_facts["minigraph_port_indices"][intf]
connections.append(conn)
Expand Down
2 changes: 1 addition & 1 deletion tests/bgp/test_bgp_update_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def bgp_update_packets(pcap_file):
"""Get bgp update packets from pcap file."""
packets = sniff(
offline=pcap_file,
lfilter=lambda p: bgp.BGPHeader in p and p[bgp.BGPHeader].type == 2
lfilter=lambda p: IP in p and bgp.BGPHeader in p and p[bgp.BGPHeader].type == 2
)
return packets

Expand Down