1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0

import datetime
import random
import re
import time
from lib.py import ksft_disruptive
from lib.py import ksft_run, ksft_pr, ksft_exit
from lib.py import ksft_eq, ksft_ne, ksft_ge, ksft_in, ksft_lt, ksft_true, ksft_raises
from lib.py import NetDrvEpEnv
from lib.py import EthtoolFamily, NetdevFamily, NlError
from lib.py import KsftSkipEx, KsftFailEx
from lib.py import rand_port, rand_ports
from lib.py import cmd, ethtool, ip, defer, CmdExitFailure, wait_file
from lib.py import GenerateTraffic


def _rss_key_str(key):
    return ":".join(["{:02x}".format(x) for x in key])


def _rss_key_rand(length):
    return [random.randint(0, 255) for _ in range(length)]


def _rss_key_check(cfg, data=None, context=0):
    if data is None:
        data = get_rss(cfg, context=context)
    if 'rss-hash-key' not in data:
        return
    non_zero = [x for x in data['rss-hash-key'] if x != 0]
    ksft_eq(bool(non_zero), True, comment=f"RSS key is all zero {data['rss-hash-key']}")


def get_rss(cfg, context=0):
    return ethtool(f"-x {cfg.ifname} context {context}", json=True)[0]


def get_drop_err_sum(cfg):
    stats = ip("-s -s link show dev " + cfg.ifname, json=True)[0]
    cnt = 0
    for key in ['errors', 'dropped', 'over_errors', 'fifo_errors',
                'length_errors', 'crc_errors', 'missed_errors',
                'frame_errors']:
        cnt += stats["stats64"]["rx"][key]
    return cnt, stats["stats64"]["tx"]["carrier_changes"]


def ethtool_create(cfg, act, opts):
    output = ethtool(f"{act} {cfg.ifname} {opts}").stdout
    # Output will be something like: "New RSS context is 1" or
    # "Added rule with ID 7", we want the integer from the end
    return int(output.split()[-1])


def require_ntuple(cfg):
    features = ethtool(f"-k {cfg.ifname}", json=True)[0]
    if not features["ntuple-filters"]["active"]:
        if features["ntuple-filters"]["fixed"]:
            raise KsftSkipEx("Device does not support ntuple-filters")
        ethtool(f"-K {cfg.ifname} ntuple-filters on")
        defer(ethtool, f"-K {cfg.ifname} ntuple-filters off")


def require_context_cnt(cfg, need_cnt):
    # There's no good API to get the context count, so the tests
    # which try to add a lot opportunisitically set the count they
    # discovered. Careful with test ordering!
    if need_cnt and cfg.context_cnt and cfg.context_cnt < need_cnt:
        raise KsftSkipEx(f"Test requires at least {need_cnt} contexts, but device only has {cfg.context_cnt}")


# Get Rx packet counts for all queues, as a simple list of integers
# if @prev is specified the prev counts will be subtracted
def _get_rx_cnts(cfg, prev=None):
    cfg.wait_hw_stats_settle()
    data = cfg.netdevnl.qstats_get({"ifindex": cfg.ifindex, "scope": ["queue"]}, dump=True)
    data = [x for x in data if x['queue-type'] == "rx"]
    max_q = max([x["queue-id"] for x in data])
    queue_stats = [0] * (max_q + 1)
    for q in data:
        queue_stats[q["queue-id"]] = q["rx-packets"]
        if prev and q["queue-id"] < len(prev):
            queue_stats[q["queue-id"]] -= prev[q["queue-id"]]
    return queue_stats


def _send_traffic_check(cfg, port, name, params):
    # params is a dict with 3 possible keys:
    #  - "target": required, which queues we expect to get iperf traffic
    #  - "empty": optional, which queues should see no traffic at all
    #  - "noise": optional, which queues we expect to see low traffic;
    #             used for queues of the main context, since some background
    #             OS activity may use those queues while we're testing
    # the value for each is a list, or some other iterable containing queue ids.

    cnts = _get_rx_cnts(cfg)
    GenerateTraffic(cfg, port=port).wait_pkts_and_stop(20000)
    cnts = _get_rx_cnts(cfg, prev=cnts)

    directed = sum(cnts[i] for i in params['target'])

    ksft_ge(directed, 20000, f"traffic on {name}: " + str(cnts))
    if params.get('noise'):
        ksft_lt(sum(cnts[i] for i in params['noise']), directed / 2,
                f"traffic on other queues ({name})':" + str(cnts))
    if params.get('empty'):
        ksft_eq(sum(cnts[i] for i in params['empty']), 0,
                f"traffic on inactive queues ({name}): " + str(cnts))


def _ntuple_rule_check(cfg, rule_id, ctx_id):
    """Check that ntuple rule references RSS context ID"""
    text = ethtool(f"-n {cfg.ifname} rule {rule_id}").stdout
    pattern = f"RSS Context (ID: )?{ctx_id}"
    ksft_true(re.search(pattern, text), "RSS context not referenced in ntuple rule")


