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