#!/usr/bin/perl

use strict;

#type: routingupdates-frequency.pl <trace file> <granularity> > file

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

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

# relevant fields in the trace file

my $clock=0;
my $count=0;
my $time=0;

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

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

	if ($time - $clock > $granularity) {
		print STDOUT "$time $count\n";
		$clock += $granularity;
		$count = 0;
	}

	if ( ($event eq 'r') && ($pkttype =~ /rtProto/) ) {
		$count++;
	}
}

print STDOUT "$time $count\n";

close DATA;

