def stopConditionPayloadPadding(self): to_pad = self.session.numMessages['snd'] if msg_level else self.session.totalBytes['snd'] divisor = self.session.dataMessages['snd'] if msg_level else self.session.dataBytes['snd'] k = closest_power_of_two(divisor) total_padding = closest_multiple(to_pad, k) log.debug("[wfpad %s] - Computed payload padding: %s (to_pad is %s and divisor is %s)" % (self.end, total_padding, to_pad, divisor)) return total_padding
def test_closest_power_of_two_of_one(self): n = 1 exp_result = 2 self.should_not_raise("Closest power of two should not raise.", mu.closest_power_of_two, n) obs_result = mu.closest_power_of_two(n) self.assertEqual(exp_result, obs_result, "The closest power of two" "to %s should be %s, not %s." % (n, exp_result, obs_result))
def stopConditionTotalPadding(self): to_pad = self.session.numMessages['snd'] if msg_level else self.session.totalBytes['snd'] total_padding = closest_power_of_two(to_pad) log.debug("[wfpad %s] - Computed total padding: %s (to_pad is %s)", self.end, total_padding, to_pad) return total_padding
def bytes_after_payload_padding(data_bytes, total_bytes, psize=1): """Return the total bytes transmitted after 'payload' padding.""" n2 = closest_power_of_two(data_bytes) m = closest_multiple(total_bytes, n2) return closest_multiple(m, psize, ceil=False)
def bytes_after_total_padding(total_bytes, psize=1): """Return the total bytes transmitted after 'total' padding.""" n2 = closest_power_of_two(total_bytes) return closest_multiple(n2, psize, ceil=False)