Skip to content

Add serialization support for BgpLayer (all message types) - #2366

Merged
seladb merged 3 commits into
seladb:devfrom
Hack15951:feature/bgp-layer-serialization
Nov 20, 2026
Merged

seladb merged 3 commits into
seladb:devfrom
Hack15951:feature/bgp-layer-serialization

Conversation

@Hack15951

Copy link
Copy Markdown

Description

Implements structured serialization for BgpLayer, as part of the serialization rollout tracked in #2278 (claims the BgpLayer task approved by @seladb in that issue).

BgpLayer now provides:

  • A SerializedFields struct declaring every field as a FieldDescriptor (units, byte order and string formats documented in Doxygen comments), including Layer::SerializedFields.
  • A serializeLayer(ObjectScope&) override that writes every field from all().
  • Tests covering the serialized output and asserting that all() matches what is written.

Covers all BGP message types: OPEN, UPDATE, NOTIFICATION, KEEPALIVE, ROUTE-REFRESH.

Definition of done (per #2278)

  • SerializedFields struct with a FieldDescriptor per field and all(), including Layer::SerializedFields
  • serializeLayer(ObjectScope&) override writing every field in all()
  • Doxygen comments on all fields (units, byte order, string formats)
  • Tests covering serialized output and all() match

Notes

  • Local pre-commit run --files is clean: clang-format passes; cppcheck reports only the pre-existing Logger.h functionStatic (cppcheck 2.22 is stricter than the CI's 2.9) — no issues in the added code.
  • Separate concern from PR Reject invalid BGP OPEN optional parameters #2303 (BGP OPEN optional-parameter validation); this PR is serialization-only.

Test plan

Tests/Packet++Test/Tests/BgpTests.cpp adds BGP serialization round-trip tests.

@Hack15951
Hack15951 requested a review from seladb as a code owner November 13, 2026 09:09
@seladb seladb mentioned this pull request Nov 13, 2026
46 of 49 tasks
Comment thread Packet++/header/BgpLayer.h Resolved
Comment thread Packet++/header/BgpLayer.h Resolved
Comment thread Packet++/src/BgpLayer.cpp Resolved
Comment thread Packet++/src/BgpLayer.cpp Resolved
Comment thread Packet++/header/BgpLayer.h Resolved
Comment thread Packet++/header/BgpLayer.h Resolved
Comment thread Packet++/header/BgpLayer.h Resolved
Comment thread Packet++/src/BgpLayer.cpp Resolved
Comment thread Packet++/src/BgpLayer.cpp Resolved
Comment thread Tests/Packet++Test/Tests/BgpTests.cpp Resolved
@Hack15951

Copy link
Copy Markdown
Author

Thanks @seladb for the thorough review! I've addressed all 11 comments:

1. Removed redundant field serialization (6 comments):

  • Removed marker (constant all-ones), optionalParameterLength, and reserved fields
  • Removed raw hex data serialization for optional parameters, path attributes, and notification data — these now only serialize structured fields (type/length)

2. Adopted ObjectFieldDescriptor<T> pattern (3 comments):

  • OptionalParameterObject, PathAttributeObject, and PrefixAndIpObject now inherit from ObjectFieldDescriptor<T>, following the SomeIpSdLayer example

3. Removed empty override (1 comment):

  • Deleted BgpKeepaliveMessageLayer::serializeLayer() which only called the base class

4. Moved serialization tests into existing parsing tests (1 comment):

  • Removed the standalone BgpLayerSerializationTest; JSON assertions are now inline in BgpLayerParsingTest, following the HttpTests pattern

Additional fix: While validating, I found the three ArrayScope objects in BgpUpdateMessageLayer::serializeLayer() weren't in separate block scopes, causing nested JSON arrays. Fixed by wrapping each in { ... }.

All 287 tests pass locally; clang-format and cppcheck are clean. Ready for re-review!

@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.72727% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.17%. Comparing base (c214e85) to head (8d4d552).
⚠️ Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
Packet++/header/BgpLayer.h 0.00% 3 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2366      +/-   ##
==========================================
+ Coverage   83.13%   83.17%   +0.04%     
==========================================
  Files         350      350              
  Lines       68819    68972     +153     
  Branches    14237    14759     +522     
==========================================
+ Hits        57212    57370     +158     
- Misses      10198    10650     +452     
+ Partials     1409      952     -457     
Flag Coverage Δ
23.11.6 6.57% <0.00%> (-0.02%) ⬇️
24.11.5 6.60% <0.00%> (+0.02%) ⬆️
25.11.1 6.56% <0.00%> (-0.03%) ⬇️
alpine320 77.32% <89.88%> (+0.05%) ⬆️
fedora42 76.85% <91.89%> (+0.05%) ⬆️
macos-15 83.16% <95.52%> (+0.04%) ⬆️
macos-26 83.16% <95.52%> (+0.04%) ⬆️
macos-26-intel 83.10% <95.52%> (+0.04%) ⬆️
mingw32 71.90% <89.83%> (+0.08%) ⬆️
mingw64 69.83% <89.83%> (+0.15%) ⬆️
npcap ?
rhel94 76.70% <91.89%> (+0.03%) ⬆️
ubuntu2204 76.74% <91.89%> (+0.05%) ⬆️
ubuntu2404 76.98% <91.89%> (+0.06%) ⬆️
ubuntu2604 76.92% <91.89%> (+0.04%) ⬆️
ubuntu2604-arm64 76.83% <89.88%> (+0.03%) ⬆️
ubuntu2604-icpx 57.98% <38.18%> (-0.10%) ⬇️
unittest 83.17% <92.72%> (+0.04%) ⬆️
windows-2022 85.75% <91.74%> (+0.14%) ⬆️
windows-2025 85.20% <87.50%> (+0.15%) ⬆️
winpcap 85.80% <91.74%> (+0.58%) ⬆️
xdp 56.50% <91.89%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@seladb
seladb merged commit c05793a into seladb:dev Nov 20, 2026
45 checks passed
@seladb

seladb commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @Hack15951 for working on this PR, much appreciated 🙏

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