📄 rstp_cli.c
字号:
#include <cli.h>
#include <cli_str.h>
#include "mod_flag.h"
#include "Base.h"
#include "../switch/br_private.h"
#include "Uid_stp.h"
#include "stp_in.h"
#define DescStringCommonShow "Show running system information \n"
#define DescStringCommonConfig "Config system's setting.\n"
/*#define BEGIN_PARSE_PORT_LIST(portlist,portno) {short _slotno,_no1,_no2,_i,tmpno; unsigned int _index;char *_cur,*_p,*_p1; char _tmp[20],_tmp1[20],_tmp2[20],_tmp_before_sub[20],cslot,cportsel ; _cur = portlist; while (_cur){bzero(_tmp,20);bzero(_tmp1,20);bzero(_tmp2,20);bzero(_tmp_before_sub,20);_slotno = 0;_no1 = 0;_no2 = 0;_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;_slotno = atoi(_tmp1);portno = atoi(_p1);cslot=_slotno&0xff;cportsel=portno&0xff;portno=xdsl_slotport2port(&_index,cslot,cportsel);}else{portno = -1; }_no1 = portno;}{_p1 = strchr(_p,':');if(_p1){strncpy(_tmp2,_p,_p1 - _p);_p1 = _p1 + 1;_slotno = atoi(_tmp2); portno = atoi(_p1);cslot=_slotno&0xff;cportsel=portno&0xff;portno=xdsl_slotport2port(&_index,cslot,cportsel); }else{portno = -1;}_no2 = portno;}} else{_p1 = strchr(_tmp,':'); if(_p1){strncpy(_tmp1,_tmp,_p1 - _tmp); _p1 = _p1 + 1; _slotno = atoi(_tmp1); portno = atoi(_p1);cslot=_slotno&0xff; cportsel=portno&0xff;portno=xdsl_slotport2port(&_index,cslot,cportsel);}else {portno = -1;} _no1 = portno;_no2 = portno; }if (_no1 > _no2){ tmpno = _no1; _no1 = _no2; _no2 = tmpno;}if(_no1 == -1||_no2 == -1){_no2 = -1;_no1 = -1;}for(_i = _no1; _i<=_no2; _i++){portno = _i;
#define END_PARSE_PORT_LIST() if(1==_i)_i+=15;} } }*/
#define BEGIN_PARSE_PORT_LIST(portlist,portno){short _slotno,_no1,_no2,_i,tmpno,cportsel; unsigned int _index;char *_cur,*_p,*_p1; char _tmp[20],_tmp1[20],_tmp2[20],_tmp_before_sub[20],cslot ; _cur = portlist; while (_cur){bzero(_tmp,20);bzero(_tmp1,20);bzero(_tmp2,20);bzero(_tmp_before_sub,20);_slotno = 0;_no1 = 0;_no2 = 0;_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;_slotno = atoi(_tmp1);portno = atoi(_p1);cslot=translateslot_in(_slotno&0xff);cportsel=portno&0xffff;portno=xdsl_slotport2port(&_index,cslot,cportsel);}else{portno = -1; }_no1 = portno;}{_p1 = strchr(_p,':');if(_p1){strncpy(_tmp2,_p,_p1 - _p);_p1 = _p1 + 1;_slotno = atoi(_tmp2); portno = atoi(_p1);cslot=translateslot_in(_slotno&0xff);cportsel=portno&0xffff;portno=xdsl_slotport2port(&_index,cslot,cportsel); }else{portno = -1;}_no2 = portno;}} else{_p1 = strchr(_tmp,':'); if(_p1){strncpy(_tmp1,_tmp,_p1 - _tmp); _p1 = _p1 + 1; _slotno = atoi(_tmp1); portno = atoi(_p1);cslot=translateslot_in(_slotno&0xff); cportsel=portno&0xffff;portno=xdsl_slotport2port(&_index,cslot,cportsel);}else {portno = -1;} _no1 = portno;_no2 = portno; }if (_no1 > _no2){ tmpno = _no1; _no1 = _no2; _no2 = tmpno;}if(_no1 == -1||_no2 == -1){_no2 = -1;_no1 = -1;}for(_i = _no1; _i<=_no2; _i++){portno = _i;
#define END_PARSE_PORT_LIST() if(1==_i)_i+=15;} } }
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;
int rstp_init()
{
set_rstp_enable();
set_rstp_disable();
}
DEFUN (ConfigRstp_Func,
ConfigRstp_CMD,
"set rstp [enable|disable]",
"Set rstp on or off.\n" "Config rstp related information.\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>}*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>" ,
DescStringCommonConfig
"Config rstp information.\n"
/*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"*/
"Input priority value, the range is 0 to 65,535, default is 32,768.\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>" ,
DescStringCommonConfig
"Config rstp information.\n"
/*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"*/
"Input max age value, the range is 6 to 40. the default is 20 seconds.\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>" ,
DescStringCommonConfig
/*DescStringCommonConfigDefaultSTPD liling 2002-02-10 省去了DEFALT 参数*/
"Config rstp information.\n"
"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"*/
"Please input forward delay value, the range is 4 to 30. the default 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>" ,
DescStringCommonConfig
"Config rstp information.\n"
/*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]",
DescStringCommonConfig
"Config rstp information.\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]",
DescStringCommonConfig
"Config rstp information.\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();
}
#ifdef _CTC_
DEFUN(RstpPortCost_func, RstpPortCost_CMD,"set rstp port <portlist> pathcost <1-200000000>",
DescStringCommonConfig "set rstp information.\n" "set rstp port information.\n" "Please input the portlist.\n" "set pathcost information.\n" "Please input the pathcost.\n")
{
return cli_prt_pcost(argc, argv);
}
int cli_prt_pcost (int argc, char** argv)
{
unsigned long value = 128;
unsigned short portno;
value = atoi(argv[1]);
BEGIN_PARSE_PORT_LIST(argv[0], portno)
{
if (is_port_uplink_port(portno) ==1)
{
set_rstp_port_cfg_value (portno, value, PT_CFG_COST);
}
}END_PARSE_PORT_LIST();
taskDelay(30);
/*printf("Port_Disable(1,%d);",portno-13);*/
for (portno = 18;portno<=24;portno++)
{
if (rstp_port_role_get(portno) ==3)
{
Port_Disable(1,portno-13);
taskDelay(100);
/*printf("Port_Enable(1,%d\r\n);",portno-13);*/
Port_Enable(1,portno-13);
}
}
}
DEFUN(RstpPortPriority_func, RstpPortPriority_CMD,"set rstp port <portlist> priority <0-240>",
DescStringCommonConfig "set rstp information.\n" "set rstp port information.\n" "Please input the portlist.\n" "set priority information.\n" "Please input the prority.\n")
{
return cli_prt_prio (argc, argv);
}
int cli_prt_prio(char argc,char **argv)
{
unsigned long value = 128;
unsigned short portno;
value = atoi(argv[1]);
BEGIN_PARSE_PORT_LIST(argv[0], portno)
{
if (is_port_uplink_port(portno) ==1)
{
printf("portno = %d,value = %d\r\n",portno,value);
set_rstp_port_cfg_value (portno, value, PT_CFG_PRIO);
}
}END_PARSE_PORT_LIST();
return 0;
}
int get_rstp_port_cfg_value(char portno,short *priority,int *port_cost)
{
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;
#ifdef _BP5116_02_
char slot;
short slot_port;
#else
char slot,slot_port;
#endif
struct net_bridge *br;
struct net_bridge_port * port;
port = br_get_port_byno(portno);
if(!port)
{
/* vty_out(vty,"port:%d not created \r\n",port_no);*/
return -1;
}
br = port->br;
rc = STP_IN_stpm_get_state (br, &uid_state);
if (rc)
{
return -1;
}
uid_port.port_no = port->port_no;
rc = STP_IN_port_get_state (port, &uid_port);
if (rc)
{
return -1;
}
memset (&uid_cfg, 0, sizeof (UID_STP_PORT_CFG_T));
rc = STP_IN_port_get_cfg (port, &uid_cfg);
if (rc)
{
return -1;
}
xdsl_port2slotport (portno, &slot, &slot_port);
slot = translateslot_out(slot);
*port_cost = uid_port.oper_port_path_cost;
*priority = (short)(uid_port.port_id>>8);
}
#endif
#if 1
int set_rstp_enable (int argc, char **argv)
#endif
{
UID_STP_CFG_T uid_cfg;
int rc;
struct net_bridge *this = /*bridge_list;*/ br_get_byname("default");/*modified by wl 2007-8-3*/
/*if (this->stp_enabled)
{
return -1;
}*/
uid_cfg.field_mask = BR_CFG_STATE;
uid_cfg.stp_enabled = STP_ENABLED;
/*printf("wl_debug:set_rstp_enable.\r\n");*/
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;
}
#if 1
int set_rstp_disable (int argc, char **argv)
#endif
{
UID_STP_CFG_T uid_cfg;
int rc;
int i;
/*printf("wl_debug,00000000000000000000000000000\r\n");*/
uid_cfg.field_mask = BR_CFG_STATE;
uid_cfg.stp_enabled = STP_DISABLED;
rc = STP_IN_stpm_disable_cfg( &uid_cfg);
/*printf("wl_debug,11111111111111111111111\r\n");*/
if (rc )
{
mn_fd_printf(cl_serv_console_fd,"meet error when you disable rstp\r\n");
}
for (i = 18;i<=24;i++)
{
driver_setportstpstate(i,4);
}
/*printf("wl_debug,222222222222222222222222\r\n");*/
return 0;
}
int set_rstp_disable1 (int argc, char **argv)
{
UID_STP_CFG_T uid_cfg;
int rc;
int i;
/*printf("wl_debug,12345\r\n");*/
uid_cfg.field_mask = BR_CFG_STATE;
uid_cfg.stp_enabled = STP_DISABLED;
rc = STP_IN_stpm_disable_cfg( &uid_cfg);
/*printf("wl_debug,11111111111111111111111\r\n");*/
if (rc )
{
mn_fd_printf(cl_serv_console_fd,"meet error when you disable rstp\r\n");
}
/* set_port_forwarding();*/
/*printf("wl_debug,222222222222222222222222\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;
#ifdef _BP5116_02_
char slot;
short slot_port;
#else
char slot,slot_port;
#endif
/*this = bridge_list;*/
this = br_get_byname("default");/*modified by wl 2007-8-3*/
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)
{
xdsl_port2slotport(uid_state.root_port&0xff,&slot,&slot_port);
/*vty_out (vty,"Root Port : %d:%d \r\n",
(unsigned long) uid_state.root_port&0xff);
*/
vty_out (vty,"Root Port : %d:%d \r\n",translateslot_out(slot),slot_port);
/*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;
}
static int CheckPortListValid (char *portlist, struct vty *vty)
{
int i, len = strlen (portlist);
char *cur;
short portno;
struct net_bridge_port *p;
int j, portno_num = 0;
short portno_list[MAXPortNum];
if (len < 1)
return 0;
for (j = 0; j < MAXPortNum; j++)
{
portno_list[j] = 0;
}
/* all char is 0-9 , - : */
cur = portlist;
for (i = 0; i < len; i++)
{
#if (_deep_bluelight_ | _xdsl_)
if (!(((*(cur + i) >= '0') && (*(cur + i) <= '9')) ||
(*(cur + i) == ',') || (*(cur + i) == '-') ||
(*(cur + i) == ':')))
return 0;
#else
#ifdef _lightsun_bluelight_
if (!(((*(cur + i) >= '0') && (*(cur + i) <= '9')) ||
(*(cur + i) == ',') || (*(cur + i) == '-')))
return 0;
#endif
#endif
}
/*BEGIN_PARSE_PORT_LIST (portlist, portno) */
/**/
{
short _slotno, _no1, _no2, _i, tmpno;
unsigned int _index;
char *_cur, *_p, *_p1;
char _tmp[20], _tmp1[20], _tmp2[20], _tmp_before_sub[20], cslot;
unsigned short cportsel;
_cur = portlist;
while (_cur)
{
bzero (_tmp, 20);
bzero (_tmp1, 20);
bzero (_tmp2, 20);
bzero (_tmp_before_sub, 20);
_slotno = 0;
_no1 = 0;
_no2 = 0;
_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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -