Ejemplo n.º 1
0
    def _config_and_run_stream_stats_test(self, rx_ports, sc=True, di=True, ts=True):

        self._reserve_ports(self.port1, self.port2)

        iteration = 1
        for port_name in [self.port1, self.port2]:
            port = self.ports[port_name]
            port.add_stream()
            port.add_stream()
            for stream in port.streams.values():
                stream.framesize = 68
                stream.vlan.vlanId = 33
                stream.dma = 'advance'
                stream.numFrames = iteration
                stream.rateMode = 'streamRateModeFps'
                iteration += 1

        self.ixia.session.set_stream_stats(rx_ports=[self.ports[r] for r in rx_ports],
                                           sequence_checking=sc, data_integrity=di, timestamp=ts)
        self.ixia.session.wait_for_up(ports=self.ports.values())

        self.ixia.session.start_transmit()
        time.sleep(2)
        self.ixia.session.stop_transmit()
        time.sleep(2)

        stream_stats = IxeStreamsStats(self.ixia.session)
        stream_stats.read_stats()
        print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))

        return stream_stats.statistics
Ejemplo n.º 2
0
def test_prbs(ixia: IxeApp, locations: List[str]) -> None:

    port1 = locations[0]
    port2 = locations[1]

    stats = _config_and_run_stream_stats_test(ixia, locations, rx_ports=[])

    assert stats[str(
        ixia.session.ports[port1].streams[1])]['tx']['framesSent'] == 1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['totalFrames'] == 1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['minLatency'] != -1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['prbsBerRatio'] == -1
    assert stats[str(
        ixia.session.ports[port2].streams[2])]['tx']['framesSent'] == 4
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['totalFrames'] == 4
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['minLatency'] != -1
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['prbsBerRatio'] == -1

    ixia.session.set_prbs()
    # For coverage we call port.wait_for_up instead of session.wait_for_up.
    ixia.session.ports[port1].wait_for_up()
    ixia.session.ports[port2].wait_for_up()

    ixia.session.clear_all_stats()
    ixia.session.start_transmit()
    time.sleep(2)
    ixia.session.stop_transmit()
    time.sleep(2)

    stream_stats = IxeStreamsStats(ixia.session)
    stream_stats.read_stats()
    print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
    stats = stream_stats.statistics

    for port in ixia.session.ports.values():
        if not int(port.isValidFeature('portFeaturePrbs')):
            pytest.skip('Port not supporting Prbs')

    assert stats[str(
        ixia.session.ports[port1].streams[1])]['tx']['framesSent'] == 1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['totalFrames'] == 1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['minLatency'] == -1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['prbsBerRatio'] != -1
    assert stats[str(
        ixia.session.ports[port2].streams[2])]['tx']['framesSent'] == 4
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['totalFrames'] == 4
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['minLatency'] == -1
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['prbsBerRatio'] != -1
Ejemplo n.º 3
0
    def testStreamStats(self):
        cfg1 = path.join(path.dirname(__file__), 'configs/stats_config_1.prt')
        cfg2 = path.join(path.dirname(__file__), 'configs/stats_config_2.prt')
        self._load_config(cfg1, cfg2)

        self.ixia.session.start_transmit()
        time.sleep(2)
        self.ixia.session.stop_transmit()

        stream_stats = IxeStreamsStats(self.ixia.session)
        self.ports[self.port1].streams[1].rx_ports = [self.ports[self.port2]]
        self.ports[self.port1].streams[2].rx_ports = [self.ports[self.port2]]
        self.ports[self.port2].rx_ports = self.ports[self.port1]
        stream_stats.read_stats()
        print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
        assert (stream_stats.statistics['1/2/1/1']['tx']['framesSent'] > 0)
        assert (stream_stats.statistics['1/2/1/1']['tx']['frameRate'] == 0)
        assert (stream_stats.statistics['1/2/1/1']['rx']['192.168.42.61/2/2']
                ['totalFrames'] > 0)
        assert (stream_stats.statistics['1/2/1/1']['rx']['frameRate'] == 0)

        print(
            json.dumps(self.ports[self.port1].read_stream_stats('totalFrames'),
                       indent=1))
        print(
            json.dumps(
                self.ports[self.port1].streams[1].read_stats('totalFrames'),
                indent=1))
