Skip to content

Instantly share code, notes, and snippets.

@aojea
Created January 22, 2015 15:16
Show Gist options
  • Save aojea/a877aa69d07f0f72a411 to your computer and use it in GitHub Desktop.
Save aojea/a877aa69d07f0f72a411 to your computer and use it in GitHub Desktop.
Perl script to generate a edge list from a bgpdump output
#!/usr/bin/perl
# Read the bgpdump output and generate a edge list with two columns source destination
use strict;
use warnings;
my $filename = $ARGV[0]; # store the 1st argument into the variable
open FILE, '<', $filename or die $!; # open the file using lexically scoped filehandle
while (<FILE>) {
my @line = split(/\|/);
my @ASpath = split(/ /,$line[6]);
my $prefix = $line[5];
for my $i (0 .. $#ASpath-1)
{
# Look for aggregated routes and split them
if ( $ASpath[$i+1] =~ m/\{/){
$ASpath[$i+1] =~ s/\{//;
$ASpath[$i+1] =~ s/\}//;
my @ASset = split(/,/,$ASpath[$i+1]);
for my $j (0 .. $#ASset)
{
print $ASpath[$i].",".$ASset[$j].",".$prefix.",".$#ASpath."\n";
}
}
else{
print $ASpath[$i].",".$ASpath[$i+1].",".$prefix.",".$#ASpath."\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment