6 SCR_DIR=`readlink -f $0 | xargs dirname`
7 TESTCASE_BN=testcase.txt
23 echo "Usage: $0 <source_directory> [seconds_timeout]"
25 echo " source_directory:"
26 echo " The source directory may contain .xml and .metadata files grouped by pairs and alphabetically classified,"
27 echo " and also (and this is VERY IMPORTANT), a file called 'origin-hosts' containing a list of Origin-Host"
28 echo " values that represents the point of view of the ADML testing system, together with the type of the"
29 echo " simulated ADML node (client/server):"
31 echo " <id>.hex.as.xml: ANNA-Diameter XML message format."
32 echo " <id>.metadata: Some decoded message information."
34 echo " origin-hosts: Example of content:"
35 echo " OCS3GPPNodeHostname.ocs3gpprealm.com server"
36 echo " ggsnNodeHostname.nodeHostRealm.com client"
38 echo " The order for the xml and metadata files comes from first dot-separated part (<id>), which is normally the"
39 echo " decoded frame from a pcap file. The xml files are ANNA-Diameter xml messages and a typical metadata file"
40 echo " would be something like this:"
41 echo " date=vie ene 29 15:37:14 CET 2016"
42 echo " timestamp=1454078234.050988000"
43 echo " src=192.168.14.42"
44 echo " dst=192.168.12.40"
47 echo " applicationid=0"
48 echo " originhost=OCSNodeHostname.ocsrealm.com"
50 echo " You can use the 'example/diameter/pcapDecoder/tsharkDecoder.sh' script over a pcap file, in order to get"
51 echo " the hexadecimal buffers and then process them with 'example/diameter/batchConverter' tool to get the xml"
52 echo " messages and metadata for each pcap diameter frame."
55 echo " seconds_timeout:"
56 echo " Timeout in seconds for the testcase. If not provided, no timeout will be programmed for the testcase."
60 echo " The resulting '$TESTCASE_BN' will have all the operations needed to program the test case and will be"
61 echo " written on same source directory referencing xml files as local-relative ones. Normally, 'change-dir'"
62 echo " operation will be used before programming to ease the procedure without having to copy the stuff into"
63 echo " installed ADML execution directory."
65 echo " Connection issues (CER/A), disconnect procedures (DPR/A), database populations and sanity checks are"
66 echo " not responsability for this script. Anyway, CER/A messages detected are symbolically linked with the"
67 echo " name 'ce<r/a>.<origin host>.xml', and missing ones are created with a basic template which the user"
68 echo " could edit and fix with the appropiate values."
74 # Nested Result-Code's not supported here (i.e. charging application)
76 grep "<avp name=\"Result-Code\"" $1 | awk -F'data=' '{ print $2 }' | cut -d\" -f2
79 # $1: metadata file; $2: xml file; $3: check Result-Code indicator; $4: client/server (ADML node role)
83 # date=Wed Oct 7 01:51:16 CEST 2015
84 # timestamp=1444175476.212667000
89 # applicationid=16777238
95 local wait_command=waitfe
96 local send_command=sendxml2e
97 [ "$adml_type" = "server" ] && { wait_command=waitfc ; send_command=sendxml2c ; }
100 # Ignore disconnect peer messages on testcase format (they have no session-id):
101 grep "^code=282$" $mtd > /dev/null
102 [ $? -eq 0 ] && return
104 local code=$(grep ^code $mtd | cut -d= -f2)
105 local isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
106 local sessionid=$(grep Session-Id $xml | cut -d\" -f4)
107 local lines=$(wc -l $TESTCASE_BN | awk '{ print $1 }')
109 local s_wait="test|1|$wait_command|$code|$((1-isrequest))"
110 [ -n "$sessionid" ] && s_wait="${s_wait}|||${sessionid}"
112 local s_send="test|1|$send_command|$xml"
114 if [ $isrequest -eq 1 ]
117 # Special case for SNR/SNA (code=8388636): the Session-Id is created on client and received on SLR previously
118 if [ "$code" = "8388636" -a "$adml_type" = "server" ]
120 s_send="test|1|$send_command|$xml|$REQUEST_STEP"
121 s_wait="test|1|$wait_command|$code|0"
124 echo "$s_send" >> $TESTCASE_BN
126 if [ -n "$resultcode" ]
128 local hbh="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
129 local hbh_matchs=( $(grep -l "$hbh" *.xml) )
130 local ans_xml=${hbh_matchs[1]}
134 _rc=$(getResultCode $ans_xml)
135 [ -n "$_rc" ] && rc=$_rc
139 s_wait="${s_wait}|${rc}"
141 echo "$s_wait" >> $TESTCASE_BN
143 local next_step_number=$((lines+1))
146 # Special case for SLR/SLA (code=8388635): the Session-Id is created on client
147 [ "$code" = "8388635" -a "$adml_type" = "server" ] && { s_wait="test|1|$wait_command|$code|1" ; REQUEST_STEP=$next_step_number ; }
148 echo "$s_wait" >> $TESTCASE_BN
151 echo "test|1|$send_command|$xml|$next_step_number" >> $TESTCASE_BN
159 [ -z "$SOURCE_DIR" ] && usage
160 SOURCE_DIR=`readlink -f $SOURCE_DIR`
161 [ ! -d "$SOURCE_DIR" ] && _exit "Can't found provided directory '$SOURCE_DIR'"
162 # Work on source directory:
165 # Must have metadata:
166 ls *.*metadata >/dev/null 2>/dev/null
167 [ $? -ne 0 ] && _exit "Cannot found '*.*metadata' files on '$SOURCE_DIR' !!"
169 # Check origin-hosts:
170 ohs_file=$SOURCE_DIR/origin-hosts
171 [ ! -f $ohs_file ] && _exit "Can't found the mandatory file '$ohs_file' !!"
172 awk '{ print $NF }' $ohs_file | egrep -qw 'client|server'
173 [ ${PIPESTATUS[1]} -ne 0 ] && _exit "Can't found any Origin-Host in '$ohs_file' with a valid ADML node role value (client or server) !!"
175 # Identify useful frames: those which are created at test-bed side (all except frames coming from tested systems):
177 0> .involved_origin_hosts
179 for oh in `awk '{ print $1 }' $ohs_file`
181 for frame in $(grep -l "^originhost=$oh$" *.*metadata | cut -d\. -f1)
183 echo "$frame" >> .involved_frames
184 echo "$oh" >> .involved_origin_hosts
185 n_involved_frames=$((n_involved_frames + 1))
188 [ $n_involved_frames -eq 0 ] && _exit "No frame has been selected within '$SOURCE_DIR' for provided origin-hosts file !!"
189 sort .involved_frames > .involved_frames_sort
190 mv .involved_frames_sort .involved_frames
192 # Messages classification:
194 0> ceas_4_establishing
195 0> cers_4_starting_origin_hosts
196 0> ceas_4_establishing_origin_hosts
197 0> requests_4_sending
198 0> answers_4_programming
203 [ -n "$TIMEOUT_SEC" ] && echo "test|1|timeout|$((TIMEOUT_SEC * 1000))" >> $TESTCASE_BN
206 for frame in `cat .involved_frames`
208 mtd=( `ls ${frame}.*metadata 2>/dev/null` )
209 [ ${#mtd[@]} -ne 1 ] && _exit "There must be one metadata file corresponding to frame '$frame' !!"
210 xml=( `ls ${frame}.*xml 2>/dev/null` )
211 [ ${#xml[@]} -ne 1 ] && _exit "There must be one xml message file corresponding to '$mtd' (frame '$frame') !!"
212 originHost=$(grep ^originhost= ${frame}.metadata | cut -d= -f2-)
214 # Ignore keep alives:
215 grep -q "^code=280$" $mtd
216 [ $? -eq 0 ] && continue
218 grep -q "^isrequest=1$" $mtd
222 grep -q "^code=257$" $mtd
225 echo $frame >> cers_4_starting
226 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CER message) !!"
227 echo "$originHost" >> cers_4_starting_origin_hosts
228 ln -sf $xml cer.${originHost}.xml
232 echo $frame >> requests_4_sending
235 adml_type=$(grep -w "$originHost" $ohs_file | awk '{ print $NF }')
236 update_testcase $mtd $xml check_result_code $adml_type
239 grep -q "^code=257$" $mtd
242 echo $frame >> ceas_4_establishing
243 originHost=$(grep ^originhost= ${frame}.metadata | cut -d= -f2-)
244 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CEA message) !!"
245 echo "$originHost" >> ceas_4_establishing_origin_hosts
246 ln -sf $xml cea.${originHost}.xml
250 echo $frame >> answers_4_programming
253 adml_type=$(grep -w "$originHost" $ohs_file | awk '{ print $NF }')
254 update_testcase $mtd $xml "" $adml_type
259 # We will replace all the requests hop-by-hop's with a unique value, to avoid bad sniffing cases (different sources using bad values).
260 # For example, the frame number could be valid enough.
263 for frame in `cat .involved_frames`
265 xml=( `ls ${frame}.*xml` )
266 mtd=( `ls ${frame}.*metadata` )
267 isrequest=$(grep "isrequest=1" $mtd)
268 if [ -n "$isrequest" ]
270 hbh_ini="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
271 sed -i 's/'$hbh_ini'/hop-by-hop-id="'$frame'"/' $xml
276 # Simplify origin hosts file (oh + adml role):
277 sort -u .involved_origin_hosts > .involved_origin_hosts_unique
278 grep -w -f .involved_origin_hosts_unique $ohs_file > .involved_origin_hosts_with_info
279 mv .involved_origin_hosts_with_info $ohs_file
280 rm .involved_origin_hosts .involved_origin_hosts_unique
283 for oh in $(awk -v input=client '{if ($2 == input) print $1;}' $ohs_file)
285 cer=$SOURCE_DIR/cer.${oh}.xml
288 echo $oh >> cers_4_starting_origin_hosts
289 echo "Missing CER: `basename $cer` (a basic template has been created, please edit & fix the unknowns)"
291 <message version="1" name="CER" application-id="0" hop-by-hop-id="1" end-by-end-id="1">
292 <avp name="Origin-Host" data="$oh"/>
293 <avp name="Origin-Realm" data="$(echo $oh | cut -d\. -f2-) $WHAT"/>
294 <avp name="Auth-Application-Id" data="16777236 $WHAT 16777238 $WHAT"/>
295 <avp name="Origin-State-Id" data="1"/>
296 <avp name="Host-IP-Address" data="1|192.168.14.42 $WHAT"/>
297 <avp name="Vendor-Id" data="193"/>
298 <avp name="Product-Name" data="afNode $WHAT ggsnNode $WHAT"/>
299 <avp name="Firmware-Revision" data="1"/>
306 for oh in $(awk -v input=server '{if ($2 == input) print $1;}' $ohs_file)
308 cea=$SOURCE_DIR/cea.${oh}.xml
311 echo $oh >> ceas_4_establishing_origin_hosts
312 echo "Missing CEA: `basename $cea` (a basic template has been created, please edit & fix the unknowns)"
314 <message version="1" name="CEA" application-id="0" hop-by-hop-id="1" end-by-end-id="1">
315 <avp name="Result-Code" data="2001" alias="DIAMETER_SUCCESS"/>
316 <avp name="Origin-Host" data="$oh"/>
317 <avp name="Origin-Realm" data="$(echo $oh | cut -d\. -f2-) $WHAT"/>
318 <avp name="Host-IP-Address" data="1|192.168.12.42 $WHAT"/>
319 <avp name="Vendor-Id" data="193"/>
320 <avp name="Product-Name" data="SAPC"/>
321 <avp name="Supported-Vendor-Id" data="5535"/>
322 <avp name="Supported-Vendor-Id" data="10415"/>
323 <avp name="Auth-Application-Id" data="16777238"/>
324 <avp name="Auth-Application-Id" data="16777236"/>
325 <avp name="Vendor-Specific-Application-Id">
326 <avp name="Vendor-Id" data="10415"/>
327 <avp name="Auth-Application-Id" data="16777238"/>
329 <avp name="Vendor-Specific-Application-Id">
330 <avp name="Vendor-Id" data="10415"/>
331 <avp name="Auth-Application-Id" data="16777236"/>
333 <avp name="Firmware-Revision" data="1"/>