Skip to content

Fix BGP pcap parsing in test_bgp_suppress_fib with scapy TCPSession#24007

Open
mike-dubrovsky wants to merge 1 commit into
sonic-net:masterfrom
mike-dubrovsky:tcp_reassemble
Open

Fix BGP pcap parsing in test_bgp_suppress_fib with scapy TCPSession#24007
mike-dubrovsky wants to merge 1 commit into
sonic-net:masterfrom
mike-dubrovsky:tcp_reassemble

Conversation

@mike-dubrovsky
Copy link
Copy Markdown
Contributor

Description of PR

Summary:
Enable scapy TCP reassembly (TCPSession) when parsing BGP pcap captures in test_bgp_suppress_fib.py, fixing AttributeError: prefix crashes caused by BGP UPDATE messages that span multiple TCP segments.

This is a follow-up to #21843 which added hasattr guards for IPv4 routes as a workaround for the same underlying issue. That PR treated the symptom (malformed route objects) but not the root cause (lack of TCP reassembly).

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Approach

What is the motivation for this PR?

test_suppress_fib_performance fails with AttributeError: prefix when parsing IPv6 BGP routes from pcap files. The root cause is that scapy.sniff() without session=TCPSession parses each TCP segment independently. When a large BGP UPDATE message (carrying many IPv6 routes) spans multiple TCP segments, scapy produces malformed/incomplete NLRI route objects that lack a prefix attribute.

#21843 partially addressed this by adding hasattr(route, 'prefix') guards for the IPv4 loops, but the IPv6 loops were left unprotected, and the root cause (missing TCP reassembly) was not fixed.

Scapy 2.7.0 added BGP TCP reassembly support (secdev/scapy#4756), but it must be explicitly enabled by passing session=TCPSession to sniff().

How did you do it?

  1. Added from scapy.sessions import TCPSession import.
  2. Passed session=TCPSession to the sniff() call in validate_route_process_perf(), so scapy reassembles the TCP stream before parsing BGP messages.

How did you verify/test it?

Tested on T1 isolated Cisco-8101 DUT. The test_suppress_fib_performance test that previously failed with AttributeError: prefix now passes consistently.

Any platform specific information?

No platform specific changes. The fix applies to all platforms.

Supported testbed topology if it's a new test case?

N/A - existing test case fix.

Documentation

N/A

Use scapy's TCPSession to reassemble BGP messages that span multiple
TCP segments before parsing. Without this, large BGP UPDATE messages
(especially with many IPv6 routes) get parsed per-packet, producing
malformed route objects that lack a 'prefix' attribute and cause
AttributeError.

Signed-off-by: mike-dubrovsky <mdubrovs@cisco.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mike-dubrovsky mike-dubrovsky changed the title Enable TCP reassembly for BGP pcap parsing in test_bgp_suppress_fib Fix BGP pcap parsing in test_bgp_suppress_fib with scapy TCPSession Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants