Commit 1c2d831e authored by Jean-Claude BAU's avatar Jean-Claude BAU

Test specific log cleaners

parent 8d7fbcea
#!/bin/bash
source genLib.sh
tmpFile1=${cleanLogName}_1.tmp
tmpFile2=${cleanLogName}_2.tmp
#tmpFile=/dev/stdout
# Tx frame tag
txFrameMax=4200000
rateList=( 10 30 50 70 80 85 90 92 95 97 99 100 )
flenList=(64 127 190 253 316 379 442 505 568 631 694 757 820 883 946 1009 1072 1135 1198 1261 1324 1387 1450 1513 1522)
rateIdx=( 0 0 0 0 )
flenIdx=( 0 0 0 0 )
lastTxFrames=( 0 0 0 0 )
streamLines=( "" "" "" "" )
streamSynchronized=( 0 0 0 0 )
#list of columns
tkStream=1
tkTxFrames=6
tkPort=1
function learning () {
local line=$1
local tokens
OLDIFS=$IFS
IFS="," read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
for i in "${!tokens[@]}"; do
if [ "${tokens[$i]}" == "TxFrames" ] ; then
tkTxFrames=$i
fi
if [ "${tokens[$i]}" == "SrcPort" ] ; then
tkPort=$i
fi
done
}
function formatHeader() {
local line=$1
s=${line/Timestamp/'Timestamp,FrameLength,NetLoad'}
echo $s
}
function formatData() {
local line=$1
OLDIFS=$IFS
IFS=",\n" read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
local txFrames=${tokens[$tkTxFrames]}
local port=`echo ${tokens[$tkPort]} | grep -o -e [0-9]$`
if [ "${rateIdx[$port]}" -ge "${#rateList[@]}" ] ; then
rateIdx[$port]=0
flenIdx[$port]=$((${flenIdx[$port]}+1))
fi
local netLoad=${rateList[ ${rateIdx[$port]} ]}
rateIdx[$port]=$(( ${rateIdx[$port]}+1 ))
local frameLength=${flenList[${flenIdx[$port]}]}
local ret="${tokens[0]},"
ret+="$frameLength,"
ret+="$netLoad,"
local i=0
for value in ${tokens[@]:1}; do
if [ "$i" -gt "0" ] ; then ret+=","; fi
ret+="$value"
i=$(( $i+1 ))
done
echo "$ret"
}
function getStreamIndex() {
local stream=$1
echo `echo $stream | grep -o -e "[0-9]*$"`
}
function lineDecoder () {
local line=$1
local tokens
OLDIFS=$IFS
IFS="," read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
local streamId=$( getStreamIndex ${tokens[$tkStream]} )
local txFrames=${tokens[$tkTxFrames]}
if [ -z "$txFrames" ] ; then return 0 ; fi
if [ "$txFrames" -gt "${txFrameMax}" ] ; then return 0; fi
if [ "$txFrames" -lt "${lastTxFrames[$streamId]}" ] ; then
formatData "${streamLines[$streamId]}"
fi
lastTxFrames[$streamId]=$txFrames
streamLines[$streamId]="$line"
}
## main
function main() {
local n=1
local lineCnt=`wc -l $logName | grep -o ^[0-9]*`
sed -i "1s/,Port,/,SrcPort,/" $logName # Change Port in the header by SrcPort
while read line ; do
if [ "$n" -eq "1" ] ; then
learning $line
formatHeader "$line"
else if [ "$n" -gt "2" ] ; then
lineDecoder "$line"
fi
fi
n=$((n+1))
#if [ "$n" -gt "10000" ] ; then break; fi
displayPercentage $lineCnt $n
done < $logName
clearDisplayPercentage
}
main > $tmpFile1
cat $tmpFile1 | sed -e "s/\r//g" | sed 's/[,]$//' > $tmpFile2
(head -n 1 $tmpFile2 && tail -n +2 $tmpFile2 | sort -t $',' -k 1,1 -k 2,2 -k 3,3 -k 4,4) >$cleanLogName
rm -f *.tmp
#!/bin/bash
source genLib.sh
# Run first the generic logCleaner
./logCleaner.sh
# Adjust errors that are not real errors
tmpFile1=${cleanLogName}_1.csv
#list of columns
tkTxFrames=4
tkRxPldErr=6
tkPort=3
adjRxPldErr=( -1 -1 -1 -1 )
function learning () {
local line=$1
local tokens
OLDIFS=$IFS
IFS="," read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
for i in "${!tokens[@]}"; do
if [ "${tokens[$i]}" == "TxFrames" ] ; then
tkTxFrames=$i
fi
if [ "${tokens[$i]}" == "RxPldErr" ] ; then
tkRxPldErr=$i
fi
if [ "${tokens[$i]}" == "SrcPort" ] ; then
tkPort=$i
fi
done
}
function getStreamIndex() {
local stream=$1
echo `echo $stream | grep -o -e "[0-9]*$"`
}
function spFormatData() {
local -a tokens=("${!1}")
local ret=""
local i=0
for value in ${tokens[@]}; do
if [ "$i" -gt "0" ] ; then ret+=","; fi
ret+="$value"
i=$(( $i+1 ))
done
echo "$ret"
}
function spLineDecoder () {
local line="$1"
local tokens
OLDIFS=$IFS
IFS="," read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
local port=$( getStreamIndex ${tokens[$tkPort]} )
local txFrames=${tokens[$tkTxFrames]}
local rxPldErr=${tokens[$tkRxPldErr]}
if [ "${adjRxPldErr[$port]}" -eq "-1" ]; then
if [ "$rxPldErr" -eq "0" ] ; then
adjRxPldErr[$port]=0
else
adjRxPldErr[$port]=1
fi
fi
if [ "${adjRxPldErr[$port]}" -eq "1" ]; then
if [ "$rxPldErr" -gt "$txFrames" ] ; then
tokens[$tkRxPldErr]=`echo "scale=0; $rxPldErr-$txFrames" | bc`
else
tokens[$tkRxPldErr]=0
fi
spFormatData tokens[@]
else
echo "$line"
fi
}
## main
function main() {
local n=1
local lineCnt=`wc -l $cleanLogName | grep -o ^[0-9]*`
sed -i "1s/,Port,/,SrcPort,/" $logName # Change Port in the header by SrcPort
while read line ; do
if [ "$n" -eq "1" ] ; then
learning "$line"
echo "$line" # No changes
else
spLineDecoder "$line"
fi
n=$((n+1))
displayPercentage $lineCnt $n
done < $cleanLogName
clearDisplayPercentage
}
main > $tmpFile1
mv $tmpFile1 $cleanLogName
#!/bin/bash
source genLib.sh
tmpFile1=${cleanLogName}_1.csv
tmpFile2=${cleanLogName}_2.csv
tmpFile3=${cleanLogName}_3.csv
#tmpFile=/dev/stdout
# Tx frame tag
txFrameMax=4200000
rateList=( 50 80 95 100 )
flenList=( 64 65 700 701 1521 1522 )
rateIdx=( 0 0 0 0 )
flenIdx=( 0 0 0 0 )
rateInitialized=( 0 0 0 0 )
mainPorts=(0 1)
secondaryPorts=(2 3)
secondaryPortsOverflow=0
lastTxFrames=( 0 0 0 0 )
streamLines=( "" "" "" "" )
streamSynchronized=( 0 0 0 0 )
#list of columns
tkStream=1
tkTxFrames=6
tkPort=1
function learning () {
local line=$1
local tokens
OLDIFS=$IFS
IFS="," read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
for i in "${!tokens[@]}"; do
if [ "${tokens[$i]}" == "TxFrames" ] ; then
tkTxFrames=$i
fi
if [ "${tokens[$i]}" == "SrcPort" ] ; then
tkPort=$i
fi
done
}
function formatHeader() {
local line=$1
s=${line/Timestamp/'Timestamp,FrameLength,NetLoad'}
echo $s
}
function getStreamIndex() {
local stream=$1
echo `echo $stream | grep -o -e "[0-9]*$"`
}
function formatData() {
local line=$1
OLDIFS=$IFS
IFS=",\n" read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
local txFrames=${tokens[$tkTxFrames]}
local port=$(getStreamIndex ${tokens[$tkPort]})
maxRateValue=$(( ${#rateList[@]}-1 ))
maxFLenValue=${#flenList[@]}
#>&2 echo "maxRateValue=$maxRateValue maxFLenValue=$maxFLenValue"
for sp in ${secondaryPorts[@]}; do
if [ "$sp" -eq "$port" ] ; then
# Secondary port
if [ "${rateIdx[$port]}" -ge "$maxRateValue" ] ; then
rateIdx[$port]=0
flenIdx[$port]=$(( ${flenIdx[$port]}+1 ))
if [ "${flenIdx[$port]}" -ge "$maxFLenValue" ] ; then
secondaryPortsOverflow=$(($secondaryPortsOverflow+1))
flenIdx[$port]=0
fi
#>&2 echo "secondaryPortsOverflow=$secondaryPortsOverflow port=$port rate=${rateIdx[$port]}"
if [ "$secondaryPortsOverflow" -eq "${#secondaryPorts[@]}" ] ; then
secondaryPortsOverflow=0
# main ports must be incremented
#>&2 echo Increment main ports
for mp in ${mainPorts[@]}; do
if [ "${rateIdx[$mp]}" -ge "$maxRateValue" ] ; then
rateIdx[$mp]=0
flenIdx[$mp]=$(( ${flenIdx[$mp]}+1 ))
else
rateIdx[$mp]=$(( ${rateIdx[$mp]}+1 ))
fi
#>&2 echo "Primaryport=$mp rate=${rateIdx[$mp]}"
done
fi
else
if [ "${rateInitialized[$port]}" -eq "0" ]; then
rateInitialized[$port]=1
else
rateIdx[$port]=$(( ${rateIdx[$port]}+1 ))
fi
fi
break
fi
done
#>&2 echo "port=$port rate= ${rateIdx[$port]} len=${flenIdx[$port]}"
local netLoad=${rateList[ ${rateIdx[$port]} ]}
local frameLength=${flenList[ ${flenIdx[$port]} ]}
local ret="${tokens[0]},"
ret+="$frameLength,"
ret+="$netLoad,"
local i=0
for value in ${tokens[@]:1}; do
if [ "$i" -gt "0" ] ; then ret+=","; fi
ret+="$value"
i=$(( $i+1 ))
done
echo "$ret"
}
function lineDecoder () {
local line=$1
local tokens
OLDIFS=$IFS
IFS="," read -a tokens <<< "$( echo $line )"
IFS=$OLDIFS
local txFrames=${tokens[$tkTxFrames]}
if [ -z "$txFrames" ] ; then return 0 ; fi
if [ "$txFrames" -eq "0" ] ; then return 0; fi
formatData "$line"
}
## main
function main() {
local fname=$1
local n=1
local lineCnt=`wc -l $fname | grep -o ^[0-9]*`
sed -i "1s/,Port,/,SrcPort,/" $fname # Change Port in the header by SrcPort
while read line ; do
if [ "$n" -eq "1" ] ; then
learning $line
formatHeader "$line"
else if [ "$n" -gt "2" ] ; then
lineDecoder "$line"
fi
fi
n=$((n+1))
#if [ "$n" -gt "10000" ] ; then break; fi
displayPercentage $lineCnt $n
done < $fname
clearDisplayPercentage
}
function reduceFile() {
local fname=$1
for p in 0 1 2 3 ; do cat $fname | grep -e "P-0-0-$p" \
| awk 'BEGIN { FS=","; lastFRx=0;lf=""} ;
{
if ( $3 != 0 && lastFRx==0) {print lf}
if ( $3 == 0 && lastFRx!=0) {print lf}
lastFRx=$3
lf=$0
}END {print lf} '> f$p.csv;
done
head -n 2 $fname >f.csv
for p in 0 1 2 3 ; do cat f$p.csv >> f.csv; done
(head -n 1 f.csv && tail -n +2 f.csv | sort -t $',' -k 1,1 -k 2,2 -k 3,3 -k 4,4)
rm -f f.csv f[0-9].csv
}
reduceFile $logName > $tmpFile1
main $tmpFile1 > $tmpFile2
cat $tmpFile2 | sed -e "s/\r//g" | sed 's/[,]$//' > $cleanLogName
rm -f $tmpFile1 $tmpFile2 $tmpFile3
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment