| .. | .. |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | CHECK_TC="yes" |
|---|
| 5 | 5 | |
|---|
| 6 | +# Can be overridden by the configuration file. See lib.sh |
|---|
| 7 | +TC_HIT_TIMEOUT=${TC_HIT_TIMEOUT:=1000} # ms |
|---|
| 8 | + |
|---|
| 6 | 9 | tc_check_packets() |
|---|
| 7 | 10 | { |
|---|
| 8 | 11 | local id=$1 |
|---|
| 9 | 12 | local handle=$2 |
|---|
| 10 | 13 | local count=$3 |
|---|
| 11 | | - local ret |
|---|
| 12 | 14 | |
|---|
| 13 | | - output="$(tc -j -s filter show $id)" |
|---|
| 14 | | - # workaround the jq bug which causes jq to return 0 in case input is "" |
|---|
| 15 | | - ret=$? |
|---|
| 16 | | - if [[ $ret -ne 0 ]]; then |
|---|
| 17 | | - return $ret |
|---|
| 18 | | - fi |
|---|
| 19 | | - echo $output | \ |
|---|
| 20 | | - jq -e ".[] \ |
|---|
| 21 | | - | select(.options.handle == $handle) \ |
|---|
| 22 | | - | select(.options.actions[0].stats.packets == $count)" \ |
|---|
| 23 | | - &> /dev/null |
|---|
| 24 | | - return $? |
|---|
| 15 | + busywait "$TC_HIT_TIMEOUT" until_counter_is "== $count" \ |
|---|
| 16 | + tc_rule_handle_stats_get "$id" "$handle" > /dev/null |
|---|
| 17 | +} |
|---|
| 18 | + |
|---|
| 19 | +tc_check_packets_hitting() |
|---|
| 20 | +{ |
|---|
| 21 | + local id=$1 |
|---|
| 22 | + local handle=$2 |
|---|
| 23 | + |
|---|
| 24 | + busywait "$TC_HIT_TIMEOUT" until_counter_is "> 0" \ |
|---|
| 25 | + tc_rule_handle_stats_get "$id" "$handle" > /dev/null |
|---|
| 25 | 26 | } |
|---|