Mininet topology visualization with Graphviz from Perl


A more perlish version of Mininet topology visualization with Graphviz.

In previous post Mininet topology visualization with Graphviz we took a look at a Perl program to generate a graph description useful to be fed into the dot program.

It turns out that we can control the full generation process from Perl:

#!/usr/bin/env perl
use 5.024;
use warnings;
use experimental qw< postderef signatures >;
no warnings qw< experimental::postderef experimental::signatures >;

use GraphViz2;

say {*STDERR} "paste your data please, then CTRL-D:" if -t;

my $g = GraphViz2->new(global => {directed => 1});
while (<>) {
   my ($A, $B) = m{
         (.*?)-eth\d+  # first part
         \s* <-> \s*   # "link" indicator
         (.*?)-eth\d+  # second part
   $g->add_edge(from => $A, to => $B, arrowhead => 'none');
$g->run(format => 'png', output_file => 'provapl.png');

I thought it would have been more difficult… but GraphViz2 is quite neat and it’s easy to learn, yay!

Comments? Octodon, , GitHub, Reddit, or drop me a line!