Ejemplo n.º 4
0
    def test_prbs(self):

        stats = self._config_and_run_stream_stats_test(rx_ports=[])

        assert(stats[str(self.ports[self.port1].streams[1])]['tx']['framesSent'] == 1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['totalFrames'] == 1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['minLatency'] != -1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['prbsBerRatio'] == -1)
        assert(stats[str(self.ports[self.port2].streams[2])]['tx']['framesSent'] == 4)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['totalFrames'] == 4)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['minLatency'] != -1)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['prbsBerRatio'] == -1)

        self.ixia.session.set_prbs()
        # For coverage we call port.wait_for_up instead of session.wait_for_up.
        self.ports[self.port1].wait_for_up()
        self.ports[self.port2].wait_for_up()

        self.ixia.session.clear_all_stats()
        self.ixia.session.start_transmit()
        time.sleep(2)
        self.ixia.session.stop_transmit()
        time.sleep(2)

        stream_stats = IxeStreamsStats(self.ixia.session)
        stream_stats.read_stats()
        print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
        stats = stream_stats.statistics

        for port in self.ports.values():
            if not int(port.isValidFeature('portFeaturePrbs')):
                self.skipTest('Port not supporting Prbs')
                return

        assert(stats[str(self.ports[self.port1].streams[1])]['tx']['framesSent'] == 1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['totalFrames'] == 1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['minLatency'] == -1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['prbsBerRatio'] != -1)
        assert(stats[str(self.ports[self.port2].streams[2])]['tx']['framesSent'] == 4)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['totalFrames'] == 4)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['minLatency'] == -1)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['prbsBerRatio'] != -1)
Ejemplo n.º 5
0
    def get_streams_stats_by_list(self, stats_list=None):
        self._logger.info(self._get_tg_log_title(), self._get_tg_log_message(),
                          True)
        super(self.__class__,
              self).get_streams_stats_by_list(stats_list=stats_list)
        stats = IxeStreamsStats(self._connector.session)
        try:
            stats.read_stats(*stats_list)
            for port in self.ports:
                for stream in self.ports[port].streams:
                    self.ports[port].streams[stream]._update_stream_stats(
                        stats)
                    # statistics_str = str(self.ports[port].streams[stream].statistics)
                    # statistics_dict = json.loads(statistics_str)
                    # self._logger.info("tx_stats - port - {}, stream - {}".format(port, stream),
                    #                   "frames_sent:{}\nframes_sent_rate:{}".format(
                    #                       statistics_dict["frames_sent"].replace("\"", ""),
                    #                       statistics_dict["frames_sent_rate"].replace("\"", "")), True)
                    # for rx_port in statistics_dict["rx_stats"][0]:
                    #     rx_dict = statistics_dict["rx_stats"][0][rx_port][0]
                    #     rx_str = ""
                    #     for key, val in rx_dict.iteritems():
                    #         rx_str += "{}:{}\n".format(key, val)
                    #     rx_str = rx_str.replace("\"", "")
                    #     rx_str = rx_str.replace("\'", "")
                    #     self._logger.info(rx_port, rx_str)
                    # self._logger.info("end_level", "end_level")

                    # stats_message = ""
                    #
                    # stats_message += "{}".format(str(self.ports[port].streams[stream].statistics))
                    # self._logger.info("port - {}, stream - {}".format(port, stream), stats_message)
        except Exception as e:
            message = "Could not get streams stats - check if streams\ports are configured to PGID\n{}".format(
                str(e))
            self._logger.info(self._get_tg_log_title(), message)
            raise Exception(message)

        self._logger.info("end_level", "end_level")
        return stats.statistics
