ioam6.sh 29 KB

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