perfsonar / owamp

A tool for performing one-way or two-way active measurements
Apache License 2.0
70 stars 30 forks source link

Add SO_BINDTODEVICE options for owping/twping/powstream #47

Closed deastoe closed 5 years ago

deastoe commented 5 years ago

Here is some example usage of the SO_BINDTODEVICE options. Here we use them for OWAMP/TWAMP operations in a VRF, by binding to the VRF master interface:

Environment:

# No route to 10.10.1.2 in the default VRF
$ ip route get 10.10.1.2
RTNETLINK answers: Network is unreachable

$ ip route get vrf vrfblue 10.10.1.2
10.10.1.2 dev ens8 table 256 src 10.10.1.1 uid 1000 
    cache

$ sudo getcap owping twping powstream
owping = cap_net_raw+p
twping = cap_net_raw+p
powstream = cap_net_raw+p

owping:

$ ./owping -c 10 10.10.1.2
owping: FILE=time.c, LINE=112, NTP: Status UNSYNC (clock offset issues likely)
owping: FILE=time.c, LINE=118, NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
owping: FILE=owping.c, LINE=1742, Unable to open control connection to 10.10.1.2.
$ 
$ ./owping -I vrfblue -c 10 10.10.1.2
owping: FILE=time.c, LINE=112, NTP: Status UNSYNC (clock offset issues likely)
owping: FILE=time.c, LINE=118, NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
Approximately 3.9 seconds until results available

--- owping statistics from [10.10.1.1]:9068 to [10.10.1.2]:9855 ---
SID:    0a0a0102dfafeec69400da1ab179ccc7
first:  2018-12-03T18:04:55.098
last:   2018-12-03T18:04:55.732
10 sent, 0 lost (0.000%), 0 duplicates
one-way delay min/median/max = 473/473/473 ms, (unsync)
one-way jitter = 0.3 ms (P95-P50)
hops = 0 (consistently)
no reordering

--- owping statistics from [10.10.1.2]:9093 to [10.10.1.1]:9777 ---
SID:    0a0a0101dfafeec61b837b4ad9897b67
first:  2018-12-03T18:04:55.103
last:   2018-12-03T18:04:55.857
10 sent, 0 lost (0.000%), 0 duplicates
one-way delay min/median/max = -472/-472/-471 ms, (unsync)
one-way jitter = 0.4 ms (P95-P50)
hops = 0 (consistently)
no reordering

twping:

$ ./twping -c 10 10.10.1.2
twping: FILE=time.c, LINE=112, NTP: Status UNSYNC (clock offset issues likely)
twping: FILE=time.c, LINE=118, NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
twping: FILE=owping.c, LINE=1742, Unable to open control connection to 10.10.1.2.
$ 
$ ./twping -I vrfblue -c 10 10.10.1.2
twping: FILE=time.c, LINE=112, NTP: Status UNSYNC (clock offset issues likely)
twping: FILE=time.c, LINE=118, NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
Approximately 4.0 seconds until results available

Directional delays may be inaccurate due to out of sync clocks!

--- twping statistics from [10.10.1.1]:8940 to [10.10.1.2]:8940 ---
SID:    0a0a0102dfafeef4d3d41743fdf78752
first:  2018-12-03T18:05:41.433
last:   2018-12-03T18:05:42.344
10 sent, 0 lost (0.000%), 0 send duplicates, 0 reflect duplicates
round-trip time min/median/max = 0.959/1.4/1.63 ms, (err=9.31e-07 ms)
send time min/median/max = 473/473/473 ms, (err=4.66e-07 ms)
reflect time min/median/max = -472/-472/-472 ms, (err=4.66e-07 ms)
reflector processing time min/max = 0.0148/0.0463 ms
two-way jitter = 0.3 ms (P95-P50)
send jitter = 0.3 ms (P95-P50)
reflect jitter = 0.1 ms (P95-P50)
send hops = 0 (consistently)
reflect hops = 0 (consistently)

powstream:

