<< DefaultAgiServer in JBoss AS 4.x | Home

Visualizing your dialplan with a graph

Asterisk-Java's Config packages and the JUNG framework

A few weeks ago, Matt Gibson posted on the asterisk-users discussion list that he was looking for a GraphViz script he had heard about a few years ago that could generate graphs of Asterisk's extensions.conf file that defines the dialplan. At the time, I had been working on a recently open-sourced application, EgoNet, for a researcher I work with. This application taught me much about social networks, particularly his specialty of egocentric networks, and it also helped me learn a ton about the Java Universal Network/Graph Framework (or JUNG). I immediately thought about combining my experience with JUNG and Asterisk, and wrote a rudimentary (read as: extremely ugly) parser for extensions.conf and generated a crude graph of the sample dialplan.

Here's a picture of it:

Original Dialplan Visualization

I posted my image back to the list and got many interesting responses. Given all of the interest, and remembering that Stefan had recently added some config file parsing to Asterisk-Java for management of the configuration file format Asterisk uses, I decided to add extensions.conf-specific parsing to his original work.

So far, I've only written in some very, very simple grouping of the different kinds extensions.conf statements, specifically support for exten and include. I've also added the parsing of the exten line to recognize the extension name, priority, application, and arguments. Because the authoritative source for all of this is pbx_config.c, I couldn't resort to flex or bison. At the moment, I haven't differentiated any further into interpreting the dialplan, as I don't really care about things like priorities like same or n+1 or anything other than basic structure.

Without further ado, I'd like to show some of what can be done with the dialplan specific parsing I've done, and give some examples, including a Java Web Start demo (so get your extensions.conf file ready!).

Example 0: Just printing out the parsed information
Initially, I just wanted a trivial example to print out what I had parsed. Here, I print out every context and its extensions. Below is the code, and then the output. I trimmed the output to show what new classes I've created outside of Stefan's original config package. The important ones are ConfigInclude and ConfigExtension, as those will give us some ties for our graph.

Show/Hide Code and Output for Example 0

Examples 1 & 2: Initial network graph definition
The next step was to decide what to graph. Because contexts are the major structural feature in a dialplan, I chose to make contexts the nodes. Next, I needed to decide what ties contexts together in order to have some edges in my graph. I chose include statements so that my graph would show the overall structure of the dialplan. You could choose anything for the ties, and later on, I throw in Goto statements as well. As you can see from the code examples, I had to add two new methods -- one for figuring out the nodes (buildGraph) and one for figuring the edges around that node (getIncludesContext). After looking at the output, I decided I needed labels on my nodes and edges. That's example 2, which I haven't shown in code here (it's included in the download at the end of the article). Finally, for example 2, I created a class, SimpleGraphViewer that handled the graph part of things here. It is based directly from the ShowLayouts demo in JUNG.

Show/Hide Code for Examples 1 & 2

Here's the output graphs of examples 1 and 2:
Example 1   Example 2

Example 3: Adding even more to the graph
After I saw example 2, I wanted to add Goto() statements as green edge ties to other context nodes and I wanted to size nodes by how many extensions they had. I also wanted to clean up all of the labeling by using color. I used JUNG's normal ways of doing both of these, which you may follow along with in the code samples. These graphs are starting to look really neat.

Show/Hide Code for Example 3

Here's the output of the extensions.conf that comes default with Asterisk, as well as output from a more complex dialplan I picked up along the way.
Example 3   Example 3b

Try it on your own extensions.conf
[Launch to try the demo] or skip ahead to download the JAR file containing the source (see the org.mbs3.* packages for the demo sources, the rest of the JAR is JUNG and Asterisk-Java).

Please note: The web start demo requires you to accept a self-signed certificate as web start won't allow the demo to read the local extensions.conf file you select! If you're worried about this, feel free to download and build the source yourself.

Here's what the demo looks like with my extensions.conf and JUNG's ISOMLayout. The demo contains two different mouse modes for interacting with the graph as well as a button to save the image. If the demo doesn't work, or you encounter any trouble or things that need to be corrected, feel free to reply and let me know. Thanks!

Example 3c

 



Re: Visualizing your dialplan with a graph

Interesting. I think you need to add labels to the transitions for it to be useful. Is it dealing with #includes? One file I loaded which uses a lot of #includes came up with a very minimal graph.

Re: Visualizing your dialplan with a graph

Hi Brett, The earlier revisions of the graph do have labels on the edges. I took it out of the final step as I began to color code the edges instead. I agree that the labels would be more useful, but I also didn't like how text-heavy the graph became when every edge was labeled (and this graph accepts parallel edges, so those were just horrible to try and discern anything from). The actual parser does handle "#include," but it doesn't do anything with them yet. It simply puts metadata on the object indicating there was an include. Right now, this is all layered in such a way that you don't necessarily have to use a file-based input -- you could use a running Asterisk. Since those would require different acts to get #include parsed, I hadn't approached the issue yet. Thanks for your feedback!

Re: Visualizing your dialplan with a graph

Hi Martin, Excellent application. Makes me see how simple my dialplan really is. :) Thanks!

Re: Visualizing your dialplan with a graph

I had to change "exten =" to "exten =>" in order to get my file to parse. Any chance of an "enhancement?"

Re: Visualizing your dialplan with a graph

Hello! That was an accidental dependency, DOH. I've updated the application to remove that dependency. I've re-uploaded the new JAR here, and if you're using Asterisk-Java from your own download, the fix will appear on the next nightly. Thank you.

Re: Visualizing your dialplan with a graph

Can I get the latest jar file. This jar file is asking for a file and I am not sure which file it is looking for.

Re: Visualizing your dialplan with a graph

It is asking you to select your extensions.conf file. Pick that and it will show you the visualization.

Add a comment Send a TrackBack