6 SCR_DIR=`readlink -f $0 | xargs dirname`
7 TESTCASE_BN=testcase.txt
20 echo "Usage: $0 <source_directory> \"[test_end_points]\" [timeout]"
22 echo " source_directory:"
24 echo " The source directory may contain .xml and .metadata files grouped by pairs and alphabetically classified:"
26 echo " 11.hex.as.xml 15.hex.as.xml 19.hex.as.xml ..."
27 echo " 11.metadata 15.metadata 19.metadata ..."
28 echo " 13.hex.as.xml 17.hex.as.xml 21.hex.as.xml ..."
29 echo " 13.metadata 17.metadata 21.metadata ..."
31 echo " The order comes from first dot-separated part, which is normally the decoded frame from a pcap file:"
33 echo " 11.hex.as.xml: would be the ANNA-Diameter decoded message from hexadecimal sniffed one."
34 echo " 11.metadata: would contain parsed metadata from tshark or another fulfilling this information:"
36 echo " date=Sat Dec 19 11:50:55 CET 2015"
37 echo " timestamp=1450522255.205673000"
42 echo " applicationid=0"
44 echo " Presented example has been achieved using the 'example/diameter/pcapDecoder/tsharkDecoder.sh' script"
45 echo " and then decoding with 'example/diameter/batchConverter' tool with appropiate diameter dictionaries."
48 echo " test_end_points: space-separated list of possible test end points (hostnames, ip addresses)"
50 echo " This script will create a basic testcase based on frames timeline (11, 13, 15, etc.), from the desired"
51 echo " end-point list. For example, from the 'gentraf' point of view, outgoing requests will be translated as"
52 echo " sendxml operations with corresponding waits for answers and successful result code (2001). CER/A are"
53 echo " detected creating a symbolic link to better reference them, and DPR/A are ignored."
55 echo " The provided test end point list shall match metadata 'src' field in order to filter the valid testcase"
56 echo " messages. In case of nothing provided (empty string) a list with the possible values from the source"
57 echo " directory will be shown."
62 echo " Timeout in seconds for the testcase. If not provided, no timeout will be programmed for the testcase."
66 echo " The resulting '$TESTCASE_BN' will have all the operations needed to program the test case and will be"
67 echo " written on same source directory referencing xml files as local-relative ones. Probably, 'change-dir'"
68 echo " operation will be used before programming to ease the procedure without having to copy the stuff into"
69 echo " installed ADML execution directory."
71 echo " Connection issues (CER/A), disconnect procedures (DPR/A), database populations and sanity checks are"
72 echo " not responsability for this script. Such operations shall be externally performed to guarantee that"
73 echo " programming this testcase is going to be valid in context of test execution. Anyway, CER messages"
74 echo " will be detected and symbolically linked with the name 'cer.<origin host>.xml'."
78 # $1: frame number (there must be .metadata and .xml files); $2: check Result-Code indicator
82 # date=Wed Oct 7 01:51:16 CEST 2015
83 # timestamp=1444175476.212667000
88 # applicationid=16777238
90 xml=( `ls ${1}.*xml 2>/dev/null` )
91 [ ${#xml[@]} -ne 1 ] && _exit "There must be one xml message file corresponding to '$mtd' !!"
94 # Ignore disconnect peer messages on testcase format (they have no session-id):
95 grep "^code=282$" $mtd > /dev/null
96 [ $? -eq 0 ] && return
98 code=$(grep ^code $mtd | cut -d= -f2)
99 isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
100 sessionid=$(grep Session-Id $xml | cut -d\" -f4)
101 lines=$(wc -l $TESTCASE_BN | awk '{ print $1 }')
103 s_waitfe="test|1|waitfe|$code|$((1-isrequest))"
104 [ -n "$sessionid" ] && s_waitfe="${s_waitfe}|||${sessionid}"
106 if [ $isrequest -eq 1 ]
108 echo "test|1|sendxml2e|$xml" >> $TESTCASE_BN
109 [ -n "$resultcode" ] && s_waitfe="${s_waitfe}|2001"
110 echo "$s_waitfe" >> $TESTCASE_BN
112 echo "$s_waitfe" >> $TESTCASE_BN
113 echo "test|1|sendxml2e|$xml|$((lines+1))" >> $TESTCASE_BN
122 │[ -z "$SOURCE_DIR" ] && usage
123 SOURCE_DIR=`readlink -f $SOURCE_DIR`
124 [ ! -d "$SOURCE_DIR" ] && _exit "Can't found provided directory '$SOURCE_DIR'"
125 # Work on source directory:
128 # Must have metadata:
129 ls *.*metadata >/dev/null 2>/dev/null
130 [ $? -ne 0 ] && _exit "Cannot found '*.*metadata' files on '$SOURCE_DIR' !!"
132 # Show possible end points if nothing provided:
134 if [ -z "$END_POINTS" ]
136 src_eps=( $(grep "^src=" *.*metadata | cut -d= -f2 | sort -u) )
137 [ ${#src_eps[@]} -eq 0 ] && _exit "No source end-points detected: metadata must have an 'src=xxx' line."
138 echo "Input a space-separated list for desired end-points to be processed as test side: "
139 echo " (available source end-points: ${src_eps[*]})"
141 [ -z "$END_POINTS" ] && _exit "Invalid empty input !!"
144 # Identify useful frames: those which are created at test-bed side (all except frames coming from tested systems):
146 for tag in $END_POINTS
148 for metadata in $(grep "^src=$tag$" *.*metadata)
150 frame=$(echo $metadata | cut -d\. -f1)
151 touch ${frame}.needed
154 ls *.needed >/dev/null 2>/dev/null
155 [ $? -ne 0 ] && _exit "No frame has been selected within '$SOURCE_DIR' for provided end-points ($END_POINTS) !!"
157 # Messages classification:
159 0> requests_4_sending
160 0> answers_4_programming
165 [ -n "$TIMEOUT_SEC" ] && echo "test|1|timeout|$((TIMEOUT_SEC * 1000))" >> $TESTCASE_BN
168 for frame in `ls *.needed | cut -d\. -f1 | sort -n`
170 file=( `ls ${frame}.*metadata 2>/dev/null` )
171 [ ${#file[@]} -ne 1 ] && _exit "There must be one metadata file corresponding to frame '$frame' !!"
173 # Ignore keep alives:
174 grep -q "^code=280$" $file
175 [ $? -eq 0 ] && continue
177 grep -q "^isrequest=1$" $file
180 grep -q "^code=257$" $file
181 [ $? -eq 0 ] && { echo $frame >> cers_4_starting ; continue ; }
182 echo $frame >> requests_4_sending
183 update_testcase $frame check_result_code
186 grep -q "^code=257$" $file
187 [ $? -eq 0 ] && continue
188 echo $frame >> answers_4_programming
189 update_testcase $frame
194 # We will replace all the requests hop-by-hop's with a unique value, to avoid bad sniffing cases (different sources using bad values).
195 # For example, the frame number could be valid enough.
199 grep sendxml $TESTCASE_BN > .involved_frames
200 n_involved=`wc -l .involved_frames | awk '{ print $1 }'`
202 for frame in `cat .involved_frames | cut -d\| -f4 | cut -d\. -f1`
204 xml=( `ls ${frame}.*xml` )
205 mtd=( `ls ${frame}.*metadata` )
206 isrequest=$(grep "isrequest=1" $mtd)
207 if [ -n "$isrequest" ]
209 hbh_ini="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
210 sed -i 's/'$hbh_ini'/hop-by-hop-id="'$frame'"/' $xml