rtbrick / bngblaster

The BNG Blaster is an open-source network tester for access and routing protocols.
https://rtbrick.github.io/bngblaster/
BSD 3-Clause "New" or "Revised" License
210 stars 34 forks source link

Question for implementing rx_avg_delay_us in bbl_stream.c #263

Open slieberth opened 5 months ago

slieberth commented 5 months ago

Hello Christian,

thanks for providing bngblaster!

It would be beneficial for us, if we can measure the average latency (= rx_avg_delay_us) in our tests. It is important for us to know the weight of rx_max_delay_us. e.g. is it just one packet or the majority of packets.

I see two options for implementing this feature:

calculation the sum over all delay_us values and divide the sum by the number of incoming packets. The drawback of this approach is that this test cannot run infinitely. (max value of 1e308 for double). python code example:

import random

min_delay_us = 0.0
max_delay_us = 0.0
sum_for_avg_delay_us = 0.0
avg_delay_us = 0.0

for rx_packets in range(1,1000, 1):
    delay_us = random.random()
    if rx_packets == 1:
        min_delay_us = delay_us
        max_delay_us = delay_us
    else:
        if delay_us < min_delay_us:
            min_delay_us = delay_us
        if delay_us > max_delay_us:
            max_delay_us = delay_us
    sum_for_avg_delay_us += delay_us

avg_delay_us = sum_for_avg_delay_us / rx_packets

print (f"min:{min_delay_us} avg:{avg_delay_us} max:{max_delay_us}")

respectively a calculation on a per packet base, which is more resource intensive, but avoids any considerations for exceeding the max value for doubles in c.

import random

min_delay_us = 0.0
max_delay_us = 0.0
avg_delay_us = 0.0

for rx_packets in range(1,1000, 1):
    delay_us = random.random()
    if rx_packets == 1:
        min_delay_us = delay_us
        max_delay_us = delay_us
        avg_delay_us = delay_us
    else:
        if delay_us < min_delay_us:
            min_delay_us = delay_us
        if delay_us > max_delay_us:
            max_delay_us = delay_us
        avg_delay_us = ((avg_delay_us * (rx_packets - 1)) + delay_us) / rx_packets

print (f"min:{min_delay_us} avg:{avg_delay_us} max:{max_delay_us}")

It has to be done on each incoming packet.

Please let me know, what you think? If you wish, I can try to implement a solution and provide a pull/merge request to you.

best regards Stefan