Graphviz examples

Like most popular open source projects, the documentation of Graphviz (http://www.graphviz.org/Documentation.php) is extensive. The challenge is often where to start. For our purpose, we will focus on dot, which draws directed graphs as hierarchies (not to be confused with the DOT language).

Let's start with the basic steps:

  1. Nodes represent our network entities, such as routers, switches, and servers.
  2. The edge represents the link between the network entities.
  3. The graph, nodes, and edges each have attributes (http://www.graphviz.org/content/attrs) that can be tweaked.
  4. After describing the network, output the network graph (http://www.graphviz.org/content/output-formats) in either the PNG, JPEG, or PDF format.

Our first example is an undirected dot graph consisting of four nodes (core, distribution, access1, and access2). The edges join the core node to the distribution node as well as distribution to both the access nodes:

$ cat chapter8_gv_1.gv
graph my_network {
core -- distribution;
distribution -- access1;
distribution -- access2;
}

The graph can be output in the dot -T<format> source -o <output file> command line:

$ dot -Tpng chapter8_gv_1.gv -o output/chapter8_gv_1.png

The resulting graph can be viewed from the following output folder:

Note that we can use a directional graph by specifying it as a digraph instead of a graph as well as using the arrow (->) sign to represent the edges. There are several attributes we can modify in the case of nodes and edges, such as the node shape, edge labels, and so on. The same graph can be modified as follows:

$ cat chapter8_gv_2.gv
digraph my_network {
node [shape=box];
size = "50 30";
core -> distribution [label="2x10G"];
distribution -> access1 [label="1G"];
distribution -> access2 [label="1G"];
}

We will output the file in PDF this time:

$ dot -Tpdf chapter8_gv_2.gv -o output/chapter8_gv_2.pdf

Take a look at the directional arrows in the new graph:

Now let's take a look at the Python wrapper around Graphviz.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.158.32