Commit Graph

30 Commits

Author SHA1 Message Date
Simon Sundberg
d85329f728 pping: Refactor output code
Simplify the three output functions by breaking them up into smaller
helper functions. Also introduce the pping_event union, which can hold
either an rtt_event or flow_event.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
Simon Sundberg
1975367a3a pping: Add end-of-flow message from userspace map cleanup
Make the flow_timeout function call the current output function to
simulate a flow-closing event. Also some other minor cleanup/fixes.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
Simon Sundberg
543f75c9d8 pping: Add support for "flow events"
Add "flow events" (flow opening or closing so far) which will trigger
a printout of message.

Note: The ppviz format will only print out the traditional rtt events
as the format does not include opening/closing messages.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
Simon Sundberg
399c9dc935 pping: Refactor json code and format
Use a JSON-writer library from iproute instead of complicated printf
statement. Also output timestamp, rtt and min_rtt as integers in
nanoseconds, rather than floats in seconds.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:26 +02:00
Simon Sundberg
148d4a26f3 pping: Change order of format_ip_address parameters
Change order of parameters for format_ip_address to follow the
convention of the printf functions where buffer is placed first,
instead of the conventions of the inet_ntop functions where buffer is
placed last.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
Simon Sundberg
f96cfb7d7c pping: Track nr sent/received packets and bytes
Add per-flow tracking of number of packets and bytes
sent/received. Add these to the JSON output format.

Also update README regarding concurrency issue when updating these
statistics.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
Simon Sundberg
d92109b3c8 pping: Replace -j and -m options with -F/--format
The format option can take the values "standard" (default), "json" and
ppviz (new name for "machine-friendly").

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
Simon Sundberg
3011bbb0b8 pping: Add "machine friendly" format
Add Kathie's "machine friendly" as an optional output format when
passing '-m' or '--machine-friendly' to pping. This format can be used
together with Kathie's ppviz tool to visaulize the output.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
Simon Sundberg
0ed39800d0 pping: Add JSON output format
Add the option to output in JSON format by passing '-j' or '--json' to
pping. Include the protocol in the JSON format, and fix so kernel-side
actually stores the protocol in the flow_address struct.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
Simon Sundberg
b4a810b09b pping: Add timestamp and min-RTT to output
To add timestamp to output, push the timestamp when packet was
processed from kernel as part of the rtt-event. Also keep track of
minimum encountered RTT for each flow in kernel, and also push that as
part of the RTT-event.

Additionally, avoid pushing RTT messages at all if no flow-state
information can be found (due to ex. being deleted from egress side),
as no valid min-RTT can then be given. Furthermore, no longer delete
flow-information once seeing the FIN-flag on egress in order to keep
useful flow-state around for RTT-messages longer. Due to the
FIN-handshake process, it is sufficient if the ingress program deletes
the flow-state upon seeing FIN. However, still delete flow-state from
either ingress or egress upon seeing RST flag, as RST does not have a
handshake process allowing for delayed deletion.

While minimum RTT could also be tracked from the userspace process,
userspace is not aware of when the flow is closed so would have to add
additional logic to keep track of minimum RTT for each flow and
periodically clean them up. Furthermore, keeping RTT statistics in the
flow-state map is useful for implementing future features, such as an
RTT-based sampling interval. It would also be useful in case pping is
changed to no longer have a long-running userspace process printing
out all the calculated RTTs, but instead simply occasionally looks up
the RTT from the flow-state map.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-06-23 15:02:25 +02:00
Simon Sundberg
20c6dbec4c pping: Remove pinning of maps
When both BPF programs are kept in the same file, no longer need to
pin the maps in order to share them between the programs.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-04-23 14:16:52 +02:00
Simon Sundberg
93b6c0eafa pping: Major refactor and add -f and -c options
Merge the pping_kern_tc.c, pping_kern_xdp.c and pping_helpers.h into
the single file pping_kern.c. Do not change any of the BPF code,
except renaming the map ts_start to packet_ts.

To handle both BPF programs kept in single ELF-file, change loading
mechanism to extract and attach both tc and XDP programs from it. Also
refactor main-method into several smaller functions to reduce its
size.

Finally, added the --force (-f) and --cleanup-interval (-c) options to
the argument parsing, and improved the parsing of the
--rate-limit (-r) option.

