Internal/Mapping/Topologies/Topo4: dbprocess.pl

File dbprocess.pl, 1.5 KB (added by zhibinwu, 18 years ago)
Line 
1#!/usr/bin/perl
2
3# this script read one or more databases and extract how many packets are sent and received respectively.
4#
5
6$sink1 = 2;
7$sink2 = 8;
8$sink3 = 12;
9$sink4 = 16;
10
11use Mysql;
12
13$hostname = 'idb1.orbit-lab.org';
14$user = 'orbit';
15#$database = 'none';
16$database= @ARGV; #grid_2006_09_06_14_52_08, grid_2006_09_06_15_29_27,grid_2006_09_06_15_39_09
17$password = 'orbit';
18$resultfile ='tempres';
19
20
21$table2 = "temp/rx_table";
22
23$driver = 'mysql';
24
25my $noiselevel = 18;
26my $now = localtime time;
27open(res, ">>$resultfile")
28 || die "Can't open result file: $!\n";
29print res "$now test results are \n";
30close res;
31
32foreach(@ARGV)
33{
34 dumpDB($_,$table2);
35}
36
37system ("awk '\$1~/node$sink1/' $table2 > temp/sink1");
38system ("awk '\$1~/node$sink2/' $table2 > temp/sink2");
39system ("awk '\$1~/node$sink3/' $table2 > temp/sink3");
40system ("awk '\$1~/node$sink4/' $table2 > temp/sink4");
41
42system("gnuplot fairplot.gp");
43print "Done. check gnuplot_plot1.ps file! \n";
44
45#we need a subfunction to read 1 database 2 table and dump to two files
46sub dumpDB
47{
48 my ($dbname, $f2) = @_;
49 open (OUTFILE2, "> $f2")
50 || die "Can't open file to save temporary RX data $!\n";
51 my $dbh = Mysql->connect($hostname, $dbname, $user, $password);
52 my $sql_query2="SELECT node_id, sequence_no, pkt_seqno, rcvd_pkt_size_sample_sum, rssi, xmitrate from receiver4_otr_receiverport";
53
54 my $sth2 = $dbh->query($sql_query2);
55 while(my @record2 = $sth2->FetchRow) {
56 print OUTFILE2 "@record2 \n";
57 }
58 close OUTFILE2;
59}
60
61
62
63