[tor-commits] [ooni-probe/master] Work on scapy related functionality
art at torproject.org
art at torproject.org
Sun Oct 7 21:59:27 UTC 2012
commit 0f78e3f66aeeb3f830f2ff2b0cd5a465a764ec9e
Author: Arturo Filastò <arturo at filasto.net>
Date: Sun Oct 7 21:57:54 2012 +0000
Work on scapy related functionality
* Discover the existence of bugs in scapy when using Arch Linux.
(probably has to do with the non existence of ifconfig, somebody should make
a ifconfig to ip wrapper that suggests the user with the equivalent ip
command. This would assist sysadmins in migrating away from a deprecated
tool and persist backward comaptibility)
* Fix bugs in runner and nettest
---
nettests/examples/example_scapyt.py | 16 ++++++++++++++++
ooni/nettest.py | 2 +-
ooni/oonicli.py | 9 +++++++++
ooni/runner.py | 4 +++-
ooni/templates/scapyt.py | 22 +++++++---------------
5 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/nettests/examples/example_scapyt.py b/nettests/examples/example_scapyt.py
index 1cc8054..403ddc5 100644
--- a/nettests/examples/example_scapyt.py
+++ b/nettests/examples/example_scapyt.py
@@ -13,3 +13,19 @@ class ExampleScapy(scapyt.ScapyTest):
inputs = [IP(dst="8.8.8.8")/TCP(dport=31337),
IP(dst="ooni.nu")/TCP(dport=31337)]
+
+ def test_sendReceive(self):
+ log.msg("Running send receive")
+ if self.receive:
+ log.msg("Sending and receiving packets.")
+ d = self.sendReceivePackets(self.buildPackets())
+ else:
+ log.msg("Sending packets.")
+ d = self.sendPackets(self.buildPackets())
+
+ def finished(data):
+ log.msg("Finished sending")
+ return data
+
+ d.addCallback(finished)
+ return
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 7f9562a..e7ae7d5 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -103,7 +103,7 @@ class TestCase(unittest.TestCase):
self.inputs = self.inputProcessor(fp)
elif not self.inputs[0]:
pass
- else:
+ elif self.inputFile:
raise usage.UsageError("No input file specified!")
# XXX perhaps we may want to name and version to be inside of a
# different object that is not called options.
diff --git a/ooni/oonicli.py b/ooni/oonicli.py
index af93af9..40c01fd 100644
--- a/ooni/oonicli.py
+++ b/ooni/oonicli.py
@@ -43,6 +43,8 @@ class Options(usage.Options, app.ReactorSelectionMixin):
"files listed on the command line")
optFlags = [["help", "h"],
+ ['debug-stacktraces', 'B',
+ 'Report deferred creation and callback stack traces'],
]
optParameters = [
@@ -96,6 +98,13 @@ def run():
except usage.error, ue:
raise SystemExit, "%s: %s" % (sys.argv[0], ue)
+ if config['debug-stacktraces']:
+ defer.setDebugging(True)
+
+ #logFile = open(config['logfile'], 'w')
+ #logFileObserver = log.FileLogObserver(logFile)
+ #log.startLoggingWithObserver(logFileObserver.emit, 0)
+
classes = runner.findTestClassesFromConfig(config)
casesList, options = runner.loadTestsAndOptions(classes)
diff --git a/ooni/runner.py b/ooni/runner.py
index 0b9503a..1a03814 100644
--- a/ooni/runner.py
+++ b/ooni/runner.py
@@ -7,6 +7,8 @@ import inspect
from twisted.internet import defer, reactor
from twisted.python import reflect, failure, usage
+from twisted.python import log as tlog
+
from twisted.trial import unittest
from twisted.trial.runner import TrialRunner, TestLoader
from twisted.trial.runner import isPackage, isTestCase, ErrorHolder
@@ -183,7 +185,7 @@ class ORunner(object):
them in input units. I also create all the report instances required to run
the tests.
"""
- def __init__(self, cases, options=None, config=None):
+ def __init__(self, cases, options=None, config=None, *arg, **kw):
self.baseSuite = InputTestSuite
self.cases = cases
self.options = options
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index ac32ad8..b2ac148 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -31,7 +31,7 @@ class ScapyTest(TestCase):
receive = True
timeout = 1
- pcapfile = '/home/x/code/networking/ooni-probe/scapytest.pcap'
+ pcapfile = None
input = IP()/TCP()
reactor = None
def setUp(self):
@@ -44,23 +44,15 @@ class ScapyTest(TestCase):
def tearDown(self):
self.reactor.stop()
- def test_sendReceive(self):
- log.msg("Running send receive")
- if self.receive:
- log.msg("Sending and receiving packets.")
- d = txsr(self.buildPackets(), pcapfile=self.pcapfile,
- timeout=self.timeout, reactor=self.reactor)
- else:
- log.msg("Sending packets.")
- d = txsend(self.buildPackets(), reactor=self.reactor)
+ def sendReceivePackets(self, packets):
+ d = txsr(packets, pcapfile=self.pcapfile,
+ timeout=10, reactor=self.reactor)
- def finished(data):
- log.msg("Finished sending")
- return data
-
- d.addCallback(finished)
return d
+ def sendPackets(self, packets):
+ return txsend(self.buildPackets(), reactor=self.reactor)
+
def buildPackets(self):
"""
Override this method to build scapy packets.
More information about the tor-commits
mailing list