$ ./powstream -p -c 10 10.10.1.2
powstream[5065]: Warning: Holes in data are likely because lossThreshold(10) is too large a fraction of approx summary session duration(1)
powstream[5065]: NTP: Status UNSYNC (clock offset issues likely)
powstream[5065]: NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
powstream[5065]: OWPControlOpen(10.10.1.2): Couldn't open 'control' connection to server: Network is unreachable
powstream[5065]: OWPControlOpen(10.10.1.2): Couldn't open 'control' connection to server: Network is unreachable
powstream[5065]: OWPControlOpen(10.10.1.2): Waiting 0.998966000 seconds before retrying
powstream[5065]: OWPControlOpen(10.10.1.2): Couldn't open 'control' connection to server: Network is unreachable
powstream[5065]: OWPControlOpen(10.10.1.2): Waiting 0.567000 seconds before retrying
powstream[5065]: OWPControlOpen(10.10.1.2): Couldn't open 'control' connection to server: Network is unreachable
powstream[5065]: OWPControlOpen(10.10.1.2): Waiting 0.996774999 seconds before retrying
^Cpowstream[5065]: SIGTERM/SIGINT Caught: Exiting.
$ 
$ ./powstream -p -T vrfblue -c 10 10.10.1.2
powstream[5066]: Warning: Holes in data are likely because lossThreshold(10) is too large a fraction of approx summary session duration(1)
powstream[5066]: NTP: Status UNSYNC (clock offset issues likely)
powstream[5066]: NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
16118365018432400441_16118365022600702779.owp
16118365018432400441_16118365022600702779.sum
16118365022600702779_16118365027207155936.owp
16118365022600702779_16118365027207155936.sum
^Cpowstream[5066]: SIGTERM/SIGINT Caught: Exiting.
$ ./owstats 16118365018432400441_16118365022600702779.owp
owstats: FILE=time.c, LINE=112, NTP: Status UNSYNC (clock offset issues likely)
owstats: FILE=time.c, LINE=118, NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.

--- owping statistics from [10.10.1.2]:9323 to [10.10.1.1]:9244 ---
SID:    0a0a0101dfafef8be46a3bdd2038d18f
first:  2018-12-03T18:08:21.896
last:   2018-12-03T18:08:22.860
10 sent, 0 lost (0.000%), 0 duplicates
one-way delay min/median/max = -472/-472/-471 ms, (unsync)
one-way jitter = 0.3 ms (P95-P50)
hops = 0 (consistently)
no reordering

Example of a bind failure:

$ ./owping -I vrfblue -c 10 10.10.1.2
owping: FILE=time.c, LINE=112, NTP: Status UNSYNC (clock offset issues likely)
owping: FILE=time.c, LINE=118, NTP: STA_NANO should be set. Make sure ntpd is running, and your NTP configuration is good.
owping: FILE=api.c, LINE=3807, Could not add capability cap_net_raw: Operation not permitted
owping: FILE=api.c, LINE=3907, SO_BINDTODEVICE vrfblue: Operation not permitted
owping: FILE=owping.c, LINE=1738, Unable to open control connection to 10.10.1.2.
vvidic commented 5 years ago

The change seems to work fine for me. Maybe just use the same command line option for all commands?

vvidic commented 5 years ago

Do we want to use -I for owping and -T for powstream because -I is already used there?

deastoe commented 5 years ago

That's right, I used -T for powstream since -I is already used. I've no issue changing to a common flag if that's preferred.

Taking the characters of "interface" it looks like the only commonly available flag would be "-C".

Another alternative could be to overload -I for powstream, since the current usage expects an integer. So if integer parsing failed it would be interpreted as an interface instead. That seems a bit messy though.

vvidic commented 5 years ago

Yes, I know that -I is usually used for interface parameter, but since that is kind of taken I had in mind some other variants like: -B (for BINDTODEVICE) -D (for device) -V (for VRF) -M (for master interface)

I don't have a strong opinion on this but once we set something we can't easily change it later so we better discuss a bit before merging the change.

deastoe commented 5 years ago

Sure. I think my preference would be for -B or -D. Since owping uses -D for DSCP value that leaves -B as my preferred option.

vvidic commented 5 years ago

OK, if nobody objects I will try to merge with -B than.

deastoe commented 5 years ago

Great, thanks! I've updated the diffs to use -B.

vvidic commented 5 years ago

Thanks for the update. Merged the patch and updated the spec file for RPM build.