aDTN.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:aDTN-python 作者: megfault 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号