Ejemplo n.º 6
0
def test_stream_stats(ixia: IxeApp, locations: List[str]) -> None:
    """ Test stream statistics. """
    print(test_stream_stats.__doc__)

    ixia.session.reserve_ports(locations, force=True)
    cfg1 = Path(__file__).parent.joinpath('configs/test_config_1.prt')
    cfg2 = Path(__file__).parent.joinpath('configs/test_config_2.prt')
    _load_configs(ixia, cfg1, cfg2)

    port1 = locations[0]
    port2 = locations[1]

    ixia.session.start_transmit()
    time.sleep(2)
    ixia.session.stop_transmit()

    stream_stats = IxeStreamsStats()
    ixia.session.ports[port1].streams[1].rx_ports = [ixia.session.ports[port2]]
    ixia.session.ports[port1].streams[2].rx_ports = [ixia.session.ports[port2]]
    ixia.session.ports[port2].rx_ports = ixia.session.ports[port1]
    stream_stats.read_stats()
    print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['tx']['framesSent'] > 0
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['tx']['frameRate'] == 0
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['rx']['totalFrames'] > 0
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['rx']['frameRate'] == 0

    print(
        json.dumps(ixia.session.ports[port1].read_stream_stats('totalFrames'),
                   indent=1))
    print(
        json.dumps(
            ixia.session.ports[port1].streams[1].read_stats('totalFrames'),
            indent=1))
