[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Update example for writing scapy tests.



commit 50df3ff29e42c733fc6dfbe64da7f4ae1cd89b9e
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sat Nov 10 00:22:55 2012 +0100

    Update example for writing scapy tests.
    * Make changes to test template of scapy tests
---
 nettests/examples/example_scapyt.py |   22 ++++++++++++++++------
 ooni/templates/scapyt.py            |   19 ++++++++++++++-----
 2 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/nettests/examples/example_scapyt.py b/nettests/examples/example_scapyt.py
index 51ffd02..a6199e2 100644
--- a/nettests/examples/example_scapyt.py
+++ b/nettests/examples/example_scapyt.py
@@ -5,13 +5,23 @@
 
 from ooni.utils import log
 from ooni.templates import scapyt
-from scapy.all import IP, TCP
+from scapy.all import IP, ICMP
 
-class ExampleBasicScapy(scapyt.BaseScapyTest):
-    name = "Example Scapy Test"
+
+class ExampleICMPPingScapy(scapyt.BaseScapyTest):
+    name = "Example ICMP Ping Test"
     author = "Arturo Filastò"
     version = 0.1
 
-    def test_send_raw_ip_frame(self):
-        log.msg("Running send receive")
-        ans, unans = self.sr(IP(dst='8.8.8.8')/TCP(), timeout=1)
+    def test_icmp_ping(self):
+        log.msg("Pinging 8.8.8.8")
+        def finished(packets):
+            print packets
+            answered, unanswered = packets
+            for snd, rcv in answered:
+                rcv.show()
+
+        packets = IP(dst='8.8.8.8')/ICMP()
+        d = self.sr(packets)
+        d.addCallback(finished)
+        return d
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index 4c18f0a..3087ac7 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -47,14 +47,23 @@ class BaseScapyTest(NetTestCase):
         Wrapper around scapy.sendrecv.sr for sending and receiving of packets
         at layer 3.
         """
-        def finished(result):
-            answered, unanswered = result
-            sent_packets, received_packets = answered
-            self.report['answered_packets'] = createPacketReport(received_packets)
-            self.report['sent_packets'] = createPacketReport(sent_packets)
+        def finished(packets):
+            log.debug("Got this bullshit")
+            answered, unanswered = packets
+            self.report['answered_packets'] = []
+            self.report['sent_packets'] = []
+            for snd, rcv in answered:
+                log.debug("Writing report %s")
+                pkt_report_r = createPacketReport(rcv)
+                pkt_report_s = createPacketReport(snd)
+                self.report['answered_packets'].append(pkt_report_r)
+                self.report['sent_packets'].append(pkt_report_s)
+                log.debug("Done")
+            return packets
 
         scapyProtocol = ScapyProtocol(*arg, **kw)
         d = scapyProtocol.startSending(packets)
+        d.addCallback(finished)
         return d
 
     def send(self, pkts, *arg, **kw):

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits