def do_no_static_route(self, line):
     """Removes IPv4 static route configuration from all non-duplicated interfaces"""
     try:
         self.platform.config_no_static_routing()
         print termstyle.green("IPv4 static routing configuration removed successfully.")
     except UserWarning as inst:
         print termstyle.magenta(inst)
 def do_show_cpu_util(self, line):
     """Fetches CPU utilization stats from the platform"""
     try: 
         print self.platform.get_cpu_util()
         print termstyle.green("*** End of show_cpu_util output ***")
     except PlatformResponseMissmatch as inst:
         print termstyle.magenta(inst)
 def do_show_nat_cfg (self, line):
     """Outputs the loaded nat provided configuration"""
     try:
         self.platform.dump_obj_config('nat')
         print termstyle.green("*** End of nat configuration ***")
     except UserWarning as inst:
         print termstyle.magenta(inst)
Example #4
0
 def do_show_nat_cfg(self, line):
     """Outputs the loaded nat provided configuration"""
     try:
         self.platform.dump_obj_config('nat')
         print termstyle.green("*** End of nat configuration ***")
     except UserWarning as inst:
         print termstyle.magenta(inst)
Example #5
0
 def do_show_static_route_cfg(self, line):
     """Outputs the loaded static route configuration"""
     try:
         self.platform.dump_obj_config('static_route')
         print termstyle.green("*** End of static route configuration ***")
     except UserWarning as inst:
         print termstyle.magenta(inst)
Example #6
0
 def do_show_nbar_stats(self, line):
     """Fetches NBAR classification stats from the platform.\nStats are available both as raw data and as percentage data."""
     try:
         print self.platform.get_nbar_stats()
         print termstyle.green("*** End of show_nbar_stats output ***")
     except PlatformResponseMissmatch as inst:
         print termstyle.magenta(inst)
 def do_show_static_route_cfg (self, line):
     """Outputs the loaded static route configuration"""
     try:
         self.platform.dump_obj_config('static_route')
         print termstyle.green("*** End of static route configuration ***")
     except UserWarning as inst:
         print termstyle.magenta(inst)
Example #8
0
 def do_show_cpu_util(self, line):
     """Fetches CPU utilization stats from the platform"""
     try:
         print self.platform.get_cpu_util()
         print termstyle.green("*** End of show_cpu_util output ***")
     except PlatformResponseMissmatch as inst:
         print termstyle.magenta(inst)
Example #9
0
    def __init__(self,
                 cfg_yaml_path=None,
                 silent_mode=False,
                 virtual_mode=False):
        #       super(InteractivePlatform, self).__init__()
        cmd.Cmd.__init__(self)
        self.virtual_mode = virtual_mode
        self.platform = CPlatform(silent_mode)
        if cfg_yaml_path is None:
            try:
                cfg_yaml_path = raw_input(
                    termstyle.cyan(
                        "Please enter a readable .yaml configuration file path: "
                    ))
                cfg_yaml_path = os.path.abspath(cfg_yaml_path)
            except KeyboardInterrupt:
                exit(-1)
        try:
            self.device_cfg = CDeviceCfg(cfg_yaml_path)
            self.platform.load_platform_data_from_file(self.device_cfg)
            if not virtual_mode:
                # if not virtual mode, try to establish a phyisical connection to platform
                self.platform.launch_connection(self.device_cfg)

        except Exception as inst:
            print termstyle.magenta(inst)
            exit(-1)
Example #10
0
 def do_no_nat(self, arg):
     """Removes NAT configuration from all non-duplicated interfaces"""
     try:
         self.platform.config_no_nat()
         print termstyle.green("NAT configuration removed successfully.")
     except UserWarning as inst:
         print termstyle.magenta(inst)
 def do_no_nat(self, arg):
     """Removes NAT configuration from all non-duplicated interfaces"""
     try: 
         self.platform.config_no_nat()
         print termstyle.green("NAT configuration removed successfully.")
     except UserWarning as inst:
         print termstyle.magenta(inst)
 def do_show_nbar_stats(self, line):
     """Fetches NBAR classification stats from the platform.\nStats are available both as raw data and as percentage data."""
     try:
         print self.platform.get_nbar_stats()
         print termstyle.green("*** End of show_nbar_stats output ***")
     except PlatformResponseMissmatch as inst:
         print termstyle.magenta(inst)
Example #13
0
 def do_no_static_route(self, line):
     """Removes IPv4 static route configuration from all non-duplicated interfaces"""
     try:
         self.platform.config_no_static_routing()
         print termstyle.green(
             "IPv4 static routing configuration removed successfully.")
     except UserWarning as inst:
         print termstyle.magenta(inst)
 def do_load_image (self, arg):
     """Loads a given image filename from tftp server (if not available on disk) and sets it as the boot image on the platform"""
     if arg:
         try:
             self.platform.load_platform_image('asr1001-universalk9.BLD_V155_2_S_XE315_THROTTLE_LATEST_20150324_100047-std.bin')#arg.split(' ')[0])
         except UserWarning as inst:
             print(termstyle.magenta(inst))
     else:
         print(termstyle.magenta("Image filename is missing."))