def test_rss_key_indir(cfg):
    """Test basics like updating the main RSS key and indirection table."""

    qcnt = len(_get_rx_cnts(cfg))
    if qcnt < 3:
        raise KsftSkipEx("Device has fewer than 3 queues (or doesn't support queue stats)")

    data = get_rss(cfg)
    want_keys = ['rss-hash-key', 'rss-hash-function', 'rss-indirection-table']
    for k in want_keys:
        if k not in data:
            raise KsftFailEx("ethtool results missing key: " + k)
        if not data[k]:
            raise KsftFailEx(f"ethtool results empty for '{k}': {data[k]}")

    _rss_key_check(cfg, data=data)
    key_len = len(data['rss-hash-key'])

    # Set the key
    key = _rss_key_rand(key_len)
    ethtool(f"-X {cfg.ifname} hkey " + _rss_key_str(key))

    data = get_rss(cfg)
    ksft_eq(key, data['rss-hash-key'])

    # Set the indirection table and the key together
    key = _rss_key_rand(key_len)
    ethtool(f"-X {cfg.ifname} equal 3 hkey " + _rss_key_str(key))
    reset_indir = defer(ethtool, f"-X {cfg.ifname} default")

    data = get_rss(cfg)
    _rss_key_check(cfg, data=data)
    ksft_eq(0, min(data['rss-indirection-table']))
    ksft_eq(2, max(data['rss-indirection-table']))

    # Reset indirection table and set the key
    key = _rss_key_rand(key_len)
    ethtool(f"-X {cfg.ifname} default hkey " + _rss_key_str(key))
    data = get_rss(cfg)
    _rss_key_check(cfg, data=data)
    ksft_eq(0, min(data['rss-indirection-table']))
    ksft_eq(qcnt - 1, max(data['rss-indirection-table']))

    # Set the indirection table
    ethtool(f"-X {cfg.ifname} equal 2")
    data = get_rss(cfg)
    ksft_eq(0, min(data['rss-indirection-table']))
    ksft_eq(1, max(data['rss-indirection-table']))

    # Check we only get traffic on the first 2 queues

    # Retry a few times in case the flows skew to a single queue.
    attempts = 3
    for attempt in range(attempts):
        cnts = _get_rx_cnts(cfg)
        GenerateTraffic(cfg).wait_pkts_and_stop(20000)
        cnts = _get_rx_cnts(cfg, prev=cnts)
        if cnts[0] >= 5000 and cnts[1] >= 5000:
            break
        ksft_pr(f"Skewed queue distribution, attempt {attempt + 1}/{attempts}: " + str(cnts))

    # 2 queues, 20k packets, must be at least 5k per queue
    ksft_ge(cnts[0], 5000, "traffic on main context (1/2): " + str(cnts))
    ksft_ge(cnts[1], 5000, "traffic on main context (2/2): " + str(cnts))
    # The other queues should be unused
    ksft_eq(sum(cnts[2:]), 0, "traffic on unused queues: " + str(cnts))

    # Restore, and check traffic gets spread again
    reset_indir.exec()

    for attempt in range(attempts):
        cnts = _get_rx_cnts(cfg)
        GenerateTraffic(cfg).wait_pkts_and_stop(20000)
        cnts = _get_rx_cnts(cfg, prev=cnts)
        if qcnt > 4:
            if sum(cnts[:2]) < sum(cnts[2:]):
                break
        else:
            if cnts[2] >= 3500:
                break
        ksft_pr(f"Skewed queue distribution, attempt {attempt + 1}/{attempts}: " + str(cnts))

    if qcnt > 4:
        # First two queues get less traffic than all the rest
        ksft_lt(sum(cnts[:2]), sum(cnts[2:]),
                "traffic distributed: " + str(cnts))
    else:
        # When queue count is low make sure third queue got significant pkts
        ksft_ge(cnts[2], 3500, "traffic distributed: " + str(cnts))


