Skip to content
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

Add RawNetworkInterfaceDriver, labgrid-raw-interface helper and example #1157

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

Bastian-Krause
Copy link
Member

Description
The RawNetworkInterfaceDriver allows "raw" control of a network interface (such as Ethernet or WiFi).

The newly added labgrid-raw-interface helper (helpers/labgrid-raw-interface) needs to be installed in the PATH and usable via sudo without password.

It supports:

  • recording traffic
  • replaying traffic
  • basic statistic collection

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • PR has been tested

@codecov
Copy link

codecov bot commented Apr 28, 2023

Codecov Report

Attention: 51 lines in your changes are missing coverage. Please review.

Comparison is base (e8fdd87) 62.9% compared to head (e3ee7f6) 62.7%.
Report is 21 commits behind head on master.

Files Patch % Lines
labgrid/driver/rawnetworkinterfacedriver.py 42.6% 51 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1157     +/-   ##
========================================
- Coverage    62.9%   62.7%   -0.2%     
========================================
  Files         161     163      +2     
  Lines       11888   12001    +113     
========================================
+ Hits         7486    7535     +49     
- Misses       4402    4466     +64     

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

Emantor
Emantor previously approved these changes Apr 28, 2023
@Emantor Emantor force-pushed the bst/network-test branch 3 times, most recently from 3d46606 to 9f26732 Compare May 4, 2023 13:45
Copy link
Member

@jluebbe jluebbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good otherwise.

@jluebbe jluebbe assigned Emantor and unassigned jluebbe May 17, 2023
@jluebbe
Copy link
Member

jluebbe commented May 24, 2023

We discussed this internally: The wrapper can be simplified by using stdin/stdout to pass packet data, as we don't need to create/open paths as root.

@Bastian-Krause
Copy link
Member Author

Rebased on master.

@Bastian-Krause
Copy link
Member Author

  • labgrid-raw-interface: use yaml instead of ini configs
  • change argument order
  • use shell redirection and stdin/stdout instead of using tcpdump's -Z and letting tcpump/tcpreplay write to capfile directly

@Bastian-Krause
Copy link
Member Author

  • labgrid-raw-interface: fix optional count argument
  • networkinterfacedriver: simplify capfile copy/close handling in get_record()
  • networkinterfacedriver: fix start_replay() for remote network interfaces

@Bastian-Krause
Copy link
Member Author

  • added documentation for /etc/labgrid/helpers.yaml
  • example: use basicConfig/StepLogger instead of StepReporter
  • labgrid-raw-interface: fix deny list defaults, always deny loopback interface
  • rawnetworkinterfacedriver: fix get_statistics()

@Bastian-Krause
Copy link
Member Author

  • rawnetworinterfacedriver: stdout is now redirected into a file in get_record(), so drop the obsolete out variable

@Bastian-Krause
Copy link
Member Author

The previous comments reflect the development history and should ease reviewing the changes.

@Bastian-Krause
Copy link
Member Author

  • labgrid-raw-interface: use longopts for tcpreplay

@Bastian-Krause
Copy link
Member Author

  • rawnetworkinterfacedriver: make start_replay() return process handle instead of waiting for the process to complete and returning a CompletedProcess

@Bastian-Krause Bastian-Krause force-pushed the bst/network-test branch 2 times, most recently from 3b6aaa0 to 481bc3e Compare October 12, 2023 14:25
@Bastian-Krause
Copy link
Member Author

Rebased one more time now that #1249 was merged.

Emantor
Emantor previously approved these changes Oct 12, 2023
@Emantor Emantor requested a review from jluebbe October 12, 2023 14:29
@jluebbe jluebbe assigned jluebbe and unassigned Emantor Oct 12, 2023
@Bastian-Krause
Copy link
Member Author

  • labgrid-raw-interface: fix wrapper path in sudoers comment
  • labgrid-raw-interface: raise exception on invalid config structure
  • rawnetworkinterfacedriver: keep single handle for record and replay instead of map, add sanity asserts to all record and replay methods
  • rawnetworkinterfacedriver: implement smarter _wrap_command() instead of _get_wrapper_prefix() and use it everywhere
  • rawnetworkinterfacedriver: add _stop() helper used by both stop_record() and stop_replay()
  • rawnetworkinterfacedriver: capture stderr on record/replay, raise CalledProcessError with return code, command, stderr on return code != 0
  • rawnetworkinterfacedriver: move filename to start_record()/start_replay() and simplify stdin/stdout handling
  • rawnetworkinterfacedriver: add contextmanager for record/replay
  • example: reduce example log level to INFO
  • example: improve/fix comments
  • example: fixed record count to 1
  • example: use os.path.join() to join path
  • example: use record contextmanager
  • example: call get_statistics() and get_address()

Example tested for remote and local use case.

Wrapper script to be deployed on machines whose network interfaces should be
controllable via the RawNetworkInterfaceDriver. A /etc/labgrid/helpers.yaml
can deny access to network interfaces. Intended to be used via sudo.

Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Signed-off-by: Bastian Krause <bst@pengutronix.de>
@Bastian-Krause
Copy link
Member Author

Rebased.

@Bastian-Krause
Copy link
Member Author

Addressed the review feedback by @jluebbe. Thanks!

jluebbe
jluebbe previously approved these changes Jan 11, 2024
Copy link
Member

@jluebbe jluebbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides #1157 (comment), this looks good. As that doesn't affect behavior, you could merge this as-is and address it in a separate PR.

This driver allows "raw" control of a network interface (such as Ethernet
or WiFi).

Signed-off-by: Bastian Krause <bst@pengutronix.de>
Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Generates an Ethernet frame via scapy using pcap, copies pcap to DUT,
replays pcap on interface, records frame locally (or on exporter, adjust
env.yaml accordingly), and compares both.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
@jluebbe jluebbe merged commit c301638 into labgrid-project:master Jan 11, 2024
8 of 10 checks passed
@Bastian-Krause Bastian-Krause deleted the bst/network-test branch January 11, 2024 16:49
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.

3 participants