Example #15
0
 def do_kill_indiscriminately (self, line):
     """Force killing of running TRex process (if exists) on the server."""
     print termstyle.green("*** Starting TRex termination ***")
     ret = self.trex.force_kill()
     if ret:
         print termstyle.green("*** End of scenario (TRex is not running now) ***")
     elif ret is None:
         print termstyle.magenta("*** End of scenario (TRex termination aborted) ***")
     else:
         print termstyle.red("*** End of scenario (TRex termination failed) ***")
 def do_check_image_existence(self, arg):
     """Check if specific image file (usually *.bin) is already stored in platform drive"""
     if arg:
         try: 
             res = self.platform.check_image_existence(arg.split(' ')[0])
             print(res)
             print(termstyle.green("*** Check image existence completed ***"))
         except PlatformResponseAmbiguity as inst:
             print(termstyle.magenta(inst))
     else:
         print(termstyle.magenta("Please provide an image name in order to check for existance."))
Example #17
0
 def do_load_image(self, arg):
     """Loads a given image filename from tftp server (if not available on disk) and sets it as the boot image on the platform"""
     if arg:
         try:
             self.platform.load_platform_image(
                 'asr1001-universalk9.BLD_V155_2_S_XE315_THROTTLE_LATEST_20150324_100047-std.bin'
             )  #arg.split(' ')[0])
         except UserWarning as inst:
             print(termstyle.magenta(inst))
     else:
         print(termstyle.magenta("Image filename is missing."))
Example #18
0
 def do_update_run_params(self, json_str):
     """Updates provided parameters on TRex running configuration. Provide using JSON string"""
     if json_str:
         try:
             upd_params = self.decoder.decode(json_str)
             self.run_params.update(upd_params)
             print termstyle.green("*** End of TRex parameters update ***")
         except ValueError as inst:
             print termstyle.magenta("Provided illegal JSON string. Please try again.\n[", inst,"]")
     else:
         print termstyle.magenta("JSON configuration string is missing. Please try again.")
 def do_switch_cfg (self, cfg_file_path):
     """Switch the current platform interface configuration with another one"""
     if cfg_file_path:
         cfg_yaml_path = os.path.abspath(cfg_file_path)
         self.device_cfg = CDeviceCfg(cfg_yaml_path)
         self.platform.load_platform_data_from_file(self.device_cfg)
         if not self.virtual_mode:
             self.platform.reload_connection(self.device_cfg)
         print termstyle.green("Configuration switching completed successfully.")
     else:
         print termstyle.magenta("Configuration file is missing. Please try again.")
Example #20
0
    def do_push_files (self, filepaths):
        """Pushes a custom file to be stored locally on TRex server.\nPush multiple files by spefiying their path separated by ' ' (space)."""
        try:
            filepaths = filepaths.split(' ')
            print termstyle.green("*** Starting pushing files ({trex_files}) to TRex. ***".format (trex_files = ', '.join(filepaths)) )
            ret_val = self.trex.push_files(filepaths)
            if ret_val:
                print termstyle.green("*** End of TRex push_files method (success) ***")
            else:
                print termstyle.magenta("*** End of TRex push_files method (failed) ***")

        except IOError as inst:
            print termstyle.magenta(inst)
Example #21
0
 def do_poll_once (self, line):
     """Performs a single poll of TRex current data dump (if TRex is running) and prompts and short version of latest result_obj"""
     print termstyle.green("*** Trying TRex single poll ***")
     try:
         last_res = dict()
         if self.trex.is_running(dump_out = last_res):
             obj = self.trex.get_result_obj()
             print obj
         else:
             print termstyle.magenta("TRex isn't currently running.")
         print termstyle.green("*** End of scenario (TRex is posssibly still running!) ***")
     except TRexException as inst:
         print termstyle.red(inst)
 def do_load_clean (self, arg):
     """Loads a clean configuration file onto the platform
     Specify no arguments will load 'clean_config.cfg' file from bootflash disk
     First argument is clean config filename
     Second argument is platform file's disk"""
     if arg:
         in_val = arg.split(' ')
         if len(in_val)==2:
             self.platform.load_clean_config(in_val[0], in_val[1])
         else:
             print termstyle.magenta("One of the config inputs is missing.")
     else:
         self.platform.load_clean_config()