Ejemplo n.º 7
0
    def test_clear_all_stats(self):

        stats = self._config_and_run_stream_stats_test(rx_ports=[])

        assert(stats[str(self.ports[self.port1].streams[1])]['tx']['framesSent'] == 1)
        assert(stats[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['totalFrames'] == 1)
        assert(stats[str(self.ports[self.port2].streams[2])]['tx']['framesSent'] == 4)
        assert(stats[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['totalFrames'] == 4)

        port_stats = IxePortsStats(self.ixia.session)
        stream_stats = IxeStreamsStats(self.ixia.session)

        port_stats.read_stats('framesSent')
        print(json.dumps(port_stats.statistics, indent=1, sort_keys=True))
        assert(port_stats.statistics[str(self.ports[self.port1])]['framesSent'] == 3)
        assert(port_stats.statistics[str(self.ports[self.port2])]['framesSent'] == 7)

        self.ports[self.port1].clear_port_stats()
        time.sleep(2)
        port_stats.read_stats('framesSent')
        print(json.dumps(port_stats.statistics, indent=1, sort_keys=True))
        assert(port_stats.statistics[str(self.ports[self.port1])]['framesSent'] == 0)
        assert(port_stats.statistics[str(self.ports[self.port2])]['framesSent'] == 7)
        stream_stats.read_stats('totalFrames')
        print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
        assert(stream_stats.statistics[str(self.ports[self.port1].streams[1])]['tx']['framesSent'] == 0)
        assert(stream_stats.statistics[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['totalFrames'] == 1)  # noqa
        assert(stream_stats.statistics[str(self.ports[self.port2].streams[2])]['tx']['framesSent'] == 4)
        assert(stream_stats.statistics[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['totalFrames'] == -1)  # noqa

        self.ixia.session.clear_all_stats()
        time.sleep(2)
        port_stats.read_stats('framesSent')
        print(json.dumps(port_stats.statistics, indent=1, sort_keys=True))
        assert(port_stats.statistics[str(self.ports[self.port1])]['framesSent'] == 0)
        assert(port_stats.statistics[str(self.ports[self.port2])]['framesSent'] == 0)
        stream_stats.read_stats('totalFrames')
        print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
        assert(stream_stats.statistics[str(self.ports[self.port1].streams[1])]['tx']['framesSent'] == 0)
        assert(stream_stats.statistics[str(self.ports[self.port1].streams[1])]['rx'][str(self.ports[self.port2])]['totalFrames'] == -1)  # noqa
        assert(stream_stats.statistics[str(self.ports[self.port2].streams[2])]['tx']['framesSent'] == 0)
        assert(stream_stats.statistics[str(self.ports[self.port2].streams[2])]['rx'][str(self.ports[self.port1])]['totalFrames'] == -1)  # noqa
Ejemplo n.º 8
0
 def get_advanced_stats(self, stats_list=None):
     self._logger.info(self._get_tg_log_title(), self._get_tg_log_message(),
                       True)
     super(self.__class__, self).get_advanced_stats()
     stats = IxeStreamsStats(self._connector.session)
     try:
         if stats_list:
             stats.read_stats(*stats_list)
         else:
             stats.read_stats()
         for port in self.ports:
             for stream in self.ports[port].streams:
                 self.ports[port].streams[stream]._update_stream_stats(
                     stats)
     except Exception as e:
         message = "Could not get streams stats - check if streams\ports are configured to PGID\n{}".format(
             str(e))
         self._logger.info(self._get_tg_log_title(), message)
         raise Exception(message)
     self._logger.info("end_level", "end_level")
     return stats.statistics
Ejemplo n.º 9
0
 def read_stream_stats(self, *stats):
     return IxeStreamsStats(self.session, *self.get_objects_by_type('stream')).read_stats(stats)
Ejemplo n.º 10
0
 def read_stats(self, *stats):
     return IxeStreamsStats(self.session, self).read_stats(*stats)[str(self)]
Ejemplo n.º 11
0
def test_clear_all_stats(ixia: IxeApp, locations: List[str]) -> None:

    port1 = locations[0]
    port2 = locations[1]

    stats = _config_and_run_stream_stats_test(ixia, locations, rx_ports=[])

    assert stats[str(
        ixia.session.ports[port1].streams[1])]['tx']['framesSent'] == 1
    assert stats[str(ixia.session.ports[port1].streams[1])]['rx'][str(
        ixia.session.ports[port2])]['totalFrames'] == 1
    assert stats[str(
        ixia.session.ports[port2].streams[2])]['tx']['framesSent'] == 4
    assert stats[str(ixia.session.ports[port2].streams[2])]['rx'][str(
        ixia.session.ports[port1])]['totalFrames'] == 4

    port_stats = IxePortsStats(ixia.session)
    stream_stats = IxeStreamsStats(ixia.session)

    port_stats.read_stats('framesSent')
    print(json.dumps(port_stats.statistics, indent=1, sort_keys=True))
    assert port_stats.statistics[str(
        ixia.session.ports[port1])]['framesSent'] == 3
    assert port_stats.statistics[str(
        ixia.session.ports[port2])]['framesSent'] == 7

    ixia.session.ports[port1].clear_port_stats()
    time.sleep(2)
    port_stats.read_stats('framesSent')
    print(json.dumps(port_stats.statistics, indent=1, sort_keys=True))
    assert port_stats.statistics[str(
        ixia.session.ports[port1])]['framesSent'] == 0
    assert port_stats.statistics[str(
        ixia.session.ports[port2])]['framesSent'] == 7
    stream_stats.read_stats('totalFrames')
    print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
    stream_1_rx = stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['rx']
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['tx']['framesSent'] == 0
    assert stream_1_rx[str(
        ixia.session.ports[port2])]['totalFrames'] == 1  # noqa
    assert stream_stats.statistics[str(
        ixia.session.ports[port2].streams[2])]['tx']['framesSent'] == 4
    assert stream_1_rx[str(
        ixia.session.ports[port1])]['totalFrames'] == -1  # noqa

    ixia.session.clear_all_stats()
    time.sleep(2)
    port_stats.read_stats('framesSent')
    print(json.dumps(port_stats.statistics, indent=1, sort_keys=True))
    assert port_stats.statistics[str(
        ixia.session.ports[port1])]['framesSent'] == 0
    assert port_stats.statistics[str(
        ixia.session.ports[port2])]['framesSent'] == 0
    stream_stats.read_stats('totalFrames')
    print(json.dumps(stream_stats.statistics, indent=1, sort_keys=True))
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['tx']['framesSent'] == 0
    assert stream_stats.statistics[str(
        ixia.session.ports[port1].streams[1])]['rx'][str(
            ixia.session.ports[port2])]['totalFrames'] == -1  # noqa
    assert stream_stats.statistics[str(
        ixia.session.ports[port2].streams[2])]['tx']['framesSent'] == 0
    assert stream_stats.statistics[str(
        ixia.session.ports[port2].streams[2])]['rx'][str(
            ixia.session.ports[port1])]['totalFrames'] == -1  # noqa
Ejemplo n.º 12
0
 def read_stats(self, *stats):
     return IxeStreamsStats(self.session,
                            self).read_stats(*stats).values()[0]