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


Python Sender.sent方法代码示例

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


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

示例1: startTraffic

# 需要导入模块: from traffic.core.helpers import Sender [as 别名]
# 或者: from traffic.core.helpers.Sender import sent [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

示例2: verify_traffic_flow

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

#.........这里部分代码省略.........
        flow_result = False
        flow_result2 = False
        flow_result3 = False

        rev_flow_result = False
        rev_flow_result1 = False
        rev_flow_result2 = False
        src_vm_vrf_name = src_vm.vn_fq_name + ':' + src_vm.vn_name
        vn_vrf_id = src_vm.get_vrf_id(src_vm.vn_fq_name, src_vm_vrf_name)

        src_port = unicode(8000)
        dpi1 = unicode(9000)
        dpi2 = unicode(9001)
        dpi3 = unicode(9002)
        dpi_list = [dpi1, dpi2, dpi3]

        vm_node_ips = []
        vm_node_ips.append(src_vm.vm_node_ip)
        if (src_vm.vm_node_ip != dst_vm.vm_node_ip):
            vm_node_ips.append(dst_vm.vm_node_ip)

#        inspect_h100= self.agent_inspect[src_vm.vm_node_ip]
#        flow_rec1= inspect_h100.get_vna_fetchflowrecord(vrf=vn_vrf_id,sip=src_vm.vm_ip,dip=dst_vm.vm_ip,sport=src_port,dport=dpi1,protocol='6')
#        flow_rec2= inspect_h100.get_vna_fetchflowrecord(vrf=vn_vrf_id,sip=src_vm.vm_ip,dip=dst_vm.vm_ip,sport=src_port,dport=dpi2,protocol='6')
#        flow_rec3= inspect_h100.get_vna_fetchflowrecord(vrf=vn_vrf_id,sip=src_vm.vm_ip,dip=dst_vm.vm_ip,sport=src_port,dport=dpi3,protocol='6')
#        flow_recs= []
#        flow_recs= [flow_rec1, flow_rec2, flow_rec3]
#        print flow_recs
#        flow_result= True
#        i= 0
#        for flow_rec in flow_recs:
#            if flow_rec is None:
#                flow_result= False
#            if flow_result is True:
#                i += 1
#        self.logger.info('%s Flows from %s to %s exist on Agent %s'%(i, src_vm.vm_ip, dst_vm.vm_ip, src_vm.vm_node_ip))

        for agent_ip in self.inputs.compute_ips:
            inspect_h = self.agent_inspect[agent_ip]
            rev_flow_result = False
            for iter in range(25):
                self.logger.debug('**** Iteration %s *****' % iter)
                reverseflowrecords = []
                reverseflowrecords = inspect_h.get_vna_fetchallflowrecords()
                if type(reverseflowrecords) == types.NoneType:
                    self.logger.debug('No flows on %s.' % agent_ip)
                    break
                else:
                    for rec in reverseflowrecords:
                        if ((rec['sip'] == dst_vm.vm_ip) and (rec['protocol'] == '6')):
                            self.logger.info(
                                'Reverse Flow from %s to %s exists.' %
                                (dst_vm.vm_ip, src_vm.vm_ip))
                            rev_flow_result = True
                            break
                        else:
                            rev_flow_result = False
                    if rev_flow_result:
                        break
                    else:
                        iter += 1
                        sleep(10)
            if rev_flow_result:
                break

        self.logger.info('Stopping Traffic now')
        for stream in stream_list:
            sender[stream].stop()
            time.sleep(5)
        for stream in stream_list:
            receiver[stream].stop()
            time.sleep(5)
        stream_sent_count = {}
        stream_recv_count = {}
        result = True
        for stream in stream_list:
            if sender[stream].sent == None:
                sender[stream].sent = 0
            if receiver[stream].recv == None:
                receiver[stream].recv = 0
            stream_sent_count[stream] = sender[stream].sent
            stream_recv_count[stream] = receiver[stream].recv
            pkt_diff = (stream_sent_count[stream] - stream_recv_count[stream])
            if pkt_diff < 0:
                self.logger.debug('Some problem with Scapy. Please check')
            elif pkt_diff in range(0, 6):
                self.logger.info(
                    '%s packets sent and %s packets received in Stream%s. No Packet Loss seen.' %
                    (stream_sent_count[stream], stream_recv_count[stream], stream_list.index(stream)))
            else:
                result = False
                assert result, '%s packets sent and %s packets received in Stream%s. Packet Loss.' % (
                    stream_sent_count[stream], stream_recv_count[stream], stream_list.index(stream))
#        if i < 1:
#            flow_result= False
#        assert flow_result,'Flows from %s to %s not seen on Agent %s'%(src_vm.vm_ip, dst_vm.vm_ip, src_vm.vm_node_ip)
        assert rev_flow_result, 'Reverse Flow from %s to %s not seen' % (
            dst_vm.vm_ip, src_vm.vm_ip)

        return True
开发者ID:rishiv,项目名称:contrail-test,代码行数:104,代码来源:ecmp_traffic.py


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