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

[tor-commits] [ooni-probe/master] Implement ICMP traceroute test



commit 8ede385b70a9d717572b95b2d5ab87085bb82cd7
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Sun Nov 11 12:55:17 2012 +0100

    Implement ICMP traceroute test
    * parametrize max_ttl and timeout
    * make max_ttl and timeout be included in the report
---
 nettests/core/traceroute.py |   70 ++++++++++++++++++++++++++++++++++++------
 ooni/templates/scapyt.py    |    3 +-
 2 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/nettests/core/traceroute.py b/nettests/core/traceroute.py
index 23f124a..4317a0e 100644
--- a/nettests/core/traceroute.py
+++ b/nettests/core/traceroute.py
@@ -14,50 +14,100 @@ from scapy.all import *
 class UsageOptions(usage.Options):
     optParameters = [
                     ['backend', 'b', '8.8.8.8', 'Test backend to use'],
-                    ['timeout', 't', 5, 'The timeout for the traceroute test']
+                    ['timeout', 't', 5, 'The timeout for the traceroute test'],
+                    ['maxttl', 'm', 30, 'The maximum value of ttl to set on packets']
                     ]
 
 class TracerouteTest(scapyt.BaseScapyTest):
     name = "Multi Protocol Traceroute Test"
     author = "Arturo Filastò"
-    version = 0.1
+    version = "0.1.1"
 
     usageOptions = UsageOptions
 
     dst_ports = [22, 23, 80, 123, 443]
+    def max_ttl_and_timeout(self):
+        max_ttl = int(self.localOptions['maxttl'])
+        timeout = int(self.localOptions['timeout'])
+        self.report['max_ttl'] = max_ttl
+        self.report['timeout'] = timeout
+        return max_ttl, timeout
 
     def test_tcp_traceroute(self):
+        """
+        Does a traceroute to the destination by sending TCP SYN packets
+        with TTLs from 1 until max_ttl.
+        """
         def finished(packets, port):
-            log.debug("Finished running TCP traceroute test" % port)
+            log.debug("Finished running TCP traceroute test on port %s" % port)
             answered, unanswered = packets
             self.report['hops_'+str(port)] = [] 
             for snd, rcv in answered:
-                report = {'ttl': snd.ttl, 'address': rcv.src}
+                report = {'ttl': snd.ttl,
+                        'address': rcv.src,
+                        'rtt': rcv.time - snd.time 
+                }
+                log.debug("%s: %s" % (port, report))
                 self.report['hops_'+str(port)].append(report)
 
         dl = []
+        max_ttl, timeout = self.max_ttl_and_timeout()
         for port in self.dst_ports:
             packets = IP(dst=self.localOptions['backend'], 
-                    ttl=(1,25),id=RandShort())/TCP(flags=0x2, dport=port)
-            d = self.sr(packets, timeout=5)
+                    ttl=(1,max_ttl),id=RandShort())/TCP(flags=0x2, dport=port)
+            d = self.sr(packets, timeout=timeout)
             d.addCallback(finished, port)
             dl.append(d)
         return defer.DeferredList(dl)
 
     def test_udp_traceroute(self):
+        """
+        Does a traceroute to the destination by sending UDP packets with empty
+        payloads with TTLs from 1 until max_ttl.
+        """
         def finished(packets, port):
-            log.debug("Finished running udp traceroute test")
+            log.debug("Finished running UDP traceroute test on port %s" % port)
             answered, unanswered = packets
             self.report['hops_'+str(port)] = []
             for snd, rcv in answered:
-                report = {'ttl': snd.ttl, 'address': rcv.src}
+                report = {'ttl': snd.ttl,
+                        'address': rcv.src,
+                        'rtt': rcv.time - snd.time 
+                }
+                log.debug("%s: %s" % (port, report))
                 self.report['hops_'+str(port)].append(report)
         dl = []
+        max_ttl, timeout = self.max_ttl_and_timeout()
         for port in self.dst_ports:
             packets = IP(dst=self.localOptions['backend'],
-                    ttl=(1,25),id=RandShort())/UDP(dport=port)
-            d = self.sr(packets, timeout=5)
+                    ttl=(1,max_ttl),id=RandShort())/UDP(dport=port)
+            d = self.sr(packets, timeout=timeout)
             d.addCallback(finished, port)
             dl.append(d)
         return defer.DeferredList(dl)
 
+    def test_icmp_traceroute(self):
+        """
+        Does a traceroute to the destination by sending ICMP echo request
+        packets with TTLs from 1 until max_ttl.
+        """
+        def finished(packets):
+            log.debug("Finished running ICMP traceroute test")
+            answered, unanswered = packets
+            self.report['hops'] = []
+            for snd, rcv in answered:
+                report = {'ttl': snd.ttl,
+                        'address': rcv.src,
+                        'rtt': rcv.time - snd.time 
+                }
+                log.debug("%s" % (report))
+                self.report['hops'].append(report)
+        dl = []
+        max_ttl, timeout = self.max_ttl_and_timeout()
+        packets = IP(dst=self.localOptions['backend'],
+                    ttl=(1,max_ttl),id=RandShort())/ICMP()
+        d = self.sr(packets, timeout=timeout)
+        d.addCallback(finished)
+        return d
+
+
diff --git a/ooni/templates/scapyt.py b/ooni/templates/scapyt.py
index c443610..feaf720 100644
--- a/ooni/templates/scapyt.py
+++ b/ooni/templates/scapyt.py
@@ -48,12 +48,11 @@ class BaseScapyTest(NetTestCase):
         at layer 3.
         """
         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" % snd)
+                log.debug("Writing report for scapy test")
                 pkt_report_r = createPacketReport(rcv)
                 pkt_report_s = createPacketReport(snd)
                 self.report['answered_packets'].append(pkt_report_r)

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