6 SCR_DIR=`readlink -f $0 | xargs dirname`
7 TESTCASE_BN=testcase.txt
24 echo "Usage: $0 <source_directory> <seconds_timeout> [variant: fast|[safe]]"
26 echo " source_directory:"
27 echo " The source directory may contain .xml and .metadata files grouped by pairs and alphabetically classified,"
28 echo " and also (and this is VERY IMPORTANT), a file called 'origin-hosts' containing a list of Origin-Host"
29 echo " values that represents the point of view of the ADML testing system, together with the type of the"
30 echo " simulated ADML node (client/server):"
32 echo " <id>.hex.as.xml: ANNA-Diameter XML message format."
33 echo " <id>.metadata: Some decoded message information."
35 echo " origin-hosts: Example of content:"
36 echo " OCS3GPPNodeHostname.ocs3gpprealm.com server"
37 echo " ggsnNodeHostname.nodeHostRealm.com client"
39 echo " The order for the xml and metadata files comes from first dot-separated part (<id>), which is normally the"
40 echo " decoded frame from a pcap file. The xml files are ANNA-Diameter xml messages and a typical metadata file"
41 echo " would be something like this:"
42 echo " date=vie ene 29 15:37:14 CET 2016"
43 echo " timestamp=1454078234.050988000"
44 echo " src=192.168.14.42"
45 echo " dst=192.168.12.40"
48 echo " applicationid=0"
49 echo " originhost=OCSNodeHostname.ocsrealm.com"
51 echo " You can use the 'example/diameter/pcapDecoder/tsharkDecoder.sh' script over a pcap file, in order to get"
52 echo " the hexadecimal buffers and then process them with 'example/diameter/batchConverter' tool to get the xml"
53 echo " messages and metadata for each pcap diameter frame."
57 echo " Two variants are implemented: 'fast', where wait conditions does not check the complete message, and"
58 echo " 'safe' which checks the full xml message content (good for function test). Default is '$VARIANT__dflt'."
61 echo " seconds_timeout:"
62 echo " Timeout in seconds for the testcase. If '-' 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. Normally, '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. Anyway, CER/A messages detected are symbolically linked with the"
73 echo " name 'ce<r/a>.<origin host>.xml', and missing ones are created with a basic template which the user"
74 echo " could edit and fix with the appropiate values."
82 [[ "$1" =~ $re ]] && return 0
87 # Nested Result-Code's not supported here (i.e. charging application)
89 grep "<avp name=\"Result-Code\"" $1 | awk -F'data=' '{ print $2 }' | cut -d\" -f2
92 # $1: code; $2: isrequest; $3: frame to start searching: direction depends on isrequest (1: downwards, 0: upwards)
99 if [ $isrequest -eq 1 ]
101 # requests shall be before frame
102 frames=( $(ls *.*metadata | cut -d\. -f1 | sort -rn | awk -v frame=$this_frame '{ if($1 < frame) print $1 }') )
104 # answers shall be after frame
105 frames=( $(ls *.*metadata | cut -d\. -f1 | sort -n | awk -v frame=$this_frame '{ if($1 > frame) print $1 }') )
113 for frame in ${frames[@]}
115 mtd=${frame}.metadata
116 [ ! -f $mtd ] && _exit "Unexpected error: can't found '$mtd' file !!"
118 _code=$(grep ^code $mtd | cut -d= -f2)
119 _isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
121 [ $_code -ne $code -o $_isrequest -ne $isrequest ] && continue
123 found="$(ls ${frame}.*.xml 2>/dev/null)"
124 [ -z "$found" ] && _exit "Unexpected error: can't found xml file for frame '${frame}' file !!"
132 # $1: metadata file; $2: xml file; $3: check Result-Code indicator; $4: client/server (ADML node role)
136 # date=Wed Oct 7 01:51:16 CEST 2015
137 # timestamp=1444175476.212667000
142 # applicationid=16777238
148 local wait_command=waitfe
150 local waitxml_command=waitfe-xml
151 local send_command=sendxml2e
152 [ "$adml_type" = "server" ] && { wait_command=waitfc ; waitxml_command=waitfc-xml ; send_command=sendxml2c ; }
155 # Ignore disconnect peer messages on testcase format (they have no session-id):
156 grep "^code=282$" $mtd > /dev/null
157 [ $? -eq 0 ] && return
159 local code=$(grep ^code $mtd | cut -d= -f2)
160 local isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
161 local sessionid=$(grep Session-Id $xml | cut -d\" -f4)
162 local lines=$(wc -l $TESTCASE_BN | awk '{ print $1 }')
164 local s_wait="test|1|$wait_command|$code|$((1-isrequest))"
166 local this_frame=$(echo $xml | cut -d\. -f1)
167 local pairxml=$(search_xml $code $((1-isrequest)) $this_frame)
168 local s_waitxml="test|1|$waitxml_command|$pairxml"
170 [ -n "$sessionid" ] && s_wait="${s_wait}|||${sessionid}"
172 local s_send="test|1|$send_command|$xml"
174 if [ $isrequest -eq 1 ]
177 # Special case for SNR/SNA (code=8388636) and STR (code=275) going to SAPC: the Session-Id is created on client and received on SLR previously
178 if [ "$adml_type" = "server" ]
180 if [ "$code" = "8388636" -o "$code" = "275" ]
182 s_send="test|1|$send_command|$xml|$REQUEST_STEP"
183 s_wait="test|1|$wait_command|$code|0|||"
187 echo "$s_send" >> $TESTCASE_BN
189 if [ -n "$resultcode" ]
191 local hbh="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
192 local hbh_matchs=( $(grep -l "$hbh" *.xml) )
193 local ans_xml=${hbh_matchs[1]}
197 _rc=$(getResultCode $ans_xml)
198 [ -n "$_rc" ] && rc=$_rc
202 s_wait="${s_wait}|${rc}"
206 if [ "$VARIANT" = "fast" ]
208 echo "$s_wait" >> $TESTCASE_BN
210 echo "$s_waitxml" >> $TESTCASE_BN
214 local next_step_number=$((lines+1))
217 # Special case for SLR/SLA (code=8388635) and STR (code=275) coming from SAPC: the Session-Id is created on client
218 if [ "$adml_type" = "server" ]
220 if [ "$code" = "8388635" -o "$code" = "275" ]
222 s_wait="test|1|$wait_command|$code|1"
223 REQUEST_STEP=$next_step_number
228 if [ "$VARIANT" = "fast" ]
230 echo "$s_wait" >> $TESTCASE_BN
232 echo "$s_waitxml" >> $TESTCASE_BN
236 echo "test|1|$send_command|$xml|$next_step_number" >> $TESTCASE_BN
244 [ -z "$SOURCE_DIR" ] && usage
245 SOURCE_DIR=`readlink -f $SOURCE_DIR`
246 [ ! -d "$SOURCE_DIR" ] && _exit "Can't found provided directory '$SOURCE_DIR'"
247 # Work on source directory:
250 # Must have metadata:
251 ls *.*metadata >/dev/null 2>/dev/null
252 [ $? -ne 0 ] && _exit "Cannot found '*.*metadata' files on '$SOURCE_DIR' !!"
254 # Check origin-hosts:
255 ohs_file=$SOURCE_DIR/origin-hosts
256 [ ! -f $ohs_file ] && _exit "Can't found the mandatory file '$ohs_file' !!"
257 awk '{ print $NF }' $ohs_file | egrep -qw 'client|server'
258 [ ${PIPESTATUS[1]} -ne 0 ] && _exit "Can't found any Origin-Host in '$ohs_file' with a valid ADML node role value (client or server) !!"
260 # Identify useful frames: those which are created at test-bed side (all except frames coming from tested systems):
262 0> .involved_origin_hosts
264 for oh in `awk '{ print $1 }' $ohs_file`
266 for frame in $(grep -l "^originhost=$oh$" *.*metadata | cut -d\. -f1)
268 echo "$frame" >> .involved_frames
269 echo "$oh" >> .involved_origin_hosts
270 n_involved_frames=$((n_involved_frames + 1))
273 [ $n_involved_frames -eq 0 ] && _exit "No frame has been selected within '$SOURCE_DIR' for provided origin-hosts file !!"
274 sort .involved_frames > .involved_frames_sort
275 mv .involved_frames_sort .involved_frames
277 # Messages classification:
279 #0> ceas_4_establishing
280 0> cers_4_starting_origin_hosts
281 0> ceas_4_establishing_origin_hosts
282 0> requests_4_sending
283 0> answers_4_programming
288 isnumber $TIMEOUT_SEC
289 [ $? -eq 0 ] && echo "test|1|timeout|$((TIMEOUT_SEC * 1000))" >> $TESTCASE_BN
292 VARIANT=$VARIANT__dflt
293 [ "$3" = "fast" ] && VARIANT=fast
296 for frame in `cat .involved_frames`
298 mtd=( `ls ${frame}.*metadata 2>/dev/null` )
299 [ ${#mtd[@]} -ne 1 ] && _exit "There must be one metadata file corresponding to frame '$frame' !!"
300 xml=( `ls ${frame}.*xml 2>/dev/null` )
301 [ ${#xml[@]} -ne 1 ] && _exit "There must be one xml message file corresponding to '$mtd' (frame '$frame') !!"
302 originHost=$(grep ^originhost= ${frame}.metadata | cut -d= -f2-)
304 # Ignore keep alives:
305 grep -q "^code=280$" $mtd
306 [ $? -eq 0 ] && continue
308 grep -q "^isrequest=1$" $mtd
312 grep -q "^code=257$" $mtd
315 #echo $frame >> cers_4_starting
316 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CER message) !!"
317 echo "$originHost" >> cers_4_starting_origin_hosts
318 ln -sf $xml cer.${originHost}.xml
322 echo $frame >> requests_4_sending
325 adml_type=$(grep -w "$originHost" $ohs_file | awk '{ print $NF }')
326 update_testcase $mtd $xml check_result_code $adml_type
329 grep -q "^code=257$" $mtd
332 #echo $frame >> ceas_4_establishing
333 originHost=$(grep ^originhost= ${frame}.metadata | cut -d= -f2-)
334 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CEA message) !!"
335 echo "$originHost" >> ceas_4_establishing_origin_hosts
336 ln -sf $xml cea.${originHost}.xml
340 echo $frame >> answers_4_programming
343 adml_type=$(grep -w "$originHost" $ohs_file | awk '{ print $NF }')
344 update_testcase $mtd $xml "" $adml_type
349 # We will replace all the requests hop-by-hop's with a unique value, to avoid bad sniffing cases (different sources using bad values).
350 # For example, the frame number could be valid enough.
353 for frame in `cat .involved_frames`
355 xml=( `ls ${frame}.*xml` )
356 mtd=( `ls ${frame}.*metadata` )
357 isrequest=$(grep "isrequest=1" $mtd)
358 if [ -n "$isrequest" ]
360 hbh_ini="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
361 sed -i 's/'$hbh_ini'/hop-by-hop-id="'$frame'"/' $xml
366 # Simplify origin hosts file (oh + adml role):
367 sort -u .involved_origin_hosts > .involved_origin_hosts_unique
368 grep -w -f .involved_origin_hosts_unique $ohs_file > .involved_origin_hosts_with_info
369 mv .involved_origin_hosts_with_info $ohs_file
370 rm .involved_origin_hosts .involved_origin_hosts_unique
373 for oh in $(awk -v input=client '{if ($2 == input) print $1;}' $ohs_file)
375 cer=$SOURCE_DIR/cer.${oh}.xml
378 echo $oh >> cers_4_starting_origin_hosts
379 echo "Missing CER: `basename $cer` (a basic template has been created, please edit & fix the unknowns)"
381 <message version="1" name="CER" application-id="0" hop-by-hop-id="1" end-to-end-id="1">
382 <avp name="Origin-Host" data="$oh"/>
383 <avp name="Origin-Realm" data="$(echo $oh | cut -d\. -f2-) $WHAT"/>
384 <avp name="Auth-Application-Id" data="16777236 $WHAT 16777238 $WHAT"/>
385 <avp name="Origin-State-Id" data="1"/>
386 <avp name="Host-IP-Address" data="1|192.168.14.42 $WHAT"/>
387 <avp name="Vendor-Id" data="193"/>
388 <avp name="Product-Name" data="afNode $WHAT ggsnNode $WHAT"/>
389 <avp name="Firmware-Revision" data="1"/>
396 for oh in $(awk -v input=server '{if ($2 == input) print $1;}' $ohs_file)
398 cea=$SOURCE_DIR/cea.${oh}.xml
401 echo $oh >> ceas_4_establishing_origin_hosts
402 echo "Missing CEA: `basename $cea` (a basic template has been created, please edit & fix the unknowns)"
404 <message version="1" name="CEA" application-id="0" hop-by-hop-id="1" end-to-end-id="1">
405 <avp name="Result-Code" data="2001" alias="DIAMETER_SUCCESS"/>
406 <avp name="Origin-Host" data="$oh"/>
407 <avp name="Origin-Realm" data="$(echo $oh | cut -d\. -f2-) $WHAT"/>
408 <avp name="Host-IP-Address" data="1|192.168.12.42 $WHAT"/>
409 <avp name="Vendor-Id" data="193"/>
410 <avp name="Product-Name" data="SAPC"/>
411 <avp name="Supported-Vendor-Id" data="5535"/>
412 <avp name="Supported-Vendor-Id" data="10415"/>
413 <avp name="Auth-Application-Id" data="16777238"/>
414 <avp name="Auth-Application-Id" data="16777236"/>
415 <avp name="Vendor-Specific-Application-Id">
416 <avp name="Vendor-Id" data="10415"/>
417 <avp name="Auth-Application-Id" data="16777238"/>
419 <avp name="Vendor-Specific-Application-Id">
420 <avp name="Vendor-Id" data="10415"/>
421 <avp name="Auth-Application-Id" data="16777236"/>
423 <avp name="Firmware-Revision" data="1"/>