Beispiel #1
0
    def do_tui (self, line):
        '''Shows a graphical console\n'''

        parser = parsing_opts.gen_parser(self,
                                         "tui",
                                         self.do_tui.__doc__,
                                         parsing_opts.XTERM)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        if opts.xterm:

            exe = './trex-console -t -q -s {0} -p {1}'.format(self.stateless_client.get_server_ip(), self.stateless_client.get_server_port())
            cmd = ['xterm', '-geometry', '111x42', '-sl', '0', '-title', 'trex_tui', '-e', exe]
            self.terminal = subprocess.Popen(cmd)

            return


        set_window_always_on_top('trex_tui')

        save_verbose = self.stateless_client.get_verbose()

        self.stateless_client.set_verbose(self.stateless_client.VERBOSE_QUIET)
        self.tui.show()
        self.stateless_client.set_verbose(save_verbose)
    def do_tui(self, line):
        """Shows a graphical console\n"""

        parser = parsing_opts.gen_parser(self, "tui", self.do_tui.__doc__, parsing_opts.XTERM)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        if opts.xterm:
            exe = ""
            if os.path.isfile("/usr/bin/wmctrl"):
                exe += "/usr/bin/wmctrl -r trex_tui -b add,above;"

            exe += "./trex-console -t -q -s {0} -p {1}".format(
                self.stateless_client.get_server_ip(), self.stateless_client.get_server_port()
            )

            cmd = ["xterm", "-geometry", "105x40", "-title", "trex_tui", "-e", exe]
            subprocess.Popen(cmd)

            return

        save_verbose = self.stateless_client.get_verbose()

        self.stateless_client.set_verbose(self.stateless_client.VERBOSE_QUIET)
        self.tui.show()
        self.stateless_client.set_verbose(save_verbose)
Beispiel #3
0
    def do_history (self, line):
        '''Manage the command history\n'''

        item = parsing_opts.ArgumentPack(['item'],
                                         {"nargs": '?',
                                          'metavar': 'item',
                                          'type': parsing_opts.check_negative,
                                          'help': "an history item index",
                                          'default': 0})

        parser = parsing_opts.gen_parser(self,
                                         "history",
                                         self.do_history.__doc__,
                                         item)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        if opts.item == 0:
            self.print_history()
        else:
            cmd = self.get_history_item(opts.item)
            if cmd == None:
                return

            self.onecmd(cmd)
    def cmd_stats_line(self, line):
        '''Fetch statistics from TRex server by port\n'''
        # define a parser
        parser = parsing_opts.gen_parser(self, "stats",
                                         self.cmd_stats_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL,
                                         parsing_opts.STATS_MASK)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")

        # determine stats mask
        mask = self._get_mask_keys(
            **self._filter_namespace_args(opts, trex_stats.ALL_STATS_OPTS))
        if not mask:
            # set to show all stats if no filter was given
            mask = trex_stats.ALL_STATS_OPTS

        stats = self.cmd_stats(opts.ports, mask)

        # print stats to screen
        for stat_type, stat_data in stats.iteritems():
            text_tables.print_table_with_header(stat_data.text_table,
                                                stat_type)

        return RC_OK()
Beispiel #5
0
    def do_tui(self, line):
        '''Shows a graphical console\n'''

        parser = parsing_opts.gen_parser(self, "tui", self.do_tui.__doc__,
                                         parsing_opts.XTERM)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        if opts.xterm:
            exe = ''
            if os.path.isfile('/usr/bin/wmctrl'):
                exe += '/usr/bin/wmctrl -r trex_tui -b add,above;'

            exe += './trex-console -t -q -s {0} -p {1}'.format(
                self.stateless_client.get_server_ip(),
                self.stateless_client.get_server_port())

            cmd = [
                'xterm', '-geometry', '105x40', '-title', 'trex_tui', '-e', exe
            ]
            subprocess.Popen(cmd)

            return

        save_verbose = self.stateless_client.get_verbose()

        self.stateless_client.set_verbose(self.stateless_client.VERBOSE_QUIET)
        self.tui.show()
        self.stateless_client.set_verbose(save_verbose)
