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
45 TERMINATE.append(None)
47 t = threading.Thread(target=stopme)
49 tunchannel.tun_fwd(tun, remote, True, True, passphrase, True, TERMINATE,
50 SUSPEND, None, tunkqueue=500, rwrite = rwrite, rread = rread,
51 cipher=cipher, queueclass=queueclass, accept_local = accept,
52 accept_remote = accept)
54 # Swallow exceptions on decryption
55 def decrypt(packet, crypter, super=tunchannel.decrypt):
57 return super(packet, crypter)
60 tunchannel.decrypt = decrypt
62 for cipher in (None, 'AES', 'Blowfish', 'DES', 'DES3'):
66 passphrase = 'Abracadabra'
68 cProfile.runctx('test(%r,%r)' % (cipher, passphrase),globals(),locals(),'tunchannel.%s.profile' % (cipher,))
70 print "Profile (%s):" % ( cipher, )
71 pstats.Stats('tunchannel.%s.profile' % cipher).strip_dirs().sort_stats('time').print_stats()
73 print "Bandwidth (%s): %.4fMb/s" % ( cipher, bytes / 200.0 * 8 / 2**20, )
76 cProfile.runctx('test(None,None,0.5)',globals(),locals(),'tunchannel.plr.profile')
78 print "Profile (50% PLR):"
79 pstats.Stats('tunchannel.plr.profile').strip_dirs().sort_stats('time').print_stats()
81 print "Bandwidth (50%% PLR): %.4fMb/s" % ( bytes / 200.0 * 8 / 2**20, )
84 cProfile.runctx('test(None,None,None,"tosqueue")',globals(),locals(),'tunchannel.tos.profile')
86 print "Profile (TOS):"
87 pstats.Stats('tunchannel.tos.profile').strip_dirs().sort_stats('time').print_stats()
89 print "Bandwidth (TOS): %.4fMb/s" % ( bytes / 200.0 * 8 / 2**20, )