def test_rss_queue_reconfigure(cfg, main_ctx=True):
    """Make sure queue changes can't override requested RSS config.

    By default main RSS table should change to include all queues.
    When user sets a specific RSS config the driver should preserve it,
    even when queue count changes. Driver should refuse to deactivate
    queues used in the user-set RSS config.
    """

    if not main_ctx:
        require_ntuple(cfg)

    # Start with 4 queues, an arbitrary known number.
    try:
        qcnt = len(_get_rx_cnts(cfg))
        ethtool(f"-L {cfg.ifname} combined 4")
        defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
    except:
        raise KsftSkipEx("Not enough queues for the test or qstat not supported")

    if main_ctx:
        ctx_id = 0
        ctx_ref = ""
    else:
        ctx_id = ethtool_create(cfg, "-X", "context new")
        ctx_ref = f"context {ctx_id}"
        defer(ethtool, f"-X {cfg.ifname} {ctx_ref} delete")

    # Indirection table should be distributing to all queues.
    data = get_rss(cfg, context=ctx_id)
    ksft_eq(0, min(data['rss-indirection-table']))
    ksft_eq(3, max(data['rss-indirection-table']))

    # Increase queues, indirection table should be distributing to all queues.
    # It's unclear whether tables of additional contexts should be reset, too.
    if main_ctx:
        ethtool(f"-L {cfg.ifname} combined 5")
        data = get_rss(cfg)
        ksft_eq(0, min(data['rss-indirection-table']))
        ksft_eq(4, max(data['rss-indirection-table']))
        ethtool(f"-L {cfg.ifname} combined 4")

    # Configure the table explicitly
    port = rand_port()
    ethtool(f"-X {cfg.ifname} {ctx_ref} weight 1 0 0 1")
    if main_ctx:
        other_key = 'empty'
        defer(ethtool, f"-X {cfg.ifname} default")
    else:
        other_key = 'noise'
        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port} context {ctx_id}"
        ntuple = ethtool_create(cfg, "-N", flow)
        defer(ethtool, f"-N {cfg.ifname} delete {ntuple}")

    _send_traffic_check(cfg, port, ctx_ref, { 'target': (0, 3),
                                              other_key: (1, 2) })

    # We should be able to increase queues, but table should be left untouched
    ethtool(f"-L {cfg.ifname} combined 5")
    data = get_rss(cfg, context=ctx_id)
    ksft_eq({0, 3}, set(data['rss-indirection-table']))

    _send_traffic_check(cfg, port, ctx_ref, { 'target': (0, 3),
                                              other_key: (1, 2, 4) })

    # Setting queue count to 3 should fail, queue 3 is used
    try:
        ethtool(f"-L {cfg.ifname} combined 3")
    except CmdExitFailure:
        pass
    else:
        raise Exception(f"Driver didn't prevent us from deactivating a used queue (context {ctx_id})")

    if not main_ctx:
        ethtool(f"-L {cfg.ifname} combined 4")
        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port} context {ctx_id} action 1"
        try:
            # this targets queue 4, which doesn't exist
            ntuple2 = ethtool_create(cfg, "-N", flow)
            defer(ethtool, f"-N {cfg.ifname} delete {ntuple2}")
        except CmdExitFailure:
            pass
        else:
            raise Exception(f"Driver didn't prevent us from targeting a nonexistent queue (context {ctx_id})")
        # change the table to target queues 0 and 2
        ethtool(f"-X {cfg.ifname} {ctx_ref} weight 1 0 1 0")
        # ntuple rule therefore targets queues 1 and 3
        try:
            ntuple2 = ethtool_create(cfg, "-N", flow)
        except CmdExitFailure:
            ksft_pr("Driver does not support rss + queue offset")
            return

        defer(ethtool, f"-N {cfg.ifname} delete {ntuple2}")
        # should replace existing filter
        ksft_eq(ntuple, ntuple2)
        _send_traffic_check(cfg, port, ctx_ref, { 'target': (1, 3),
                                                  'noise' : (0, 2) })
        # Setting queue count to 3 should fail, queue 3 is used
        try:
            ethtool(f"-L {cfg.ifname} combined 3")
        except CmdExitFailure:
            pass
        else:
            raise Exception(f"Driver didn't prevent us from deactivating a used queue (context {ctx_id})")


def test_rss_resize(cfg):
    """Test resizing of the RSS table.

    Some devices dynamically increase and decrease the size of the RSS
    indirection table based on the number of enabled queues.
    When that happens driver must maintain the balance of entries
    (preferably duplicating the smaller table).
    """

    channels = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
    ch_max = channels['combined-max']
    qcnt = channels['combined-count']

    if ch_max < 2:
        raise KsftSkipEx(f"Not enough queues for the test: {ch_max}")

    ethtool(f"-L {cfg.ifname} combined 2")
    defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")

    ethtool(f"-X {cfg.ifname} weight 1 7")
    defer(ethtool, f"-X {cfg.ifname} default")

    ethtool(f"-L {cfg.ifname} combined {ch_max}")
    data = get_rss(cfg)
    ksft_eq(0, min(data['rss-indirection-table']))
    ksft_eq(1, max(data['rss-indirection-table']))

    ksft_eq(7,
            data['rss-indirection-table'].count(1) /
            data['rss-indirection-table'].count(0),
            f"Table imbalance after resize: {data['rss-indirection-table']}")


def test_hitless_key_update(cfg):
    """Test that flows may be rehashed without impacting traffic.

    Some workloads may want to rehash the flows in response to an imbalance.
    Most effective way to do that is changing the RSS key. Check that changing
    the key does not cause link flaps or traffic disruption.

    Disrupting traffic for key update is not a bug, but makes the key
    update unusable for rehashing under load.
    """
    data = get_rss(cfg)
    key_len = len(data['rss-hash-key'])

    ethnl = EthtoolFamily()
    key = random.randbytes(key_len)

    tgen = GenerateTraffic(cfg)
    try:
        errors0, carrier0 = get_drop_err_sum(cfg)
        t0 = datetime.datetime.now()
        ethnl.rss_set({"header": {"dev-index": cfg.ifindex}, "hkey": key})
        t1 = datetime.datetime.now()
        errors1, carrier1 = get_drop_err_sum(cfg)
    finally:
        tgen.wait_pkts_and_stop(5000)

    ksft_lt((t1 - t0).total_seconds(), 0.15)
    ksft_eq(errors1 - errors0, 0)
    ksft_eq(carrier1 - carrier0, 0)


