txtimestamp.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 1ms
  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 2ms
  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 1000us
  23. # ACK will be delayed 6000us: 1 + 2 ms round-trip
  24. local -r args="$@ -v 1000 -V 6000"
  25. ./txtimestamp ${args} -4 -L 127.0.0.1
  26. ./txtimestamp ${args} -6 -L ::1
  27. }
  28. run_test_tcpudpraw() {
  29. local -r args=$@
  30. run_test_v4v6 ${args} # tcp
  31. run_test_v4v6 ${args} -u # udp
  32. run_test_v4v6 ${args} -r # raw
  33. run_test_v4v6 ${args} -R # raw (IPPROTO_RAW)
  34. run_test_v4v6 ${args} -P # pf_packet
  35. }
  36. run_test_all() {
  37. setup
  38. run_test_tcpudpraw # setsockopt
  39. run_test_tcpudpraw -C # cmsg
  40. run_test_tcpudpraw -n # timestamp w/o data
  41. echo "OK. All tests passed"
  42. }
  43. run_test_one() {
  44. setup
  45. ./txtimestamp $@
  46. }
  47. usage() {
  48. echo "Usage: $0 [ -r | --run ] <txtimestamp args> | [ -h | --help ]"
  49. echo " (no args) Run all tests"
  50. echo " -r|--run Run an individual test with arguments"
  51. echo " -h|--help Help"
  52. }
  53. main() {
  54. if [[ $# -eq 0 ]]; then
  55. run_test_all
  56. else
  57. if [[ "$1" = "-r" || "$1" == "--run" ]]; then
  58. shift
  59. run_test_one $@
  60. else
  61. usage
  62. fi
  63. fi
  64. }
  65. if [[ -z "$(ip netns identify)" ]]; then
  66. ./in_netns.sh $0 $@
  67. else
  68. main $@
  69. fi