示例#1
0
def test_bats_sr(from_file, to_file):
	def a():
		print 'a()'
	loss_rate = 0.1
	r = 0
	e = Encoder.fromfile(from_file)
	d = NIODecoder.tofile(to_file, os.path.getsize(from_file), a, hashFile(from_file))
	# d = Decoder.tofile(to_file, os.path.getsize(from_file))
	rec = Recoder(BATCH_SIZE, PACKET_SIZE)

	while not d.complete():
		s = e.genPacket()
		if s:
			if random() >= loss_rate:
				s = rec.genPacket(s,1)
				if random() >= loss_rate:
					d.receivePacket(s)
					r += 1
	print 'received:%d,decoded:%d'%(r, d.getDecoded())
示例#2
0
def test_bats_sr(from_file, to_file):
    def a():
        print 'a()'

    loss_rate = 0.1
    r = 0
    e = Encoder.fromfile(from_file)
    d = NIODecoder.tofile(to_file, os.path.getsize(from_file), a,
                          hashFile(from_file))
    # d = Decoder.tofile(to_file, os.path.getsize(from_file))
    rec = Recoder(BATCH_SIZE, PACKET_SIZE)

    while not d.complete():
        s = e.genPacket()
        if s:
            if random() >= loss_rate:
                s = rec.genPacket(s, 1)
                if random() >= loss_rate:
                    d.receivePacket(s)
                    r += 1
    print 'received:%d,decoded:%d' % (r, d.getDecoded())
示例#3
0
def main():
    global g_decoding_finised

    enc = Encoder.fromfile(sys.argv[1])    

    # Create recoder instance
    rec = Recoder(16, PACKET_SIZE)

    # channel loss rate
    r = 0.05
    buf = []

    while not g_decoding_finised:

        send = enc.genPacket() # Generate a packet

    # new batch
        if send == '':

            if len(buf) > 0:
                tmp = ''.join(buf)
                for i in xrange(0, 16):
                    if random() >= r:
                        resend = rec.genPacket(tmp, len(buf))
                        dec.receivePacket(resend)

                del buf[0:len(buf)]
        # old batch
        else:
	#simulate channel
            if random() >= r:
                buf.append(send)

    dec.waitDecodingThread()
    ret = subprocess.call(['diff',
                           sys.argv[1],
                           'output'])
    sys.exit(ret)
示例#4
0
    # channel loss rate
    r = 0.05

    import time
    t0 = time.time()
    buf = []
    while not dec.complete():
        send = enc.genPacket()  # Generate a packet
        #Test for new batch
        if send == '':
            # Recode
            if len(buf) > 0:
                tmp = ''.join(buf)
                for i in range(0, 16):
                    if random() >= r:
                        resend = rec.genPacket(tmp, len(buf))
                        dec.receivePacket(resend)
                        Rcnt += 1
                    else:
                        pass
                        #print "Packet lost in second link"
                # reset buffer
                del buf[0:len(buf)]
            else:
                pass
                #print "All packets in batch lost"
            continue
        #simulate channel
        if random() >= r:
            buf.append(send)
        else:
示例#5
0
	#for i in range(10240):
	#	enc.genPacket()
	#print "Ended...", time.time()-t0
	#sys.exit(1)
buf = []
while not dec.complete():
	send = enc.genPacket() # Generate a packet
	#Test for new batch
	if send == '':
		#print "New Batch!"
		# Recode
		if len(buf) > 0:
			tmp = ''.join(buf)
			for i in range(0, 16):
				if random() >= r:
					resend = rec.genPacket(tmp, len(buf))
					dec.receivePacket(resend)
					Rcnt += 1
				else:
					pass
						#print "Packet lost in second link"
				# reset buffer
			del buf[0:len(buf)]
		else:
			#print "All packets in batch lost"
			pass
		continue
	#simulate channel
	if random() >= r:
		buf.append(send)
	else: