Ticket #21: support for netpipe stats traces
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 26 Apr 2011 16:31:46 +0000 (18:31 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 26 Apr 2011 16:31:46 +0000 (18:31 +0200)
src/nepi/testbeds/planetlab/interfaces.py
src/nepi/testbeds/planetlab/metadata_v01.py
test/testbeds/planetlab/execute.py

index 876e6d0..c5e23ac 100644 (file)
@@ -5,6 +5,9 @@ from constants import TESTBED_ID
 import nepi.util.ipaddr2 as ipaddr2
 import nepi.util.server as server
 import plcapi
+import subprocess
+import os
+import os.path
 
 class NodeIface(object):
     def __init__(self, api=None):
@@ -191,7 +194,6 @@ class NetPipe(object):
         # set up rule
         scope, options = self._get_ruledef()
         command = "sudo -S netconfig config %s %s %s" % (self.mode, scope, options)
-        print command
         
         (out,err),proc = server.popen_ssh_command(
             command,
@@ -249,3 +251,39 @@ class NetPipe(object):
             
             self.configured = False
     
+    def sync_trace(self, local_dir, whichtrace):
+        if whichtrace != 'netpipeStats':
+            raise ValueError, "Unsupported trace %s" % (whichtrace,)
+        
+        local_path = os.path.join(local_dir, "netpipe_stats_%s" % (self.mode,))
+        
+        # create parent local folders
+        proc = subprocess.Popen(
+            ["mkdir", "-p", os.path.dirname(local_path)],
+            stdout = open("/dev/null","w"),
+            stdin = open("/dev/null","r"))
+
+        if proc.wait():
+            raise RuntimeError, "Failed to synchronize trace: %s %s" % (out,err,)
+        
+        (out,err),proc = server.popen_ssh_command(
+            "echo 'Rules:' ; sudo -S netconfig show rules ; echo 'Pipes:' ; sudo -S netconfig show pipes",
+            host = self.node.hostname,
+            port = None,
+            user = self.node.slicename,
+            agent = None,
+            ident_key = self.node.ident_path,
+            server_key = self.node.server_key
+            )
+        
+        if proc.wait():
+            raise RuntimeError, "Failed to synchronize trace: %s %s" % (out,err,)
+        
+        # dump results to file
+        f = open(local_path, "wb")
+        f.write(err or "")
+        f.write(out or "")
+        f.close()
+        
+        return local_path
+    
index faa5379..b0b0c47 100644 (file)
@@ -604,6 +604,11 @@ traces = dict({
                 "name": "buildlog",
                 "help": "Output of the build process",
               }), 
+    
+    "netpipe_stats": dict({
+                "name": "netpipeStats",
+                "help": "Information about rule match counters, packets dropped, etc.",
+              }),
     })
 
 create_order = [ INTERNET, NODE, NODEIFACE, TUNIFACE, NETPIPE, APPLICATION ]
@@ -681,7 +686,7 @@ factories_info = dict({
                                "bw_in","plr_in","delay_in",
                                "bw_out","plr_out","delay_out"],
             "connector_types": ["node"],
-            "traces": ["stdout", "stderr"]
+            "traces": ["netpipe_stats"]
         }),
 })
 
index 0156d73..4b67d3d 100755 (executable)
@@ -222,6 +222,7 @@ echo 'OKIDOKI'
         instance.defer_create_set(7, "plrIn", 0.001) # 0.1% plr inbound - regular loss
         instance.defer_create_set(7, "delayOut", int(1500 * 8 / (12.0/1024.0) / 1000)) # tx delay at 12kbps in ms
         instance.defer_create_set(7, "delayIn", int(1500 * 8 / (64.0/1024.0) / 1000)) # rx delay at 64kbps in ms
+        instance.defer_add_trace(7, "netpipeStats")
         instance.defer_connect(2, "pipes", 7, "node")
         instance.defer_create(8, "Application")
         instance.defer_create_set(8, "command", "time wget -q -O /dev/null http://www.google.com/") # Fetch ~10kb
@@ -246,6 +247,10 @@ echo 'OKIDOKI'
         minutes = int(match.group("min"))
         seconds = float(match.group("sec"))
         self.assertTrue((minutes * 60 + seconds) > 1.0, "Emulation not effective: %s" % (test_result,))
+        
+        netpipe_stats = instance.trace(7, "netpipeStats")
+        self.assertTrue(netpipe_stats, "Unavailable netpipe stats")
+        
         instance.stop()
         instance.shutdown()