Statistics
| Branch: | Revision:

wcn_emulator / scripts / measure_breakage_time.py @ 2f8f6071

History | View | Annotate | Download (3.49 KB)

1
#!/usr/bin/env python
2

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

    
6
from misclibs import navigateRoutingTables, LoopError
7
from collections import defaultdict
8
import glob
9
import json
10
import copy
11

    
12
class resultParser():
13

    
14
    def readTopology(self, pathPrefix):
15
        jsonRt = defaultdict(dict)
16
        nodeSet = set()
17
        failedNodes = {}
18
        signallingSent = 0
19
        for topoFile in glob.glob(pathPrefix+"*.json"):
20
            try:
21
                f = open(topoFile, "r")
22
                j = json.load(f)
23
            except Exception as e:
24
                print "NOK", str(e)
25
                sys.exit(1)
26
            #nodeIP = ".".join(j["node"].split(":")[0].split(".")[:3])
27
            nodeIP = j["node"].split(":")[0]
28
            if j["fail"] == True:
29
                failedNodes[nodeIP] = j["failtime"]
30
            rt = j["log"]
31
            signallingSent += j["signalling"]
32
            for logId, logDump in rt.items():
33
                jsonRt[logId][nodeIP] = logDump["RT"]
34
                jsonRt[logId]["time"] = logDump["time"]
35
            nodeSet.add(str(nodeIP))
36
        return jsonRt, nodeSet, failedNodes, signallingSent
37
    
38
    
39
    def checkRoutingTables(self, jsonRt, ns, failedNodes):
40
        errors = 0
41
        loops = 0
42
        jsonRtPurged = copy.deepcopy(jsonRt)
43
    
44
        for failedNode, failureTime in failedNodes.items():
45
            if jsonRt["time"] > failureTime and failedNode in ns:
46
                ns.remove(failedNode)
47
    
48
        nl = list(ns)
49
        routesOk = 0
50
        for i in range(len(nl)):
51
            sIP = nl[i]
52
            for j in range(len(nl)):
53
                if i == j:
54
                    continue
55
                dIP = nl[j]
56
                try:
57
                    route = navigateRoutingTables(jsonRtPurged, sIP,
58
                        dIP, [], 0)
59
                except KeyError as e:
60
                    errors += 1
61
                    print "NOK!: there is no route from ", sIP, "to", dIP
62
                    continue
63
                except LoopError:
64
                    print "NOK: there is a loop from", sIP, "to", dIP
65
                    loops += 1
66
                    continue
67
                print "OK!: route", route
68
                routesOk += 1
69
        return routesOk, errors, loops
70

    
71

    
72
    def parseAllRuns(self, jsonRt, nodeSet, failedNodes):
73

    
74
        retDict = {}
75
        for logId, rt in sorted(jsonRt.items(), 
76
                key = lambda x: int(x[0]))[:-1]:
77
            # skip the last one, misalignments with random timers can 
78
            # produce partial data
79
            retDict[jsonRt[logId]["time"]] = \
80
                    self.checkRoutingTables(jsonRt[logId], nodeSet,
81
                            failedNodes)
82
        return retDict
83

    
84

    
85
if __name__ == "__main__":
86

    
87
    if len(sys.argv) < 2:
88
        print "This script parses dumps of routing tables, recomputes all the shortest paths"
89
        print "and finds the number and time of breakage of the network"
90
        print "usage: ./measure_breakage_time.py ",\
91
                "path_prefix"
92
        print "path_prefix is the prefix of the routing table files generated by dummyrouting"
93
        sys.exit(1)
94

    
95

    
96
    pathPrefix = sys.argv[1]
97

    
98
    p = resultParser()
99
    jsonRt, nodeSet, failedNodes, signallingSent = p.readTopology(pathPrefix)
100

    
101
    if not nodeSet:
102
        print "NOK: can not read routing tables"
103
        sys.exit(1)
104

    
105
    results = p.parseAllRuns(jsonRt, nodeSet, failedNodes)
106

    
107
    for time in sorted(results):
108
        print "FailedRoutes", time, results[time]
109
    print "Signalling: ", signallingSent
110

    
111