def test_rss_context_dump(cfg):
    """
    Test dumping RSS contexts. This tests mostly exercises the kernel APIs.
    """

    # Get a random key of the right size
    data = get_rss(cfg)
    if 'rss-hash-key' in data:
        key_data = _rss_key_rand(len(data['rss-hash-key']))
        key = _rss_key_str(key_data)
    else:
        key_data = []
        key = "ba:ad"

    ids = []
    try:
        ids.append(ethtool_create(cfg, "-X", f"context new"))
        defer(ethtool, f"-X {cfg.ifname} context {ids[-1]} delete")

        ids.append(ethtool_create(cfg, "-X", f"context new weight 1 1"))
        defer(ethtool, f"-X {cfg.ifname} context {ids[-1]} delete")

        ids.append(ethtool_create(cfg, "-X", f"context new hkey {key}"))
        defer(ethtool, f"-X {cfg.ifname} context {ids[-1]} delete")
    except CmdExitFailure:
        if not ids:
            raise KsftSkipEx("Unable to add any contexts")
        ksft_pr(f"Added only {len(ids)} out of 3 contexts")

    expect_tuples = set([(cfg.ifname, -1)] + [(cfg.ifname, ctx_id) for ctx_id in ids])

    # Dump all
    ctxs = cfg.ethnl.rss_get({}, dump=True)
    tuples = [(c['header']['dev-name'], c.get('context', -1)) for c in ctxs]
    ksft_eq(len(tuples), len(set(tuples)), "duplicates in context dump")
    ctx_tuples = set([ctx for ctx in tuples if ctx[0] == cfg.ifname])
    ksft_eq(expect_tuples, ctx_tuples)

    # Sanity-check the results
    for data in ctxs:
        ksft_ne(set(data.get('indir', [1])), {0}, "indir table is all zero")
        ksft_ne(set(data.get('hkey', [1])), {0}, "key is all zero")

        # More specific checks
        if len(ids) > 1 and data.get('context') == ids[1]:
            ksft_eq(set(data['indir']), {0, 1},
                    "ctx1 - indir table mismatch")
        if len(ids) > 2 and data.get('context') == ids[2]:
            ksft_eq(data['hkey'], bytes(key_data), "ctx2 - key mismatch")

    # Ifindex filter
    ctxs = cfg.ethnl.rss_get({'header': {'dev-name': cfg.ifname}}, dump=True)
    tuples = [(c['header']['dev-name'], c.get('context', -1)) for c in ctxs]
    ctx_tuples = set(tuples)
    ksft_eq(len(tuples), len(ctx_tuples), "duplicates in context dump")
    ksft_eq(expect_tuples, ctx_tuples)

    # Skip ctx 0
    expect_tuples.remove((cfg.ifname, -1))

    ctxs = cfg.ethnl.rss_get({'start-context': 1}, dump=True)
    tuples = [(c['header']['dev-name'], c.get('context', -1)) for c in ctxs]
    ksft_eq(len(tuples), len(set(tuples)), "duplicates in context dump")
    ctx_tuples = set([ctx for ctx in tuples if ctx[0] == cfg.ifname])
    ksft_eq(expect_tuples, ctx_tuples)

    # And finally both with ifindex and skip main
    ctxs = cfg.ethnl.rss_get({'header': {'dev-name': cfg.ifname}, 'start-context': 1}, dump=True)
    ctx_tuples = set([(c['header']['dev-name'], c.get('context', -1)) for c in ctxs])
    ksft_eq(expect_tuples, ctx_tuples)


def test_rss_context(cfg, ctx_cnt=1, create_with_cfg=None):
    """
    Test separating traffic into RSS contexts.
    The queues will be allocated 2 for each context:
     ctx0  ctx1  ctx2  ctx3
    [0 1] [2 3] [4 5] [6 7] ...
    """

    require_ntuple(cfg)

    requested_ctx_cnt = ctx_cnt

    # Try to allocate more queues when necessary
    qcnt = len(_get_rx_cnts(cfg))
    if qcnt < 2 + 2 * ctx_cnt:
        try:
            ksft_pr(f"Increasing queue count {qcnt} -> {2 + 2 * ctx_cnt}")
            ethtool(f"-L {cfg.ifname} combined {2 + 2 * ctx_cnt}")
            defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
        except:
            raise KsftSkipEx("Not enough queues for the test")

    ports = rand_ports(ctx_cnt)

    # Use queues 0 and 1 for normal traffic
    ethtool(f"-X {cfg.ifname} equal 2")
    defer(ethtool, f"-X {cfg.ifname} default")

    for i in range(ctx_cnt):
        want_cfg = f"start {2 + i * 2} equal 2"
        create_cfg = want_cfg if create_with_cfg else ""

        try:
            ctx_id = ethtool_create(cfg, "-X", f"context new {create_cfg}")
            defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")
        except CmdExitFailure:
            # try to carry on and skip at the end
            if i == 0:
                raise
            ksft_pr(f"Failed to create context {i + 1}, trying to test what we got")
            ctx_cnt = i
            if cfg.context_cnt is None:
                cfg.context_cnt = ctx_cnt
            break

        _rss_key_check(cfg, context=ctx_id)

        if not create_with_cfg:
            ethtool(f"-X {cfg.ifname} context {ctx_id} {want_cfg}")
            _rss_key_check(cfg, context=ctx_id)

        # Sanity check the context we just created
        data = get_rss(cfg, ctx_id)
        ksft_eq(min(data['rss-indirection-table']), 2 + i * 2, "Unexpected context cfg: " + str(data))
        ksft_eq(max(data['rss-indirection-table']), 2 + i * 2 + 1, "Unexpected context cfg: " + str(data))

        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {ports[i]} context {ctx_id}"
        ntuple = ethtool_create(cfg, "-N", flow)
        defer(ethtool, f"-N {cfg.ifname} delete {ntuple}")

        _ntuple_rule_check(cfg, ntuple, ctx_id)

    for i in range(ctx_cnt):
        _send_traffic_check(cfg, ports[i], f"context {i}",
                            { 'target': (2+i*2, 3+i*2),
                              'noise': (0, 1),
                              'empty': list(range(2, 2+i*2)) + list(range(4+i*2, 2+2*ctx_cnt)) })

    if requested_ctx_cnt != ctx_cnt:
        raise KsftSkipEx(f"Tested only {ctx_cnt} contexts, wanted {requested_ctx_cnt}")


