netlab Network Topology Graphs
A netlab user sent me an intriguing question: “Would it be possible to get network topology graphs out of the tool?”
I did something similar a long while ago for a simple network automation project (and numerous networking engineers built really interesting stuff while attending the Building Network Automation Solutions course), so it seemed like a no-brainer. As always, things aren’t as easy as they look.
Creating a data structure that describes the network as a graph of nodes and links is trivial; the hard part is auto-placement – how do you position the nodes to make the graph look decent. While there are several tools that can take graph description in JSON or YAML format and even use networking icons to draw switches and routers, I haven’t found one (in that category) that would be able to solve the placement problem, so I had go back to the granddaddy of graphing tools: graphviz.
I used graphviz earlier, and used Jinja2 templates to generate graph descriptions in DOT language. It was a royal pain. This time, I decided to do it with Python (much easier) and created a whole framework within netlab in case you want to expand the functionality (and hopefully contribute it back to the project).
So far, netlab can create two types of graphs:
- Topology (nodes and links), optionally clustering nodes into autonomous systems;
- BGP autonomous systems and sessions.
To create the graphs you have to:
- Install graphviz
- Run netlab create to create a graph description (.dot file)
- Run one of the graphviz commands to create a graph in desired output format (they support over a dozen formats)
- Enjoy the end results.
For example, I was using the network topology from one of my BGP examples to create a simple network topology graph:
netlab create -o graph dot graph.dot -T png -o netsim-graph-topo.png
- netlab create uses topology.yml as the default lab topology description and creates graph.dot as the default graph description. You can change both with CLI options.
- dot is one of the graphviz graph drawing commands. You have to specify the graph description (graph.dot), output format (png) and output file name.
Changing the graph type to BGP (by using graph:bgp CLI parameter with netlab create) creates a graph of IBGP and EBGP sessions:
netlab create -o graph:bgp dot graph.dot -T png -o netsim-graph-bgp.png
For more details, please read the netlab documentation, in particular the graph output module page.
From the viewpoint of someone with a networking background are there some books, videos or other material as a preparation to understand your (Python) code? Is there a documentation about your software design/philosophy? I saw that there are some comments in your code (no blaming) which help but it's still hard for me to follow.
I'm positive there are tons of good programming or software design/engineering books out there that will help you get started, but I wouldn't know what to recommend -- I went over some of those hurdles in 1980s.
Programming is not my core business, and so there's no documentation on my software design philosophy. On a somewhat tangential note, you wouldn't believe how many programmers claim there's no need for code comments because their code is obvious and self-documenting ;)
If you have any specific question just send it my way; if you'd like to implement a new feature in netsim-tools, open a GitHub issue and we'll go from there.