def run_test(port_in, port_out, size, count, rate): key = int(os.urandom(2).encode('hex'), 16) log.msg('Session: %d' % (key, )) p1 = PacketSource(('127.0.0.1', port_in), size, count, rate, key) p2 = PacketSink(key) ep1 = reactor.listenUDP(0, p1) ep2 = reactor.listenUDP(port_out, p2) yield p1.df yield p2.df yield p1.start() yield df_sleep(2) sent = count lost = count - p2.count dup = p2.count - len(p2.id_set) bitrate = rate * size * 8 / 1e6 log.msg('Sent %d, Lost %d, Dup: %d, Packet rate: %d pkt/s, Bitrate: %.2f MBit/s, Lmin %.2f ms, Lmax %.2f ms, Lavg %.2f ms' % \ (sent, lost, dup, rate, bitrate, 1000.0 * p2.lmin, 1000.0 * p2.lmax, 1000.0 * p2.lavg / p2.count if p2.count else -1)) yield ep1.stopListening() yield ep2.stopListening() defer.returnValue((lost, p2.lavg / p2.count if p2.count else -1, bitrate))
def test_rssi_injection(self): addr = ('127.0.0.1', 14551) p = SendPacket('test', addr) ep3 = reactor.listenUDP(9999, p) yield df_sleep(0.1) try: self.p1.send_rssi(1, 2, 3, 4) ts = time.time() _data, _addr = yield p.df self.assertLess(time.time() - ts, 1.0) self.assertEqual(_addr, addr) self.assertEqual( _data, '\xfd\t\x00\x00\x00\x03\xf2m\x00\x00\x02\x00\x03\x00\x01\x01d\x00\x04\xa8\xad' ) finally: ep3.stopListening()
def run_test(port_in, port_out, size, count, rate): p1 = PacketSource(('127.0.0.1', port_in), size, count, rate) p2 = PacketSink() ep1 = reactor.listenUDP(0, p1) ep2 = reactor.listenUDP(port_out, p2) yield p1.df yield p2.df yield p1.start() yield df_sleep(1) sent = count lost = count - p2.count bitrate = rate * size * 8 / 1e6 log.msg('Sent %d, Lost %d, Packet rate: %d pkt/s, Bitrate: %.2f MBit/s, Lmin %f, Lmax %f, Lavg %f' % \ (sent, lost, rate, bitrate, p2.lmin, p2.lmax, p2.lavg / p2.count if p2.count else -1)) yield ep1.stopListening() yield ep2.stopListening() defer.returnValue((lost, p2.lavg / p2.count if p2.count else -1, bitrate))
def test_tuntap(self): # Test manually via "ping -I tuntest1 192.168.77.2" and "tcpdump -i tuntest2 -nn -p icmp" return df_sleep(1)