Example #23
0
 def do_switch_cfg(self, cfg_file_path):
     """Switch the current platform interface configuration with another one"""
     if cfg_file_path:
         cfg_yaml_path = os.path.abspath(cfg_file_path)
         self.device_cfg = CDeviceCfg(cfg_yaml_path)
         self.platform.load_platform_data_from_file(self.device_cfg)
         if not self.virtual_mode:
             self.platform.reload_connection(self.device_cfg)
         print termstyle.green(
             "Configuration switching completed successfully.")
     else:
         print termstyle.magenta(
             "Configuration file is missing. Please try again.")
Example #24
0
 def do_load_clean(self, arg):
     """Loads a clean configuration file onto the platform
     Specify no arguments will load 'clean_config.cfg' file from bootflash disk
     First argument is clean config filename
     Second argument is platform file's disk"""
     if arg:
         in_val = arg.split(' ')
         if len(in_val) == 2:
             self.platform.load_clean_config(in_val[0], in_val[1])
         else:
             print termstyle.magenta("One of the config inputs is missing.")
     else:
         self.platform.load_clean_config()
Example #25
0
 def do_check_image_existence(self, arg):
     """Check if specific image file (usually *.bin) is already stored in platform drive"""
     if arg:
         try:
             res = self.platform.check_image_existence(arg.split(' ')[0])
             print res
             print termstyle.green(
                 "*** Check image existence completed ***")
         except PlatformResponseAmbiguity as inst:
             print termstyle.magenta(inst)
     else:
         print termstyle.magenta(
             "Please provide an image name in order to check for existance."
         )
Example #26
0
    def do_run_until_finish (self, sample_rate):
        """Starts TRex and sample server until run is done."""
        print termstyle.green("*** Starting TRex run_until_finish scenario ***")

        if not sample_rate: # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            self.trex.sample_to_run_finish(sample_rate)
            print termstyle.green("*** End of TRex run ***")
        except ValueError as inst:
            print termstyle.magenta("Provided illegal sample rate value. Please try again.\n[", inst,"]")
        except TRexException as inst:
            print termstyle.red(inst)
Example #27
0
    def do_run_until_condition (self, sample_rate):
        """Starts TRex and sample server until condition is satisfied."""
        print termstyle.green("*** Starting TRex run until condition is satisfied scenario ***")

        def condition (result_obj):
                return result_obj.get_current_tx_rate()['m_tx_pps'] > 200000

        if not sample_rate: # use default sample rate if not passed
            sample_rate = 5
        try:
            sample_rate = int(sample_rate)
            ret = self.trex.start_trex(**self.run_params)
            ret_val = self.trex.sample_until_condition(condition, sample_rate)
            print ret_val
            print termstyle.green("*** End of TRex run ***")
        except ValueError as inst:
            print termstyle.magenta("Provided illegal sample rate value. Please try again.\n[", inst,"]")
        except TRexException as inst:
            print termstyle.red(inst)
Example #28
0
 def do_run_and_poll (self, sample_rate):
     """Starts TRex and sample server manually until run is done."""
     print termstyle.green("*** Starting TRex run and manually poll scenario ***")
     if not sample_rate: # use default sample rate if not passed
         sample_rate = 5
     try:
         sample_rate = int(sample_rate)
         ret = self.trex.start_trex(**self.run_params)
         last_res = dict()
         while self.trex.is_running(dump_out = last_res):
             obj = self.trex.get_result_obj()
             if (self.verbose):
                 print obj
             # do WHATEVER here
             time.sleep(sample_rate)
             
         print termstyle.green("*** End of TRex run ***")
     except ValueError as inst:
         print termstyle.magenta("Provided illegal sample rate value. Please try again.\n[", inst,"]")
     except TRexException as inst:
         print termstyle.red(inst)
    def __init__(self, cfg_yaml_path = None, silent_mode = False, virtual_mode = False ):
#       super(InteractivePlatform, self).__init__()
        cmd.Cmd.__init__(self)
        self.virtual_mode   = virtual_mode
        self.platform       = CPlatform(silent_mode)
        if cfg_yaml_path is None:
            try:
                cfg_yaml_path = raw_input(termstyle.cyan("Please enter a readable .yaml configuration file path: "))
                cfg_yaml_path = os.path.abspath(cfg_yaml_path)
            except KeyboardInterrupt:
                exit(-1)
        try:
            self.device_cfg = CDeviceCfg(cfg_yaml_path)
            self.platform.load_platform_data_from_file(self.device_cfg)
            if not virtual_mode:
                # if not virtual mode, try to establish a phyisical connection to platform
                self.platform.launch_connection(self.device_cfg)

        except Exception as inst:
            print termstyle.magenta(inst)
            exit(-1)
Example #30
0
 def stopFactory(self):
     print termstyle.magenta(termstyle.bold('stopping factory'))
     return