def test_rss_context4(cfg):
    test_rss_context(cfg, 4)


def test_rss_context32(cfg):
    test_rss_context(cfg, 32)


def test_rss_context4_create_with_cfg(cfg):
    test_rss_context(cfg, 4, create_with_cfg=True)


def test_rss_context_queue_reconfigure(cfg):
    test_rss_queue_reconfigure(cfg, main_ctx=False)


def test_rss_context_out_of_order(cfg, ctx_cnt=4):
    """
    Test separating traffic into RSS contexts.
    Contexts are removed in semi-random order, and steering re-tested
    to make sure removal doesn't break steering to surviving contexts.
    Test requires 3 contexts to work.
    """

    require_ntuple(cfg)
    require_context_cnt(cfg, 4)

    # Try to allocate more queues when necessary
    qcnt = len(_get_rx_cnts(cfg))
    if qcnt < 2 + 2 * ctx_cnt:
        try:
            ksft_pr(f"Increasing queue count {qcnt} -> {2 + 2 * ctx_cnt}")
            ethtool(f"-L {cfg.ifname} combined {2 + 2 * ctx_cnt}")
            defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
        except:
            raise KsftSkipEx("Not enough queues for the test")

    ntuple = []
    ctx = []
    ports = rand_ports(ctx_cnt)

    def remove_ctx(idx):
        ntuple[idx].exec()
        ntuple[idx] = None
        ctx[idx].exec()
        ctx[idx] = None

    def check_traffic():
        for i in range(ctx_cnt):
            if ctx[i]:
                expected = {
                    'target': (2+i*2, 3+i*2),
                    'noise': (0, 1),
                    'empty': list(range(2, 2+i*2)) + list(range(4+i*2, 2+2*ctx_cnt))
                }
            else:
                expected = {
                    'target': (0, 1),
                    'empty':  range(2, 2+2*ctx_cnt)
                }

            _send_traffic_check(cfg, ports[i], f"context {i}", expected)

    # Use queues 0 and 1 for normal traffic
    ethtool(f"-X {cfg.ifname} equal 2")
    defer(ethtool, f"-X {cfg.ifname} default")

    for i in range(ctx_cnt):
        ctx_id = ethtool_create(cfg, "-X", f"context new start {2 + i * 2} equal 2")
        ctx.append(defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete"))

        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {ports[i]} context {ctx_id}"
        ntuple_id = ethtool_create(cfg, "-N", flow)
        ntuple.append(defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}"))

    check_traffic()

    # Remove middle context
    remove_ctx(ctx_cnt // 2)
    check_traffic()

    # Remove first context
    remove_ctx(0)
    check_traffic()

    # Remove last context
    remove_ctx(-1)
    check_traffic()


def test_rss_context_overlap(cfg, other_ctx=0):
    """
    Test contexts overlapping with each other.
    Use 4 queues for the main context, but only queues 2 and 3 for context 1.
    """

    require_ntuple(cfg)
    if other_ctx:
        require_context_cnt(cfg, 2)

    queue_cnt = len(_get_rx_cnts(cfg))
    if queue_cnt < 4:
        try:
            ksft_pr(f"Increasing queue count {queue_cnt} -> 4")
            ethtool(f"-L {cfg.ifname} combined 4")
            defer(ethtool, f"-L {cfg.ifname} combined {queue_cnt}")
        except:
            raise KsftSkipEx("Not enough queues for the test")

    if other_ctx == 0:
        ethtool(f"-X {cfg.ifname} equal 4")
        defer(ethtool, f"-X {cfg.ifname} default")
    else:
        other_ctx = ethtool_create(cfg, "-X", "context new")
        ethtool(f"-X {cfg.ifname} context {other_ctx} equal 4")
        defer(ethtool, f"-X {cfg.ifname} context {other_ctx} delete")

    ctx_id = ethtool_create(cfg, "-X", "context new")
    ethtool(f"-X {cfg.ifname} context {ctx_id} start 2 equal 2")
    defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")

    port = rand_port()
    if other_ctx:
        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port} context {other_ctx}"
        ntuple_id = ethtool_create(cfg, "-N", flow)
        ntuple = defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}")

    # Test the main context
    attempts = 3
    for attempt in range(attempts):
        cnts = _get_rx_cnts(cfg)
        GenerateTraffic(cfg, port=port).wait_pkts_and_stop(20000)
        cnts = _get_rx_cnts(cfg, prev=cnts)
        if sum(cnts[:2]) >= 7000 and sum(cnts[2:4]) >= 7000:
            break
        ksft_pr(f"Skewed queue distribution, attempt {attempt + 1}/{attempts}: " + str(cnts))

    ksft_ge(sum(cnts[ :4]), 20000, "traffic on main context: " + str(cnts))
    ksft_ge(sum(cnts[ :2]),  7000, "traffic on main context (1/2): " + str(cnts))
    ksft_ge(sum(cnts[2:4]),  7000, "traffic on main context (2/2): " + str(cnts))
    if other_ctx == 0:
        ksft_eq(sum(cnts[4: ]),     0, "traffic on other queues: " + str(cnts))

    # Now create a rule for context 1 and make sure traffic goes to a subset
    if other_ctx:
        ntuple.exec()
    flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port} context {ctx_id}"
    ntuple_id = ethtool_create(cfg, "-N", flow)
    defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}")

    cnts = _get_rx_cnts(cfg)
    GenerateTraffic(cfg, port=port).wait_pkts_and_stop(20000)
    cnts = _get_rx_cnts(cfg, prev=cnts)

    directed = sum(cnts[2:4])
    ksft_lt(sum(cnts[ :2]), directed / 2, "traffic on main context: " + str(cnts))
    ksft_ge(directed, 20000, "traffic on extra context: " + str(cnts))
    if other_ctx == 0:
        ksft_eq(sum(cnts[4: ]),     0, "traffic on other queues: " + str(cnts))


