Created
January 22, 2015 15:16
-
-
Save aojea/a877aa69d07f0f72a411 to your computer and use it in GitHub Desktop.
Perl script to generate a edge list from a bgpdump output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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