NOTE: The verifier rejects program in it's current state as too
large (over 1 million instructions). Setting the TCP_MAX_OPTIONS in
pping_kern.c to 5 (or less) solves this. Unsure at the moment what
causes the verifier to think the program is so large, as the code in
pping_kern.c is identical to the one from the three files it was
merged from.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-04-15 14:13:54 +02:00
Simon Sundberg
9168b47cca pping: Refactor init_rodata
Refactor init_rodata to search for the first map with ".rodata" in its
name. Should be more robust than previous solution which first tried
to construct the name for the rodata map, and then find the map by
name.

Also remove some outcommented code that was not used.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-29 14:55:41 +02:00
Simon Sundberg
cc8a16650b pping: Add userspace configuration
Implement basic mechanic for parsing arguments from userspace and
passing them to a global config variable in the BPF programs.

This also changes the basic use of the program from:
    $./pping interface
to:
    $./pping -i interface

Also, revert to using the memset solution for the map_ipv4_to_ipv6
function to avoid the ipv4_prefix constant being stored in the .rodata
section. This makes it easier to set the value for the global config
variable from userspace, as the only thing left in the .rodata section
is the config struct.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-22 12:23:27 +01:00
Simon Sundberg
0b2107f5c4 pping: Add periodic cleanup of flow state
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-09 17:50:27 +01:00
Simon Sundberg
5204cd1e3c pping: Minor cleanup/refactor
Remove some out-commented code. Also use bpf_object__unpin_maps
instead of manually unpinning the ts_start map. Additionally, change
map_ipv4_to_ipv6 to use clearer implementation (that now also works
for tc due to always using libbpf to load program).

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-09 12:21:39 +01:00
Simon Sundberg
1446e6edec pping: Load tc-bpf program with libbpf
Load and pin the tc-bpf program in pping.c using libbpf, and only
attach the pinned program using iproute. That way, can use features
that are not supported by the old iproute loader, even if iproute does
not have libbpf support.

To support this change, extend bpf_egress_loader with option to load
pinned program. Additionally, remove configure script and parts of
Makefile that are no longer needed. Furthermore, remove multiple
definitions of ts_start map, and place singular definition in
pping_helpers.h which is included by both BPF programs.

Also, some minor fixes based on Toke's review.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-02 17:40:51 +01:00
Simon Sundberg
cecd6b54f2 pping: Inital rate limit implementation
Add a per-flow rate limit, limiting how often new timestamp entries
can be created. As part of this, add per-flow state keeping track
of when last timestamp was created and last seen identifier for each
flow.

Additionally, remove timestamp entry as soon as RTT is
calculated, as last seen identifier is used to find first unique value
instead. Furthermore, remove packet_timestamp struct and only use
__u64 as timestamp, as used memeber is no longer needed.

This initial commit lacks cleanup of flow-state, user-configuration of
rate limit, mechanism to handle bursts etc.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-03-01 18:16:48 +01:00
Simon Sundberg
3268ba87bb pping: Refactor TC and XDP programs
Refactor TC and XDP programs to reuse common logic for parsing
packets. Add functions for parsing packets for an identifier to
pping_helpers.h which both TC and XDP parts use. Also make it easier
to extend pping with support for new protocols, as only new parsing
functions have to be added and inserted into a single place.

Also add reserved members to end of structs in pping.h to indicate
padding.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-09 18:09:30 +01:00
Simon Sundberg
eafdf87d80 pping: Fix struct alginment issues
Move some members in network_tuple and rtt_event around to avoid holes.

Also remove some uncecessary parentheses before & operator, and add
local definitions of AF_INET and AF_INET6.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-09 13:00:28 +01:00
Simon Sundberg
670df84bd9 pping: Add IPv6 support
Several changes to add IPv6 support:
- Change structs in pping.h
  - replace ipv4_flow with network_tuple
  - rename ts_key to packet_id
  - rename ts_timestamp to packet_timestamp
- Add map_ipv4_to_ipv4 in pping_helpers.h
  - Also remove obsolete fill_ipv4_flow
- Rewrite pping_kern*
  - parse either IPv4 or IPv6 header (depending on proto)
  - Use map_ipv4_to_ipv6 to store IPv4 address in network_tuple
Support printout of IPv6 addresses in pping.c
  - Add function format_ip_address as wrapper over inet_ntop
  - Change handle_rtt_event to first format IP-address strings in
    local buffers, then perform single printout