def test_rss_context_overlap2(cfg):
    test_rss_context_overlap(cfg, True)


def test_flow_add_context_missing(cfg):
    """
    Test that we are not allowed to add a rule pointing to an RSS context
    which was never created.
    """

    require_ntuple(cfg)

    # Find a context which doesn't exist
    for ctx_id in range(1, 100):
        try:
            get_rss(cfg, context=ctx_id)
        except CmdExitFailure:
            break

    with ksft_raises(CmdExitFailure) as cm:
        flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port 1234 context {ctx_id}"
        ntuple_id = ethtool_create(cfg, "-N", flow)
        ethtool(f"-N {cfg.ifname} delete {ntuple_id}")
    if cm.exception:
        ksft_in('Invalid argument', cm.exception.cmd.stderr)


def test_delete_rss_context_busy(cfg):
    """
    Test that deletion returns -EBUSY when an rss context is being used
    by an ntuple filter.
    """

    require_ntuple(cfg)

    # create additional rss context
    ctx_id = ethtool_create(cfg, "-X", "context new")
    ctx_deleter = defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")

    # utilize context from ntuple filter
    port = rand_port()
    flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port} context {ctx_id}"
    ntuple_id = ethtool_create(cfg, "-N", flow)
    defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}")

    # attempt to delete in-use context
    try:
        ctx_deleter.exec_only()
        ctx_deleter.cancel()
        raise KsftFailEx(f"deleted context {ctx_id} used by rule {ntuple_id}")
    except CmdExitFailure:
        pass


def test_rss_ntuple_addition(cfg):
    """
    Test that the queue offset (ring_cookie) of an ntuple rule is added
    to the queue number read from the indirection table.
    """

    require_ntuple(cfg)

    queue_cnt = len(_get_rx_cnts(cfg))
    if queue_cnt < 4:
        try:
            ksft_pr(f"Increasing queue count {queue_cnt} -> 4")
            ethtool(f"-L {cfg.ifname} combined 4")
            defer(ethtool, f"-L {cfg.ifname} combined {queue_cnt}")
        except:
            raise KsftSkipEx("Not enough queues for the test")

    # Use queue 0 for normal traffic
    ethtool(f"-X {cfg.ifname} equal 1")
    defer(ethtool, f"-X {cfg.ifname} default")

    # create additional rss context
    ctx_id = ethtool_create(cfg, "-X", "context new equal 2")
    defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")

    # utilize context from ntuple filter
    port = rand_port()
    flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port} context {ctx_id} action 2"
    try:
        ntuple_id = ethtool_create(cfg, "-N", flow)
    except CmdExitFailure:
        raise KsftSkipEx("Ntuple filter with RSS and nonzero action not supported")
    defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}")

    _send_traffic_check(cfg, port, f"context {ctx_id}", { 'target': (2, 3),
                                                          'empty' : (1,),
                                                          'noise' : (0,) })


