metadata:
  name: traffic-control-basic
  format: "Apertis Test Definition 1.0"
  image-type: any
  image-arch: any
  type: functional
  exec-type: manual
  priority: low
  maintainer: "Apertis Project"
  description: "Test basic traffic control support. This test does not use tcmmd
                but it could catch missing support in the kernel or misbehaving
                traffic control."

  resources:
    - "A web server with a large file to download."

  macro_install_packages_preconditions: wget

  pre-conditions:
    - "Check whether tcmmd >= 0.1.6 is installed:"
    - "$ dpkg -l tcmmd"
    - "Check that tcmmd is not running (kill it if it was launched from a
       previous test)"
    - "$ ps aux | grep tcmmd"
    - "Check you have connectivity to your web server:"
    - "$ wget http://$SERVER_IP/file"
    - "Check what is your main network interface (eth0, ens32, wlan0...) and note
       your IP."
    - "$ ifconfig"

  expected:
    - "There should be no error."
    - "Bandwidth usage with a random TCP source port should be around 4.8KB/s."
    - "Bandwidth usage with a specific TCP source port should be around 78KB/s."

  post-conditions:
    - "If the script was interrupted, the traffic control rules can be removed
       with:"
    - "$ sudo tc qdisc del dev $NET_INTERFACE ingress"

run:
  steps:
    - "As root, run the script:"
    - "$ sudo MAIN_LINK=$NET_INTERFACE PORT=12345 /usr/share/tcmmd/tests/manual-test.sh"
    - "The script will install traffic control rules with different ingress
       bandwidth for TCP connections using the source port 12345 and other TCP
       connections. The rules will wait and you will have time to check the
       bandwidth with wget in another terminal."
    - "Check bandwidth usage from a random TCP source port:"
    - "$ wget http://$SERVER_IP/file -O /dev/null"
    - "Check bandwidth usage with a specific TCP source port:"
    - "$ wget --bind-address=$SOURCE_IP --bind-port=12345 http://$SERVER_IP/file -O /dev/null"