1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0+ 3 # 4 # Author: Justin Iurman <justin.iurman@uliege.b 5 # 6 # This script evaluates the IOAM insertion for 7 # consistency directly inside packets on the r 8 # into three categories: OUTPUT (evaluates the 9 # INPUT (evaluates the IOAM processing by a re 10 # wider use cases that do not fall into the ot 11 # and INPUT tests only use a two-node topology 12 # tests use the entire three-node topology (al 13 # documented inside its own handler in the cod 14 # 15 # An IOAM domain is configured from Alpha to G 16 # When either Beta or Gamma is the destination 17 # Alpha adds an IOAM option (Pre-allocated Tra 18 # 19 # 20 # +-------------------+ 21 # | | 22 # | Alpha netns | 23 # | | 24 # | +-------------+ | 25 # | | veth0 | | 26 # | | db01::2/64 | | 27 # | +-------------+ | 28 # | . | 29 # +-------------------+ 30 # . 31 # . 32 # . 33 # +-------------------------------- 34 # | . 35 # | +-------------+ 36 # | | veth0 | 37 # | | db01::1/64 | .............. 38 # | +-------------+ 39 # | 40 # | Beta netns 41 # | 42 # +-------------------------------- 43 # 44 # 45 # 46 # ===================================== 47 # | Alpha - IOAM configu 48 # +==================================== 49 # | Node ID | 1 50 # +------------------------------------ 51 # | Node Wide ID | 11111111 52 # +------------------------------------ 53 # | Ingress ID | 0xffff (defau 54 # +------------------------------------ 55 # | Ingress Wide ID | 0xffffffff (d 56 # +------------------------------------ 57 # | Egress ID | 101 58 # +------------------------------------ 59 # | Egress Wide ID | 101101 60 # +------------------------------------ 61 # | Namespace Data | 0xdeadbee0 62 # +------------------------------------ 63 # | Namespace Wide Data | 0xcafec0caf00 64 # +------------------------------------ 65 # | Schema ID | 777 66 # +------------------------------------ 67 # | Schema Data | something tha 68 # +------------------------------------ 69 # 70 # 71 # ===================================== 72 # | Beta - IOAM configu 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 | 0xcafec0caf11 89 # +------------------------------------ 90 # | Schema ID | 666 91 # +------------------------------------ 92 # | Schema Data | Hello there - 93 # +------------------------------------ 94 # 95 # 96 # ===================================== 97 # | Gamma - IOAM configu 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 (defau 108 # +------------------------------------ 109 # | Egress Wide ID | 0xffffffff (d 110 # +------------------------------------ 111 # | Namespace Data | 0xdeadbee2 112 # +------------------------------------ 113 # | Namespace Wide Data | 0xcafec0caf22 114 # +------------------------------------ 115 # | Schema ID | 0xffffff (= N 116 # +------------------------------------ 117 # | Schema Data | 118 # +------------------------------------ 119 120 source lib.sh 121 122 ############################################## 123 # 124 # WARNING: Be careful if you modify the block 125 # synchronized with configurations in 126 # reflect the same. 127 # 128 ############################################## 129 130 ALPHA=( 131 1 132 11111111 133 0xffff 134 0xffffffff 135 101 136 101101 137 0xdeadbee0 138 0xcafec0caf00dc0de 139 777 140 "something that will be 4n-aligned" 141 ) 142 143 BETA=( 144 2 145 22222222 146 201 147 201201 148 202 149 202202 150 0xdeadbee1 151 0xcafec0caf11dc0de 152 666 153 "Hello there -Obi" 154 ) 155 156 GAMMA=( 157 3 158 33333333 159 301 160 301301 161 0xffff 162 0xffffffff 163 0xdeadbee2 164 0xcafec0caf22dc0de 165 0xffffff 166 "" 167 ) 168 169 TESTS_OUTPUT=" 170 out_undef_ns 171 out_no_room 172 out_bits 173 out_full_supp_trace 174 " 175 176 TESTS_INPUT=" 177 in_undef_ns 178 in_no_room 179 in_oflag 180 in_bits 181 in_full_supp_trace 182 " 183 184 TESTS_GLOBAL=" 185 fwd_full_supp_trace 186 " 187 188 189 ############################################## 190 # 191 # LIBRARY 192 # 193 ############################################## 194 195 check_kernel_compatibility() 196 { 197 setup_ns ioam_tmp_node 198 ip link add name veth0 netns $ioam_tmp_node 199 peer name veth1 netns $ioam_tmp_node 200 201 ip -netns $ioam_tmp_node link set veth0 up 202 ip -netns $ioam_tmp_node link set veth1 up 203 204 ip -netns $ioam_tmp_node ioam namespace add 205 ns_ad=$? 206 207 ip -netns $ioam_tmp_node ioam namespace show 208 ns_sh=$? 209 210 if [[ $ns_ad != 0 || $ns_sh != 0 ]] 211 then 212 echo "SKIP: kernel version probably too ol 213 ip link del veth0 2>/dev/null || true 214 cleanup_ns $ioam_tmp_node || true 215 exit $ksft_skip 216 fi 217 218 ip -netns $ioam_tmp_node route add db02::/64 219 trace prealloc type 0x800000 ns 0 siz 220 tr_ad=$? 221 222 ip -netns $ioam_tmp_node -6 route | grep -q 223 tr_sh=$? 224 225 if [[ $tr_ad != 0 || $tr_sh != 0 ]] 226 then 227 echo "SKIP: cannot attach an ioam trace to 228 "without CONFIG_IPV6_IOAM6_LWTUNNEL?" 229 ip link del veth0 2>/dev/null || true 230 cleanup_ns $ioam_tmp_node || true 231 exit $ksft_skip 232 fi 233 234 ip link del veth0 2>/dev/null || true 235 cleanup_ns $ioam_tmp_node || true 236 237 lsmod | grep -q "ip6_tunnel" 238 ip6tnl_loaded=$? 239 240 if [ $ip6tnl_loaded = 0 ] 241 then 242 encap_tests=0 243 else 244 modprobe ip6_tunnel &>/dev/null 245 lsmod | grep -q "ip6_tunnel" 246 encap_tests=$? 247 248 if [ $encap_tests != 0 ] 249 then 250 ip a | grep -q "ip6tnl0" 251 encap_tests=$? 252 253 if [ $encap_tests != 0 ] 254 then 255 echo "Note: ip6_tunnel not found neith 256 "kernel, tests that require it (e 257 fi 258 fi 259 fi 260 } 261 262 cleanup() 263 { 264 ip link del ioam-veth-alpha 2>/dev/null || t 265 ip link del ioam-veth-gamma 2>/dev/null || t 266 267 cleanup_ns $ioam_node_alpha $ioam_node_beta 268 269 if [ $ip6tnl_loaded != 0 ] 270 then 271 modprobe -r ip6_tunnel 2>/dev/null || true 272 fi 273 } 274 275 setup() 276 { 277 setup_ns ioam_node_alpha ioam_node_beta ioam 278 279 ip link add name ioam-veth-alpha netns $ioam 280 peer name ioam-veth-betaL netns $ioam 281 ip link add name ioam-veth-betaR netns $ioam 282 peer name ioam-veth-gamma netns $ioam 283 284 ip -netns $ioam_node_alpha link set ioam-vet 285 ip -netns $ioam_node_beta link set ioam-veth 286 ip -netns $ioam_node_beta link set ioam-veth 287 ip -netns $ioam_node_gamma link set ioam-vet 288 289 ip -netns $ioam_node_alpha addr add db01::2/ 290 ip -netns $ioam_node_alpha link set veth0 up 291 ip -netns $ioam_node_alpha link set lo up 292 ip -netns $ioam_node_alpha route add db02::/ 293 ip -netns $ioam_node_alpha route del db01::/ 294 ip -netns $ioam_node_alpha route add db01::/ 295 296 ip -netns $ioam_node_beta addr add db01::1/6 297 ip -netns $ioam_node_beta addr add db02::1/6 298 ip -netns $ioam_node_beta link set veth0 up 299 ip -netns $ioam_node_beta link set veth1 up 300 ip -netns $ioam_node_beta link set lo up 301 302 ip -netns $ioam_node_gamma addr add db02::2/ 303 ip -netns $ioam_node_gamma link set veth0 up 304 ip -netns $ioam_node_gamma link set lo up 305 ip -netns $ioam_node_gamma route add db01::/ 306 307 # - IOAM config - 308 ip netns exec $ioam_node_alpha sysctl -wq ne 309 ip netns exec $ioam_node_alpha sysctl -wq ne 310 ip netns exec $ioam_node_alpha sysctl -wq ne 311 ip netns exec $ioam_node_alpha sysctl -wq ne 312 ip -netns $ioam_node_alpha ioam namespace ad 313 ip -netns $ioam_node_alpha ioam schema add $ 314 ip -netns $ioam_node_alpha ioam namespace se 315 316 ip netns exec $ioam_node_beta sysctl -wq net 317 ip netns exec $ioam_node_beta sysctl -wq net 318 ip netns exec $ioam_node_beta sysctl -wq net 319 ip netns exec $ioam_node_beta sysctl -wq net 320 ip netns exec $ioam_node_beta sysctl -wq net 321 ip netns exec $ioam_node_beta sysctl -wq net 322 ip netns exec $ioam_node_beta sysctl -wq net 323 ip netns exec $ioam_node_beta sysctl -wq net 324 ip -netns $ioam_node_beta ioam namespace add 325 ip -netns $ioam_node_beta ioam schema add ${ 326 ip -netns $ioam_node_beta ioam namespace set 327 328 ip netns exec $ioam_node_gamma sysctl -wq ne 329 ip netns exec $ioam_node_gamma sysctl -wq ne 330 ip netns exec $ioam_node_gamma sysctl -wq ne 331 ip netns exec $ioam_node_gamma sysctl -wq ne 332 ip netns exec $ioam_node_gamma sysctl -wq ne 333 ip -netns $ioam_node_gamma ioam namespace ad 334 335 sleep 1 336 337 ip netns exec $ioam_node_alpha ping6 -c 5 -W 338 if [ $? != 0 ] 339 then 340 echo "Setup FAILED" 341 cleanup &>/dev/null 342 exit 0 343 fi 344 } 345 346 log_test_passed() 347 { 348 local desc=$1 349 printf "TEST: %-60s [ OK ]\n" "${desc}" 350 } 351 352 log_test_failed() 353 { 354 local desc=$1 355 printf "TEST: %-60s [FAIL]\n" "${desc}" 356 } 357 358 log_results() 359 { 360 echo "- Tests passed: ${npassed}" 361 echo "- Tests failed: ${nfailed}" 362 } 363 364 run_test() 365 { 366 local name=$1 367 local desc=$2 368 local node_src=$3 369 local node_dst=$4 370 local ip6_dst=$5 371 local trace_type=$6 372 local ioam_ns=$7 373 local type=$8 374 375 ip netns exec $node_dst ./ioam6_parser $name 376 local spid=$! 377 sleep 0.1 378 379 ip netns exec $node_src ping6 -t 64 -c 1 -W 380 if [ $? != 0 ] 381 then 382 nfailed=$((nfailed+1)) 383 log_test_failed "${desc}" 384 kill -2 $spid &>/dev/null 385 else 386 wait $spid 387 if [ $? = 0 ] 388 then 389 npassed=$((npassed+1)) 390 log_test_passed "${desc}" 391 else 392 nfailed=$((nfailed+1)) 393 log_test_failed "${desc}" 394 fi 395 fi 396 } 397 398 run() 399 { 400 echo 401 printf "%0.s-" {1..74} 402 echo 403 echo "OUTPUT tests" 404 printf "%0.s-" {1..74} 405 echo 406 407 # set OUTPUT settings 408 ip netns exec $ioam_node_beta sysctl -wq net 409 410 for t in $TESTS_OUTPUT 411 do 412 $t "inline" 413 [ $encap_tests = 0 ] && $t "encap" 414 done 415 416 # clean OUTPUT settings 417 ip netns exec $ioam_node_beta sysctl -wq net 418 ip -netns $ioam_node_alpha route change db01 419 420 421 echo 422 printf "%0.s-" {1..74} 423 echo 424 echo "INPUT tests" 425 printf "%0.s-" {1..74} 426 echo 427 428 # set INPUT settings 429 ip -netns $ioam_node_alpha ioam namespace de 430 431 for t in $TESTS_INPUT 432 do 433 $t "inline" 434 [ $encap_tests = 0 ] && $t "encap" 435 done 436 437 # clean INPUT settings 438 ip -netns $ioam_node_alpha ioam namespace ad 439 data ${ALPHA[6]} wide ${ALPHA[7]} 440 ip -netns $ioam_node_alpha ioam namespace se 441 ip -netns $ioam_node_alpha route change db01 442 443 echo 444 printf "%0.s-" {1..74} 445 echo 446 echo "GLOBAL tests" 447 printf "%0.s-" {1..74} 448 echo 449 450 for t in $TESTS_GLOBAL 451 do 452 $t "inline" 453 [ $encap_tests = 0 ] && $t "encap" 454 done 455 456 echo 457 log_results 458 } 459 460 bit2type=( 461 0x800000 0x400000 0x200000 0x100000 0x080000 462 0x008000 0x004000 0x002000 0x001000 0x000800 463 0x000080 0x000040 0x000020 0x000010 0x000008 464 ) 465 bit2size=( 4 4 4 4 4 4 4 4 8 8 8 4 4 4 4 4 4 4 466 467 468 ############################################## 469 # 470 # OUTPUT tests 471 # 472 # Two nodes (sender/receiver), IOAM disabled 473 ############################################## 474 475 out_undef_ns() 476 { 477 ############################################ 478 # Make sure that the encap node won't fill t 479 # namespace is not configured locally. 480 ############################################ 481 local desc="Unknown IOAM namespace" 482 483 [ "$1" = "encap" ] && mode="$1 tundst db01:: 484 [ "$1" = "encap" ] && ip -netns $ioam_node_b 485 486 ip -netns $ioam_node_alpha route change db01 487 trace prealloc type 0x800000 ns 0 siz 488 489 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 490 db01::1 0x800000 0 $1 491 492 [ "$1" = "encap" ] && ip -netns $ioam_node_b 493 } 494 495 out_no_room() 496 { 497 ############################################ 498 # Make sure that the encap node won't fill t 499 # Overflow flag since there is no room enoug 500 ############################################ 501 local desc="Missing trace room" 502 503 [ "$1" = "encap" ] && mode="$1 tundst db01:: 504 [ "$1" = "encap" ] && ip -netns $ioam_node_b 505 506 ip -netns $ioam_node_alpha route change db01 507 trace prealloc type 0xc00000 ns 123 s 508 509 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 510 db01::1 0xc00000 123 $1 511 512 [ "$1" = "encap" ] && ip -netns $ioam_node_b 513 } 514 515 out_bits() 516 { 517 ############################################ 518 # Make sure that, for each trace type bit, t 519 # (i) fill the trace with its data when it 520 # (ii) not fill the trace with its data whe 521 ############################################ 522 local desc="Trace type with bit <n> only" 523 524 local tmp=${bit2size[22]} 525 bit2size[22]=$(( $tmp + ${#ALPHA[9]} + ((4 - 526 527 [ "$1" = "encap" ] && mode="$1 tundst db01:: 528 [ "$1" = "encap" ] && ip -netns $ioam_node_b 529 530 for i in {0..22} 531 do 532 ip -netns $ioam_node_alpha route change db 533 trace prealloc type ${bit2type[$i]} 534 dev veth0 &>/dev/null 535 536 local cmd_res=$? 537 local descr="${desc/<n>/$i}" 538 539 if [[ $i -ge 12 && $i -le 21 ]] 540 then 541 if [ $cmd_res != 0 ] 542 then 543 npassed=$((npassed+1)) 544 log_test_passed "$descr ($1 mode)" 545 else 546 nfailed=$((nfailed+1)) 547 log_test_failed "$descr ($1 mode)" 548 fi 549 else 550 run_test "out_bit$i" "$descr ($1 mode) 551 $ioam_node_beta db01::1 ${bit2type[ 552 fi 553 done 554 555 [ "$1" = "encap" ] && ip -netns $ioam_node_b 556 557 bit2size[22]=$tmp 558 } 559 560 out_full_supp_trace() 561 { 562 ############################################ 563 # Make sure that the encap node will correct 564 # "full trace" here does NOT mean all bits ( 565 ############################################ 566 local desc="Full supported trace" 567 568 [ "$1" = "encap" ] && mode="$1 tundst db01:: 569 [ "$1" = "encap" ] && ip -netns $ioam_node_b 570 571 ip -netns $ioam_node_alpha route change db01 572 trace prealloc type 0xfff002 ns 123 s 573 574 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 575 db01::1 0xfff002 123 $1 576 577 [ "$1" = "encap" ] && ip -netns $ioam_node_b 578 } 579 580 581 ############################################## 582 # 583 # INPUT tests 584 # 585 # Two nodes (sender/receiver), the sender 586 # insertion -> the IOAM namespace configur 587 # and is used in the inserted trace to for 588 ############################################## 589 590 in_undef_ns() 591 { 592 ############################################ 593 # Make sure that the receiving node won't fi 594 # namespace is not configured locally. 595 ############################################ 596 local desc="Unknown IOAM namespace" 597 598 [ "$1" = "encap" ] && mode="$1 tundst db01:: 599 [ "$1" = "encap" ] && ip -netns $ioam_node_b 600 601 ip -netns $ioam_node_alpha route change db01 602 trace prealloc type 0x800000 ns 0 siz 603 604 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 605 db01::1 0x800000 0 $1 606 607 [ "$1" = "encap" ] && ip -netns $ioam_node_b 608 } 609 610 in_no_room() 611 { 612 ############################################ 613 # Make sure that the receiving node won't fi 614 # Overflow flag if there is no room enough f 615 ############################################ 616 local desc="Missing trace room" 617 618 [ "$1" = "encap" ] && mode="$1 tundst db01:: 619 [ "$1" = "encap" ] && ip -netns $ioam_node_b 620 621 ip -netns $ioam_node_alpha route change db01 622 trace prealloc type 0xc00000 ns 123 s 623 624 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 625 db01::1 0xc00000 123 $1 626 627 [ "$1" = "encap" ] && ip -netns $ioam_node_b 628 } 629 630 in_bits() 631 { 632 ############################################ 633 # Make sure that, for each trace type bit, t 634 # (i) fill the trace with its data when it 635 # (ii) not fill the trace with its data whe 636 ############################################ 637 local desc="Trace type with bit <n> only" 638 639 local tmp=${bit2size[22]} 640 bit2size[22]=$(( $tmp + ${#BETA[9]} + ((4 - 641 642 [ "$1" = "encap" ] && mode="$1 tundst db01:: 643 [ "$1" = "encap" ] && ip -netns $ioam_node_b 644 645 for i in {0..11} {22..22} 646 do 647 ip -netns $ioam_node_alpha route change db 648 trace prealloc type ${bit2type[$i]} 649 dev veth0 650 651 run_test "in_bit$i" "${desc/<n>/$i} ($1 mo 652 $ioam_node_beta db01::1 ${bit2type[ 653 done 654 655 [ "$1" = "encap" ] && ip -netns $ioam_node_b 656 657 bit2size[22]=$tmp 658 } 659 660 in_oflag() 661 { 662 ############################################ 663 # Make sure that the receiving node won't fi 664 # flag is set. 665 ############################################ 666 local desc="Overflow flag is set" 667 668 # Exception: 669 # Here, we need the sender to set the Over 670 # back the IOAM namespace that was previou 671 ip -netns $ioam_node_alpha ioam namespace ad 672 673 [ "$1" = "encap" ] && mode="$1 tundst db01:: 674 [ "$1" = "encap" ] && ip -netns $ioam_node_b 675 676 ip -netns $ioam_node_alpha route change db01 677 trace prealloc type 0xc00000 ns 123 s 678 679 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 680 db01::1 0xc00000 123 $1 681 682 [ "$1" = "encap" ] && ip -netns $ioam_node_b 683 684 # And we clean the exception for this test t 685 # other INPUT tests 686 ip -netns $ioam_node_alpha ioam namespace de 687 } 688 689 in_full_supp_trace() 690 { 691 ############################################ 692 # Make sure that the receiving node will cor 693 # careful, "full trace" here does NOT mean a 694 ############################################ 695 local desc="Full supported trace" 696 697 [ "$1" = "encap" ] && mode="$1 tundst db01:: 698 [ "$1" = "encap" ] && ip -netns $ioam_node_b 699 700 ip -netns $ioam_node_alpha route change db01 701 trace prealloc type 0xfff002 ns 123 s 702 703 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 704 db01::1 0xfff002 123 $1 705 706 [ "$1" = "encap" ] && ip -netns $ioam_node_b 707 } 708 709 710 ############################################## 711 # 712 # GLOBAL tests 713 # 714 # Three nodes (sender/router/receiver), IOAM 715 ############################################## 716 717 fwd_full_supp_trace() 718 { 719 ############################################ 720 # Make sure that all three nodes correctly f 721 # by checking that the trace data is consist 722 ############################################ 723 local desc="Forward - Full supported trace" 724 725 [ "$1" = "encap" ] && mode="$1 tundst db02:: 726 [ "$1" = "encap" ] && ip -netns $ioam_node_g 727 728 ip -netns $ioam_node_alpha route change db02 729 trace prealloc type 0xfff002 ns 123 s 730 731 run_test ${FUNCNAME[0]} "${desc} ($1 mode)" 732 db02::2 0xfff002 123 $1 733 734 [ "$1" = "encap" ] && ip -netns $ioam_node_g 735 } 736 737 738 ############################################## 739 # 740 # MAIN 741 # 742 ############################################## 743 744 npassed=0 745 nfailed=0 746 747 if [ "$(id -u)" -ne 0 ] 748 then 749 echo "SKIP: Need root privileges" 750 exit $ksft_skip 751 fi 752 753 if [ ! -x "$(command -v ip)" ] 754 then 755 echo "SKIP: Could not run test without ip to 756 exit $ksft_skip 757 fi 758 759 ip ioam &>/dev/null 760 if [ $? = 1 ] 761 then 762 echo "SKIP: iproute2 too old, missing ioam c 763 exit $ksft_skip 764 fi 765 766 check_kernel_compatibility 767 768 cleanup &>/dev/null 769 setup 770 run 771 cleanup &>/dev/null
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.