ioam6.sh 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # Author: Justin Iurman <justin.iurman@uliege.be>
  5. #
  6. # This script evaluates the IOAM insertion for IPv6 by checking the IOAM data
  7. # consistency directly inside packets on the receiver side. Tests are divided
  8. # into three categories: OUTPUT (evaluates the IOAM processing by the sender),
  9. # INPUT (evaluates the IOAM processing by a receiver) and GLOBAL (evaluates
  10. # wider use cases that do not fall into the other two categories). Both OUTPUT
  11. # and INPUT tests only use a two-node topology (alpha and beta), while GLOBAL
  12. # tests use the entire three-node topology (alpha, beta, gamma). Each test is
  13. # documented inside its own handler in the code below.
  14. #
  15. # An IOAM domain is configured from Alpha to Gamma but not on the reverse path.
  16. # When either Beta or Gamma is the destination (depending on the test category),
  17. # Alpha adds an IOAM option (Pre-allocated Trace) inside a Hop-by-hop.
  18. #
  19. #
  20. # +-------------------+ +-------------------+
  21. # | | | |
  22. # | Alpha netns | | Gamma netns |
  23. # | | | |
  24. # | +-------------+ | | +-------------+ |
  25. # | | veth0 | | | | veth0 | |
  26. # | | db01::2/64 | | | | db02::2/64 | |
  27. # | +-------------+ | | +-------------+ |
  28. # | . | | . |
  29. # +-------------------+ +-------------------+
  30. # . .
  31. # . .
  32. # . .
  33. # +----------------------------------------------------+
  34. # | . . |
  35. # | +-------------+ +-------------+ |
  36. # | | veth0 | | veth1 | |
  37. # | | db01::1/64 | ................ | db02::1/64 | |
  38. # | +-------------+ +-------------+ |
  39. # | |
  40. # | Beta netns |
  41. # | |
  42. # +----------------------------------------------------+
  43. #
  44. #
  45. #
  46. # =============================================================
  47. # | Alpha - IOAM configuration |
  48. # +===========================================================+
  49. # | Node ID | 1 |
  50. # +-----------------------------------------------------------+
  51. # | Node Wide ID | 11111111 |
  52. # +-----------------------------------------------------------+
  53. # | Ingress ID | 0xffff (default value) |
  54. # +-----------------------------------------------------------+
  55. # | Ingress Wide ID | 0xffffffff (default value) |
  56. # +-----------------------------------------------------------+
  57. # | Egress ID | 101 |
  58. # +-----------------------------------------------------------+
  59. # | Egress Wide ID | 101101 |
  60. # +-----------------------------------------------------------+
  61. # | Namespace Data | 0xdeadbee0 |
  62. # +-----------------------------------------------------------+
  63. # | Namespace Wide Data | 0xcafec0caf00dc0de |
  64. # +-----------------------------------------------------------+
  65. # | Schema ID | 777 |
  66. # +-----------------------------------------------------------+
  67. # | Schema Data | something that will be 4n-aligned |
  68. # +-----------------------------------------------------------+
  69. #
  70. #
  71. # =============================================================
  72. # | Beta - IOAM configuration |
  73. # +===========================================================+
  74. # | Node ID | 2 |
  75. # +-----------------------------------------------------------+
  76. # | Node Wide ID | 22222222 |
  77. # +-----------------------------------------------------------+
  78. # | Ingress ID | 201 |
  79. # +-----------------------------------------------------------+
  80. # | Ingress Wide ID | 201201 |
  81. # +-----------------------------------------------------------+
  82. # | Egress ID | 202 |
  83. # +-----------------------------------------------------------+
  84. # | Egress Wide ID | 202202 |
  85. # +-----------------------------------------------------------+
  86. # | Namespace Data | 0xdeadbee1 |
  87. # +-----------------------------------------------------------+
  88. # | Namespace Wide Data | 0xcafec0caf11dc0de |
  89. # +-----------------------------------------------------------+
  90. # | Schema ID | 666 |
  91. # +-----------------------------------------------------------+
  92. # | Schema Data | Hello there -Obi |
  93. # +-----------------------------------------------------------+
  94. #
  95. #
  96. # =============================================================
  97. # | Gamma - IOAM configuration |
  98. # +===========================================================+
  99. # | Node ID | 3 |
  100. # +-----------------------------------------------------------+
  101. # | Node Wide ID | 33333333 |
  102. # +-----------------------------------------------------------+
  103. # | Ingress ID | 301 |
  104. # +-----------------------------------------------------------+
  105. # | Ingress Wide ID | 301301 |
  106. # +-----------------------------------------------------------+
  107. # | Egress ID | 0xffff (default value) |
  108. # +-----------------------------------------------------------+
  109. # | Egress Wide ID | 0xffffffff (default value) |
  110. # +-----------------------------------------------------------+
  111. # | Namespace Data | 0xdeadbee2 |
  112. # +-----------------------------------------------------------+
  113. # | Namespace Wide Data | 0xcafec0caf22dc0de |
  114. # +-----------------------------------------------------------+
  115. # | Schema ID | 0xffffff (= None) |
  116. # +-----------------------------------------------------------+
  117. # | Schema Data | |
  118. # +-----------------------------------------------------------+
  119. source lib.sh
  120. ################################################################################
  121. # #
  122. # WARNING: Be careful if you modify the block below - it MUST be kept #
  123. # synchronized with configurations inside ioam6_parser.c and always #
  124. # reflect the same. #
  125. # #
  126. ################################################################################
  127. ALPHA=(
  128. 1 # ID
  129. 11111111 # Wide ID
  130. 0xffff # Ingress ID
  131. 0xffffffff # Ingress Wide ID
  132. 101 # Egress ID
  133. 101101 # Egress Wide ID
  134. 0xdeadbee0 # Namespace Data
  135. 0xcafec0caf00dc0de # Namespace Wide Data
  136. 777 # Schema ID (0xffffff = None)
  137. "something that will be 4n-aligned" # Schema Data
  138. )
  139. BETA=(
  140. 2
  141. 22222222
  142. 201
  143. 201201
  144. 202
  145. 202202
  146. 0xdeadbee1
  147. 0xcafec0caf11dc0de
  148. 666
  149. "Hello there -Obi"
  150. )
  151. GAMMA=(
  152. 3
  153. 33333333
  154. 301
  155. 301301
  156. 0xffff
  157. 0xffffffff
  158. 0xdeadbee2
  159. 0xcafec0caf22dc0de
  160. 0xffffff
  161. ""
  162. )
  163. TESTS_OUTPUT="
  164. out_undef_ns
  165. out_no_room
  166. out_bits
  167. out_full_supp_trace
  168. "
  169. TESTS_INPUT="
  170. in_undef_ns
  171. in_no_room
  172. in_oflag
  173. in_bits
  174. in_full_supp_trace
  175. "
  176. TESTS_GLOBAL="
  177. fwd_full_supp_trace
  178. "
  179. ################################################################################
  180. # #
  181. # LIBRARY #
  182. # #
  183. ################################################################################
  184. check_kernel_compatibility()
  185. {
  186. setup_ns ioam_tmp_node
  187. ip link add name veth0 netns $ioam_tmp_node type veth \
  188. peer name veth1 netns $ioam_tmp_node
  189. ip -netns $ioam_tmp_node link set veth0 up
  190. ip -netns $ioam_tmp_node link set veth1 up
  191. ip -netns $ioam_tmp_node ioam namespace add 0
  192. ns_ad=$?
  193. ip -netns $ioam_tmp_node ioam namespace show | grep -q "namespace 0"
  194. ns_sh=$?
  195. if [[ $ns_ad != 0 || $ns_sh != 0 ]]
  196. then
  197. echo "SKIP: kernel version probably too old, missing ioam support"
  198. ip link del veth0 2>/dev/null || true
  199. cleanup_ns $ioam_tmp_node || true
  200. exit $ksft_skip
  201. fi
  202. ip -netns $ioam_tmp_node route add db02::/64 encap ioam6 mode inline \
  203. trace prealloc type 0x800000 ns 0 size 4 dev veth0
  204. tr_ad=$?
  205. ip -netns $ioam_tmp_node -6 route | grep -q "encap ioam6"
  206. tr_sh=$?
  207. if [[ $tr_ad != 0 || $tr_sh != 0 ]]
  208. then
  209. echo "SKIP: cannot attach an ioam trace to a route, did you compile" \
  210. "without CONFIG_IPV6_IOAM6_LWTUNNEL?"
  211. ip link del veth0 2>/dev/null || true
  212. cleanup_ns $ioam_tmp_node || true
  213. exit $ksft_skip
  214. fi
  215. ip link del veth0 2>/dev/null || true
  216. cleanup_ns $ioam_tmp_node || true
  217. lsmod | grep -q "ip6_tunnel"
  218. ip6tnl_loaded=$?
  219. if [ $ip6tnl_loaded = 0 ]
  220. then
  221. encap_tests=0
  222. else
  223. modprobe ip6_tunnel &>/dev/null
  224. lsmod | grep -q "ip6_tunnel"
  225. encap_tests=$?
  226. if [ $encap_tests != 0 ]
  227. then
  228. ip a | grep -q "ip6tnl0"
  229. encap_tests=$?
  230. if [ $encap_tests != 0 ]
  231. then
  232. echo "Note: ip6_tunnel not found neither as a module nor inside the" \
  233. "kernel, tests that require it (encap mode) will be omitted"
  234. fi
  235. fi
  236. fi
  237. }
  238. cleanup()
  239. {
  240. ip link del ioam-veth-alpha 2>/dev/null || true
  241. ip link del ioam-veth-gamma 2>/dev/null || true
  242. cleanup_ns $ioam_node_alpha $ioam_node_beta $ioam_node_gamma || true
  243. if [ $ip6tnl_loaded != 0 ]
  244. then
  245. modprobe -r ip6_tunnel 2>/dev/null || true
  246. fi
  247. }
  248. setup()
  249. {
  250. setup_ns ioam_node_alpha ioam_node_beta ioam_node_gamma
  251. ip link add name ioam-veth-alpha netns $ioam_node_alpha type veth \
  252. peer name ioam-veth-betaL netns $ioam_node_beta
  253. ip link add name ioam-veth-betaR netns $ioam_node_beta type veth \
  254. peer name ioam-veth-gamma netns $ioam_node_gamma
  255. ip -netns $ioam_node_alpha link set ioam-veth-alpha name veth0
  256. ip -netns $ioam_node_beta link set ioam-veth-betaL name veth0
  257. ip -netns $ioam_node_beta link set ioam-veth-betaR name veth1
  258. ip -netns $ioam_node_gamma link set ioam-veth-gamma name veth0
  259. ip -netns $ioam_node_alpha addr add db01::2/64 dev veth0
  260. ip -netns $ioam_node_alpha link set veth0 up
  261. ip -netns $ioam_node_alpha link set lo up
  262. ip -netns $ioam_node_alpha route add db02::/64 via db01::1 dev veth0
  263. ip -netns $ioam_node_alpha route del db01::/64
  264. ip -netns $ioam_node_alpha route add db01::/64 dev veth0
  265. ip -netns $ioam_node_beta addr add db01::1/64 dev veth0
  266. ip -netns $ioam_node_beta addr add db02::1/64 dev veth1
  267. ip -netns $ioam_node_beta link set veth0 up
  268. ip -netns $ioam_node_beta link set veth1 up
  269. ip -netns $ioam_node_beta link set lo up
  270. ip -netns $ioam_node_gamma addr add db02::2/64 dev veth0
  271. ip -netns $ioam_node_gamma link set veth0 up
  272. ip -netns $ioam_node_gamma link set lo up
  273. ip -netns $ioam_node_gamma route add db01::/64 via db02::1 dev veth0
  274. # - IOAM config -
  275. ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.ioam6_id=${ALPHA[0]}
  276. ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.ioam6_id_wide=${ALPHA[1]}
  277. ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id=${ALPHA[4]}
  278. ip netns exec $ioam_node_alpha sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${ALPHA[5]}
  279. ip -netns $ioam_node_alpha ioam namespace add 123 data ${ALPHA[6]} wide ${ALPHA[7]}
  280. ip -netns $ioam_node_alpha ioam schema add ${ALPHA[8]} "${ALPHA[9]}"
  281. ip -netns $ioam_node_alpha ioam namespace set 123 schema ${ALPHA[8]}
  282. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.all.forwarding=1
  283. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.ioam6_id=${BETA[0]}
  284. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.ioam6_id_wide=${BETA[1]}
  285. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
  286. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_id=${BETA[2]}
  287. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${BETA[3]}
  288. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth1.ioam6_id=${BETA[4]}
  289. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth1.ioam6_id_wide=${BETA[5]}
  290. ip -netns $ioam_node_beta ioam namespace add 123 data ${BETA[6]} wide ${BETA[7]}
  291. ip -netns $ioam_node_beta ioam schema add ${BETA[8]} "${BETA[9]}"
  292. ip -netns $ioam_node_beta ioam namespace set 123 schema ${BETA[8]}
  293. ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.ioam6_id=${GAMMA[0]}
  294. ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.ioam6_id_wide=${GAMMA[1]}
  295. ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
  296. ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id=${GAMMA[2]}
  297. ip netns exec $ioam_node_gamma sysctl -wq net.ipv6.conf.veth0.ioam6_id_wide=${GAMMA[3]}
  298. ip -netns $ioam_node_gamma ioam namespace add 123 data ${GAMMA[6]} wide ${GAMMA[7]}
  299. sleep 1
  300. ip netns exec $ioam_node_alpha ping6 -c 5 -W 1 db02::2 &>/dev/null
  301. if [ $? != 0 ]
  302. then
  303. echo "Setup FAILED"
  304. cleanup &>/dev/null
  305. exit 0
  306. fi
  307. }
  308. log_test_passed()
  309. {
  310. local desc=$1
  311. printf "TEST: %-60s [ OK ]\n" "${desc}"
  312. }
  313. log_test_failed()
  314. {
  315. local desc=$1
  316. printf "TEST: %-60s [FAIL]\n" "${desc}"
  317. }
  318. log_results()
  319. {
  320. echo "- Tests passed: ${npassed}"
  321. echo "- Tests failed: ${nfailed}"
  322. }
  323. run_test()
  324. {
  325. local name=$1
  326. local desc=$2
  327. local node_src=$3
  328. local node_dst=$4
  329. local ip6_dst=$5
  330. local trace_type=$6
  331. local ioam_ns=$7
  332. local type=$8
  333. ip netns exec $node_dst ./ioam6_parser $name $trace_type $ioam_ns $type &
  334. local spid=$!
  335. sleep 0.1
  336. ip netns exec $node_src ping6 -t 64 -c 1 -W 1 $ip6_dst &>/dev/null
  337. if [ $? != 0 ]
  338. then
  339. nfailed=$((nfailed+1))
  340. log_test_failed "${desc}"
  341. kill -2 $spid &>/dev/null
  342. else
  343. wait $spid
  344. if [ $? = 0 ]
  345. then
  346. npassed=$((npassed+1))
  347. log_test_passed "${desc}"
  348. else
  349. nfailed=$((nfailed+1))
  350. log_test_failed "${desc}"
  351. fi
  352. fi
  353. }
  354. run()
  355. {
  356. echo
  357. printf "%0.s-" {1..74}
  358. echo
  359. echo "OUTPUT tests"
  360. printf "%0.s-" {1..74}
  361. echo
  362. # set OUTPUT settings
  363. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=0
  364. for t in $TESTS_OUTPUT
  365. do
  366. $t "inline"
  367. [ $encap_tests = 0 ] && $t "encap"
  368. done
  369. # clean OUTPUT settings
  370. ip netns exec $ioam_node_beta sysctl -wq net.ipv6.conf.veth0.ioam6_enabled=1
  371. ip -netns $ioam_node_alpha route change db01::/64 dev veth0
  372. echo
  373. printf "%0.s-" {1..74}
  374. echo
  375. echo "INPUT tests"
  376. printf "%0.s-" {1..74}
  377. echo
  378. # set INPUT settings
  379. ip -netns $ioam_node_alpha ioam namespace del 123
  380. for t in $TESTS_INPUT
  381. do
  382. $t "inline"
  383. [ $encap_tests = 0 ] && $t "encap"
  384. done
  385. # clean INPUT settings
  386. ip -netns $ioam_node_alpha ioam namespace add 123 \
  387. data ${ALPHA[6]} wide ${ALPHA[7]}
  388. ip -netns $ioam_node_alpha ioam namespace set 123 schema ${ALPHA[8]}
  389. ip -netns $ioam_node_alpha route change db01::/64 dev veth0
  390. echo
  391. printf "%0.s-" {1..74}
  392. echo
  393. echo "GLOBAL tests"
  394. printf "%0.s-" {1..74}
  395. echo
  396. for t in $TESTS_GLOBAL
  397. do
  398. $t "inline"
  399. [ $encap_tests = 0 ] && $t "encap"
  400. done
  401. echo
  402. log_results
  403. }
  404. bit2type=(
  405. 0x800000 0x400000 0x200000 0x100000 0x080000 0x040000 0x020000 0x010000
  406. 0x008000 0x004000 0x002000 0x001000 0x000800 0x000400 0x000200 0x000100
  407. 0x000080 0x000040 0x000020 0x000010 0x000008 0x000004 0x000002
  408. )
  409. bit2size=( 4 4 4 4 4 4 4 4 8 8 8 4 4 4 4 4 4 4 4 4 4 4 4 )
  410. ################################################################################
  411. # #
  412. # OUTPUT tests #
  413. # #
  414. # Two nodes (sender/receiver), IOAM disabled on ingress for the receiver. #
  415. ################################################################################
  416. out_undef_ns()
  417. {
  418. ##############################################################################
  419. # Make sure that the encap node won't fill the trace if the chosen IOAM #
  420. # namespace is not configured locally. #
  421. ##############################################################################
  422. local desc="Unknown IOAM namespace"
  423. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  424. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  425. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  426. trace prealloc type 0x800000 ns 0 size 4 dev veth0
  427. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  428. db01::1 0x800000 0 $1
  429. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  430. }
  431. out_no_room()
  432. {
  433. ##############################################################################
  434. # Make sure that the encap node won't fill the trace and will set the #
  435. # Overflow flag since there is no room enough for its data. #
  436. ##############################################################################
  437. local desc="Missing trace room"
  438. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  439. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  440. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  441. trace prealloc type 0xc00000 ns 123 size 4 dev veth0
  442. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  443. db01::1 0xc00000 123 $1
  444. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  445. }
  446. out_bits()
  447. {
  448. ##############################################################################
  449. # Make sure that, for each trace type bit, the encap node will either: #
  450. # (i) fill the trace with its data when it is a supported bit #
  451. # (ii) not fill the trace with its data when it is an unsupported bit #
  452. ##############################################################################
  453. local desc="Trace type with bit <n> only"
  454. local tmp=${bit2size[22]}
  455. bit2size[22]=$(( $tmp + ${#ALPHA[9]} + ((4 - (${#ALPHA[9]} % 4)) % 4) ))
  456. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  457. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  458. for i in {0..22}
  459. do
  460. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  461. trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
  462. dev veth0 &>/dev/null
  463. local cmd_res=$?
  464. local descr="${desc/<n>/$i}"
  465. if [[ $i -ge 12 && $i -le 21 ]]
  466. then
  467. if [ $cmd_res != 0 ]
  468. then
  469. npassed=$((npassed+1))
  470. log_test_passed "$descr ($1 mode)"
  471. else
  472. nfailed=$((nfailed+1))
  473. log_test_failed "$descr ($1 mode)"
  474. fi
  475. else
  476. run_test "out_bit$i" "$descr ($1 mode)" $ioam_node_alpha \
  477. $ioam_node_beta db01::1 ${bit2type[$i]} 123 $1
  478. fi
  479. done
  480. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  481. bit2size[22]=$tmp
  482. }
  483. out_full_supp_trace()
  484. {
  485. ##############################################################################
  486. # Make sure that the encap node will correctly fill a full trace. Be careful,#
  487. # "full trace" here does NOT mean all bits (only supported ones). #
  488. ##############################################################################
  489. local desc="Full supported trace"
  490. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  491. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  492. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  493. trace prealloc type 0xfff002 ns 123 size 100 dev veth0
  494. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  495. db01::1 0xfff002 123 $1
  496. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  497. }
  498. ################################################################################
  499. # #
  500. # INPUT tests #
  501. # #
  502. # Two nodes (sender/receiver), the sender MUST NOT fill the trace upon #
  503. # insertion -> the IOAM namespace configured on the sender is removed #
  504. # and is used in the inserted trace to force the sender not to fill it. #
  505. ################################################################################
  506. in_undef_ns()
  507. {
  508. ##############################################################################
  509. # Make sure that the receiving node won't fill the trace if the related IOAM #
  510. # namespace is not configured locally. #
  511. ##############################################################################
  512. local desc="Unknown IOAM namespace"
  513. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  514. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  515. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  516. trace prealloc type 0x800000 ns 0 size 4 dev veth0
  517. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  518. db01::1 0x800000 0 $1
  519. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  520. }
  521. in_no_room()
  522. {
  523. ##############################################################################
  524. # Make sure that the receiving node won't fill the trace and will set the #
  525. # Overflow flag if there is no room enough for its data. #
  526. ##############################################################################
  527. local desc="Missing trace room"
  528. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  529. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  530. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  531. trace prealloc type 0xc00000 ns 123 size 4 dev veth0
  532. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  533. db01::1 0xc00000 123 $1
  534. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  535. }
  536. in_bits()
  537. {
  538. ##############################################################################
  539. # Make sure that, for each trace type bit, the receiving node will either: #
  540. # (i) fill the trace with its data when it is a supported bit #
  541. # (ii) not fill the trace with its data when it is an unsupported bit #
  542. ##############################################################################
  543. local desc="Trace type with bit <n> only"
  544. local tmp=${bit2size[22]}
  545. bit2size[22]=$(( $tmp + ${#BETA[9]} + ((4 - (${#BETA[9]} % 4)) % 4) ))
  546. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  547. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  548. for i in {0..11} {22..22}
  549. do
  550. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  551. trace prealloc type ${bit2type[$i]} ns 123 size ${bit2size[$i]} \
  552. dev veth0
  553. run_test "in_bit$i" "${desc/<n>/$i} ($1 mode)" $ioam_node_alpha \
  554. $ioam_node_beta db01::1 ${bit2type[$i]} 123 $1
  555. done
  556. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  557. bit2size[22]=$tmp
  558. }
  559. in_oflag()
  560. {
  561. ##############################################################################
  562. # Make sure that the receiving node won't fill the trace since the Overflow #
  563. # flag is set. #
  564. ##############################################################################
  565. local desc="Overflow flag is set"
  566. # Exception:
  567. # Here, we need the sender to set the Overflow flag. For that, we will add
  568. # back the IOAM namespace that was previously configured on the sender.
  569. ip -netns $ioam_node_alpha ioam namespace add 123
  570. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  571. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  572. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  573. trace prealloc type 0xc00000 ns 123 size 4 dev veth0
  574. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  575. db01::1 0xc00000 123 $1
  576. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  577. # And we clean the exception for this test to get things back to normal for
  578. # other INPUT tests
  579. ip -netns $ioam_node_alpha ioam namespace del 123
  580. }
  581. in_full_supp_trace()
  582. {
  583. ##############################################################################
  584. # Make sure that the receiving node will correctly fill a full trace. Be #
  585. # careful, "full trace" here does NOT mean all bits (only supported ones). #
  586. ##############################################################################
  587. local desc="Full supported trace"
  588. [ "$1" = "encap" ] && mode="$1 tundst db01::1" || mode="$1"
  589. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 up
  590. ip -netns $ioam_node_alpha route change db01::/64 encap ioam6 mode $mode \
  591. trace prealloc type 0xfff002 ns 123 size 80 dev veth0
  592. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_beta \
  593. db01::1 0xfff002 123 $1
  594. [ "$1" = "encap" ] && ip -netns $ioam_node_beta link set ip6tnl0 down
  595. }
  596. ################################################################################
  597. # #
  598. # GLOBAL tests #
  599. # #
  600. # Three nodes (sender/router/receiver), IOAM fully enabled on every node. #
  601. ################################################################################
  602. fwd_full_supp_trace()
  603. {
  604. ##############################################################################
  605. # Make sure that all three nodes correctly filled the full supported trace #
  606. # by checking that the trace data is consistent with the predefined config. #
  607. ##############################################################################
  608. local desc="Forward - Full supported trace"
  609. [ "$1" = "encap" ] && mode="$1 tundst db02::2" || mode="$1"
  610. [ "$1" = "encap" ] && ip -netns $ioam_node_gamma link set ip6tnl0 up
  611. ip -netns $ioam_node_alpha route change db02::/64 encap ioam6 mode $mode \
  612. trace prealloc type 0xfff002 ns 123 size 244 via db01::1 dev veth0
  613. run_test ${FUNCNAME[0]} "${desc} ($1 mode)" $ioam_node_alpha $ioam_node_gamma \
  614. db02::2 0xfff002 123 $1
  615. [ "$1" = "encap" ] && ip -netns $ioam_node_gamma link set ip6tnl0 down
  616. }
  617. ################################################################################
  618. # #
  619. # MAIN #
  620. # #
  621. ################################################################################
  622. npassed=0
  623. nfailed=0
  624. if [ "$(id -u)" -ne 0 ]
  625. then
  626. echo "SKIP: Need root privileges"
  627. exit $ksft_skip
  628. fi
  629. if [ ! -x "$(command -v ip)" ]
  630. then
  631. echo "SKIP: Could not run test without ip tool"
  632. exit $ksft_skip
  633. fi
  634. ip ioam &>/dev/null
  635. if [ $? = 1 ]
  636. then
  637. echo "SKIP: iproute2 too old, missing ioam command"
  638. exit $ksft_skip
  639. fi
  640. check_kernel_compatibility
  641. cleanup &>/dev/null
  642. setup
  643. run
  644. cleanup &>/dev/null