#!/usr/bin/perl

use strict;

#type: throughput.pl <trace file> <required node> <granularity> > file

my $infile=$ARGV[0];
my $tonode=$ARGV[1];
my $granularity=$ARGV[2];

# We compute how many bytes were transmitted during time interval specified
# by granularity parameter in seconds

# relevant fields in the trace file
my $event;
my $time;
my $from;
my $to;
my $pkttype;
my $pktsize;
my $rest;

my $sum=0;
my $clock=0;
my $throughput;
my $line;

open(DATA, "<$infile") || die "Can't open $infile";

while ($line = <DATA>) {
	($event, $time, $from, $to, $pkttype, $pktsize, $rest) = split(' ', $line);

	if ( ($event eq 'd')) {
		$sum += 1;
	}
	print STDOUT "$time $sum\n";
}

print STDOUT "$time $sum\n";

close DATA;
