txtimestamp.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Send packets with transmit timestamps over loopback with netem
  5. # Verify that timestamps correspond to netem delay
  6. set -e
  7. setup() {
  8. # set 1ms delay on lo egress
  9. tc qdisc add dev lo root netem delay 10ms
  10. # set 2ms delay on ifb0 egress
  11. modprobe ifb
  12. ip link add ifb_netem0 type ifb
  13. ip link set dev ifb_netem0 up
  14. tc qdisc add dev ifb_netem0 root netem delay 20ms
  15. # redirect lo ingress through ifb0 egress
  16. tc qdisc add dev lo handle ffff: ingress
  17. tc filter add dev lo parent ffff: \
  18. u32 match mark 0 0xffff \
  19. action mirred egress redirect dev ifb_netem0
  20. }
  21. run_test_v4v6() {
  22. # SND will be delayed 10ms
  23. # ACK will be delayed 60ms: 10 + 20 ms round-trip
  24. # allow +/- tolerance of 8ms
  25. # wait for ACK to be queued
  26. local -r args="$@ -v 10000 -V 60000 -t 8000 -S 80000"
  27. ./txtimestamp ${args} -4 -L 127.0.0.1
  28. ./txtimestamp ${args} -6 -L ::1
  29. }
  30. run_test_tcpudpraw() {
  31. local -r args=$@
  32. run_test_v4v6 ${args} # tcp
  33. run_test_v4v6 ${args} -u # udp
  34. run_test_v4v6 ${args} -u -o 42 # udp with fixed tskey
  35. run_test_v4v6 ${args} -r # raw
  36. run_test_v4v6 ${args} -r -o 42 # raw
  37. run_test_v4v6 ${args} -R # raw (IPPROTO_RAW)
  38. run_test_v4v6 ${args} -P # pf_packet
  39. }
  40. run_test_all() {
  41. setup
  42. run_test_tcpudpraw # setsockopt
  43. run_test_tcpudpraw -C # cmsg
  44. run_test_tcpudpraw -n # timestamp w/o data
  45. echo "OK. All tests passed"
  46. }
  47. run_test_one() {
  48. setup
  49. ./txtimestamp $@
  50. }
  51. usage() {
  52. echo "Usage: $0 [ -r | --run ] <txtimestamp args> | [ -h | --help ]"
  53. echo " (no args) Run all tests"
  54. echo " -r|--run Run an individual test with arguments"
  55. echo " -h|--help Help"
  56. }
  57. main() {
  58. if [[ $# -eq 0 ]]; then
  59. run_test_all
  60. else
  61. if [[ "$1" = "-r" || "$1" == "--run" ]]; then
  62. shift
  63. run_test_one $@
  64. else
  65. usage
  66. fi
  67. fi
  68. }
  69. if [[ -z "$(ip netns identify)" ]]; then
  70. ./in_netns.sh $0 $@
  71. else
  72. main $@
  73. fi