Example #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())
Example #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())
Example #3
0
	#sys.exit(ret)
	pass


def cal_hash(f, block_size):
	while True:
		data = f.read(block_size)
		if not data:
			break
		hashlib.sha256().update(data)
	return hashlib.sha256().hexdigest()

enc = Encoder.fromfile(sys.argv[1])	
myfile = open(sys.argv[1], 'rb')

dec = NIODecoder.tofile('output', os.path.getsize(sys.argv[1]), callback, cal_hash(myfile, 512*1024))

myfile.close()

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

	
Rcnt = 1
Scnt = 1

# channel loss rate
r = 0.05
	
	#for i in range(30000):
	#	send = enc.genPacket()
Example #4
0
    pass


def cal_hash(f, block_size):
    while True:
        data = f.read(block_size)
        if not data:
            break
        hashlib.sha256().update(data)
    return hashlib.sha256().hexdigest()


enc = Encoder.fromfile(sys.argv[1])
myfile = open(sys.argv[1], 'rb')

dec = NIODecoder.tofile('output', os.path.getsize(sys.argv[1]), callback,
                        cal_hash(myfile, 512 * 1024))

myfile.close()

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

Rcnt = 1
Scnt = 1

# channel loss rate
r = 0.05

#for i in range(30000):
#	send = enc.genPacket()
#print "Ended"