Statistics
| Branch: | Revision:

wcn_emulator / scripts / compare_topologies_recursively.py @ d08d134a

History | View | Annotate | Download (1.81 KB)

1
#!/usr/bin/env python
2

    
3
import sys
4
sys.path.append('../community_networks_analysis')
5

    
6
from misclibs import navigateRoutingTables
7
from gengraphs import loadGraph
8
import glob
9
import json
10
import networkx as nx
11

    
12
if len(sys.argv) != 3:
13
    print "usage: ./compare_topologies_recursively.py ",\
14
            "path_prefix full_topology"
15
    sys.exit(1)
16

    
17
pathPrefix = sys.argv[1]
18
topoFile = sys.argv[2]
19
g = loadGraph(topoFile, remap=True)
20
print g.nodes()
21

    
22
jsonRt = {}
23
nodeList = set()
24

    
25
for topoFile in glob.glob(pathPrefix+"*.rt"):
26
    try:
27
        f = open(topoFile, "r")
28
        j = json.load(f)
29
    except Exception as e:
30
        print "NOK", str(e)
31
        sys.exit(1)
32
    nodeIP = ".".join(j["node"].split(":")[0].split(".")[:3])
33
    rt = j["rt"]
34
    jsonRt[nodeIP] = {}
35
    for dest, nh in rt.items():
36
        shortDest = ".".join(dest.split(".")[:3])
37
        shortNh = ".".join(nh[0].split(".")[:3])
38
        jsonRt[nodeIP][shortDest] = [shortNh] + nh[1:]
39

    
40
    nodeList.add(str(nodeIP))
41

    
42

    
43
nl = list(nodeList)
44

    
45

    
46
#for node, rt  in jsonRt.items():
47
#    if len(rt) != len(nl) - 1:
48
#        print "node ", node, "misses some routes"
49
#        print json.dumps(jsonRt, indent=1)
50
#        sys.exit(1)
51

    
52
#print json.dumps(jsonRt, indent=1)
53
errors = 0
54
for i in range(len(nl)):
55
    for j in range(i+1, len(nl)):
56
        s = int(nl[i].split(".")[2])
57
        d = int(nl[j].split(".")[2])
58
        print "== rt ", s, d
59
        route = navigateRoutingTables(jsonRt, nl[i],
60
                nl[j], [], 0)
61
        allroutes = [p for p in nx.all_shortest_paths(g, s, d)]
62

    
63
        shortedRoute =  [int(r.split(".")[2]) for r in route[0]]
64
        print "XX", shortedRoute
65
        print "YY", allroutes
66

    
67
        if shortedRoute not in allroutes:
68
            print "NOK!: route", shortedRoute, "not in ", allroutes
69
            errors += 1
70

    
71
print "Found ", errors, "errors"
72

    
73

    
74

    
75

    
76

    
77

    
78