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))
예제 #2
0
    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
예제 #3
0
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')
예제 #4
0
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
예제 #5
0
class XenaNetworks(TrafficGeneratorChassis):
    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 _verify_port_action(self, port_name):
        if self.is_connected() and self._verify_port_string(port_name) and \
           port_name in self.port_data:
            return (True)
        return (False)

    def _verify_port_string(self, port_name):
        xport = port_name.split(',')
        if len(xport) != 2:
            return False

        for number in xport:
            try:
                if int(number) < 0:
                    return False

            except ValueError:
                return False

        return True

    def connect(self):
        if not self.is_connected():
            self.__xena_socket.connect()
            self.__xena_manager = XenaManager(self.__xena_socket,
                                              self.username,
                                              password=self.password)

            if self.__xena_manager is not None:
                #
                # Re-add previously configured ports
                #
                for port in self.port_data.keys():
                    self.port_data[port] = self._reserve_port(port)

        return self.is_connected()

    def disconnect(self):
        del (self.__xena_manager)
        self.__xena_socket.disconnect()
        self.__xena_socket = None
        return False

    def is_connected(self):
        if self.__xena_socket.is_connected() and \
           self.__xena_manager is not None:
            return True

        return False

    def _reserve_port(self, port_name):
        if not self._verify_port_string(port_name):
            return False

        xport = self.__xena_manager.add_port(
            port_name.split(',')[0],
            port_name.split(',')[1])
        if xport is None:
            return None

        return _XenaNetworksPort(port_name, xport)

    def reserve_port(self, port_name):
        xport = self._reserve_port(port_name)
        if xport is None:
            return False
        return super(XenaNetworks, self).reserve_port(port_name, xport)

    def release_port(self, port_name):
        if not self._verify_port_string(port_name) or \
           port_name not in self.port_data:
            return False

        self.__xena_manager.remove_port(
            port_name.split(',')[0],
            port_name.split(',')[1])

        return super(XenaNetworks, self).release_port(port_name)

    def clear_statistics(self, port_name):
        if self._verify_port_action(port_name):
            self.port_data[port_name].clear_statistics()

    def take_tx_statistics_snapshot(self, port_name):
        if self._verify_port_action(port_name):
            self.port_data[port_name].take_tx_statistics_snapshot()

    def take_rx_statistics_snapshot(self, port_name):
        if self._verify_port_action(port_name):
            self.port_data[port_name].take_rx_statistics_snapshot()

    def get_tx_statistics_snapshots(self, port_name):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].get_tx_statistics_snapshots()
        return None

    def get_rx_statistics_snapshots(self, port_name):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].get_rx_statistics_snapshots()
        return None

    def start_traffic(self, port_name):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].start_traffic()
        return False

    def stop_traffic(self, port_name):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].stop_traffic()
        return False

    def configure_traffic_stream(self, port_name, traffic_flows, nr_of_flows,
                                 packet_size, **kwargs):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].configure_traffic_stream(
                traffic_flows, nr_of_flows, packet_size, **kwargs)
        return False

    def next_traffic_stream(self, port_name):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].next_traffic_stream()
        return False

    def get_port_limits(self, port_name):
        if self._verify_port_action(port_name):
            return self.port_data[port_name].get_port_limits()
        return dict()
예제 #6
0
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 = avg_max = avg_min = cnt = 0
    for timestamp in full_stats.keys():
        stats = full_stats[timestamp]
        lat = stats['pr_tpldlatency']['1']['avg']
        max_lat = stats['pr_tpldlatency']['1']['max']
        min_lat = stats['pr_tpldlatency']['1']['min']
        avg_lat += lat
        avg_max += max_lat
        avg_min += min_lat
        cnt += 1

    print "Average latency: %.2f ns" % (avg_lat / cnt)
    print "Max latency: %.2f ns" % (avg_max / cnt)
    print "Min latency: %.2f ns" % (avg_min / cnt)
    write_csv("latency.csv", "Latency RX Stats", full_stats)
    del xm
    del xsocket
예제 #7
0
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
예제 #8
0
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