Welcome, Guest. Please login or register.

Author Topic: NeDi2GrapML  (Read 50454 times)

acoto

  • Guest
NeDi2GrapML
« on: February 25, 2012, 02:36:50 pm »
Hello NeDi Community,


Some time ago Dave Wapstra, a friend from Cisco created a perl script to convert a text file containing CDP details into a network Schematic in GraphML format.

On last week I rewrote part of the script and created NeDi2GraphML.pl

NeDi2GraphML.pl reads some tables from MySQL NeDi database, and optionaly some some control files and then generates a detailed network schematic in GraphML format

yEd from yWorks is an excellent free application to view/edit GraphML.

I placed the script, some helping files and screenshots in:

http://sourceforge.net/projects/nedi2graphml/

Attached a couple of schematics from my lab.


Please take a look.

Regards,

Adrian


pc_sg

  • Guest
Re: NeDi2GrapML
« Reply #1 on: February 27, 2012, 08:53:26 am »
Very interesting!

Could you give us (at least me) some more hints (or a procedure) on how to "install and configure" NeDi2GraphML in a running NeDi environment?

TIA!

Paolo

acoto

  • Guest
Re: NeDi2GrapML
« Reply #2 on: February 27, 2012, 02:56:42 pm »
Hello Paolo,

Well, let´s see.

Unzip the file on a working directory on the same machine running NeDi.

The folder:  shall contains
  - NeDi2GraphML.pl: the script file.
  - icons.csv: a sample icon reference file
  - groups.csv: a sample groups reference file
  - geo.csv: a sample (x,y) position reference file.
  - icosns: a folder containing some icons in SVG format


You have to modify next lines at the beginning of the script:
  my $mysql_db="nedi";                   # mysql database
  my $mysql_user="nedi";                 # mysql username
  my $mysql_pass="dbpa55";               # mysql password
  my $mysql_host="localhost";            # mysql host


and place the correct credentials.

Now, we are ready to go. A simple run:

  perl NeDi2GraphML.pl -o File.GraphML

should create a simple schematic. using circles for routers, squares for switchs and triangles for endpoints. Open it in yEd.

At this point all devices are overlapped at position (0,0), not fancy at all. Experiment a bit with yEd Automatic Layout tools, I bet you will be happy soon... Try the Layout Organic :)

Regards,

Adrian


« Last Edit: February 27, 2012, 03:46:44 pm by acoto »

acoto

  • Guest
Re: NeDi2GrapML
« Reply #3 on: February 27, 2012, 03:26:27 pm »
Now,

For a better looking schematic, we can add SVG icons!

The option "--icn icons.csv" instructs NeDi2GrapML to use the references in "icons.csv" and add icons to schematic.

"icons.csv" is a comma separated values file, with the next format per line:

#   icon,<type>,<regex>,<link>,<width>,<weight>,<boxcolor>
#
#      <type>:  "cdpsvc" - CDP announced services: "Router" "Switch" "Bridge"...
#               "devtype" - Device Type "Cisco-3640" "Cisco-3845"...
#               "devname" - Specific device Name "RCore001" "RAccess001" "SWDCT..."
#     <regex>:  matching regular Expression
#      <link>:  file location
#     <width>:  icon width
#    <height>:  icon height     
#  <boxcolor>:  color used when no icon, or zoom out


NeDi2GraphML will follow next type priority: devname > devtype > cdpsvc

An Example File:

icon,cdpsvc,Router,./icons/cisco/blue/router.svg,32,24,#0065A2
icon,cdpsvc,Bridge,./icons/cisco/blue/switch.svg,36,24,#0065A2
icon,devtype,^Node,./icons/cisco/grey/generic-pc.svg,20,20,#707070
icon,devtype,^Hub,./icons/cisco/cyan/hub-small.svg,32,24,#00B38A
icon,devtype,^Cisco-364,./icons/cisco/blue/router.svg,32,24,#0065A2
icon,devtype,^Cisco-720,./icons/cisco/blue/router-mpls.svg,32,24,#0065A2
icon,devname,^RCore,./icons/cisco/red/router-mpls-p.svg,48,48,#CC092F
icon,devname,^RDist,./icons/cisco/orange2/router-mpls-pe.svg,48,40,#FF5A00


