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):
# 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,
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
+
"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 ]
"bw_in","plr_in","delay_in",
"bw_out","plr_out","delay_out"],
"connector_types": ["node"],
- "traces": ["stdout", "stderr"]
+ "traces": ["netpipe_stats"]
}),
})
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
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()