Virtual Network Visualization

OpenSolaris supports virtual networks using virtual interfaces connected with virtual switches. This feature was introduced with Project Crossbow in OpenSolaris 2009.06. To visualize the internal network(s), I created a perl script which takes the output of dladm show-link and dladm show-linkprop -o link,value -p zone and generates a dot-File, which then can be rendered using Graphviz.

Update: You might also be interested in the Crossbow Virtual Wire Demo Tool.

dladm2dot.pl

#! /usr/bin/perl
 
$STYLE{'etherstub'} = "shape=box";
$STYLE{'phys'} = "color=black";
$STYLE{'vnic'} = "color=blue";
#$STYLE{'unknown'} = "fontcolor=red";
$STYLE{'up'} = "fontcolor=green";
 
print "digraph vnet {\n";
 
open INPUT, "dladm show-link|";
# skip first line
<INPUT>;
while (defined($line=<INPUT>)) {
	if ($line =~ /^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$/) {
		$s = $STYLE{$2};
		$s .= ",".$STYLE{$4} if defined($STYLE{$4});
		print "	// $line	$1 [$s];\n";
		if ($5 ne '--') {
			print "	$1 -> $5;\n";
		}
	}
}
close INPUT;
 
open INPUT, "dladm show-linkprop -o link,value -p zone|";
# skip first line
<INPUT>;
while (defined($line=<INPUT>)) {
	if (($line =~ /^([^\s]+)\s+([^\s]+)$/) && ($2 ne '--')) {
		print "	subgraph \"cluster_$2\" { $1; label = \"$2\"; }\n";
	}
}
close INPUT;
 
print "}\n";

Example

Example's Result

Input

LINK        CLASS    MTU    STATE    OVER
e1000g0     phys     1500   up       --
e1000g1     phys     1500   unknown  --
isc_net0    etherstub 9000  unknown  --
isc0        vnic     9000   up       isc_net0
isc1        vnic     9000   up       isc_net0
isc2        vnic     9000   up       isc_net0
LINK         VALUE
e1000g0      --
e1000g1      --
isc_net0     --
isc0         --
isc1         isc1
isc2         isc2

Output

digraph vnet {
	// e1000g0     phys     1500   up       --
	e1000g0 [color=black,fontcolor=green];
	// e1000g1     phys     1500   unknown  --
	e1000g1 [color=black];
	// isc_net0    etherstub 9000  unknown  --
	isc_net0 [shape=box];
	// isc0        vnic     9000   up       isc_net0
	isc0 [color=blue,fontcolor=green];
	isc0 -> isc_net0;
	// isc1        vnic     9000   up       isc_net0
	isc1 [color=blue,fontcolor=green];
	isc1 -> isc_net0;
	// isc2        vnic     9000   up       isc_net0
	isc2 [color=blue,fontcolor=green];
	isc2 -> isc_net0;
	subgraph "cluster_isc1" { isc1; label = "isc1"; }
	subgraph "cluster_isc2" { isc2; label = "isc2"; }
}