File: trsplit

package info (click to toggle)
ns2 2.35%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 78,796 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (126 lines) | stat: -rwxr-xr-x 2,762 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
eval 'exec perl -S $0 ${1+"$@"}'  # -*-Mode:Perl; perl-indent-level:8-*-
    if 0;

#require 5.003;

#
# Contributed by Giao Nguyen, http://daedalus.cs.berkeley.edu/~gnguyen
#

sub Usage
{
	$0 =~ s/.*\/([^\/]+)$/$1/;
	print <<EOF;
Split ns trace file into files for individual connection
Usage:  $0 [options] files
options: -c comment:  comment to print at the end along with total throughput
	 -f	:  force new file for each connection
	 -psize size of packet in bytes
	 -tt	trace type
	 -pt	packet type	(list)
	 -fid   flow id 	(list)
	 -ctt	trace type column
	 -cpt	packet type column
	 -ctime	time column
	 -csrc	source address column
	 -cdst	destination address column
EOF
	exit;
}

sub Getopt
{
	local($spec) = @_;
	local($key);
	&Usage if ($#ARGV < 0);
	while ($_ = $ARGV[0], /^-(\w+)/) {
		shift @ARGV;
		$key = $1;
		$opt{$key} = (index($spec, "$key:") >= 0) ? shift @ARGV : 1;
		$_ = "\$$key";
		if ($key =~ /^(tt|pt|fid)$/) {
			# concat to get list of values for a field in the trace
			eval "$_ = $_ . '$opt{$key} '";
		} else {
			eval "$_ = $opt{$key}";
		}
	}
}


# default information on the trace
$psize = 1000;			# packet size in bytes
# Column numbers for each field in the trace
$ctt = 1;
$ctime = 2;
$cpt = 5;
$cfid = 8;
$csrc = 9;
$cdst = 10;
$cseq = 11;
# the file descriptor number to started with
$fdcount = 4;

# Set a couple of defaults if not given at the command line
&Getopt(":c:psize:tt:ctt:ctime:cpt:cfid:csrc:cdst:cseq:");
$force = $opt{'f'};
$tt = '-'	if (! $tt);
$pt = 'tcp'	if (! $pt);
$fid = 0	if (! $fid);


shift @ARGV while ($#ARGV >= 0 && (! -r $ARGV[0]));

# process the trace file
while (<>)
{
	chop;
	@col = ('', split);
	$count{$col[$ctt]}++;
	next if (index($tt, $col[1]) < 0);
	next if (index($pt, $col[$cpt]) < 0);
	next if (index($fid, $col[$cfid]) < 0);

	$src = $col[$csrc];
	$dst = $col[$cdst];
	$key = "$col[1]_$col[$cpt]_$src_$dst";
	$time{$key} = $col[$ctime];
	$pktcnt{$key}++;
	$seqno{$key} = $col[$cseq];

	if ($force) {
		$fd = $opened{$key};
		if (! $fd) {
			$opened{$key} = $fd = $fdcount++;
			open($fd, ">${ARGV}_$key");
		}
		printf $fd "%0.6f\t%d\n", $col[$ctime], $col[$cseq];
	}
}


# print the per-connection information to STDOUT
@keys = sort (keys %time);
foreach $key (@keys) {
	$t = $time{$key};
	$s = $seqno{$key};
	if ($s > $pktcnt{$key}) {
		$s = $pktcnt{$key};
	}
	$maxtime = $t  if ($t > $maxtime);
	$maxpkt += $s;
	printf("%s\t%0.6f\t%d\t%0.6f\t%0.6f\n",
	       $key, $t, $s, $s/$t, 0.008 * $psize * $s/$t);
}

# print summary information to STDERR
if ($maxtime > 0) {
	printf STDERR " %d\t%0.6f\t%s\t",
	$#keys+1, 0.008 * $psize * $maxpkt / $maxtime, $opt{'c'};

	@keys = sort (keys %count);
	foreach $key (@keys) {
		print STDERR $key, $count{$key}, " ";
	}
	print STDERR "\n";
}