Loading prrt/prrt.py→prrt/prrt.pyx +22 −22 Original line number Diff line number Diff line Loading @@ -155,20 +155,20 @@ class PrrtChannelParameters: self.data_rate_btl_fwd, self.data_rate_btl_bwd) class ApplicationParameters: # maxLatency float in seconds # maxResidualLossRate in percent class PrrtApplicationParameters: # max_latency float in seconds # max_residual_loss_rate in percent def __init__(self, maxLatency, maxResidualLossRate): self.maxLatency = maxLatency self.maxResidualLossRate = maxResidualLossRate def __init__(self, max_latency, max_residual_loss_rate): self.max_latency = max_latency self.max_residual_loss_rate = max_residual_loss_rate def __repr__(self): return "ApplicationParameters(maxLatency={},maxResidualLossRate={})".format(self.maxLatency, self.maxResidualLossRate) return "PrrtApplicationParameters(max_latency={}, max_residual_loss_rate={})".format(self.max_latency, self.max_residual_loss_rate) def __str__(self): return "({},{})".format(self.maxLatency, self.maxResidualLossRate) return "({},{})".format(self.max_latency, self.max_residual_loss_rate) class PrrtSystemParameters: def __init__(self, Loading Loading @@ -197,7 +197,6 @@ class PrrtSystemParameters: self.packet_loss_detection_delay) class PrrtCodingConfiguration: p_e = 0.0 def __init__(self, n, k, n_p=None): if n < k: raise ValueError("n must be greater or equal k.") Loading @@ -223,19 +222,20 @@ class PrrtCodingConfiguration: # def __eq__() # Calculate the redundancy information this coding configuration causes, given a certain channel. def sum_error_prob_over_sent_packets(self, sent_packets_item): def sum_error_prob_over_sent_packets(self, sent_packets_item, p_e): error_prob = 0 for i in range(sent_packets_item + 1, sent_packets_item + self.k + 1): error_prob += self.get_error_prob(i, sent_packets_item + self.k) error_prob += self.get_error_prob(i, sent_packets_item + self.k, p_e) return error_prob def get_error_prob(self, i, sent_packets_item): return comb(sent_packets_item, i) * (self.p_e ** i) * ((1 - self.p_e) ** (sent_packets_item - i)) # TODO: Maybe running in parallel to optimize runtime def get_error_prob(self, i, sent_packets_item, p_e): return comb(sent_packets_item, i) * (p_e ** i) * ((1 - p_e) ** (sent_packets_item - i)) def get_redundant_information(self, prrtChannelParameters): self.p_e = prrtChannelParameters.loss_rate_fwd p_e = prrtChannelParameters.loss_rate_fwd sent_redundant_packets = np.cumsum(self.n_p) # Cumulative sum of all redundant packets up to each cycle error_prob_up_to_every_cycle = list(map(lambda x : self.sum_error_prob_over_sent_packets(x), sent_redundant_packets[1:])) error_prob_up_to_every_cycle = list(map(lambda x : self.sum_error_prob_over_sent_packets(x, p_e), sent_redundant_packets[1:])) ri = 1 / self.k * self.n_p[0] + 1 / self.k * np.dot(error_prob_up_to_every_cycle, self.n_p[1:]) return ri Loading @@ -256,17 +256,17 @@ class PrrtCodingConfiguration: prrtSystemParameters.packet_loss_detection_delay req_delay_list = list(map(lambda c : prrtChannelParameters.rtt_prop_fwd + np.dot(self.n_p[c], prrtSystemParameters.redundancy_packet_transmission_delay) + prrtSystemParameters.processing_delay)) if (fec_delay + np.dot(self.len(self.n_p), req_delay_list) <= prrtApplicationParameters.maxLatency): if (fec_delay + np.dot(self.len(self.n_p), req_delay_list) <= prrtApplicationParameters.max_latency): return True def is_maximum_loss_fulfilled(self, prrtApplicationParameters): def is_maximum_loss_fulfilled(self, prrtApplicationParameters, prrtChannelParameters): total_packet_erasure = 0 for i in range(1, self.k): for j in range(max(self.n - self.k + 1, i), self.n - self.k + i): packet_erasure_at_i = i * self.hypergeometric_distribution(self.n, self.k, i, j) * self.get_error_prob(j, self.n) packet_erasure_at_i = i * self.hypergeometric_distribution(self.n, self.k, i, j) * self.get_error_prob(j, self.n, prrtChannelParameters.loss_rate_fwd) total_packet_erasure += packet_erasure_at_i residual_packet_erasure_rate = (1 / self.k) * total_packet_erasure # Pr(k, n) if (residual_packet_erasure_rate <= prrtApplicationParameters.maxResidualLossRate): if (residual_packet_erasure_rate <= prrtApplicationParameters.max_residual_loss_rate): return True Loading @@ -283,7 +283,7 @@ cdef class PrrtSocket: cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port) # Channel Properties property prrtChannelParameters: property prrt_channel_parameters: def __get__(self): return PrrtChannelParameters(cprrt.PrrtSocket_get_plr_fwd(self._c_socket), 0, # TODO: Implement PrrtSocket_get_plr_bwd Loading @@ -293,7 +293,7 @@ cdef class PrrtSocket: cprrt.PrrtSocket_get_btlbw_back(self._c_socket)) property prrtSystemParameters: property prrt_system_parameters: def __get__(self): TODO = "" # Measured by X-Lap return PrrtSystemParameters(cprrt.PrrtSocket_get_block_coding_delay, Loading tests/prrt/prrt_coding_configuration_test.py→tests/prrt/test_prrt_coding_configuration.py +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import prrt # print(sys.path) # print(dir(prrt.__path__)) # print(prrt.__file__) class TestStringMethods(unittest.TestCase): class TestPrrtCodingConfiguration(unittest.TestCase): def test_ri_01(self): prrt_cp_obj = prrt.PrrtChannelParameters(0.1, 0, 0, 0, 0, 0) Loading Loading
prrt/prrt.py→prrt/prrt.pyx +22 −22 Original line number Diff line number Diff line Loading @@ -155,20 +155,20 @@ class PrrtChannelParameters: self.data_rate_btl_fwd, self.data_rate_btl_bwd) class ApplicationParameters: # maxLatency float in seconds # maxResidualLossRate in percent class PrrtApplicationParameters: # max_latency float in seconds # max_residual_loss_rate in percent def __init__(self, maxLatency, maxResidualLossRate): self.maxLatency = maxLatency self.maxResidualLossRate = maxResidualLossRate def __init__(self, max_latency, max_residual_loss_rate): self.max_latency = max_latency self.max_residual_loss_rate = max_residual_loss_rate def __repr__(self): return "ApplicationParameters(maxLatency={},maxResidualLossRate={})".format(self.maxLatency, self.maxResidualLossRate) return "PrrtApplicationParameters(max_latency={}, max_residual_loss_rate={})".format(self.max_latency, self.max_residual_loss_rate) def __str__(self): return "({},{})".format(self.maxLatency, self.maxResidualLossRate) return "({},{})".format(self.max_latency, self.max_residual_loss_rate) class PrrtSystemParameters: def __init__(self, Loading Loading @@ -197,7 +197,6 @@ class PrrtSystemParameters: self.packet_loss_detection_delay) class PrrtCodingConfiguration: p_e = 0.0 def __init__(self, n, k, n_p=None): if n < k: raise ValueError("n must be greater or equal k.") Loading @@ -223,19 +222,20 @@ class PrrtCodingConfiguration: # def __eq__() # Calculate the redundancy information this coding configuration causes, given a certain channel. def sum_error_prob_over_sent_packets(self, sent_packets_item): def sum_error_prob_over_sent_packets(self, sent_packets_item, p_e): error_prob = 0 for i in range(sent_packets_item + 1, sent_packets_item + self.k + 1): error_prob += self.get_error_prob(i, sent_packets_item + self.k) error_prob += self.get_error_prob(i, sent_packets_item + self.k, p_e) return error_prob def get_error_prob(self, i, sent_packets_item): return comb(sent_packets_item, i) * (self.p_e ** i) * ((1 - self.p_e) ** (sent_packets_item - i)) # TODO: Maybe running in parallel to optimize runtime def get_error_prob(self, i, sent_packets_item, p_e): return comb(sent_packets_item, i) * (p_e ** i) * ((1 - p_e) ** (sent_packets_item - i)) def get_redundant_information(self, prrtChannelParameters): self.p_e = prrtChannelParameters.loss_rate_fwd p_e = prrtChannelParameters.loss_rate_fwd sent_redundant_packets = np.cumsum(self.n_p) # Cumulative sum of all redundant packets up to each cycle error_prob_up_to_every_cycle = list(map(lambda x : self.sum_error_prob_over_sent_packets(x), sent_redundant_packets[1:])) error_prob_up_to_every_cycle = list(map(lambda x : self.sum_error_prob_over_sent_packets(x, p_e), sent_redundant_packets[1:])) ri = 1 / self.k * self.n_p[0] + 1 / self.k * np.dot(error_prob_up_to_every_cycle, self.n_p[1:]) return ri Loading @@ -256,17 +256,17 @@ class PrrtCodingConfiguration: prrtSystemParameters.packet_loss_detection_delay req_delay_list = list(map(lambda c : prrtChannelParameters.rtt_prop_fwd + np.dot(self.n_p[c], prrtSystemParameters.redundancy_packet_transmission_delay) + prrtSystemParameters.processing_delay)) if (fec_delay + np.dot(self.len(self.n_p), req_delay_list) <= prrtApplicationParameters.maxLatency): if (fec_delay + np.dot(self.len(self.n_p), req_delay_list) <= prrtApplicationParameters.max_latency): return True def is_maximum_loss_fulfilled(self, prrtApplicationParameters): def is_maximum_loss_fulfilled(self, prrtApplicationParameters, prrtChannelParameters): total_packet_erasure = 0 for i in range(1, self.k): for j in range(max(self.n - self.k + 1, i), self.n - self.k + i): packet_erasure_at_i = i * self.hypergeometric_distribution(self.n, self.k, i, j) * self.get_error_prob(j, self.n) packet_erasure_at_i = i * self.hypergeometric_distribution(self.n, self.k, i, j) * self.get_error_prob(j, self.n, prrtChannelParameters.loss_rate_fwd) total_packet_erasure += packet_erasure_at_i residual_packet_erasure_rate = (1 / self.k) * total_packet_erasure # Pr(k, n) if (residual_packet_erasure_rate <= prrtApplicationParameters.maxResidualLossRate): if (residual_packet_erasure_rate <= prrtApplicationParameters.max_residual_loss_rate): return True Loading @@ -283,7 +283,7 @@ cdef class PrrtSocket: cprrt.PrrtSocket_bind(self._c_socket, host.encode("utf8"), port) # Channel Properties property prrtChannelParameters: property prrt_channel_parameters: def __get__(self): return PrrtChannelParameters(cprrt.PrrtSocket_get_plr_fwd(self._c_socket), 0, # TODO: Implement PrrtSocket_get_plr_bwd Loading @@ -293,7 +293,7 @@ cdef class PrrtSocket: cprrt.PrrtSocket_get_btlbw_back(self._c_socket)) property prrtSystemParameters: property prrt_system_parameters: def __get__(self): TODO = "" # Measured by X-Lap return PrrtSystemParameters(cprrt.PrrtSocket_get_block_coding_delay, Loading
tests/prrt/prrt_coding_configuration_test.py→tests/prrt/test_prrt_coding_configuration.py +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ import prrt # print(sys.path) # print(dir(prrt.__path__)) # print(prrt.__file__) class TestStringMethods(unittest.TestCase): class TestPrrtCodingConfiguration(unittest.TestCase): def test_ri_01(self): prrt_cp_obj = prrt.PrrtChannelParameters(0.1, 0, 0, 0, 0, 0) Loading