TunChannel optimization: do not even format packets if there is no stderr output...
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Fri, 29 Jul 2011 15:28:13 +0000 (17:28 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Fri, 29 Jul 2011 15:28:13 +0000 (17:28 +0200)
src/nepi/testbeds/planetlab/scripts/tun_connect.py
src/nepi/util/tunchannel.py

index 8d2802b..1126649 100644 (file)
@@ -359,7 +359,7 @@ def tun_fwd(tun, remote):
         cipher_key = options.cipher_key,
         udp = options.udp,
         TERMINATE = TERMINATE,
-        stderr = open("/dev/null","w")
+        stderr = None
     )
 
 
@@ -520,6 +520,14 @@ try:
             + ["-w",options.pcap_capture,"-U"] * bool(options.pcap_capture) )
     
     print >>sys.stderr, "Connected"
+    
+    # Try to give us high priority
+    try:
+        os.nice(-20)
+    except:
+        # Ignore errors, we might not have enough privileges,
+        # or perhaps there is no os.nice support in the system
+        pass
 
     tun_fwd(tun, remote)
 
index 7967dc6..5c02a9d 100644 (file)
@@ -173,10 +173,11 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, stderr
         crypto_mode = False
         crypter = None
 
-    if crypto_mode:
-        print >>stderr, "Packets are transmitted in CIPHER"
-    else:
-        print >>stderr, "Packets are transmitted in PLAINTEXT"
+    if stderr is not None:
+        if crypto_mode:
+            print >>stderr, "Packets are transmitted in CIPHER"
+        else:
+            print >>stderr, "Packets are transmitted in PLAINTEXT"
     
     # Limited frame parsing, to preserve packet boundaries.
     # Which is needed, since /dev/net/tun is unbuffered
@@ -213,14 +214,17 @@ def tun_fwd(tun, remote, with_pi, ether_mode, cipher_key, udp, TERMINATE, stderr
                 if not udp:
                     # in UDP mode, we ignore errors - packet loss man...
                     raise
-            print >>stderr, '>', formatPacket(packet, ether_mode)
+            if stderr is not None:
+                print >>stderr, '>', formatPacket(packet, ether_mode)
         if tun in wrdy and packetReady(bkbuf, ether_mode):
             packet, bkbuf = pullPacket(bkbuf, ether_mode)
-            formatted = formatPacket(packet, ether_mode)
+            if stderr is not None:
+                formatted = formatPacket(packet, ether_mode)
             if with_pi:
                 packet = piWrap(packet, ether_mode)
             os.write(tun.fileno(), packet)
-            print >>stderr, '<', formatted
+            if stderr is not None:
+                print >>stderr, '<', formatted
         
         # check incoming data packets
         if tun in rdrdy: