#!/bin/bash

. lib.sh

ids="0 $(seq 255 256 2047)"

prepare() {
    sshgw 'for i in `seq 0 2047`; do cangw -A -s can0 -d can1 -f $(printf %x $i):7ff; done'
}

main() {
    if [ "$kvers" = 3.0.4-rt14-00008-gb2052fd -a "$load" = eth -a $traffic != oneatatime ]; then echo "Skipping eth test"; SKIPPED=1; return; fi
    if [ "$kvers" = 3.4.33-rt47-00004-gc58c9ae -a "$load" = eth -a $traffic != oneatatime ]; then echo "Skipping eth test"; SKIPPED=1; return; fi

    for i in $ids; do
	latester -d can0 -d can1 -d can2 -c $COUNT -i $i $(traffic_and_length 2) -n id-$i
    done
}

ADDITIONAL_PLOTS=detail

plot_cmds() {
    if [[ "$1" = detail ]]; then
	range=0:0.8
	echo "set logscale y"
    else
	range=0.01:100
	echo "set logscale xy"
    fi
    cat <<EOF
set title "2048 GW rules (one per id, mask 0x7FF), no modifications"
set grid xtics mxtics ytics mytics lw 1, lw 0.5
set xlabel "GW latency [ms]"
set ylabel "Latency profile [frames]"
plot [$range] [1:$COUNT] \\
EOF
    lt=1
    for i in $ids; do
	echo_plot "\"id-$i-hist.txt\" with lp lt $lt title \"Message id $i\""
        lt=$((lt+1))
    done
}
    
test_end