#!/bin/bash

source ./cmd_utils.sh
source ./kernel_config_utils.sh
source ./net_utils.sh

tc_check() {
    is_error=false
    if ! kernel_config_check CONFIG_NET_SCH_TBF sch_tbf; then
        is_error=true
    fi
    if ! kernel_config_check CONFIG_NET_SCH_NETEM sch_netem; then
        is_error=true
    fi
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    local ifname="dodo"

    netif_new $ifname

    is_error=false
    if ! tc_rule_check $ifname tbf rate 10Mbit latency 1000ms burst 100kb; then
        is_error=true
    fi
    if ! tc_rule_check $ifname netem loss 10%; then
        is_error=true
    fi
    if ! tc_rule_check $ifname netem delay 10ms; then
        is_error=true
    fi
    netif_delete $ifname
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    return 0
}

