pping: Add switch for which IP stats are aggregated by

By default ePPing will aggregate RTTs based on the src IP of the reply
packet. I.e. the RTT A->B->A will be aggregated based on IP of B. In
some scenarios it may be more interesting to aggregate based on the
dst IP of the reply packet (IP of A in above example). Therefore, add
a switch (--aggregate-reverse) which makes ePPing aggregate RTTs
based on the dst IP of the reply packet instead of the src IP. In
other words, by default ePPing will aggregate traffic based on where
it's going to, but with this switch you can make ePPing aggregate
traffic based on where it's comming from instead.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
Simon Sundberg
2023-07-04 17:52:05 +02:00
parent 5ef4ffdd1b
commit a301900fbd
3 changed files with 14 additions and 3 deletions

View File

@@ -15,6 +15,7 @@ static const char *__doc__ =
#include <unistd.h>
#include <getopt.h>
#include <stdbool.h>
#include <ctype.h>
#include <signal.h> // For detecting Ctrl-C
#include <sys/resource.h> // For setting rlmit
#include <time.h>
@@ -66,6 +67,8 @@ static const char *__doc__ =
* returned as negative values). */
#define PPING_ABORT 5555
#define ARG_AGG_REVERSE 256
enum pping_output_format {
PPING_OUTPUT_STANDARD,
PPING_OUTPUT_JSON,
@@ -160,6 +163,7 @@ static const struct option long_options[] = {
{ "aggregate", required_argument, NULL, 'a' }, // Aggregate RTTs every X seconds instead of reporting them individually
{ "aggregate-subnets-v4", required_argument, NULL, '4' }, // Set the subnet size for IPv4 when aggregating (default 24)
{ "aggregate-subnets-v6", required_argument, NULL, '6' }, // Set the subnet size for IPv6 when aggregating (default 48)
{ "aggregate-reverse", no_argument, NULL, ARG_AGG_REVERSE }, // Aggregate RTTs by dst IP of reply packet (instead of src like default)
{ 0, 0, NULL, 0 }
};
@@ -179,7 +183,7 @@ static void print_usage(char *argv[])
if (long_options[i].flag != NULL)
printf(" flag (internal value:%d)",
*long_options[i].flag);
else
else if (isalnum(long_options[i].val))
printf(" short-option: -%c", long_options[i].val);
printf("\n");
}
@@ -267,6 +271,7 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config)
config->bpf_config.skip_syn = true;
config->bpf_config.push_individual_events = true;
config->bpf_config.agg_rtts = false;
config->bpf_config.agg_by_dst = false;
while ((opt = getopt_long(argc, argv, "hflTCsi:r:R:t:c:F:I:x:a:4:6:",
long_options, NULL)) != -1) {
@@ -405,6 +410,9 @@ static int parse_arguments(int argc, char *argv[], struct pping_config *config)
return -EINVAL;
config->agg_conf.ipv6_prefix_len = user_int;
break;
case ARG_AGG_REVERSE:
config->bpf_config.agg_by_dst = true;
break;
case 'h':
printf("HELP:\n");
print_usage(argv);

View File

@@ -72,7 +72,7 @@ struct bpf_config {
bool skip_syn;
bool push_individual_events;
bool agg_rtts;
__u8 reserved;
bool agg_by_dst; // dst of reply packet
};
struct ipprefix_key {

View File

@@ -1123,7 +1123,10 @@ static void pping_match_packet(struct flow_state *f_state, void *ctx,
f_state->srtt = calculate_srtt(f_state->srtt, rtt);
send_rtt_event(ctx, rtt, f_state, p_info);
aggregate_rtt(rtt, &p_info->pid.flow.saddr.ip, p_info->pid.flow.ipv);
aggregate_rtt(rtt,
config.agg_by_dst ? &p_info->pid.flow.daddr.ip :
&p_info->pid.flow.saddr.ip,
p_info->pid.flow.ipv);
}
/*