Beispiel #6
0
    def do_history(self, line):
        '''Manage the command history\n'''

        item = parsing_opts.ArgumentPack(
            ['item'], {
                "nargs": '?',
                'metavar': 'item',
                'type': parsing_opts.check_negative,
                'help': "an history item index",
                'default': 0
            })

        parser = parsing_opts.gen_parser(self, "history",
                                         self.do_history.__doc__, item)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        if opts.item == 0:
            self.print_history()
        else:
            cmd = self.get_history_item(opts.item)
            if cmd == None:
                return

            self.onecmd(cmd)
    def do_history(self, line):
        """Manage the command history\n"""

        item = parsing_opts.ArgumentPack(
            ["item"],
            {
                "nargs": "?",
                "metavar": "item",
                "type": parsing_opts.check_negative,
                "help": "an history item index",
                "default": 0,
            },
        )

        parser = parsing_opts.gen_parser(self, "history", self.do_history.__doc__, item)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        if opts.item == 0:
            self.print_history()
        else:
            cmd = self.get_history_item(opts.item)
            if cmd == None:
                return

            self.onecmd(cmd)
    def cmd_stats_line (self, line):
        '''Fetch statistics from TRex server by port\n'''
        # define a parser
        parser = parsing_opts.gen_parser(self,
                                         "stats",
                                         self.cmd_stats_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL,
                                         parsing_opts.STATS_MASK)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")

        # determine stats mask
        mask = self._get_mask_keys(**self._filter_namespace_args(opts, trex_stats.ALL_STATS_OPTS))
        if not mask:
            # set to show all stats if no filter was given
            mask = trex_stats.ALL_STATS_OPTS

        stats = self.cmd_stats(opts.ports, mask)

        # print stats to screen
        for stat_type, stat_data in stats.iteritems():
            text_tables.print_table_with_header(stat_data.text_table, stat_type)


        return RC_OK()
    def cmd_streams_line(self, line):
        '''Fetch streams statistics from TRex server by port\n'''
        # define a parser
        parser = parsing_opts.gen_parser(self,
                                         "streams",
                                         self.cmd_streams_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL,
                                         parsing_opts.STREAMS_MASK)#,
                                         #parsing_opts.FULL_OUTPUT)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")

        streams = self.cmd_streams(opts.ports, set(opts.streams))
        if not streams:
            # we got no streams running

            print format_text("No streams found with desired filter.\n", "bold", "magenta")
            return RC_ERR("No streams found with desired filter.")
        else:
            # print stats to screen
            for stream_hdr, port_streams_data in streams.iteritems():
                text_tables.print_table_with_header(port_streams_data.text_table,
                                                    header= stream_hdr.split(":")[0] + ":",
                                                    untouched_header= stream_hdr.split(":")[1])
            return RC_OK()
    def cmd_start_line (self, line):
        '''Start selected traffic in specified ports on TRex\n'''
        # define a parser
        parser = parsing_opts.gen_parser(self,
                                         "start",
                                         self.cmd_start_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL,
                                         parsing_opts.TOTAL,
                                         parsing_opts.FORCE,
                                         parsing_opts.STREAM_FROM_PATH_OR_FILE,
                                         parsing_opts.DURATION,
                                         parsing_opts.MULTIPLIER_STRICT,
                                         parsing_opts.DRY_RUN)

        opts = parser.parse_args(line.split())


        if opts is None:
            return RC_ERR("bad command line parameters")


        if opts.dry:
            print format_text("\n*** DRY RUN ***", 'bold')

        if opts.db:
            stream_list = self.streams_db.get_stream_pack(opts.db)
            rc = RC(stream_list != None)
            rc.annotate("Load stream pack (from DB):")
            if rc.bad():
                return RC_ERR("Failed to load stream pack")

        else:
            # load streams from file
            stream_list = None;
            try:
              stream_list = self.streams_db.load_yaml_file(opts.file[0])
            except Exception as e:
                s = str(e)
                rc=RC_ERR(s)
                rc.annotate()
                return rc

            rc = RC(stream_list != None)
            rc.annotate("Load stream pack (from file):")
            if stream_list == None:
                return RC_ERR("Failed to load stream pack")


        # total has no meaning with percentage - its linear
        if opts.total and (opts.mult['type'] != 'percentage'):
            # if total was set - divide it between the ports
            opts.mult['value'] = opts.mult['value'] / len(opts.ports)

        return self.cmd_start(opts.ports, stream_list, opts.mult, opts.force, opts.duration, opts.dry)
    def cmd_pause_line(self, line):
        '''Pause active traffic in specified ports on TRex\n'''
        parser = parsing_opts.gen_parser(self, "pause",
                                         self.cmd_stop_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line parameters")

        return self.cmd_pause(opts.ports)
    def cmd_pause_line (self, line):
        '''Pause active traffic in specified ports on TRex\n'''
        parser = parsing_opts.gen_parser(self,
                                         "pause",
                                         self.cmd_stop_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line parameters")

        return self.cmd_pause(opts.ports)
    def cmd_clear_line(self, line):
        '''Clear cached local statistics\n'''
        # define a parser
        parser = parsing_opts.gen_parser(self, "clear",
                                         self.cmd_clear_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")
        return self.cmd_clear(opts.ports)
    def cmd_validate_line(self, line):
        '''validates port(s) stream configuration\n'''

        parser = parsing_opts.gen_parser(self, "validate",
                                         self.cmd_validate_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line paramters")

        rc = self.cmd_validate(opts.ports)
        return rc
    def cmd_clear_line (self, line):
        '''Clear cached local statistics\n'''
        # define a parser
        parser = parsing_opts.gen_parser(self,
                                         "clear",
                                         self.cmd_clear_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")
        return self.cmd_clear(opts.ports)
    def cmd_validate_line (self, line):
        '''validates port(s) stream configuration\n'''

        parser = parsing_opts.gen_parser(self,
                                         "validate",
                                         self.cmd_validate_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line paramters")

        rc = self.cmd_validate(opts.ports)
        return rc
    def cmd_start_line(self, line):
        '''Start selected traffic in specified ports on TRex\n'''
        # define a parser
        parser = parsing_opts.gen_parser(
            self, "start", self.cmd_start_line.__doc__,
            parsing_opts.PORT_LIST_WITH_ALL, parsing_opts.TOTAL,
            parsing_opts.FORCE, parsing_opts.STREAM_FROM_PATH_OR_FILE,
            parsing_opts.DURATION, parsing_opts.MULTIPLIER_STRICT,
            parsing_opts.DRY_RUN)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")

        if opts.dry:
            print format_text("\n*** DRY RUN ***", 'bold')

        if opts.db:
            stream_list = self.streams_db.get_stream_pack(opts.db)
            rc = RC(stream_list != None)
            rc.annotate("Load stream pack (from DB):")
            if rc.bad():
                return RC_ERR("Failed to load stream pack")

        else:
            # load streams from file
            stream_list = None
            try:
                stream_list = self.streams_db.load_yaml_file(opts.file[0])
            except Exception as e:
                s = str(e)
                rc = RC_ERR(s)
                rc.annotate()
                return rc

            rc = RC(stream_list != None)
            rc.annotate("Load stream pack (from file):")
            if stream_list == None:
                return RC_ERR("Failed to load stream pack")

        # total has no meaning with percentage - its linear
        if opts.total and (opts.mult['type'] != 'percentage'):
            # if total was set - divide it between the ports
            opts.mult['value'] = opts.mult['value'] / len(opts.ports)

        return self.cmd_start(opts.ports, stream_list, opts.mult, opts.force,
                              opts.duration, opts.dry)
    def cmd_connect_line(self, line):
        '''Connects to the TRex server'''
        # define a parser
        parser = parsing_opts.gen_parser(self, "connect",
                                         self.cmd_connect_line.__doc__,
                                         parsing_opts.FORCE)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")

        if opts.force:
            rc = self.cmd_connect(mode="RWF")
        else:
            rc = self.cmd_connect(mode="RW")
    def cmd_connect_line (self, line):
        '''Connects to the TRex server'''
        # define a parser
        parser = parsing_opts.gen_parser(self,
                                         "connect",
                                         self.cmd_connect_line.__doc__,
                                         parsing_opts.FORCE)

        opts = parser.parse_args(line.split())

        if opts is None:
            return RC_ERR("bad command line parameters")

        if opts.force:
            rc = self.cmd_connect(mode = "RWF")
        else:
            rc = self.cmd_connect(mode = "RW")
    def cmd_update_line(self, line):
        '''Update port(s) speed currently active\n'''
        parser = parsing_opts.gen_parser(self, "update",
                                         self.cmd_update_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL,
                                         parsing_opts.MULTIPLIER,
                                         parsing_opts.TOTAL)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line paramters")

        # total has no meaning with percentage - its linear
        if opts.total and (opts.mult['type'] != 'percentage'):
            # if total was set - divide it between the ports
            opts.mult['value'] = opts.mult['value'] / len(opts.ports)

        return self.cmd_update(opts.ports, opts.mult)
    def cmd_wait_line (self, line):
        '''wait for a period of time\n'''

        parser = parsing_opts.gen_parser(self,
                                         "wait",
                                         self.cmd_wait_line.__doc__,
                                         parsing_opts.DURATION)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line parameters")

        delay_sec = opts.duration if (opts.duration > 0) else 1

        print format_text("Waiting for {0} seconds...\n".format(delay_sec), 'bold')
        time.sleep(delay_sec)

        return RC_OK()
    def cmd_wait_line(self, line):
        '''wait for a period of time\n'''

        parser = parsing_opts.gen_parser(self, "wait",
                                         self.cmd_wait_line.__doc__,
                                         parsing_opts.DURATION)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line parameters")

        delay_sec = opts.duration if (opts.duration > 0) else 1

        print format_text("Waiting for {0} seconds...\n".format(delay_sec),
                          'bold')
        time.sleep(delay_sec)

        return RC_OK()
    def cmd_update_line (self, line):
        '''Update port(s) speed currently active\n'''
        parser = parsing_opts.gen_parser(self,
                                         "update",
                                         self.cmd_update_line.__doc__,
                                         parsing_opts.PORT_LIST_WITH_ALL,
                                         parsing_opts.MULTIPLIER,
                                         parsing_opts.TOTAL)

        opts = parser.parse_args(line.split())
        if opts is None:
            return RC_ERR("bad command line paramters")

        # total has no meaning with percentage - its linear
        if opts.total and (opts.mult['type'] != 'percentage'):
            # if total was set - divide it between the ports
            opts.mult['value'] = opts.mult['value'] / len(opts.ports)

        return self.cmd_update(opts.ports, opts.mult)
    def do_events(self, line):
        """shows events recieved from server\n"""

        x = parsing_opts.ArgumentPack(
            ["-c", "--clear"], {"action": "store_true", "default": False, "help": "clear the events log"}
        )

        parser = parsing_opts.gen_parser(self, "events", self.do_events.__doc__, x)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        events = self.stateless_client.get_events()
        for ev in events:
            print ev

        if opts.clear:
            self.stateless_client.clear_events()
            print format_text("\n\nEvent log was cleared\n\n")
Beispiel #25
0
    def do_events(self, line):
        '''shows events recieved from server\n'''

        x = parsing_opts.ArgumentPack(
            ['-c', '--clear'], {
                'action': "store_true",
                'default': False,
                'help': "clear the events log"
            })

        parser = parsing_opts.gen_parser(self, "events",
                                         self.do_events.__doc__, x)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        events = self.stateless_client.get_events()
        for ev in events:
            print ev

        if opts.clear:
            self.stateless_client.clear_events()
            print format_text("\n\nEvent log was cleared\n\n")
Beispiel #26
0
    def do_events (self, line):
        '''shows events recieved from server\n'''

        x = parsing_opts.ArgumentPack(['-c','--clear'],
                                      {'action' : "store_true",
                                       'default': False,
                                       'help': "clear the events log"})

        parser = parsing_opts.gen_parser(self,
                                         "events",
                                         self.do_events.__doc__,
                                         x)

        opts = parser.parse_args(line.split())
        if opts is None:
            return

        events = self.stateless_client.get_events()
        for ev in events:
            print ev

        if opts.clear:
            self.stateless_client.clear_events()
            print format_text("\n\nEvent log was cleared\n\n")