[
    {
        "id": "afa9",
        "name": "Add u32 with source match",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress"
        ],
        "cmdUnderTest": "$TC filter add dev $DEV1 ingress protocol ip prio 1 u32 match ip src 127.0.0.1/32 flowid 1:1 action ok",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol ip pref 1 u32 chain (0[ ]+$|0 fh 800: ht divisor 1|0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1.*match 7f000001/ffffffff at 12)",
        "matchCount": "3",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "6aa7",
        "name": "Add/Replace u32 with source match and invalid indev",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress"
        ],
        "cmdUnderTest": "$TC filter replace dev $DEV1 ingress protocol ip prio 1 u32 match ip src 127.0.0.1/32 indev notexist20 flowid 1:1 action ok",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol ip pref 1 u32 chain 0",
        "matchCount": "0",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "bc4d",
        "name": "Replace valid u32 with source match and invalid indev",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress",
            "$TC filter add dev $DEV1 ingress protocol ip prio 1 u32 match ip src 127.0.0.3/32 flowid 1:3 action ok"
        ],
        "cmdUnderTest": "$TC filter replace dev $DEV1 ingress protocol ip prio 1 u32 match ip src 127.0.0.2/32 indev notexist20 flowid 1:2 action ok",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol ip pref 1 u32 chain (0[ ]+$|0 fh 800: ht divisor 1|0 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:3.*match 7f000003/ffffffff at 12)",
        "matchCount": "3",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "648b",
        "name": "Add u32 with custom hash table",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress"
        ],
        "cmdUnderTest": "$TC filter add dev $DEV1 ingress prio 99 handle 42: u32 divisor 256",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "pref 99 u32 chain (0[ ]+$|0 fh 42: ht divisor 256|0 fh 800: ht divisor 1)",
        "matchCount": "3",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "6658",
        "name": "Add/Replace u32 with custom hash table and invalid handle",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress"
        ],
        "cmdUnderTest": "$TC filter replace dev $DEV1 ingress prio 99 handle 42:42 u32 divisor 256",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "pref 99 u32 chain 0",
        "matchCount": "0",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "9d0a",
        "name": "Replace valid u32 with custom hash table and invalid handle",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress",
            "$TC filter add dev $DEV1 ingress prio 99 handle 42: u32 divisor 256"
        ],
        "cmdUnderTest": "$TC filter replace dev $DEV1 ingress prio 99 handle 42:42 u32 divisor 128",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "pref 99 u32 chain (0[ ]+$|0 fh 42: ht divisor 256|0 fh 800: ht divisor 1)",
        "matchCount": "3",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "1644",
        "name": "Add u32 filter that links to a custom hash table",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress",
            "$TC filter add dev $DEV1 ingress prio 99 handle 43: u32 divisor 256"
        ],
        "cmdUnderTest": "$TC filter add dev $DEV1 ingress protocol ip prio 98 u32 link 43: hashkey mask 0x0000ff00 at 12 match ip src 192.168.0.0/16",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol ip pref 98 u32 chain (0[ ]+$|0 fh 801: ht divisor 1|0 fh 801::800 order 2048 key ht 801 bkt 0 link 43:.*match c0a80000/ffff0000 at 12.*hash mask 0000ff00 at 12)",
        "matchCount": "3",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "74c2",
        "name": "Add/Replace u32 filter with invalid hash table id",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress"
        ],
        "cmdUnderTest": "$TC filter replace dev $DEV1 ingress protocol ip prio 20 u32 ht 47:47 action drop",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol ip pref 20 u32 chain 0",
        "matchCount": "0",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "1fe6",
        "name": "Replace valid u32 filter with invalid hash table id",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress",
            "$TC filter add dev $DEV1 ingress protocol ip prio 99 handle 43: u32 divisor 1",
            "$TC filter add dev $DEV1 ingress protocol ip prio 98 u32 ht 43: match tcp src 22 FFFF classid 1:3"
        ],
        "cmdUnderTest": "$TC filter replace dev $DEV1 ingress protocol ip prio 98 u32 ht 43:1 match tcp src 23 FFFF classid 1:4",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol ip pref 99 u32 chain (0[ ]+$|0 fh (43|800): ht divisor 1|0 fh 43::800 order 2048 key ht 43 bkt 0 flowid 1:3.*match 00160000/ffff0000 at nexthdr\\+0)",
        "matchCount": "4",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "0692",
        "name": "Test u32 sample option, divisor 256",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress",
            "$TC filter add dev $DEV1 ingress prio 99 handle 1: u32 divisor 256"
        ],
        "cmdUnderTest": "bash -c \"for mask in ff ffff ffffff ffffffff ff00ff ff0000ff ffff00ff; do $TC filter add dev $DEV1 ingress prio 99 u32 ht 1: sample u32 0x10203040 \\$mask match u8 0 0 classid 1:1; done\"",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol all pref 99 u32( (chain|fh|order) [0-9:]+){3} key ht 1 bkt 40 flowid 1:1",
        "matchCount": "7",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "2478",
        "name": "Test u32 sample option, divisor 16",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 ingress",
            "$TC filter add dev $DEV1 ingress prio 99 handle 1: u32 divisor 256"
        ],
        "cmdUnderTest": "bash -c \"for mask in 70 f0 ff0 fff0 ff00f0; do $TC filter add dev $DEV1 ingress prio 99 u32 ht 1: sample u32 0x10203040 \\$mask match u8 0 0 classid 1:1; done\"",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1 ingress",
        "matchPattern": "filter protocol all pref 99 u32( (chain|fh|order) [0-9:]+){3} key ht 1 bkt 4 flowid 1:1",
        "matchCount": "5",
        "teardown": [
            "$TC qdisc del dev $DEV1 ingress"
        ]
    },
    {
        "id": "0c37",
        "name": "Try to delete class referenced by u32 after a replace",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 parent root handle 10: drr",
            "$TC class add dev $DEV1 parent root classid 1 drr",
            "$TC filter add dev $DEV1 parent 10: prio 1 u32 match icmp type 1 0xff classid 10:1 action ok",
            "$TC filter replace dev $DEV1 parent 10: prio 1 u32 match icmp type 1 0xff classid 10:1 action drop"
        ],
        "cmdUnderTest": "$TC class delete dev $DEV1 parent 10: classid 10:1",
        "expExitCode": "2",
        "verifyCmd": "$TC class show dev $DEV1",
        "matchPattern": "class drr 10:1",
        "matchCount": "1",
        "teardown": [
            "$TC qdisc del dev $DEV1 parent root drr"
        ]
    },
    {
        "id": "bd32",
        "name": "Try to delete hashtable referenced by another u32 filter",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 parent root handle 10: drr",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 handle 1: u32 divisor 1",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 800: match ip src any link 1:"
        ],
        "cmdUnderTest": "$TC filter delete dev $DEV1 parent 10: prio 2 handle 1: u32",
        "expExitCode": "2",
        "verifyCmd": "$TC filter show dev $DEV1",
        "matchPattern": "protocol ip pref 2 u32 chain 0 fh 1:",
        "matchCount": "1",
        "teardown": [
            "$TC qdisc del dev $DEV1 parent root drr"
        ]
    },
    {
        "id": "4585",
        "name": "Delete small tree of u32 hashtables and filters",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 parent root handle 10: drr",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 handle 1: u32 divisor 1",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 handle 2: u32 divisor 1",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 handle 3: u32 divisor 2",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 handle 4: u32 divisor 1",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 1: match ip src any action drop",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 2: match ip src any action drop",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 3: match ip src any link 2:",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 3: match ip src any link 1:",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 4: match ip src any action drop",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 800: match ip src any link 3:",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 ht 800: match ip src any link 4:"
        ],
        "cmdUnderTest": "$TC filter delete dev $DEV1 parent 10:",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1",
        "matchPattern": "protocol ip pref 2 u32",
        "matchCount": "0",
        "teardown": [
            "$TC qdisc del dev $DEV1 parent root drr"
        ]
    },
    {
        "id": "1234",
        "name": "Exercise IDR leaks by creating/deleting a filter many (2048) times",
        "category": [
            "filter",
            "u32"
        ],
        "plugins": {
            "requires": "nsPlugin"
        },
        "setup": [
            "$TC qdisc add dev $DEV1 parent root handle 10: drr",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 2 u32 match ip src 0.0.0.2/32 action drop",
            "$TC filter add dev $DEV1 parent 10:0 protocol ip prio 3 u32 match ip src 0.0.0.3/32 action drop"
        ],
        "cmdUnderTest": "bash -c 'for i in {1..2048} ;do echo filter delete dev $DEV1 pref 3;echo filter add dev $DEV1 parent 10:0 protocol ip prio 3 u32 match ip src 0.0.0.3/32 action drop;done | $TC -b -'",
        "expExitCode": "0",
        "verifyCmd": "$TC filter show dev $DEV1",
        "matchPattern": "protocol ip pref 3 u32",
        "matchCount": "3",
        "teardown": [
            "$TC qdisc del dev $DEV1 parent root drr"
        ]
    }
]