def test_rss_default_context_rule(cfg):
    """
    Allocate a port, direct this port to context 0, then create a new RSS
    context and steer all TCP traffic to it (context 1).  Verify that:
      * Traffic to the specific port continues to use queues of the main
        context (0/1).
      * Traffic to any other TCP port is redirected to the new context
        (queues 2/3).
    """

    require_ntuple(cfg)

    queue_cnt = len(_get_rx_cnts(cfg))
    if queue_cnt < 4:
        try:
            ksft_pr(f"Increasing queue count {queue_cnt} -> 4")
            ethtool(f"-L {cfg.ifname} combined 4")
            defer(ethtool, f"-L {cfg.ifname} combined {queue_cnt}")
        except Exception as exc:
            raise KsftSkipEx("Not enough queues for the test") from exc

    # Use queues 0 and 1 for the main context
    ethtool(f"-X {cfg.ifname} equal 2")
    defer(ethtool, f"-X {cfg.ifname} default")

    # Create a new RSS context that uses queues 2 and 3
    ctx_id = ethtool_create(cfg, "-X", "context new start 2 equal 2")
    defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")

    # Generic low-priority rule: redirect all TCP traffic to the new context.
    # Give it an explicit higher location number (lower priority).
    flow_generic = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} context {ctx_id} loc 1"
    ethtool(f"-N {cfg.ifname} {flow_generic}")
    defer(ethtool, f"-N {cfg.ifname} delete 1")

    ports = rand_ports(2)
    # Specific high-priority rule for a random port that should stay on context 0.
    # Assign loc 0 so it is evaluated before the generic rule.
    port_main = ports[0]
    flow_main = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port_main} context 0 loc 0"
    ethtool(f"-N {cfg.ifname} {flow_main}")
    defer(ethtool, f"-N {cfg.ifname} delete 0")

    _ntuple_rule_check(cfg, 1, ctx_id)

    # Verify that traffic matching the specific rule still goes to queues 0/1
    _send_traffic_check(cfg, port_main, "context 0",
                        { 'target': (0, 1),
                          'empty' : (2, 3) })

    # And that traffic for any other port is steered to the new context
    port_other = ports[1]
    _send_traffic_check(cfg, port_other, f"context {ctx_id}",
                        { 'target': (2, 3),
                          'noise' : (0, 1) })


def _set_flow_hash(cfg, fl_type, fields, context=0):
    req = {"header": {"dev-index": cfg.ifindex},
           "flow-hash": {fl_type: fields}}
    if context:
        req["context"] = context
    cfg.ethnl.rss_set(req)


def _get_flow_hash(cfg, fl_type, context=0):
    req = {"header": {"dev-index": cfg.ifindex}}
    if context:
        req["context"] = context
    rss = cfg.ethnl.rss_get(req)
    return rss.get("flow-hash", {}).get(fl_type, set())


def test_rss_context_flow_hash(cfg):
    """
    Validate, with traffic, that an additional RSS context honors the
    flow-hash field selection. If the driver lacks per-context field
    configuration ("ops->rxfh_per_ctx_fields") fall back to setting the
    fields on the main context, which the kernel applies device-wide.
    """

    require_ntuple(cfg)

    queue_cnt = len(_get_rx_cnts(cfg))
    if queue_cnt < 6:
        try:
            ksft_pr(f"Increasing queue count {queue_cnt} -> 6")
            ethtool(f"-L {cfg.ifname} combined 6")
            defer(ethtool, f"-L {cfg.ifname} combined {queue_cnt}")
        except CmdExitFailure as exc:
            raise KsftSkipEx("Not enough queues for the test") from exc

    fl_type = f"tcp{cfg.addr_ipver}"
    if not _get_flow_hash(cfg, fl_type):
        raise KsftSkipEx(f"Device does not report flow-hash for {fl_type}")

    # Reserve queues 0/1 for main, build a new context spanning 2..5
    ethtool(f"-X {cfg.ifname} equal 2")
    defer(ethtool, f"-X {cfg.ifname} default")
    ctx_id = ethtool_create(cfg, "-X", "context new start 2 equal 4")
    defer(ethtool, f"-X {cfg.ifname} context {ctx_id} delete")

    port = rand_port()
    flow = f"flow-type {fl_type} dst-ip {cfg.addr} dst-port {port} context {ctx_id}"
    ntuple = ethtool_create(cfg, "-N", flow)
    defer(ethtool, f"-N {cfg.ifname} delete {ntuple}")

    ip_only = {"ip-src", "ip-dst"}
    ip_l4   = ip_only | {"l4-b-0-1", "l4-b-2-3"}

    # Try per-context flow-hash; fall back to main context if unsupported.
    cfg_ctx = ctx_id
    try:
        orig = _get_flow_hash(cfg, fl_type, context=ctx_id)
        _set_flow_hash(cfg, fl_type, ip_only, context=ctx_id)
    except NlError:
        ksft_pr("Per-context flow-hash not supported, using device-wide")
        cfg_ctx = 0
        orig = _get_flow_hash(cfg, fl_type)
        _set_flow_hash(cfg, fl_type, ip_only)
    defer(_set_flow_hash, cfg, fl_type, orig, context=cfg_ctx)

    def measure():
        cnts = _get_rx_cnts(cfg)
        GenerateTraffic(cfg, port=port).wait_pkts_and_stop(20000)
        cnts = _get_rx_cnts(cfg, prev=cnts)
        ctx_cnts = cnts[2:6]
        directed = sum(ctx_cnts)
        used = sum(1 for c in ctx_cnts if c > directed / 200)
        return cnts, directed, used

    # IP-only hash: iperf3 streams share src/dst IP, all should land on the
    # same queue inside the context's range.
    cnts, directed, used = measure()
    ksft_ge(directed, 20000, f"traffic on context {ctx_id} (IP-only): {cnts}")
    ksft_eq(used, 1, f"IP-only hash should use one queue in context {ctx_id}, got: {cnts}")

    # IP+L4 hash: streams have distinct src ports, traffic should spread.
    _set_flow_hash(cfg, fl_type, ip_l4, context=cfg_ctx)

    cnts, directed, used = measure()
    ksft_ge(directed, 20000, f"traffic on context {ctx_id} (IP+L4): {cnts}")
    ksft_ge(used, 2, f"IP+L4 hash should spread across context {ctx_id} queues, got: {cnts}")


