6 SCR_DIR=`readlink -f $0 | xargs dirname`
7 TESTCASE_BN=testcase.txt
22 echo "Usage: $0 <source_directory> \"[test_end_points]\" [timeout]"
24 echo " source_directory:"
26 echo " The source directory may contain .xml and .metadata files grouped by pairs and alphabetically classified:"
28 echo " 11.hex.as.xml 15.hex.as.xml 19.hex.as.xml ..."
29 echo " 11.metadata 15.metadata 19.metadata ..."
30 echo " 13.hex.as.xml 17.hex.as.xml 21.hex.as.xml ..."
31 echo " 13.metadata 17.metadata 21.metadata ..."
33 echo " The order comes from first dot-separated part, which is normally the decoded frame from a pcap file:"
35 echo " 11.hex.as.xml: would be the ANNA-Diameter decoded message from hexadecimal sniffed one."
36 echo " 11.metadata: would contain parsed metadata from tshark or another fulfilling this information:"
38 echo " date=Sat Dec 19 11:50:55 CET 2015"
39 echo " timestamp=1450522255.205673000"
44 echo " applicationid=0"
46 echo " Presented example has been achieved using the 'example/diameter/pcapDecoder/tsharkDecoder.sh' script"
47 echo " and then decoding with 'example/diameter/batchConverter' tool with appropiate diameter dictionaries."
50 echo " test_end_points: space-separated list of possible test end points (hostnames, ip addresses)"
52 echo " This script will create a basic testcase based on frames timeline (11, 13, 15, etc.), from the desired"
53 echo " end-point list. For example, from the 'gentraf' point of view, outgoing requests will be translated as"
54 echo " sendxml operations with corresponding waits for answers and corresponding result codes (normally 2001)"
55 echo " if those answers are provided (2001 will be assigned as result-code condition if no answer is found)."
56 echo " CER/A are detected creating a symbolic link to better reference them, and DPR/A are ignored."
58 echo " The provided test end point list shall match metadata 'src' field in order to filter the valid testcase"
59 echo " messages. In case of nothing provided (empty string) a list with the possible values from the source"
60 echo " directory will be shown."
65 echo " Timeout in seconds for the testcase. If not provided, no timeout will be programmed for the testcase."
69 echo " The resulting '$TESTCASE_BN' will have all the operations needed to program the test case and will be"
70 echo " written on same source directory referencing xml files as local-relative ones. Probably, 'change-dir'"
71 echo " operation will be used before programming to ease the procedure without having to copy the stuff into"
72 echo " installed ADML execution directory."
74 echo " Connection issues (CER/A), disconnect procedures (DPR/A), database populations and sanity checks are"
75 echo " not responsability for this script. Such operations shall be externally performed to guarantee that"
76 echo " programming this testcase is going to be valid in context of test execution. Anyway, CER messages"
77 echo " will be detected and symbolically linked with the name 'cer.<origin host>.xml'."
79 echo " PCAPS WITHOUT CER/CEA MESSAGES:"
81 echo " There is a helper tool to build CER/CEA messages for involved origin hosts. This is useful when the"
82 echo " pcap file analyzed miss the capabilities exchange messages: touch the file 'create_cer_and_cea' inside"
83 echo " the source directory, and follow the instructions."
89 grep "<avp name=\"Origin-Host\"" $1 | cut -d\" -f4
93 # Nested Result-Code's not supported here (i.e. charging application)
95 grep "<avp name=\"Result-Code\"" $1 | awk -F'data=' '{ print $2 }' | cut -d\" -f2
98 # $1: metadata file; $2: xml file; $3: check Result-Code indicator
102 # date=Wed Oct 7 01:51:16 CEST 2015
103 # timestamp=1444175476.212667000
108 # applicationid=16777238
113 # Ignore disconnect peer messages on testcase format (they have no session-id):
114 grep "^code=282$" $mtd > /dev/null
115 [ $? -eq 0 ] && return
117 local code=$(grep ^code $mtd | cut -d= -f2)
118 local isrequest=$(grep ^isrequest $mtd | cut -d= -f2)
119 local sessionid=$(grep Session-Id $xml | cut -d\" -f4)
120 local lines=$(wc -l $TESTCASE_BN | awk '{ print $1 }')
122 local s_waitfe="test|1|waitfe|$code|$((1-isrequest))"
123 [ -n "$sessionid" ] && s_waitfe="${s_waitfe}|||${sessionid}"
125 if [ $isrequest -eq 1 ]
127 echo "test|1|sendxml2e|$xml" >> $TESTCASE_BN
128 if [ -n "$resultcode" ]
130 local hbh="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
131 local hbh_matchs=( $(grep -l "$hbh" *.xml) )
132 local ans_xml=${hbh_matchs[1]}
136 _rc=$(getResultCode $ans_xml)
137 [ -n "$_rc" ] && rc=$_rc
139 s_waitfe="${s_waitfe}|${rc}"
141 echo "$s_waitfe" >> $TESTCASE_BN
143 echo "$s_waitfe" >> $TESTCASE_BN
144 echo "test|1|sendxml2e|$xml|$((lines+1))" >> $TESTCASE_BN
152 [ -z "$SOURCE_DIR" ] && usage
153 SOURCE_DIR=`readlink -f $SOURCE_DIR`
154 [ ! -d "$SOURCE_DIR" ] && _exit "Can't found provided directory '$SOURCE_DIR'"
155 # Work on source directory:
158 # Must have metadata:
159 ls *.*metadata >/dev/null 2>/dev/null
160 [ $? -ne 0 ] && _exit "Cannot found '*.*metadata' files on '$SOURCE_DIR' !!"
162 # Show possible end points if nothing provided:
164 if [ -z "$END_POINTS" ]
166 src_eps=( $(grep "^src=" *.*metadata | cut -d= -f2 | sort -u) )
167 [ ${#src_eps[@]} -eq 0 ] && _exit "No source end-points detected: metadata must have an 'src=xxx' line."
168 if [ ${#src_eps[@]} -eq 1 ]
171 echo "Detected a unique end-point: $END_POINTS"
173 echo "Input a space-separated list for desired end-points to be processed as test side: "
174 echo " (available source end-points: ${src_eps[*]})"
176 [ -z "$END_POINTS" ] && _exit "Invalid empty input !!"
180 # Identify useful frames: those which are created at test-bed side (all except frames coming from tested systems):
182 for tag in $END_POINTS
184 for metadata in $(grep "^src=$tag$" *.*metadata)
186 frame=$(echo $metadata | cut -d\. -f1)
187 touch ${frame}.needed
190 ls *.needed >/dev/null 2>/dev/null
191 [ $? -ne 0 ] && _exit "No frame has been selected within '$SOURCE_DIR' for provided end-points ($END_POINTS) !!"
193 # Messages classification:
195 0> ceas_4_establishing
196 0> cers_4_starting_origin_hosts
197 0> ceas_4_establishing_origin_hosts
198 0> requests_4_sending
199 0> answers_4_programming
204 [ -n "$TIMEOUT_SEC" ] && echo "test|1|timeout|$((TIMEOUT_SEC * 1000))" >> $TESTCASE_BN
207 for frame in `ls *.needed | cut -d\. -f1 | sort -n`
209 mtd=( `ls ${frame}.*metadata 2>/dev/null` )
210 [ ${#mtd[@]} -ne 1 ] && _exit "There must be one metadata file corresponding to frame '$frame' !!"
211 xml=( `ls ${frame}.*xml 2>/dev/null` )
212 [ ${#xml[@]} -ne 1 ] && _exit "There must be one xml message file corresponding to '$mtd' (frame '$frame') !!"
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 originHost=$(getOriginHost $xml)
227 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CER message) !!"
228 echo "$originHost" >> cers_4_starting_origin_hosts
229 ln -sf $xml cer.${originHost}.xml
233 echo $frame >> requests_4_sending
234 update_testcase $mtd $xml check_result_code
237 grep -q "^code=257$" $mtd
240 echo $frame >> ceas_4_establishing
241 originHost=$(getOriginHost $xml)
242 [ -z "$originHost" ] && _exit "Missing Origin-Host (frame $frame, CEA message) !!"
243 echo "$originHost" >> ceas_4_establishing_origin_hosts
244 ln -sf $xml cea.${originHost}.xml
248 echo $frame >> answers_4_programming
249 update_testcase $mtd $xml
255 # We will replace all the requests hop-by-hop's with a unique value, to avoid bad sniffing cases (different sources using bad values).
256 # For example, the frame number could be valid enough.
261 grep sendxml $TESTCASE_BN > .involved_frames
262 n_involved=`wc -l .involved_frames | awk '{ print $1 }'`
264 for frame in `cat .involved_frames | cut -d\| -f4 | cut -d\. -f1`
266 xml=( `ls ${frame}.*xml` )
267 involved_xmls="$involved_xmls $xml"
268 mtd=( `ls ${frame}.*metadata` )
269 isrequest=$(grep "isrequest=1" $mtd)
270 if [ -n "$isrequest" ]
272 hbh_ini="$(grep -o "hop-by-hop-id=\"[0-9]*\"" $xml)"
273 sed -i 's/'$hbh_ini'/hop-by-hop-id="'$frame'"/' $xml
278 if [ -f $SOURCE_DIR/create_cer_and_cea ]
280 # PCAPs without CER messages ...
281 if [ ! -s cers_4_starting_origin_hosts ]
283 if [ $n_involved -ne 0 ]
285 grep "<avp name=\"Origin-Host\"" $involved_xmls | cut -d\" -f4 | sort -u > cers_4_starting_origin_hosts
286 for oh in `cat cers_4_starting_origin_hosts`
288 cer_file=cer.${oh}.xml
290 echo "WARNING: perhaps you should configure '$cer_file' because it is missing in the pcap file provided."
291 echo " Currently it contains a basic template but you must fill/fix the unknowns '$WHAT'."
292 cat << EOF > $cer_file
293 <message version="1" name="CER" application-id="0" hop-by-hop-id="1" end-by-end-id="1">
294 <avp name="Origin-Host" data="$oh"/>
295 <avp name="Origin-Realm" data="$(echo $oh | cut -d\. -f2-) $WHAT"/>
296 <avp name="Auth-Application-Id" data="16777236 $WHAT 16777238 $WHAT"/>
297 <avp name="Origin-State-Id" data="1"/>
298 <avp name="Host-IP-Address" data="1|192.168.14.42 $WHAT"/>
299 <avp name="Vendor-Id" data="193"/>
300 <avp name="Product-Name" data="afNode $WHAT ggsnNode $WHAT"/>
301 <avp name="Firmware-Revision" data="1"/>
306 # echo "WARNING: No 'sendxml' primitives on testcase ??"
310 # PCAPs without CEA messages ...
311 if [ ! -s ceas_4_establishing_origin_hosts ]
313 if [ $n_involved -ne 0 ]
315 grep "<avp name=\"Origin-Host\"" $involved_xmls | cut -d\" -f4 | sort -u > ceas_4_establishing_origin_hosts
316 for oh in `cat ceas_4_establishing_origin_hosts`
318 cea_file=cea.${oh}.xml
320 echo "WARNING: perhaps you should configure '$cea_file' because it is missing in the pcap file provided."
321 echo " Currently it contains a basic template but you must fill/fix the unknowns '$WHAT'."
322 cat << EOF > $cea_file
323 <message version="1" name="CEA" application-id="0" hop-by-hop-id="1" end-by-end-id="1">
324 <avp name="Result-Code" data="2001" alias="DIAMETER_SUCCESS"/>
325 <avp name="Origin-Host" data="$oh"/>
326 <avp name="Origin-Realm" data="$(echo $oh | cut -d\. -f2-) $WHAT"/>
327 <avp name="Host-IP-Address" data="1|192.168.12.42 $WHAT"/>
328 <avp name="Vendor-Id" data="193"/>
329 <avp name="Product-Name" data="SAPC"/>
330 <avp name="Supported-Vendor-Id" data="5535"/>
331 <avp name="Supported-Vendor-Id" data="10415"/>
332 <avp name="Auth-Application-Id" data="16777238"/>
333 <avp name="Auth-Application-Id" data="16777236"/>
334 <avp name="Vendor-Specific-Application-Id">
335 <avp name="Vendor-Id" data="10415"/>
336 <avp name="Auth-Application-Id" data="16777238"/>
338 <avp name="Vendor-Specific-Application-Id">
339 <avp name="Vendor-Id" data="10415"/>
340 <avp name="Auth-Application-Id" data="16777236"/>
342 <avp name="Firmware-Revision" data="1"/>
347 # echo "WARNING: No 'sendxml' primitives on testcase ??"