mpls_lib.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
  4. TST_MIN_KVER="4.3"
  5. TST_NEEDS_TMPDIR=1
  6. TST_NEEDS_ROOT=1
  7. TST_NEEDS_DRIVERS="mpls_router mpls_iptunnel mpls_gso"
  8. TST_NEEDS_CMDS="sysctl modprobe"
  9. TST_TEST_DATA="icmp tcp udp"
  10. TST_NETLOAD_BINDTODEVICE=
  11. . tst_net.sh
  12. mpls_cleanup()
  13. {
  14. local flush_dev="ip -f mpls route flush dev"
  15. $flush_dev lo > /dev/null 2>&1
  16. tst_rhost_run -c "$flush_dev lo" > /dev/null
  17. [ -n "$rpf_loc" ] && sysctl -q net.ipv4.conf.all.rp_filter=$rpf_loc
  18. [ -n "$rpf_rmt" ] && tst_rhost_run -s -c "sysctl -q net.ipv4.conf.all.rp_filter=$rpf_rmt"
  19. }
  20. mpls_virt_cleanup()
  21. {
  22. ip route del $ip_virt_remote/32 dev ltp_v0 > /dev/null 2>&1
  23. ip route del $ip6_virt_remote/128 dev ltp_v0 > /dev/null 2>&1
  24. tst_rhost_run -c "ip route del $ip_virt_local/32 dev ltp_v0" > /dev/null
  25. tst_rhost_run -c "ip route del $ip6_virt_local/128 dev ltp_v0" > /dev/null
  26. virt_cleanup
  27. mpls_cleanup
  28. }
  29. mpls_setup()
  30. {
  31. local label="$1"
  32. tst_net_run -s "modprobe -a $TST_NEEDS_DRIVERS"
  33. ROD sysctl -q net.mpls.conf.$(tst_iface).input=1
  34. tst_set_sysctl net.mpls.conf.lo.input 1 safe
  35. tst_set_sysctl net.mpls.platform_labels $label safe
  36. rpf_loc="$(sysctl -n net.ipv4.conf.all.rp_filter)"
  37. tst_rhost_run -s -c "sysctl -q net.mpls.conf.$(tst_iface rhost).input=1"
  38. rpf_rmt="$(tst_rhost_run -c 'sysctl -n net.ipv4.conf.all.rp_filter')"
  39. tst_set_sysctl net.ipv4.conf.all.rp_filter 2 safe
  40. }
  41. mpls_setup_tnl()
  42. {
  43. local ip_loc="$1"
  44. local ip_rmt="$2"
  45. local label="$3"
  46. local mask
  47. echo "$ip_loc" | grep -q ':' && mask=128 || mask=32
  48. ROD ip route add $ip_rmt/$mask encap mpls $label dev ltp_v0
  49. ROD ip -f mpls route add $((label + 1)) dev lo
  50. tst_rhost_run -s -c "ip route add $ip_loc/$mask encap mpls $((label + 1)) dev ltp_v0"
  51. tst_rhost_run -s -c "ip -f mpls route add $label dev lo"
  52. }
  53. mpls_virt_setup()
  54. {
  55. mpls_setup 62
  56. virt_lib_setup
  57. tst_res TINFO "test $virt_type with MPLS"
  58. virt_setup "local $(tst_ipaddr) remote $(tst_ipaddr rhost) dev $(tst_iface)" \
  59. "local $(tst_ipaddr rhost) remote $(tst_ipaddr) dev $(tst_iface rhost)"
  60. mpls_setup_tnl $ip_virt_local $ip_virt_remote 60
  61. mpls_setup_tnl $ip6_virt_local $ip6_virt_remote 50
  62. tst_set_sysctl net.mpls.conf.ltp_v0.input 1 safe
  63. }
  64. mpls_virt_test()
  65. {
  66. local type=$2
  67. local max_size=$TST_NET_MAX_PKT
  68. if [ "$type" = "icmp" ]; then
  69. tst_ping $ip_virt_local $ip_virt_remote 10 100 1000 2000 $max_size
  70. tst_ping $ip6_virt_local $ip6_virt_remote 10 100 1000 2000 $max_size
  71. else
  72. tst_netload -S $ip_virt_local -H $ip_virt_remote -T $type -n 10 -N 10
  73. tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -n 10 -N 10
  74. tst_netload -S $ip_virt_local -H $ip_virt_remote -T $type -A $max_size
  75. tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -A $max_size
  76. fi
  77. }