def main(args): _LOGGER.setLevel(logging.DEBUG if args.debug else logging.INFO) stream_logger = logging.StreamHandler(sys.stdout) stream_logger.setFormatter( logging.Formatter( '[%(levelname)-5s] %(asctime)s : (%(name)s) - %(message)s')) _LOGGER.addHandler(stream_logger) xena_socket = XenaSocket(args.chassis) xena_socket.connect() xena_manager = XenaLossMonitorManager(xena_socket, 'Monitor') port0 = xena_manager.add_port(args.module, args.ports[0]) port1 = xena_manager.add_port(args.module, args.ports[1]) totaltime = 0 while totaltime < args.length: time.sleep(1) totaltime += 1 total_lossport0 = 0 total_lossport1 = 0 if totaltime % args.interval == 0: # retrieve rx stats from each port port0.grab_all_rx_stats() port1.grab_all_rx_stats() # update total loss statistics total_lossport0 = port0.get_total_errors_counter() total_lossport1 = port1.get_total_errors_counter() _LOGGER.info( 'Port 0 total lost frames: {}'.format(total_lossport0)) _LOGGER.info( 'Port 1 total lost frames: {}'.format(total_lossport1))
def __init__(self, **kwargs): super(XenaNetworks, self).__init__(**kwargs) self.hostname = kwargs.pop("hostname", "localhost") self.username = kwargs.pop("username", "test") self.password = kwargs.pop("password", "xena") self.__xena_socket = XenaSocket(self.hostname) self.__xena_manager = None
def main(args): _LOGGER.setLevel(logging.INFO) stream_logger = logging.StreamHandler(sys.stdout) stream_logger.setFormatter( logging.Formatter( '[%(levelname)-5s] %(asctime)s : (%(name)s) - %(message)s')) _LOGGER.addHandler(stream_logger) xena_socket = XenaSocket(args.chassis) xena_socket.connect() time.sleep(1) # create the manager session xm = XenaManager(xena_socket, 'TestUser') time.sleep(1) try: # add port 0 and configure port0 = xm.add_port(args.module, args.ports[0]) port0.reserve() port0.clear_all_rx_stats() port0.clear_all_tx_stats() # add port 1 and configure port1 = xm.add_port(args.module, args.ports[1]) port1.reserve() port1.clear_all_rx_stats() port1.clear_all_tx_stats() except Exception as e: print( 'An exception occurred while attempting to add and configure ports' ) print(e) try: # add a single stream and configure s1_p0 = port0.add_stream(0) s1_p0.set_packet_limit(args.duration * args.pps) s1_p0.set_stream_on() s1_p0.set_rate_pps(args.pps) s1_p0.set_packet_header(pkthdr1) s1_p0.set_packet_length_fixed(args.pkt_size, 1518) s1_p0.set_packet_payload_incrementing('0x00') s1_p0.set_packet_protocol('ETHERNET', 'IP') s1_p0.set_test_payload_id(1) # enable multistream if args.number_streams: m1_s1_p0 = s1_p0.add_modifier() m1_s1_p0.set_modifier(32, 0xffff0000, 'inc', 1) m1_s1_p0.set_modifier_range(0, 1, args.number_streams) # begin network traffic port0.start_traffic() time.sleep(args.duration + 2) port0.stop_traffic() # retrieve traffic statistics port1.grab_all_rx_stats() grab_stats = port1.dump_all_rx_stats() # reorganize stats dict stats = {} for timestamp, stat in grab_stats.items(): for key in stat: stats[key] = stat[key] # packets sent pkt_sent = args.duration * args.pps print('Packets sent: {}'.format(pkt_sent)) # packets received pr_total = stats.get('pr_total') pkt_rec = pr_total.get('packets') # latency pr_tpldlatency = stats.get('pr_tpldlatency') tmp = pr_tpldlatency.get('1') pkt_latency_avg = tmp.get('avg') print('Packet latency: {} ns'.format(pkt_latency_avg)) # packets lost pkt_lost = pkt_sent - pkt_rec # sometimes returns negative loss, TODO: find out why print('Packets received: {}'.format(pkt_rec)) print('Packets lost: {}'.format(pkt_lost)) except Exception as e: print( 'An exception occurred while attempting to add and configure stream' ) print(e) finally: # disconnect from Xena print('Disconnecting from Xena chassis...') del xm del xena_socket print('Connection severed')
def main(): # create the test packet pkthdr = build_test_packet() # create the communication socket xsocket = XenaSocket('10.0.0.1') if not xsocket.connect(): sys.exit(-1) # create the manager session xm = XenaManager(xsocket, 'fbl') # add port 0 and configure port0 = xm.add_port(1, 0) if not port0: print "Fail to add port" sys.exit(-1) port0.set_pause_frames_off() # add port 1 and configure port1 = xm.add_port(1, 1) if not port1: print "Fail to add port" sys.exit(-1) port1.set_pause_frames_off() # add a single stream and configure s1_p0 = port0.add_stream(1) s1_p0.set_stream_on() s1_p0.disable_packet_limit() s1_p0.set_rate_fraction() s1_p0.set_packet_header(pkthdr) s1_p0.set_packet_length_fixed(64, 1518) s1_p0.set_packet_payload_incrementing('0x00') s1_p0.disable_test_payload_id() s1_p0.set_frame_csum_on() # start the traffic port0.start_traffic() time.sleep(4) # fetch stats for i in range(1, 10): port1.grab_all_rx_stats() time.sleep(1) # stop traffic port0.stop_traffic() # release resources full_stats = port1.dump_all_rx_stats() avg = cnt = 0 for timestamp in full_stats.keys(): stats = full_stats[timestamp] pps = stats['pr_total']['pps'] avg += pps cnt += 1 print "Average: %.2f pps" % (avg / cnt) write_csv("single_stream.csv", "Single Stream RX Stats", full_stats) del xm del xsocket
def main(): # create the test packet pkthdr = build_test_packet() # create the communication socket xsocket = XenaSocket('10.0.0.1') if not xsocket.connect(): sys.exit(-1) # create the manager session xm = XenaManager(xsocket, 'fbl') # add port 0 and configure port0 = xm.add_port(1, 0) if not port0: print "Fail to add port" sys.exit(-1) port0.set_pause_frames_off() # add port 1 and configure port1 = xm.add_port(1, 1) if not port1: print "Fail to add port" sys.exit(-1) port1.set_pause_frames_off() # add a single stream and configure s1_p0 = port0.add_stream(1) s1_p0.set_stream_on() s1_p0.disable_packet_limit() s1_p0.set_rate_fraction() s1_p0.set_rate_pps(100) s1_p0.set_packet_header(pkthdr) s1_p0.set_packet_length_fixed(64, 1518) s1_p0.set_packet_payload_incrementing('0x00') s1_p0.set_test_payload_id(1) s1_p0.set_frame_csum_on() # start the traffic port0.start_traffic() time.sleep(4) # fetch stats for i in range(1, 300): port1.grab_all_rx_stats() time.sleep(1) # stop traffic port0.stop_traffic() # release resources full_stats = port1.dump_all_rx_stats() avg_lat = max_lat = min_lat = cnt = 0 for timestamp in full_stats.keys(): stats = full_stats[timestamp] lat = stats['pr_tpldlatency']['1']['avg'] max_tmp = stats['pr_tpldlatency']['1']['max'] min_tmp = stats['pr_tpldlatency']['1']['min'] max_lat = max_tmp if max_tmp > max_lat else max_lat min_lat = min_tmp if min_tmp < min_lat else min_lat avg_lat += lat cnt += 1 print "Average latency: %.2f ns" % (avg_lat / cnt) print "Max latency: %.2f ns" % (max_lat) print "Min latency: %.2f ns" % (min_lat) write_csv("latency.csv", "Latency RX Stats", full_stats) del xm del xsocket