0

I have a simple dot file with the list of nodes and edges. Each node is the network device. Devices connected to each other through interfaces, so i used head and tail labels as interface name:

"172.16.3.205" -- "172.16.3.178" [taillabel="27", headlabel="1:16"];

I'm trying to find all simple paths between 2 given nodes and get list of nodes and correct interfaces:

import networkx as nx
G=nx.read_dot('out.gv')
for path in nx.all_simple_paths(G,source='172.16.3.178',target='172.16.3.207'):
    path = G.subgraph(path)
    path.edges(data=True)

and I'm getting something like this:

[('172.16.3.178', '172.16.3.205', {'taillabel': '"27"', 'headlabel': '"1:16"'}), ('172.16.3.203', '172.16.3.205', {'taillabel': '"27"', 'headlabel': '"26"'}), ('172.16.3.203', '172.16.3.207', {'taillabel': '"26"', 'headlabel': '"28"'})]

'172.16.3.178' switched with '172.16.3.205'. Is there a way to save order?

P.S. Actually, I don't really need to draw a graph. I just need a list (or something more useful) of nodes with interfaces that involved in path like this: [('172.16.3.178', {'1:16'}), ('172.16.3.203', {'27', '26'}), ('172.16.3.205', {'26', '27'}), ('172.16.3.207', {'28'})]

Mr.Pisos
  • 26
  • 2
  • So are the edges directed for your real-world application? It appears that you are expecting some sort of implicit direction. A graph is not going to be directed, but it is possible to define a directed graph in networkx – Joel Oct 28 '15 at 04:27
  • No. I don't expect direction. I'm thinking about using labels as nodes or mark labels somehow so i can always know which node it belongs to. Maybe I don't even need to use graphs, but i don't know the simplest way to find all paths between 2 points. – Mr.Pisos Oct 28 '15 at 10:10
  • The fact that you are referring to a 'head' and a 'tail' really makes me think that there is some direction to this. Are you sure there isn't direction? Can these edges really be crossed in both directions? Or is there a different edge with the head and tail swapped in these cases? So in particular, are you okay with the path being A-B-C-D where C is the 'tail' of both the B-C and C-D edges? – Joel Oct 28 '15 at 18:39
  • I'm referring to a head and a tail, because I don't know where I can place interface numbers . Yes, edges can be crossed in both directions. I'm ok with the path, where C is the tail only if this edges stored in file like this (in your case it must look like A -- B, C -- B, C -- D) – Mr.Pisos Oct 28 '15 at 22:46

0 Answers0