8 from nepi.util import tunchannel
10 remote = open("/dev/zero","r+b")
11 tun = open("/dev/zero","r+b")
13 def rwrite(remote, packet, remote_fd = remote.fileno(), os_write=os.write, len=len):
16 return os_write(remote_fd, packet)
18 def rread(remote, maxlen, remote_fd = remote.fileno(), os_read=os.read):
20 rv = os_read(remote_fd, maxlen)
24 def test(cipher, passphrase, plr=None, queuemodule=None):
27 def accept(packet, direction, rng=random.random):
33 sys.path.append(os.path.join(
34 os.path.dirname(__file__),
35 'src','nepi','testbeds','planetlab','scripts'))
36 queuemodule = __import__(queuemodule)
37 queueclass = queuemodule.queueclass
43 TERMINATE.append(None)
44 t = threading.Thread(target=stopme)
46 tunchannel.tun_fwd(tun, remote, True, True, passphrase, True, TERMINATE, None, tunkqueue=500,
47 rwrite = rwrite, rread = rread, cipher=cipher, queueclass=queueclass,
48 accept_local = accept, accept_remote = accept)
50 # Swallow exceptions on decryption
51 def decrypt(packet, crypter, super=tunchannel.decrypt):
53 return super(packet, crypter)
56 tunchannel.decrypt = decrypt
58 for cipher in (None, 'AES', 'Blowfish', 'DES', 'DES3'):
62 passphrase = 'Abracadabra'
64 cProfile.runctx('test(%r,%r)' % (cipher, passphrase),globals(),locals(),'tunchannel.%s.profile' % (cipher,))
66 print "Profile (%s):" % ( cipher, )
67 pstats.Stats('tunchannel.%s.profile' % cipher).strip_dirs().sort_stats('time').print_stats()
69 print "Bandwidth (%s): %.4fMb/s" % ( cipher, bytes / 200.0 * 8 / 2**20, )
72 cProfile.runctx('test(None,None,0.5)',globals(),locals(),'tunchannel.plr.profile')
74 print "Profile (50% PLR):"
75 pstats.Stats('tunchannel.plr.profile').strip_dirs().sort_stats('time').print_stats()
77 print "Bandwidth (50%% PLR): %.4fMb/s" % ( bytes / 200.0 * 8 / 2**20, )
80 cProfile.runctx('test(None,None,None,"tosqueue")',globals(),locals(),'tunchannel.tos.profile')
82 print "Profile (TOS):"
83 pstats.Stats('tunchannel.tos.profile').strip_dirs().sort_stats('time').print_stats()
85 print "Bandwidth (TOS): %.4fMb/s" % ( bytes / 200.0 * 8 / 2**20, )