forked from cmand/scamper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc_analysis_dump.py
executable file
·54 lines (50 loc) · 1.86 KB
/
sc_analysis_dump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
#
# Program: $Id: sc_analysis_dump.py 1551 2015-02-11 14:14:09Z rbeverly $
# Author: Robert Beverly <[email protected]>
# Description: Parse a binary warts capture according to warts.5
#
import sys
from sc_warts import WartsReader
scamper_stop_reasons = ['none', 'completed', 'unreach', 'icmp', 'loop', 'gaplimit', 'error', 'hoplimit', 'gss', 'halted']
def trace_to_tod(flags, hops):
assert(flags['tracetyp'] == 4)
# First, determine if destination replied.
(path_complete, dest_replied, dest_rtt, request_ttl, reply_ttl) = ('I', 'N', '0', '0', '0')
haltreason = scamper_stop_reasons[flags['stopreas']]
if haltreason == 'none' or haltreason == 'completed':
destination = hops.pop()
path_complete = 'C'
dest_replied = 'R'
dest_rtt = str(destination['rtt']/1000.0)
request_ttl = str(destination['probettl'])
reply_ttl = str(destination['replyttl'])
print "\t".join(["T", flags['srcaddr'], flags['dstaddr']]),
print "\t".join([str(flags['listid']), str(flags['cycleid'])]),
print "\t" + str(int(flags['timeval'])),
# DestReplied, DestRTT, RequestTTL, ReplyTTL
print "\t".join([dest_replied, dest_rtt, request_ttl, reply_ttl]),
# HaltReason/HaltReasonData
if haltreason == 'none' or haltreason == 'completed':
print "\tS\t0",
elif haltreason == 'unreach':
print "\tU\t" + str(flags['stopdata']),
elif haltreason == 'loop':
print "\tL\t0",
elif haltreason == 'gaplimit':
print "\tG\t0" + str(flags['stopdata']),
else:
print "\t?\t0",
# PathComplete
print "\t" + path_complete,
# PerHopData
for hop in hops:
print "\t" + ",".join([hop['addr'], str(hop['rtt']/1000.0), '1']),
print
if __name__ == "__main__":
assert len(sys.argv) == 2
w = WartsReader(sys.argv[1], verbose=False)
while True:
(flags, hops) = w.next()
if flags == False: break
trace_to_tod(flags, hops)