The first two lines will place generic router and switch icons to devices that match "Router" or "Bridge" capabilities on CDP.

The next four lines will add icons, to specific device types "Node" "Hub" "Cisco-364x" and "Cisco-720x".

The final two lines, will add icons to specific device names.

The last column is a bit cryptic. When zooming out in yEd, at some point it will replace the SVG icon for an squared box. That column tells yEd to use an specific color for the box.

Now, after we modified icons.csv file to our specific needs, we can proceed:

perl NeDi2GraphML.pl -o NiceSchematic.graphml --icn icons.csv

Get the file. Have fun!

A note:

  NeDi2Graph.pl may add some "Hubs" when it thinks the real topology has them.

A couple extra options:

"-n" will add NeDi nodes (aka endpoints) (be careful, may be slow and memory consuming)
"--edgelabels full" will add labels containing interface names

perl NeDi2GraphML.pl -o NSEdgeLabels.graphml -n --edgelabels full --icn icons.csv

« Last Edit: February 27, 2012, 03:44:44 pm by acoto »

pc_sg

  • Guest
Re: NeDi2GrapML
« Reply #4 on: February 27, 2012, 03:53:06 pm »
Thanks!
 I've just done a first rough test and (with minimal command line) result is interesting!
Without your note about "all icon collapsed" the shown images was unusable...
This confirm that a short "how to" is useful!
Yes, I agree, Organic is one of the best arrangement.

I've seen the strange (and fake) HUB connection. I supposed that is related to an irregular behaviour of old 3500XL switches (that CiscoWorks show connected by a backbone, instead that cascading as really are).
But this doesn't happen in every 3500XL stack. And I see some 3500XL switches in another stack completely disconnected.

May depend on another reason...

Anyway, I'll play some more on this nite addon!

Thanks again!

Paolo

pc_sg

  • Guest
Re: NeDi2GrapML
« Reply #5 on: February 27, 2012, 04:08:36 pm »
May be first bug?

Using --icn and both your original example icons.csv, or a new one with the exact line from you previous message returns this (second case):

Code: [Select]
Useless use of sort in void context at ./NeDi2GraphML.pl line 1011.
Useless use of sort in void context at ./NeDi2GraphML.pl line 1155.
--------------------------------------------------
Enabled Options:
  + Output file: NiceSchematic.graphml
  + Icon file: ./icone.csv
--------------------------------------------------
Loading Icons
Connecting Database
Processing Devices Table
Processing Links Table
Hunting Hubs
Use of uninitialized value $i in array element at ./NeDi2GraphML.pl line 777.
Use of uninitialized value $i in array element at ./NeDi2GraphML.pl line 777.
Use of uninitialized value $i in array element at ./NeDi2GraphML.pl line 777.
Use of uninitialized value $i in array element at ./NeDi2GraphML.pl line 777.
Use of uninitialized value $i in array element at ./NeDi2GraphML.pl line 777.
Attempt to free unreferenced scalar: SV 0xa0e5590, Perl interpreter: 0x9e4e008 at ./NeDi2GraphML.pl line 786.
Attempt to free unreferenced scalar: SV 0xa0e5590, Perl interpreter: 0x9e4e008 at ./NeDi2GraphML.pl line 788.
Segmentation fault

debug switch doesn't add any more significant (for me)

May I missed something?

TIA!

Paolo

acoto

  • Guest
Re: NeDi2GrapML
« Reply #6 on: February 27, 2012, 04:25:45 pm »
Hello Paolo,

Yep, looks like a beginner mistake on that lines... (nested for with the same variable name... doh!...)

Will post a correction asap.

I wonder why I never get that on my lab...


AC


pc_sg

  • Guest
Re: NeDi2GrapML
« Reply #7 on: February 27, 2012, 04:28:27 pm »
Fine!

I'll wait!

Paolo

P.S. seen your PM.

acoto

  • Guest
Re: NeDi2GrapML
« Reply #8 on: February 27, 2012, 04:38:12 pm »
NeDi2GraphML v0.7 uploaded!

Please try again with this new version.

Regards,

Adrian


acoto

  • Guest
Re: NeDi2GrapML
« Reply #9 on: February 27, 2012, 05:01:36 pm »
Second Update Today NeDi2GraphML v0.8
  Corrected another bug on node description links list

