Skip to content

#1754 Add Modbus Support #1823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: dev
Choose a base branch
from
Draft

Conversation

yahyayozo
Copy link

  • Add ModbusLayer first implementation with header parsing only (no test included)

@yahyayozo yahyayozo requested a review from seladb as a code owner May 18, 2025 18:15
@yahyayozo yahyayozo marked this pull request as draft May 18, 2025 18:16
Copy link

codecov bot commented May 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.00%. Comparing base (8bcb200) to head (166c15c).
Report is 4 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1823      +/-   ##
==========================================
+ Coverage   80.40%   83.00%   +2.59%     
==========================================
  Files         278      284       +6     
  Lines       44998    48877    +3879     
  Branches    10245    10560     +315     
==========================================
+ Hits        36180    40569    +4389     
- Misses       7033     7526     +493     
+ Partials     1785      782    -1003     
Flag Coverage Δ
alpine320 75.06% <ø> (+0.01%) ⬆️
fedora42 75.15% <ø> (+0.01%) ⬆️
macos-13 80.53% <ø> (+0.01%) ⬆️
macos-14 80.53% <ø> (+0.01%) ⬆️
macos-15 80.51% <ø> (+0.01%) ⬆️
mingw32 71.39% <ø> (?)
mingw64 71.34% <ø> (?)
npcap 85.02% <ø> (?)
rhel94 74.93% <ø> (+0.02%) ⬆️
ubuntu2004 58.52% <ø> (+<0.01%) ⬆️
ubuntu2004-zstd 58.66% <ø> (+0.02%) ⬆️
ubuntu2204 74.85% <ø> (-0.01%) ⬇️
ubuntu2204-icpx 61.49% <ø> (+<0.01%) ⬆️
ubuntu2404 75.11% <ø> (+0.04%) ⬆️
ubuntu2404-arm64 75.07% <ø> (-0.01%) ⬇️
unittest 83.00% <ø> (+2.59%) ⬆️
windows-2019 85.04% <ø> (?)
windows-2022 85.06% <ø> (?)
winpcap 85.20% <ø> (?)
xdp 50.51% <ø> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@Dimi1010 Dimi1010 linked an issue May 19, 2025 that may be closed by this pull request
@yahyayozo yahyayozo marked this pull request as ready for review May 21, 2025 20:13
@yahyayozo
Copy link
Author

yahyayozo commented May 21, 2025

@seladb I've prepared only 1 constructor which initiates the layer with default fields values
Can you please mention what are the other constructors I need to implement? also please mention if I need to follow on other protocols layers?

@seladb
Copy link
Owner

seladb commented May 22, 2025

@yahyayozo we usually have at least 2 c'tors, sometimes more:

  1. As part of the packet parsing flow. For example:
    MplsLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
    which is used here (and in some other places also):
    m_NextLayer = new MplsLayer(payload, payloadLen, this, m_Packet);
  2. When the user wants to create a new layer of this type. This is the c'tor you already implemented, but usually we don't implement (only) c'tors with zero arguments. We tend to implement c'tors that allow the user to build the layer. In your case, I'd add arguments like transactionId, unitId and functionCode

@yahyayozo
Copy link
Author

Hi @seladb can you please guide me briefly on how to add tests for my ModbusLayer for parsing/crafting headers? As I want to pass to function types request/response after testing the header part.

@seladb
Copy link
Owner

seladb commented May 25, 2025

@yahyayozo sure! You can learn about tests here: https://pcapplusplus.github.io/docs/tests

At a high level:

  • You should add your tests under Tests/Packet++Test/Tests (don't forget to add your .cpp file to CMakeFiles.txt)
  • The tests use a homegrown testing framework. A test case is PTF_TEST_CASE. You can write 3 of those: for parsing, crafting, and editing
  • You can find the possible assertions here, the most common one is PTF_ASSERT_EQUAL(actual, expected)
  • You need to add your test cases to https://github.com/seladb/PcapPlusPlus/blob/master/Tests/Packet%2B%2BTest/main.cpp and add a PTF_RUN_TEST for each test case
  • When you build the tests, you should run them from the Tests/Packet++Test directory, like this: Bin/Packet++Test -t <YOUR_TEST_CASE>

Please look at similar tests that were written for other layers and follow the same patterns.

Please let me know if you have any questions.

@yahyayozo
Copy link
Author

@seladb I'll add tests for the headers crafting/parsing implementation and then you can a review before we move to adding the different PDU types

@yahyayozo yahyayozo marked this pull request as draft May 28, 2025 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Modbus Protocol Support
3 participants