@ksft_disruptive
def test_rss_context_persist_ifupdown(cfg, pre_down=False):
    """
    Test that RSS contexts and their associated ntuple filters persist across
    an interface down/up cycle.

    """

    require_ntuple(cfg)

    qcnt = len(_get_rx_cnts(cfg))
    if qcnt < 6:
        try:
            ethtool(f"-L {cfg.ifname} combined 6")
            defer(ethtool, f"-L {cfg.ifname} combined {qcnt}")
        except Exception as exc:
            raise KsftSkipEx("Not enough queues for the test") from exc

    ethtool(f"-X {cfg.ifname} equal 2")
    defer(ethtool, f"-X {cfg.ifname} default")

    ifup = defer(ip, f"link set dev {cfg.ifname} up")
    if pre_down:
        ip(f"link set dev {cfg.ifname} down")

    try:
        ctx1_id = ethtool_create(cfg, "-X", "context new start 2 equal 2")
        defer(ethtool, f"-X {cfg.ifname} context {ctx1_id} delete")
    except CmdExitFailure as exc:
        raise KsftSkipEx("Create context not supported with interface down") from exc

    ctx2_id = ethtool_create(cfg, "-X", "context new start 4 equal 2")
    defer(ethtool, f"-X {cfg.ifname} context {ctx2_id} delete")

    port_ctx2 = rand_port()
    flow = f"flow-type tcp{cfg.addr_ipver} dst-ip {cfg.addr} dst-port {port_ctx2} context {ctx2_id}"
    ntuple_id = ethtool_create(cfg, "-N", flow)
    defer(ethtool, f"-N {cfg.ifname} delete {ntuple_id}")

    if not pre_down:
        ip(f"link set dev {cfg.ifname} down")
    ifup.exec()

    wait_file(f"/sys/class/net/{cfg.ifname}/carrier",
        lambda x: x.strip() == "1", deadline=20)

    remote_addr = cfg.remote_addr_v[cfg.addr_ipver]
    for _ in range(10):
        if cmd(f"ping -c 1 -W 1 {remote_addr}", fail=False).ret == 0:
            break
        time.sleep(1)
    else:
        raise KsftSkipEx("Cannot reach remote host after interface up")

    ctxs = cfg.ethnl.rss_get({'header': {'dev-name': cfg.ifname}}, dump=True)

    data1 = [c for c in ctxs if c.get('context') == ctx1_id]
    ksft_eq(len(data1), 1, f"Context {ctx1_id} should persist after ifup")

    data2 = [c for c in ctxs if c.get('context') == ctx2_id]
    ksft_eq(len(data2), 1, f"Context {ctx2_id} should persist after ifup")

    _ntuple_rule_check(cfg, ntuple_id, ctx2_id)

    cnts = _get_rx_cnts(cfg)
    GenerateTraffic(cfg).wait_pkts_and_stop(20000)
    cnts = _get_rx_cnts(cfg, prev=cnts)

    main_traffic = sum(cnts[0:2])
    ksft_ge(main_traffic, 18000, f"Main context traffic distribution: {cnts}")
    ksft_lt(sum(cnts[2:6]), 500, f"Other context queues should be mostly empty: {cnts}")

    _send_traffic_check(cfg, port_ctx2, f"context {ctx2_id}",
                        {'target': (4, 5),
                         'noise': (0, 1),
                         'empty': (2, 3)})


def test_rss_context_persist_create_and_ifdown(cfg):
    """
    Create RSS contexts then cycle the interface down and up.
    """
    test_rss_context_persist_ifupdown(cfg, pre_down=False)


def test_rss_context_persist_ifdown_and_create(cfg):
    """
    Bring interface down first, then create RSS contexts and bring up.
    """
    test_rss_context_persist_ifupdown(cfg, pre_down=True)


def main() -> None:
    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
        cfg.context_cnt = None
        cfg.ethnl = EthtoolFamily()
        cfg.netdevnl = NetdevFamily()

        ksft_run([test_rss_key_indir, test_rss_queue_reconfigure,
                  test_rss_resize, test_hitless_key_update,
                  test_rss_context, test_rss_context4, test_rss_context32,
                  test_rss_context_dump, test_rss_context_queue_reconfigure,
                  test_rss_context_overlap, test_rss_context_overlap2,
                  test_rss_context_out_of_order, test_rss_context4_create_with_cfg,
                  test_flow_add_context_missing,
                  test_delete_rss_context_busy, test_rss_ntuple_addition,
                  test_rss_default_context_rule,
                  test_rss_context_flow_hash,
                  test_rss_context_persist_create_and_ifdown,
                  test_rss_context_persist_ifdown_and_create],
                 args=(cfg, ))
    ksft_exit()


if __name__ == "__main__":
    main()