AC

pc_sg

  • Guest
Re: NeDi2GrapML
« Reply #10 on: February 28, 2012, 09:23:49 am »
Hi Adrian, v0.8 runs fine. No more errors.

Is very strange the behaviour on 3500XL switches stacks. Look at attached snapshot. Is a stack of 6 switches, but is shown as 4 connected (through a fake hub) and another 2 connected each other (ever through a fake hub), but separed from other 4.

This is the "show cdp neighbors" output of one of the "alone switches"
Code: [Select]
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
                  S - Switch, H - Host, I - IGMP, r - Repeater

Device ID        Local Intrfce     Holdtme    Capability  Platform  Port ID
NENS0051.sas.itn Gig 0/2            157         T S       WS-C3524-XGig 0/2
NENS0052.sas.itn Gig 0/2            151         T S       WS-C3524-XGig 0/2
NENS0055.sas.itn Gig 0/2            149         T S       WS-C3524-XGig 0/2
NENS0054.sas.itn Gig 0/2            122         T S       WS-C3524-XGig 0/2
NENS0056.sas.itn Gig 0/2            172         T S       WS-C3524-XGig 0/2

Nothing strange in this configuration...

Anyway, I remind you that CiscoWorks LMS shows 3500XL switches stacked trough a sort of bus (or a LAN backbone). Look at the second attachment.

Bye!

Paolo


acoto

  • Guest
Re: NeDi2GrapML
« Reply #11 on: February 28, 2012, 02:45:06 pm »
Hello Paolo,

The logic besides that fake hub is, if we have a local interface with two or more CDP neighbors, we can draw several times the same link, or assume there is a layer 1 or layer 2 device in the middle, working like a Hub. I prefer that second approach so NeDi2GraphML inserts a virtual node, and call it "Hub-XX". At some point you may change the Hub Icon for something that represents better the Stack...

Now, what I find strange in this specific case, is that we are getting two Hubs, one joining switches 51, 52, 54 and 56, and the other joining switches 53 and 55.

May you please check the links table for that 6 switches, to verify which CDP links NeDi has on Database.

Regards,

Adrian



 
« Last Edit: February 28, 2012, 03:13:47 pm by acoto »

pc_sg

  • Guest
Re: NeDi2GrapML
« Reply #12 on: February 29, 2012, 11:53:53 am »
AHi Adrian!

Here some dump:

Code: [Select]
NENS0051
Gi0/1 NENS0002 on Gi2/0/5 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0056 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0055 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0054 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0053 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0052 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012

Code: [Select]
NENS0052
Gi0/2 NENS0056 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0053 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0051 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0055 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0054 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012

Code: [Select]
NENS0053
Gi0/2 NENS0056 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0055 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0054 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0052 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0051 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012

Code: [Select]
NENS0054
Gi0/2 NENS0056 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0055 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0053 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0052 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0051 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012

Code: [Select]
NENS0055
Gi0/2 NENS0053 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0056 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0054 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0052 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0051 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012

Code: [Select]
NENS0056
Gi0/1 NENS0002 on Gi3/0/5 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0055 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0054 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0052 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0053 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012
Gi0/2 NENS0051 on Gi0/2 (Vlan0 FD) 1G CDP Discovered Wed Feb 29 11:45:01 2012

Is enough for your debuging?

There is another way to dump needed information?

Paolo

acoto

  • Guest
Re: NeDi2GrapML
« Reply #13 on: February 29, 2012, 03:24:06 pm »
Hello Paolo,

Your database seems to be correct, you have a full CDP mesh between NENS005x devices.

At this point I think my initial algorithm to discover possible hubs is not bulletproof. I have to re-think it.

If anyone knows a good book about node-edge algorithms it will help  :)

Regards,

Adrian


acoto

  • Guest
Re: NeDi2GrapML
« Reply #14 on: March 01, 2012, 02:49:56 am »
Hello

I just uploaded NeDi2GraphML v0.9.

A little change, added a protection to -n option, to avoid adding links for orphan nodes.

(pending the correction for hubs detection... still need more time for that.)

Regards

Adrian
« Last Edit: March 01, 2012, 02:54:30 am by acoto »