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 corresponding result codes (normally 2001)"
53 echo " if those answers are provided (2001 will be assigned as result-code condition if no answer is found)."
54 echo " CER/A are detected creating a symbolic link to better reference them, and DPR/A are ignored."
56 echo " The provided test end point list shall match metadata 'src' field in order to filter the valid testcase"
57 echo " messages. In case of nothing provided (empty string) a list with the possible values from the source"
58 echo " directory will be shown."
63 echo " Timeout in seconds for the testcase. If not provided, no timeout will be programmed for the testcase."
67 echo " The resulting '$TESTCASE_BN' will have all the operations needed to program the test case and will be"
68 echo " written on same source directory referencing xml files as local-relative ones. Probably, 'change-dir'"
69 echo " operation will be used before programming to ease the procedure without having to copy the stuff into"
70 echo " installed ADML execution directory."
72 echo " Connection issues (CER/A), disconnect procedures (DPR/A), database populations and sanity checks are"
73 echo " not responsability for this script. Such operations shall be externally performed to guarantee that"
74 echo " programming this testcase is going to be valid in context of test execution. Anyway, CER messages"
75 echo " will be detected and symbolically linked with the name 'cer.<origin host>.xml'."
81 grep "<avp name=\"Origin-Host\"" $1 | cut -d\" -f4
85 # Nested Result-Code's not supported here (i.e. charging application)
87 grep "<avp name=\"Result-Code\"" $1 | awk -F'data=' '{ print $2 }' | cut -d\" -f2
90 # $1: metadata file; $2: xml file; $3: check Result-Code indicator
94 # date=Wed Oct 7 01:51:16 CEST 2015
95 # timestamp=1444175476.212667000
100 # applicationid=16777238
105 # Ignore disconnect peer messages on testcase format (they have no session-id):
106 grep "^code=282$" $mtd > /dev/null
107 [ $? -eq 0 ] && return
109 local code=$(grep ^code $mtd | cut -d= -f2)
110 local isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
111 local sessionid=$(grep Session-Id $xml | cut -d\" -f4)
112 local lines=$(wc -l $TESTCASE_BN | awk '{ print $1 }')
114 local s_waitfe="test|1|waitfe|$code|$((1-isrequest))"
115 [ -n "$sessionid" ] && s_waitfe="${s_waitfe}|||${sessionid}"
117 if [ $isrequest -eq 1 ]
119 echo "test|1|sendxml2e|$xml" >> $TESTCASE_BN
120 if [ -n "$resultcode" ]
122 local hbh="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
123 local hbh_matchs=( $(grep -l "$hbh" *.xml) )
124 local ans_xml=${hbh_matchs[1]}
128 _rc=$(getResultCode $ans_xml)
129 [ -n "$_rc" ] && rc=$_rc
131 s_waitfe="${s_waitfe}|${rc}"
133 echo "$s_waitfe" >> $TESTCASE_BN
135 echo "$s_waitfe" >> $TESTCASE_BN
136 echo "test|1|sendxml2e|$xml|$((lines+1))" >> $TESTCASE_BN
145 [ -z "$SOURCE_DIR" ] && usage
146 SOURCE_DIR=`readlink -f $SOURCE_DIR`
147 [ ! -d "$SOURCE_DIR" ] && _exit "Can't found provided directory '$SOURCE_DIR'"
148 # Work on source directory:
151 # Must have metadata:
152 ls *.*metadata >/dev/null 2>/dev/null
153 [ $? -ne 0 ] && _exit "Cannot found '*.*metadata' files on '$SOURCE_DIR' !!"
155 # Show possible end points if nothing provided:
157 if [ -z "$END_POINTS" ]
159 src_eps=( $(grep "^src=" *.*metadata | cut -d= -f2 | sort -u) )
160 [ ${#src_eps[@]} -eq 0 ] && _exit "No source end-points detected: metadata must have an 'src=xxx' line."
161 if [ ${#src_eps[@]} -eq 1 ]
164 echo "Detected a unique end-point: $END_POINTS"
166 echo "Input a space-separated list for desired end-points to be processed as test side: "
167 echo " (available source end-points: ${src_eps[*]})"
169 [ -z "$END_POINTS" ] && _exit "Invalid empty input !!"
173 # Identify useful frames: those which are created at test-bed side (all except frames coming from tested systems):
175 for tag in $END_POINTS
177 for metadata in $(grep "^src=$tag$" *.*metadata)
179 frame=$(echo $metadata | cut -d\. -f1)
180 touch ${frame}.needed
183 ls *.needed >/dev/null 2>/dev/null
184 [ $? -ne 0 ] && _exit "No frame has been selected within '$SOURCE_DIR' for provided end-points ($END_POINTS) !!"
186 # Messages classification:
188 0> cers_4_starting_origin_hosts
189 0> requests_4_sending
190 0> answers_4_programming
195 [ -n "$TIMEOUT_SEC" ] && echo "test|1|timeout|$((TIMEOUT_SEC * 1000))" >> $TESTCASE_BN
198 for frame in `ls *.needed | cut -d\. -f1 | sort -n`
200 mtd=( `ls ${frame}.*metadata 2>/dev/null` )
201 [ ${#mtd[@]} -ne 1 ] && _exit "There must be one metadata file corresponding to frame '$frame' !!"
202 xml=( `ls ${frame}.*xml 2>/dev/null` )
203 [ ${#xml[@]} -ne 1 ] && _exit "There must be one xml message file corresponding to '$mtd' (frame '$frame') !!"
205 # Ignore keep alives:
206 grep -q "^code=280$" $mtd
207 [ $? -eq 0 ] && continue
209 grep -q "^isrequest=1$" $mtd
212 grep -q "^code=257$" $mtd
215 echo $frame >> cers_4_starting
216 originHost=$(getOriginHost $xml)
217 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CER message) !!"
218 echo "$originHost" >> cers_4_starting_origin_hosts
219 ln -sf $xml cer.${originHost}.xml
222 echo $frame >> requests_4_sending
223 update_testcase $mtd $xml check_result_code
226 grep -q "^code=257$" $mtd
227 [ $? -eq 0 ] && continue
228 echo $frame >> answers_4_programming
229 update_testcase $mtd $xml
234 # We will replace all the requests hop-by-hop's with a unique value, to avoid bad sniffing cases (different sources using bad values).
235 # For example, the frame number could be valid enough.
239 grep sendxml $TESTCASE_BN > .involved_frames
240 n_involved=`wc -l .involved_frames | awk '{ print $1 }'`
242 for frame in `cat .involved_frames | cut -d\| -f4 | cut -d\. -f1`
244 xml=( `ls ${frame}.*xml` )
245 mtd=( `ls ${frame}.*metadata` )
246 isrequest=$(grep "isrequest=1" $mtd)
247 if [ -n "$isrequest" ]
249 hbh_ini="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
250 sed -i 's/'$hbh_ini'/hop-by-hop-id="'$frame'"/' $xml