While some steps have been taken to be more general towards different
types of packet identifiers (not just the currently supported TCP
timestamps), significant refactorization of pping_kern* will still be
required. Also, pping_kern_xdp and pping_kern_tc also have large
sections of very similar code that can be refactored into functions.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-08 20:28:46 +01:00
Simon Sundberg
1bb5a44152 pping: Create pin-folder and check if root
Create the /sys/fs/bpf/tc folder if it does not exist. Also check if
pping is run as root, otherwise inform user that it must run as root.

Libbpf will attempt to create the /sys/fs/bpf/tc/globals directory
when pinning the map, however it will not do so recursivly (so will
fail if /sys/fs/bpf/tc does not exist). So as a temporary solution,
attempt to create /sys/fs/bpf/tc (however, if sys/fs/bpf is not
mounted this will still fail).

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:56:49 +01:00
Simon Sundberg
c777287af2 pping: Minor refactor and whitespace fixes
Refactor tc_bpf_load and tc_bpf_clear to use a common run_program
function which does the fork+execv.

Enclose compound statement defines in parenthesis.

Removed argument CLOCK_MONOTONIC from callers to parameterless
function get_time_ns().

Also fix some weird spacing in pping_helpers.h, and fix some
formatting issues, using clang-format with the kernel source tree
.clang-format on the whole tree.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:52:40 +01:00
Simon Sundberg
7410d5cc2c pping: Various minor fixes
Perform various fixes and tweaks:
- Rename several defines to make them more informative
- Remove unrolling of loop in BPF programs
- Reuse defines for program sections between userspace and kernel
  space programs
- Perform fork+exec to run bpf_egress_loader script instead of
  system()
- Add comment to copied scripts indicating I've modified them
- Add pping.h and pping_helpers.h as dependencies in Makefile

Also, add a brief description of what PPing is and how it works to
README

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:48:01 +01:00
Simon Sundberg
71c6458712 pping: Fix incorrect printout of IP-address
Split the print statements for RTTs into two parts to avoid inet_ntoa
overwriting one of the IP-addresses (causing both source and
destitionation address to appear the same). Also flip the order of
source and destination to be the same as Pollere's pping.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:47:15 +01:00
Simon Sundberg
b920d72fe0 pping: Let libbpf pin map and clean up TC and map at end
Switch order so XDP program loads first, so the ts_start map is
automatically pinned by libbpf (solves issue with tc not preserving
the name of the map).

Unload the TCP-BPF program (or rather remove the entire clsact qdisc
it is attached to) using bpg_egress_loader script once program
exits. Also unpin ts_start map on program shutdown.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:44:33 +01:00
Simon Sundberg
337126306b pping: Switch to BTF-defined maps for XDP program
Make loader use libbpf's existing functionality for reusing pinned
maps. The name for map not kept by tc, so cannot get fd of map by
name. Use fd of first encountered map as temporary workaround.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:44:06 +01:00
Simon Sundberg
d3a5de62c4 pping: Format code and add SPDX lincense tags
Format the code using the .clang-format from the kernel source tree,
with a few manual tweaks here and there. Also, remove the TODO list
from comment of pping.c and instead put it in TODO.md.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:43:03 +01:00
Simon Sundberg
1010e53065 pping: Share ts_start map, pping at working stage
Make tc pin the ts_start map when loading the TC-BPF program, and
rewrite XDP loader to reuse map pinned by tc.

Also add comment with TODO list in pping.c.

Testing pping by adding a delay through a netem qdisc in the test
environment shows that the reported RTT will approach 100ms for any
delay lower than 100ms, but the correct RTT for any delay over
100ms. Root cause is unknown, but Pollere's original pping
implementation (as well as a bpftrace based pping implementation)
shows the same issue. This issue has not been observed when running on
real interfaces without a netem qdisc.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:41:40 +01:00
Simon Sundberg
954c66b0e8 pping: Add TC-BPF program for egress
Split and rename files so there is one userspace program (pping) and
two kernel-space ones (one for XDP and one for TC-BPF).

Copy the shell script for loading the TC-BPF program from
traffic-pacing-edt folder, but add support for loading a specific
section.

The XDP and TC-BPF programs do not share the ts_start map, so program
does not work.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
2021-02-04 19:39:16 +01:00