@@ -4909,6 +4909,91 @@ def interface(ctx, namespace):
49094909 config_db = ConfigDBConnector (use_unix_socket_path = True , namespace = str (namespace ))
49104910 config_db .connect ()
49114911 ctx .obj = {'config_db' : config_db , 'namespace' : str (namespace )}
4912+
4913+
4914+ @config .group (cls = clicommon .AliasedGroup , name = 'switch-fast-linkup' , context_settings = CONTEXT_SETTINGS )
4915+ @click .pass_context
4916+ def switch_fast_linkup_group (ctx ):
4917+ """Configure fast link-up global configuration parameters"""
4918+ pass
4919+
4920+
4921+ # 'global' subcommand
4922+ @switch_fast_linkup_group .command (name = 'global' )
4923+ @click .option ('--polling-time' , type = int , required = False , help = 'Polling time (sec)' )
4924+ @click .option ('--guard-time' , type = int , required = False , help = 'Guard time (sec)' )
4925+ @click .option ('--ber' , '--ber-threshold' , type = int , required = False , help = 'BER threshold exponent (e.g., 12 for 1e-12)' )
4926+ @clicommon .pass_db
4927+ def switch_fast_linkup_global_cmd (db , polling_time , guard_time , ber ):
4928+ """Configure global fast link-up feature parameters"""
4929+ if polling_time is None and guard_time is None and ber is None :
4930+ raise click .UsageError ('Failed to configure fast link-up global: no options are provided' )
4931+ # Read capability and ranges from STATE_DB for validation
4932+ state_db = db .db .STATE_DB
4933+ cap_tbl = db .db .get_all (state_db , 'SWITCH_CAPABILITY|switch' ) or {}
4934+ if cap_tbl .get ('FAST_LINKUP_CAPABLE' , 'false' ) != 'true' :
4935+ raise click .ClickException ('Fast link-up is not supported on this platform' )
4936+
4937+ poll_range = cap_tbl .get ('FAST_LINKUP_POLLING_TIMER_RANGE' ).split (',' )
4938+ guard_range = cap_tbl .get ('FAST_LINKUP_GUARD_TIMER_RANGE' ).split (',' )
4939+
4940+ data = {}
4941+ if polling_time is not None :
4942+ if not (int (poll_range [0 ]) <= int (polling_time ) <= int (poll_range [1 ])):
4943+ raise click .ClickException ('polling_time {} out of supported range [{}, {}]' .format (
4944+ polling_time , poll_range [0 ], poll_range [1 ]))
4945+ data ['polling_time' ] = str (polling_time )
4946+ if guard_time is not None :
4947+ if not (int (guard_range [0 ]) <= int (guard_time ) <= int (guard_range [1 ])):
4948+ raise click .ClickException ('guard_time {} out of supported range [{}, {}]' .format (
4949+ guard_time , guard_range [0 ], guard_range [1 ]))
4950+ data ['guard_time' ] = str (guard_time )
4951+ if ber is not None :
4952+ if int (ber ) < 1 or int (ber ) > 255 :
4953+ raise click .ClickException ('ber_threshold {} out of supported range [1, 255]' .format (ber ))
4954+ data ['ber_threshold' ] = str (ber )
4955+ try :
4956+ db .cfgdb .mod_entry ('SWITCH_FAST_LINKUP' , 'GLOBAL' , data )
4957+
4958+ log .log_notice ('Configured fast link-up global: {}' .format (data ))
4959+ except Exception as e :
4960+ log .log_error ('Failed to configure fast link-up global: {}' .format (str (e )))
4961+ raise SystemExit (1 )
4962+
4963+
4964+ # 'fast-linkup' subcommand
4965+ @interface .command ('fast-linkup' )
4966+ @click .argument ('interface_name' , metavar = '<interface_name>' , required = True )
4967+ @click .argument (
4968+ 'mode' ,
4969+ metavar = '<enabled|disabled|true|false|on|off>' ,
4970+ required = True ,
4971+ type = click .Choice (['enabled' , 'disabled' , 'true' , 'false' , 'on' , 'off' ])
4972+ )
4973+ @click .option ('-v' , '--verbose' , is_flag = True , help = 'Enable verbose output' )
4974+ @clicommon .pass_db
4975+ def fast_linkup (db , interface_name , mode , verbose ):
4976+ """Enable/disable fast link-up on an interface"""
4977+ config_db = db .cfgdb
4978+
4979+ if clicommon .get_interface_naming_mode () == 'alias' :
4980+ interface_name = interface_alias_to_name (config_db , interface_name )
4981+ if interface_name is None :
4982+ raise click .ClickException ("'interface_name' is None!" )
4983+ if not interface_name_is_valid (config_db , interface_name ):
4984+ raise click .ClickException ('Interface name is invalid. Please enter a valid interface name' )
4985+
4986+ # Read capability from STATE_DB for validation
4987+ state_db = db .db .STATE_DB
4988+ cap_tbl = db .db .get_all (state_db , 'SWITCH_CAPABILITY|switch' ) or {}
4989+ if cap_tbl .get ('FAST_LINKUP_CAPABLE' , 'false' ) != 'true' :
4990+ raise click .ClickException ('Fast link-up is not supported on this platform' )
4991+
4992+ log .log_info ("'interface fast-linkup {} {}' executing..." .format (interface_name , mode ))
4993+ command = ['portconfig' , '-p' , str (interface_name ), '-fl' , str (mode )]
4994+ if verbose :
4995+ command += ['-vv' ]
4996+ clicommon .run_command (command , display_cmd = verbose )
49124997#
49134998# 'startup' subcommand
49144999#
0 commit comments