Revision 2f8f6071 scripts/measure_breakage_time.py

View differences:

scripts/measure_breakage_time.py
9 9
import json
10 10
import copy
11 11

  
12
def readTopology(pathPrefix):
13
    jsonRt = defaultdict(dict)
14
    nodeSet = set()
15
    failedNodes = {}
16
    for topoFile in glob.glob(pathPrefix+"*.json"):
17
        try:
18
            f = open(topoFile, "r")
19
            j = json.load(f)
20
        except Exception as e:
21
            print "NOK", str(e)
22
            sys.exit(1)
23
        #nodeIP = ".".join(j["node"].split(":")[0].split(".")[:3])
24
        nodeIP = j["node"].split(":")[0]
25
        if j["fail"] == True:
26
            failedNodes[nodeIP] = j["failtime"]
27
        rt = j["log"]
28
        for logId, logDump in rt.items():
29
            jsonRt[logId][nodeIP] = logDump["RT"]
30
            jsonRt[logId]["time"] = logDump["time"]
31
        nodeSet.add(str(nodeIP))
32
    return jsonRt, nodeSet, failedNodes
33

  
34

  
35
def checkRoutingTables(jsonRt, ns, failedNodes):
36
    errors = 0
37
    loops = 0
38
    jsonRtPurged = copy.deepcopy(jsonRt)
39

  
40
    for failedNode, failureTime in failedNodes.items():
41
        if jsonRt["time"] > failureTime and failedNode in ns:
42
            ns.remove(failedNode)
43

  
44
    nl = list(ns)
45
    routesOk = 0
46
    for i in range(len(nl)):
47
        sIP = nl[i]
48
        for j in range(len(nl)):
49
            if i == j:
50
                continue
51
            dIP = nl[j]
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"):
52 20
            try:
53
                route = navigateRoutingTables(jsonRtPurged, sIP,
54
                    dIP, [], 0)
55
            except KeyError as e:
56
                errors += 1
57
                print str(e)
58
                print sIP, jsonRt[sIP]
59
                print dIP, jsonRt[dIP]
60
                print "NOK!: there is no route from ", sIP, "to", dIP
61
                continue
62
            except LoopError:
63
                print "NOK: there is a loop from", sIP, "to", dIP
64
                loops += 1
65
                continue
66
            print "OK!: route", route
67
            routesOk += 1
68
    return routesOk, errors, loops
69

  
70

  
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
71 83

  
72 84

  
73 85
if __name__ == "__main__":
......
83 95

  
84 96
    pathPrefix = sys.argv[1]
85 97

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

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

  
93
    for logId, rt in sorted(jsonRt.items(), key = lambda x: int(x[0]))[:-1]:
94
        # skip the last one, misalignments with random timers can 
95
        # produce partial data
96
        routesOk, routeErrors, loopErrors = \
97
                checkRoutingTables(jsonRt[logId], nodeSet,
98
                        failedNodes)
99
        print "XX", jsonRt[logId]["time"], routesOk, routeErrors, loopErrors
105
    results = p.parseAllRuns(jsonRt, nodeSet, failedNodes)
106

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

  
101 111

  

Also available in: Unified diff