def _send(self):
"""
Send a batch of randomly selected packets from the sending pool, then ensure the sending pool gets refilled if
necessary. The packets are encapsulated in an Ethernet frame of type 0xcafe and removed from the sending pool,
and finally broadcast in a batch.
This function reschedules itself to occur every sending_freq seconds.
"""
self._scheduler.enter(self._sending_freq, 1, self._send)
log_debug("Sending scheduler queue length: {}".format(len(self._scheduler.queue)))
if self._sending:
batch = []
s = sample(self._sending_pool, self._batch_size)
for pkt in s:
batch.append(Ether(dst="ff:ff:ff:ff:ff:ff", src=self._mac_address, type=ETHERTYPE) / pkt)
self._sending_pool.remove(pkt)
t_before = time()
_gen_send_repeatable(self._sending_socket, batch, iface=self._wireless_interface, verbose=False)
t_after = time()
with open(self._stats_file_name, 'a') as stats_file:
stats_file.write('{},{},{}\n'.format(t_before, t_after, len(batch)))
self._sent_pkt_counter += len(batch)
log_network("snt {} in {}s".format(len(batch), t_after - t_before))
self._prepare_sending_pool()
评论列表
文章目录