当前位置: 首页>>代码示例>>Python>>正文


Python Sender.poll方法代码示例

本文整理汇总了Python中traffic.core.helpers.Sender.poll方法的典型用法代码示例。如果您正苦于以下问题:Python Sender.poll方法的具体用法?Python Sender.poll怎么用?Python Sender.poll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traffic.core.helpers.Sender的用法示例。


在下文中一共展示了Sender.poll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startTraffic

# 需要导入模块: from traffic.core.helpers import Sender [as 别名]
# 或者: from traffic.core.helpers.Sender import poll [as 别名]

#.........这里部分代码省略.........
            self.rx_local_host = Host(
                self.inputs.cfgm_ip,
                self.inputs.host_data[self.rx_vm_node_ip]['username'],
                self.inputs.host_data[self.rx_vm_node_ip]['password'])
            self.send_host = Host(self.vm_fip_info[self.tx_vm_fixture.vm_name])
            self.recv_host = Host(self.vm_fip_info[self.rx_vm_fixture.vm_name])
        self.sender = list()
        self.receiver = list()
        self.num_streams = 0

        if fip is None:
            self.dst_ips = list(); self.src_ips = list()
            if af == 'dual' or af == 'v4':
                self.src_ips.extend(self.tx_vm_fixture.get_vm_ips(
                                    vn_fq_name=tx_vn_fq_name, af='v4'))
                self.dst_ips.extend(self.rx_vm_fixture.get_vm_ips(
                                    vn_fq_name=rx_vn_fq_name, af='v4'))
            if af == 'dual' or af == 'v6':
                self.src_ips.extend(self.tx_vm_fixture.get_vm_ips(
                                    vn_fq_name=tx_vn_fq_name, af='v6'))
                self.dst_ips.extend(self.rx_vm_fixture.get_vm_ips(
                                    vn_fq_name=rx_vn_fq_name, af='v6'))
        else:
            self.dst_ips = [fip]
            self.src_ips = [self.tx_vm_fixture.vm_ip]
        if len(self.dst_ips) > len(self.src_ips):
            raise Exception('No of destination ips cant be greater than'
                            ' source ips, for multi stream case')

        for index in range(len(self.dst_ips)):
            name = name + '_dst' + str(index) + '_'
            for i in range(num_streams):
                self.name = name + self.stream_proto + str(i)
                self.dport = start_port + i
                m = "Send protocol %s traffic to port %s" % (
                    self.stream_proto, self.dport)
                if self.stream_proto == 'icmp':
                    m = "Send protocol %s traffic" % self.stream_proto
                self.logger.info(m)
                stream = Stream(proto=self.stream_proto,
                                src=self.src_ips[index],
                                dst=self.dst_ips[index],
                                dport=self.dport)
                if fip:
                   listener = self.rx_vm_fixture.vm_ip
                else:
                   listener = self.dst_ips[index]
                # stream profile...
                if cfg_profile == 'ContinuousSportRange':
                    profile = ContinuousSportRange(stream=stream,
                                                   startport=self.start_sport,
                                                   endport=self.endport,
                                                   listener=listener,
                                                   size=self.packet_size,
                                                   chksum=self.chksum, pps=pps)
                elif cfg_profile == 'ContinuousProfile':
                    profile = ContinuousProfile(stream=stream,
                                                listener=listener,
                                                size=self.packet_size,
                                                chksum=self.chksum)
                # sender profile...
                sender = Sender(self.name, profile, self.tx_local_host,
                                self.send_host, self.inputs.logger)
                receiver = Receiver(self.name, profile, self.rx_local_host,
                                    self.recv_host, self.inputs.logger)
                self.logger.info("tx vm - node %s, mdata_ip %s, vm_ip %s" %(
                                 self.tx_local_host.ip, self.send_host.ip,
                                 self.src_ips[index]))
                self.logger.info("rx vm - node %s, mdata_ip %s, vm_ip %s" %(
                                 self.rx_local_host.ip, self.recv_host.ip,
                                 self.dst_ips[index]))
                receiver.start()
                self.logger.info("Starting %s traffic from %s to %s" %(
                                  self.stream_proto, self.src_ips[index],
                                  self.dst_ips[index]))
                sender.start()
                retries = 10
                j = 0
                sender.sent = None
                while j < retries and sender.sent == None:
                    # wait before checking for stats as it takes time for file
                    # update with stats
                    time.sleep(5)
                    sender.poll()
                # end while
                if sender.sent == None:
                    msg = "send %s traffic failure from %s " % (
                        self.stream_proto, self.src_ips[index])
                    self.logger.info(
                        "traffic tx stats not available !!, details: %s" % msg)
                else:
                    self.logger.info(
                        "traffic running good, sent %s pkts so far.." %
                        sender.sent)
                self.sender.append(sender)
                self.receiver.append(receiver)
                self.num_streams += 1
        if msg != None:
            status = False
        return {'status': status, 'msg': msg}
开发者ID:Ankitja,项目名称:contrail-test,代码行数:104,代码来源:traffic_tests.py


注:本文中的traffic.core.helpers.Sender.poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。