📄 stp_api.c
字号:
* FUNCTION NAME:stp_set_edgeport_disable
* DESCRIPTION:关闭边缘端口功能。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void stp_set_edgeport_disable(int gport)
{
if(check_gport_valid(gport)&&(edgeport_array[gport-1].port_state))
{
edgeport_array[gport-1].port_state = 0;
stp_set_edgeport_config(gport);
}
else
{
printL("Port has not been setted to edge port state!\n","");
}
}
/****************************************************************************
* FUNCTION NAME:stp_print_edge_port
* DESCRIPTION:打印边缘端口信息。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void stp_print_edge_port(void)
{
int gport;
printL("Edge port map:\n","");
printL("PORT :","");
for(gport=0;gport<24;gport++)
{
printL("%3d","",gport+1);
}
printL("\n","");
printL("VALUE:","");
for(gport=0;gport<24;gport++)
{
printL("%3d","",edgeport_array[gport].port_state);
}
printL("\n","");
printL("VALUE 1:THIS PORT IS EDGEPORT.\n","");
printL("VALUE 0:THIS PORT IS NOT EDGEPORT.\n","");
}
/****************************************************************************
* FUNCTION NAME:clear_edgeport_falg
* DESCRIPTION:清除边缘端口标记。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void clear_edgeport_falg(void)
{
int gport;
for(gport=0;gport<24;gport++)
{
edgeport_array[gport].port_state = 0;
DB_FILE_SET(STP_CONFIG_FILE,STP_SECTION1,edgeport_array[gport].port_key,"0");
}
}
/****************************************************************************
* FUNCTION NAME:stp_set_edgeport_config
* DESCRIPTION:把边缘端口信息添加到数据库中。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
int stp_set_edgeport_config(int port_id)
{
char* filename = STP_CONFIG_FILE;
char* psection = NULL;
char* pkey = NULL;
char pkey_value [20];
int ret;
int index ;
memset(pkey_value,0,20);
index = port_id -1 ;
psection = STP_SECTION1;
pkey = edgeport_array[index].port_key;
if(edgeport_array[index].port_state == 1)
{
sprintf(pkey_value,"%s","1");
}
else if(edgeport_array[index].port_state == 0)
{
sprintf(pkey_value,"%s","0");
}
ret = DB_FILE_SET(filename,psection,pkey,pkey_value);
return ret;
}
/****************************************************************************
* FUNCTION NAME:stp_get_edgeport_config
* DESCRIPTION:从数据库中读取数据。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void stp_get_edgeport_config(void)
{
char* filename = STP_CONFIG_FILE;
char* psection = NULL;
char* pkey = NULL;
char pkey_value[20];
int ret;
int index;
memset(pkey_value,0,20);
psection = STP_SECTION1;
for(index=0;index<24;index++)
{
pkey = edgeport_array[index].port_key;
ret = DB_FILE_GET(filename,psection,pkey,pkey_value);
if(ret == OK)
{
edgeport_array[index].port_state = atoi(pkey_value);
}
else
{
/* printL("Read config db fail.ret = %d\n","",ret); */
}
}
}
/****************************************************************************
* FUNCTION NAME:stp_set_tree_attribute
* DESCRIPTION:测试程序。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void stp_set_tree_attribute(int tree_id,char *section,char *key,char *key_value)
{
spantree_t *stp;
char* filename = STP_CONFIG_FILE;
int ret;
char buf[20];
memset(buf,0,20);
stp = stp_lookup_from_stp_id(tree_id);
if (stp == NULL)
{
/* printL("ERROR:stp :%d is not exist!","",tree_id); */
return;
}
ret = DB_FILE_SET(filename,section,key,key_value);
ret = DB_FILE_GET(filename,section,key,buf);
}
/****************************************************************************
* FUNCTION NAME:stp_delete_section
* DESCRIPTION:删除生成树在数据库的数据。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void stp_delete_section(int tree_id)
{
spantree_t *stp;
char* filename = STP_CONFIG_FILE;
int ret,count = 0,next_line = 0,i = 0,rc = 0;
char buf[20];
char psection[20],name_sec[20];
/*char section_of_file[20];
int i*/
memset(buf,0,20);
memset(psection,0,20);
memset(name_sec,0,20);
stp = stp_lookup_from_stp_id(tree_id);
if (stp == NULL)
{
/* printL("ERROR:stp :%d is not exist!","",tree_id); */
return;
}
/*i=0;*/
sprintf(psection,"%d",tree_id);
count = DB_FILE_GET_SECS_NUM(filename);
for(i = 0;i < count;i++)
{
rc = DB_FILE_GET_ITER_SEC(filename,name_sec,&next_line);
if(rc != CFG_OK){
break;
}
if (strcmp(name_sec,psection) == 0){
DB_FILE_DEL_SEC(filename,psection);
}
}
return;
}
/****************************************************************************
* FUNCTION NAME:stp_get_tree_attribute
* DESCRIPTION:生成树从数据库中读取的数据。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
int stp_get_tree_attribute(int tree_id,char *section,char *key,char *buf)
{
char* filename = STP_CONFIG_FILE;
int ret;
spantree_t *stp;
stp = stp_lookup_from_stp_id(tree_id);
if (stp == NULL)
{
printL("ERROR:stp :%d is not exist!","",tree_id);
return -1;
}
ret = DB_FILE_GET(filename,section,key,buf);
if(ret == 0) return 0;
return -1;
}
/****************************************************************************
* FUNCTION NAME:stp_get_common_config_from_db
* DESCRIPTION:把生成树从数据库中读取的数据写到运行值中。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
int stp_get_common_config_from_db( spantree_t *stp)
{
char section[20],buf[20];
int value;
memset(section,0,20);
sprintf(section,"%d",stp->external_id);
if(stp_get_tree_attribute(stp->external_id,section,"delay",buf) == 0)
{
value = atoi(buf);
if ( value < 4 || value > 30)
{
printL("ERROR: time must be <4 - 30> seconds\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
stp->bridge_forward_delay = value;
}
}
if(stp_get_tree_attribute(stp->external_id,section,"filterage",buf) == 0)
{
value = atoi(buf);
if ( value < 0)
{
printL("ERROR: vlaue < 0 .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
stp->l2_age = value;
}
}
if(stp_get_tree_attribute(stp->external_id,section,"hello",buf) == 0)
{
value = atoi(buf);
if ( value <1 || value > 10)
{
printL("ERROR: time must be <1 - 10> seconds .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
stp->bridge_hello_time = value;
}
}
if(stp_get_tree_attribute(stp->external_id,section,"maxage",buf) == 0)
{
value = atoi(buf);
if ( value < 0)
{
printL("ERROR: vlaue < 0 .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
stp->bridge_max_age = value;
}
}
if(stp_get_tree_attribute(stp->external_id,section,"priority",buf) == 0)
{
value = atoi(buf);
if ( value < 1 || value > 65535)
{
printL("ERROR:priority must be <1 - 65535> .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
stp->saved_priority = value;
}
}
return 0;
}
void stp_set_priority_for_all_stp(void)
{
spantree_t *stp;
uint16 new_priority =0;
FOR_ALL_STP(stp){
if(stp==NULL){
return;
}
new_priority=0;
if ((stp->saved_priority < 1) ||
(stp->saved_priority > 65535)){
continue;
}
new_priority = stp->saved_priority&0xf000;
new_priority += stp->external_id;
stp_set_bridge_priority(stp->external_id, new_priority);
}
}
/****************************************************************************
* FUNCTION NAME:print_attribute_stp
* DESCRIPTION:显示生成树的数据库值。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
int stp_print_attibute_info( int tree_id)
{
char section[20],buf[20];
int value;
memset(section,0,20);
sprintf(section,"%d",tree_id);
if(stp_get_tree_attribute(tree_id,section,"delay",buf) == 0)
{
value = atoi(buf);
if ( value < 4 || value > 30)
{
printL("ERROR: time must be <4 - 30> seconds\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
printL("forward_delay :%d \n","\n",value);
}
}
if(stp_get_tree_attribute(tree_id,section,"filterage",buf) == 0)
{
value = atoi(buf);
if ( value < 0)
{
printL("ERROR: vlaue < 0 .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
printL("l2_age: %d\n","\n",value);
}
}
if(stp_get_tree_attribute(tree_id,section,"hello",buf) == 0)
{
value = atoi(buf);
if ( value <1 || value > 10)
{
printL("ERROR: time must be <1 - 10> seconds .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
printL("hello_time: %d\n","\n",value);
}
}
if(stp_get_tree_attribute(tree_id,section,"maxage",buf) == 0)
{
value = atoi(buf);
if ( value < 0)
{
printL("ERROR: vlaue < 0 .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
printL("bridge_max_age: %d\n","\n",value);
}
}
if(stp_get_tree_attribute(tree_id,section,"priority",buf) == 0)
{
value = atoi(buf);
if ( value < 1 || value > 65535)
{
printL("ERROR:priority must be <1 - 65535> .\n","错误:定时器值必须在<4 - 30>秒之间\n");
}
else
{
printL("priority: %d\n","\n",value);
}
}
return 0;
}
/****************************************************************************
* FUNCTION NAME:print_attribute_stp
* DESCRIPTION:显示生成树的配置属性和运行属性。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void print_attribute_stp(void)
{
spantree_t *stp;
FOR_ALL_STP(stp)
{
if(stp != NULL)
{
printL("STP %d INFO IN DATABASE:\n","",stp->external_id);
stp_print_attibute_info( stp->external_id);
printL("STP %d INFO IN RUNNING:\n","",stp->external_id);
printL("forward_delay :%d \n","\n",stp->bridge_forward_delay);
printL("priority:%d \n","",stp->saved_priority);
printL("bridge_max_age:%d\n","",stp->bridge_max_age);
printL("hello_time:%d \n","",stp->bridge_hello_time);
printL("l2_age:%d\n","",stp->l2_age);
printL("\n","");
}
}
}
/****************************************************************************
* FUNCTION NAME:stp_shutdown
* DESCRIPTION:删除所有生成树。
* AUTHOR/DATE: ZHOUGUIS
****************************************************************************/
void stp_shutdown( void )
{
int tree_id;
spantree_t *stp_exists;
spantree_t *stp;
FOR_ALL_STP(stp)
{
break; // get first stp of list;
}
if(stp != NULL)
{
stp_lock_link();
while(stp != NULL) // delete all stp on this list;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -