📄 rstp_cli.~c
字号:
#include <nos_cli.h>
#include "nos_mod_flag.h"
#include <nos_syslog.h>
#include "Base.h"
#include "../stp/eth_br_private.h"
#include "Uid_stp.h"
#define DescStringCommonShow "Show running system information \n"
#define BEGIN_PARSE_PORT_LIST(portlist,portno) { short _devno,_no1,_no2,_i,tmpno; char *_cur,*_p,*_p1; char _tmp[20],_tmp1[20],_tmp2[20],_tmp_before_sub[20]; _cur = portlist; while (_cur) { bzero(_tmp,20); bzero(_tmp1,20); bzero(_tmp2,20); bzero(_tmp_before_sub,20); _p = strchr(_cur,','); if(_p) { strncpy(_tmp,_cur,_p - _cur); _cur = _p + 1; } else { strcpy(_tmp,_cur); _cur = NULL; } _p = strchr(_tmp,'-'); if (_p) { strncpy(_tmp_before_sub,_tmp,_p - _tmp); _p = _p +1; { _p1 = strchr(_tmp_before_sub,':'); if(_p1) { strncpy(_tmp1,_tmp_before_sub,_p1 - _tmp_before_sub); _p1 = _p1 + 1; _devno = atoi(_tmp1); portno = atoi(_p1); portno = getportno(_devno,portno); } else { portno = atoi(_tmp_before_sub); } _no1 = portno; } { _p1 = strchr(_p,':'); if(_p1) { strncpy(_tmp2,_p,_p1 - _p); _p1 = _p1 + 1; _devno = atoi(_tmp2); portno = atoi(_p1); portno = getportno(_devno,portno); } else { portno = atoi(_p); } _no2 = portno; } } else { _p1 = strchr(_tmp,':'); if(_p1) { strncpy(_tmp1,_tmp,_p1 - _tmp); _p1 = _p1 + 1; _devno = atoi(_tmp1); portno = atoi(_p1); portno = getportno(_devno,portno); } else { portno = atoi(_tmp); } _no1 = portno; _no2 = portno; } if (_no1 > _no2) { tmpno = _no1; _no1 = _no2; _no2 = tmpno; } for(_i = _no1; _i<=_no2; _i++) { portno = _i;
#define END_PARSE_PORT_LIST() } } }
typedef struct {
/* service data */
unsigned long field_mask; /* which fields to change */
char vlan_name[NAME_LEN]; /* name of the VLAN, key of the bridge */
/* protocol data */
int port_priority;
unsigned long admin_port_path_cost; /* ADMIN_PORT_PATH_COST_AUTO - auto sence */
ADMIN_P2P_T admin_point2point;
unsigned char admin_edge;
unsigned char admin_non_stp; /* 1- doesn't participate in STP, 1 - regular */
#ifdef STP_DBG
unsigned int skip_rx;
unsigned int skip_tx;
#endif
} UID_STP_PORT_CFG_T;
char g_detail = 0;
DEFUN (ConfigRstp_Func,
ConfigRstp_CMD,
"rstp [enable|disable]",
"Set rstp on or off.\n" "Enable rstp.\n" "Disable rstp \n"
)
{
if (strcmp ("enable", argv[0]) == 0)
set_rstp_enable();
else
set_rstp_disable();
}
DEFUN(ShowRstp_Func,
ShowRstp_CMD,
"show rstp {port [<portlist>|all]}*1" ,
DescStringCommonShow
"Display RSTP information.\n"
"Display port-specific STP information.\n"
"Display input the port number list which you want to display.\n"
"Display all ports in the system.\n" )
{
if(argc == 0)
return show_rstp_br(NULL,vty);
else if(argc == 1)
return show_rstp_port(argv[0],vty);
else
return -1;
}
DEFUN(ConfigRstpBridgePriority_Func,
ConfigRstpBridgePriority_CMD,
"set rstp priority <0-65535>" ,
DescStringCommonShow
/*DescStringCommonConfigDefaultSTPD liling 2002-02-10 省去了DEAULT参数*/
"Specifies the priority of this STPD. \n"
"Input priority value, the range is 0 through 65,535, the default setting is 32,768. A setting of 0 indicates the highest priority.\n")
{
if(argc !=1)
return -1;
else
{
set_bridge_cfg_value (atoi(argv[0]), BR_CFG_PRIO,vty);
return;
}
}
/* liling 2002-02-10 修改命令的显示 */
DEFUN(ConfigRstpBridgeMaxAge_Func,
ConfigRstpBridgeMaxAge_CMD,
"set rstp maxage <6-40>" ,
DescStringCommonShow
/*DescStringCommonConfigDefaultSTPD liling 2002-02-10 省去了DEFAULT参数*/
"Specifies the maximum age of a BPDU in this STPD.\n"
"Input max age value, the range is 6 through 40. the default setting is 20 seconds.Note that the time must be greater than, or equal to 2 * (Hello Time + 1) and less than, or equal to 2 * (Forward Delay –1).\n")
{
if(argc !=1)
return -1;
else
{
set_bridge_cfg_value (atoi(argv[0]), BR_CFG_AGE,vty);
return;
}
}
DEFUN(ConfigRstpBridgeForwarddelay_Func,
ConfigRstpBridgeForwarddelay_CMD,
"set rstp forwarddelay <4-30>" ,
DescStringCommonShow
/*DescStringCommonConfigDefaultSTPD liling 2002-02-10 省去了DEFALT 参数*/
"Specifies the forwarddelay of this STPD.\n"
"Please input forward delay value, the range is 4 through 30. the default setting is 15 seconds..\n")
{
if(argc !=1)
return -1;
else
{
set_bridge_cfg_value (atoi(argv[0]), BR_CFG_DELAY,vty);
return;
}
}
/* liling 2002-02-10 修改命令的显示 */
DEFUN(ConfigRstpBridgeHelloTime_Func,
ConfigRstpBridgeHelloTime_CMD,
"set rstp hellotime <1-10>" ,
DescStringCommonShow
/*DescStringCommonConfigDefaultSTPD liling 2002-02-10 省去了DEFAULT参数*/
"Specifies the hellotime of this STPD.\n"
"Input hello time value, the range is 1 through 10. the default setting is 2 seconds. .\n")
{
int time = atoi(argv[0]);
if(argc !=1)
return -1;
else
{
set_bridge_cfg_value (time, BR_CFG_HELLO,vty);
return;
}
}
DEFUN (ConfigRstp_ForceVersionFunc,
ConfigRstp_ForceVersion_CMD,
"set rstp forceversion [rapid|slow]",
"Set rstp on or off.\n" "Enable rstp.\n" "Disable rstp \n"
)
{
if (strcmp ("rapid", argv[0]) == 0)
set_bridge_cfg_value (2L, BR_CFG_FORCE_VER);
else
set_bridge_cfg_value (0L, BR_CFG_FORCE_VER);
}
DEFUN (ConfigRstp_PortDetailFunc,
ConfigRstp_PortDetail_CMD,
"rstp port show detail [enable|disable]",
"Set rstp on or off.\n" "Enable rstp.\n" "Disable rstp \n"
)
{
if (strcmp ("enable", argv[0]) == 0)
g_detail = 1;
else
g_detail = 0;
}
DEFUN(RstpOneSecond_Func,
RstpOneSecond_CMD,
"one second" ,
DescStringCommonShow
"time pass one second.\n" )
{
STP_IN_one_second();
}
static int set_rstp_enable (int argc, char **argv)
{
UID_STP_CFG_T uid_cfg;
int rc;
struct net_bridge *this = bridge_list;
if (this->stp_enabled)
{
return;
}
uid_cfg.field_mask = BR_CFG_STATE;
uid_cfg.stp_enabled = STP_ENABLED;
rc = STP_IN_stpm_set_cfg (&uid_cfg,0);
if (rc)
{
/* printf ("can't enable: %s\n", STP_IN_get_error_explanation (rc));*/
}
return 0;
}
static int set_rstp_disable (int argc, char **argv)
{
UID_STP_CFG_T uid_cfg;
int rc;
uid_cfg.field_mask = BR_CFG_STATE;
uid_cfg.stp_enabled = STP_DISABLED;
rc = STP_IN_stpm_disable_cfg( &uid_cfg);
if (rc )
{
mn_fd_printf(cl_serv_console_fd,"meet error when you disable rstp\r\n");
}
return 0;
}
static int show_rstp_br (char* portlist, struct vty * vty)
{
UID_STP_STATE_T uid_state;
UID_STP_CFG_T uid_cfg;
int rc;
struct net_bridge *this;
this = bridge_list;
if(!this)
{
vty_out(vty,"bridge %s not exist?\r\n","default");
return 0;
}
if( STP_ENABLED != this->admin_state )
{
vty_out(vty,"Bridge Rapid Spanning Tree Protocol is disabled \r\n");
return 0;
}
rc = STP_IN_stpm_get_state (this, &uid_state);
if (rc)
{
/*printf ("can't get rstp bridge state: %s\n",
STP_IN_get_error_explanation (rc));*/
return 0;
}
rc = STP_IN_stpm_get_cfg ( &uid_cfg);
if (rc)
{
/*printf ("can't get rstp bridge configuration: %s\n",
STP_IN_get_error_explanation (rc));*/
return 0;
}
vty_out(vty," RSTP Domain default information\r\n" );
vty_out(vty,"----------------------------------------------------------------\r\n");
vty_out(vty,"\r\n");
vty_out(vty,"-- Bridge Info --\r\n");
print_bridge_id (&uid_state.bridge_id, 0,vty);
if (uid_cfg.force_version < 2)
{
vty_out (vty,"Force Version : stp\r\n");
}
vty_out (vty,"Bridge Max Age : %2d\r\n", (int) uid_cfg.max_age);
vty_out (vty,"Bridge Hello Time : %2d\r\n",(int) uid_cfg.hello_time);
vty_out (vty,"Bridge Forward Delay : %2d\r\n",(int) uid_cfg.forward_delay);
vty_out (vty,"Hold Time : %2d\r\n", (int) uid_cfg.hold_time);
vty_out (vty,"\r\n");
vty_out (vty,"-- Designated Root --\r\n");
print_bridge_id (&uid_state.designated_root, 1,vty);
if (uid_state.root_port)
{
vty_out (vty,"Root Port : %04d \r\n",
(unsigned long) uid_state.root_port&0xff);
/*CLI_out_port_id (uid_state.root_port & 0xfff, False);*/
/* vty_out (vty,"), Root Cost : %-lu\r\n",
(unsigned long) uid_state.root_path_cost);*/
}
else
{
vty_out (vty,"Root Port : none\r\n");
}
if (uid_state.Topo_Change)
vty_out (vty,"Topology Change Count : %lu\r\n", uid_state.Topo_Change_Count);
else
vty_out (vty,"Time Since Topology Change : %lu\r\n",
uid_state.timeSince_Topo_Change);
vty_out (vty,"Max Age : %2d\r\n",(int) uid_state.max_age);
vty_out (vty,"Hello Time : %2d\r\n",(int) uid_state.hello_time);
vty_out (vty,"Forward Delay : %2d\r\n",(int) uid_state.forward_delay);
return 0;
}
int show_rstp_port(char* portlist, struct vty * vty)
{
char detail;
short portno;
struct net_bridge_port * p;
if(strcmp(portlist,"all"))
{
if(!CheckPortListValid(portlist,vty))
{
if(vty)
vty_out(vty,"Invalid Port List <%s> \r\n",portlist);
return -1;
}
detail = 0;
BEGIN_PARSE_PORT_LIST(portlist,portno)
{
/*gprintportstp(portno,vty);*/
show_rstp_port_detail(portno, g_detail,vty);
}END_PARSE_PORT_LIST();
}
else
{
BEGGIN_PARSE_ALL_PORT(p)
{
/*gprintportstp(p->port_no,vty);*/
show_rstp_port_detail(p->port_no, g_detail,vty);
}END_PARSE_ALL_PORT(p);
}
return 0;
}
static void show_rstp_port_detail_old (short port_no, int detail,struct vty *vty)
{
UID_STP_STATE_T uid_state;
UID_STP_PORT_STATE_T uid_port;
UID_STP_PORT_CFG_T uid_cfg;
int port_index;
int rc;
struct net_bridge *br;
struct net_bridge_port * port;
port = br_get_port_byno(port_no);
if(!port)
{
vty_out(vty,"port:%d not created \r\n",port_no);
return;
}
br = port->br;
rc = STP_IN_stpm_get_state (br, &uid_state);
if (rc)
{
/*printf ("can't get rstp bridge state: %s\n",
STP_IN_get_error_explanation (rc));
*/
}
/*else if (!detail)
{
vty_out (vty,"BridgeId:\r\n ");
print_bridge_id (&uid_state.bridge_id, 0,vty);
vty_out (vty,"RootId:\r\n ");
print_bridge_id (&uid_state.designated_root, 1,vty);
}
*/
uid_port.port_no = port->port_no;
rc = STP_IN_port_get_state (port, &uid_port);
if (rc)
{
/* printf ("can't get rstp port state: %s\n",STP_IN_get_error_explanation (rc));*/
return;
}
memset (&uid_cfg, 0, sizeof (UID_STP_PORT_CFG_T));
rc = STP_IN_port_get_cfg (port, &uid_cfg);
if (rc)
{
/* printf ("can't get rstp port config: %s\n",
STP_IN_get_error_explanation (rc));*/
return ;
}
vty_out(vty,"---------------------------------------------------------------------------\r\n");
vty_out(vty," Port:%d 's RSTP Information \r\n",port_no);
if (detail)
{
/*vty_out (vty,"Stp Port\r\n ");*/
/*CLI_out_port_id (port_index, False);*/
#if 0
printf (": PortId: %04lx in vlan '%s' with tag %d:\n",
(unsigned long) uid_port.port_id, uid_state.vlan_name,
(int) uid_state.vlan_id);
#else
/* vty_out (vty,"PortId: %04lx in Bridge '%s':\r\n",
(unsigned long) uid_port.port_id, uid_state.vlan_name);*/
#endif
vty_out (vty,"Priority: %-d\r\n", (int) (uid_port.port_id >> 8));
vty_out (vty,"State: %-16s", stp_state2str (uid_port.state,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -