Skip to content

Commit

Permalink
Add sample code for WartsWriter class
Browse files Browse the repository at this point in the history
  • Loading branch information
rbeverly committed Aug 30, 2018
1 parent 4e88dad commit 0b946e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Scamper Tools
# Scamper Python Tools

Scamper is a scalable, efficient, and feature-rich Internet packet
prober from CAIDA (http://www.caida.org/tools/measurement/scamper/).

Scamper is written in C and stores data in a binary "warts" format.
Scamper stores data in a binary "warts" format.

These tools replicate the functionality of scamper's utilities by
providing native python implementations. The following files
Expand All @@ -17,4 +17,5 @@ are included:
* sc_analysis_dump.py: covert scamper traces to easily parsed text
* sc_wartsgrep.py: create warts file containing only records of specified target
* sc_sample.py: sample python using warts class (for developers)
* sc_sample_writer.py: sample python using warts_writer class (for developers)
* sc_attach.py: interact with scamper over control socket
39 changes: 39 additions & 0 deletions sc_sample_writer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python
# Program: $Id: $
# Author: Robert Beverly <rbeverly@nps.edu>
# Description: Example use of sc_warts_writer library.
#
import sys
import time
from sc_warts_writer import WartsWriter, WartsTrace

if __name__ == "__main__":
assert len(sys.argv) == 2

now = time.time()
w = WartsWriter(sys.argv[1])
w.write_list(1, 1, 'sc_sample_writer demo')
w.write_cycle(1, 1, 1, now)
tr = WartsTrace()
tr.add({'listid' : 1, 'srcport' : 1234, 'dstport' : 80,
'srcaddr' : '1.2.3.4', 'dstaddr' : '5.6.7.8',
'attempts' : 2, 'tracetyp' : 2, 'probehop' : 7,
'probesent' : 5, 'firsttl' : 4, 'timeval' : now + 1})

# hopflags (SCAMPER_TRACE_HOP_FLAG_REPLY_TTL)
reply = {'addr' : '4.4.4.4', 'rtt' : 23456,
'ipid' : 1234, 'probesize' : 60,
'replysize' : 54, 'probettl' : 4,
'replyttl' : 60, 'tos' : 0,
'icmp' : 4, 'hopflags' : 0x10}
tr.add_reply(reply)
reply = {'addr' : '6.6.6.6', 'rtt' : 834567,
'ipid' : 1234, 'probesize' : 60,
'replysize' : 54, 'probettl' : 6,
'replyttl' : 58, 'tos' : 0,
'icmp' : 4, 'hopflags' : 0x10}
tr.add_reply(reply)
w.write_object(tr)

# finish
w.write_cycle_stop(1, now+10)

0 comments on commit 0b946e4

Please sign in to comment.