📄 lms.c
字号:
}
/* 光口标签范围是session协商的结果 */
/* 增加保护,如果记录的当前标签值超过配置范围改成配置范围的最小值,从头查找 */
else
{
if((local_label_busy_flags.currhuntvpi[p]<
label_req->label_range[0].min_label.atm_label.label.flags.vpi)||
(local_label_busy_flags.currhuntvpi[p]>
label_req->label_range[0].max_label.atm_label.label.flags.vpi))
{
local_label_busy_flags.currhuntvpi[p] =
label_req->label_range[0].min_label.atm_label.label.flags.vpi;
printf("lms.c, add protect, interface port vpi exceed limit!!!");
}
if((local_label_busy_flags.currhuntvci[p] <
label_req->label_range[0].min_label.atm_label.label.flags.vci)||
(local_label_busy_flags.currhuntvci[p] >
label_req->label_range[0].max_label.atm_label.label.flags.vci))
{
local_label_busy_flags.currhuntvci[p] =
label_req->label_range[0].min_label.atm_label.label.flags.vci;
printf("lms.c, add protect, interface port vci exceed limit!!!");
}
head = &(local_label_busy_flags.busyAtmLabelFlags[p][0]);
if((local_label_busy_flags.currhuntvpi[p] == label_req->label_range[0].min_label.atm_label.label.flags.vpi)
&&(local_label_busy_flags.currhuntvci[p] == label_req->label_range[0].min_label.atm_label.label.flags.vci))
{
recnewhuntflag = 0;
}
for( t = 0; t < label_req->label_range_num; t++)
{
for(vpi = local_label_busy_flags.currhuntvpi[p];
vpi <= label_req->label_range[t].max_label.atm_label.label.flags.vpi;
vpi ++)
{
vci = local_label_busy_flags.currhuntvci[p];
sit = vpi*(local_label_busy_flags.maxvci[p]+1)+vci+1;
if(!(local_label_busy_flags.currhuntvci[p] &0x01))
{
if(label_req->flags & MPLS_LABEL_REQUEST_EVEN)
{
if(vpi == 0 && vci == 32)
vci += 2;
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_ODD)
{
vci += 1;
sit += 1;
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_BIDIRECT)
increment = 1;
else
MPLS_ASSERT(1);
}
else
{
if(label_req->flags & MPLS_LABEL_REQUEST_EVEN)
{
vci += 1;
sit += 1;
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_ODD)
{
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_BIDIRECT)
increment = 1;
else
MPLS_ASSERT(1);
}
for( ;
vci <= label_req->label_range[t].max_label.atm_label.label.flags.vci;
vci += increment)
{
exit = mpls_check_label_busy(sit, head);
if( exit == MPLS_FALSE )
{
local_label_busy_flags.currhuntvci[p] = vci+increment;
if(local_label_busy_flags.currhuntvci[p] >
label_req->label_range[0].max_label.atm_label.label.flags.vci)
{
local_label_busy_flags.currhuntvci[p] =
label_req->label_range[0].min_label.atm_label.label.flags.vci;
local_label_busy_flags.currhuntvpi[p] = vpi+1;
if(vpi == label_req->label_range[0].max_label.atm_label.label.flags.vpi)
{
local_label_busy_flags.currhuntvpi[p] =
label_req->label_range[0].min_label.atm_label.label.flags.vpi;
}
}
break;
}
sit += increment;
}
if( exit == MPLS_FALSE )
break;
}
if( exit == MPLS_FALSE )
break;
}
/* 没有查到而且需要从头再查一遍 */
if((exit != MPLS_FALSE) && (recnewhuntflag == 1))
{
printf(" inface port, renew search vpi,vci !!!!");
for( t = 0; t < label_req->label_range_num; t++)
{
for(vpi = label_req->label_range[t].min_label.atm_label.label.flags.vpi;
vpi <= label_req->label_range[t].max_label.atm_label.label.flags.vpi;
vpi ++)
{
vci = label_req->label_range[t].min_label.atm_label.label.flags.vci;
sit = vpi*(local_label_busy_flags.maxvci[p]+1)+vci+1;
if(!(label_req->label_range[t].min_label.atm_label.label.flags.vci &0x01))
{
if(label_req->flags & MPLS_LABEL_REQUEST_EVEN)
{
if(vpi == 0 && vci == 32)
vci += 2;
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_ODD)
{
vci += 1;
sit += 1;
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_BIDIRECT)
increment = 1;
else
MPLS_ASSERT(1);
}
else
{
if(label_req->flags & MPLS_LABEL_REQUEST_EVEN)
{
vci += 1;
sit += 1;
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_ODD)
{
increment = 2;
}
else if(label_req->flags & MPLS_LABEL_REQUEST_BIDIRECT)
increment = 1;
else
MPLS_ASSERT(1);
}
for( ;
vci <= label_req->label_range[t].max_label.atm_label.label.flags.vci;
vci += increment)
{
exit = mpls_check_label_busy(sit, head);
if( exit == MPLS_FALSE )
{
local_label_busy_flags.currhuntvci[p] = vci+increment;
if(local_label_busy_flags.currhuntvci[p] >
label_req->label_range[0].max_label.atm_label.label.flags.vci)
{
local_label_busy_flags.currhuntvci[p] =
label_req->label_range[0].min_label.atm_label.label.flags.vci;
local_label_busy_flags.currhuntvpi[p] = vpi+1;
if(vpi == label_req->label_range[0].max_label.atm_label.label.flags.vpi)
{
local_label_busy_flags.currhuntvpi[p] =
label_req->label_range[0].min_label.atm_label.label.flags.vpi;
}
}
break;
}
sit += increment;
}
if( exit == MPLS_FALSE )
break;
}
if( exit == MPLS_FALSE )
break;
}
}
}
if(exit != MPLS_FALSE)
{
label_ack->ack = MPLS_FAIL;
local_label_busy_flags.interface[p].session_index = label_req -> session_index;
/* hunt no label, memory sessionindex. when have label, notify ldp label is use */
}
else
{
label_ack->ack = MPLS_SUCCESS;
label_ack->label.type = MPLS_LABEL_PER_INTERFACE;
label_ack->label.atm_label.label.flags.res = 0;
label_ack->label.atm_label.label.flags.vpi = vpi;
label_ack->label.atm_label.label.flags.vci = vci;
}
return;
}
/***********************************************************************/
/* FUNCTION NAME : mpls_lms_get_genlabel() */
/* DESCRIPTION: : hunt general label */
/* INPUT : void */
/* OUTPUT : unsigned long label */
/* AUTHOR/DATE : shi.zhaohui/ 02.06.19 */
/* GLOBAL : none */
/* History : */
/************************************************************************/
unsigned long mpls_lms_get_genlabel( )
{
genlabel_link *next_genlabel;
unsigned long label = 0;
if(genlabel_head == MPLS_NULL)
{
MPLS_MEM_ALLOC(genlabel_head,(genlabel_link *),sizeof(genlabel_link),genlblmem);
if(genlabel_head == MPLS_NULL)
{
printf(" no apply enough memory(lms) !!!!");
#ifdef MPLS_LMS_DEBUG
MPLS_ASSERT(genlabel_head);
#endif
return 0;
}
else /* first hunt label */
{
genlabel_head -> minlabel = MPLS_LABEL_MIN;
genlabel_head -> maxlabel = MPLS_LABEL_MIN;
genlabel_head -> front = MPLS_NULL;
genlabel_head -> next = MPLS_NULL;
genlbl_min_busy = 1;
return MPLS_LABEL_MIN;
}
}
else
{
/*wengqing 2002.12.25 for general label
for example yhis envirionment:
genlabel_head: 20 -- 30, but 16 -- 19 will be lost
*/
if(genlbl_min_busy == 0)
{
if(genlabel_head -> minlabel == MPLS_LABEL_MIN+1)
{
genlabel_head->minlabel = MPLS_LABEL_MIN;
}
else
{
next_genlabel = MPLS_NULL;
MPLS_MEM_ALLOC(next_genlabel,(genlabel_link *),sizeof(genlabel_link),genlblmem);
if(next_genlabel)
{
next_genlabel->minlabel = next_genlabel->maxlabel = MPLS_LABEL_MIN;
next_genlabel->front = MPLS_NULL;
next_genlabel->next = genlabel_head;
genlabel_head->front = next_genlabel;
genlabel_head = next_genlabel;
}
}
genlbl_min_busy = 1;
return MPLS_LABEL_MIN;
}
/* wengqing addd end */
if(genlabel_head -> maxlabel == MPLS_LABEL_MAX)
{
/* label exhaust, note flag. when release label, inform ldp has label to use*/
genlabel_busy_flag = 1;
return 0;
}
else
{
label = ++(genlabel_head -> maxlabel);
if(genlabel_head -> next != MPLS_NULL)
{
next_genlabel = (genlabel_link *)genlabel_head -> next;
if(next_genlabel -> minlabel == (genlabel_head -> maxlabel + 1))
{
combgenlbl(genlabel_head, next_genlabel);
}
}
return label;
}
}
}
/***********************************************************************/
/* FUNCTION NAME : combgenlbl()
/* DESCRIPTION: : combination gen label
/* INPUT : genlabel_link *frontlbl, genlabel_link *nextlbl
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.06.19
/* GLOBAL : none
/* History :
/* wengqing 2002.12.25 add init value
/************************************************************************/
void combgenlbl( genlabel_link *frontlbl, genlabel_link *nextlbl)
{
frontlbl -> next = nextlbl -> next;
if(nextlbl -> next)
(nextlbl -> next)->front = frontlbl;
frontlbl -> maxlabel = nextlbl -> maxlabel;
nextlbl->minlabel = 0;
nextlbl->maxlabel = 0;
nextlbl->front = 0;
nextlbl->next = 0;
MPLS_MEM_FREE(nextlbl, genlblmem);
nextlbl = MPLS_NULL;
/* free(nextlbl); */
}
/***********************************************************************/
/* FUNCTION NAME : mpls_lms_rel_atmlabel()
/* DESCRIPTION: : release atm label process
/* INPUT : mpls_lms_label_rel * label_rel,
mpls_lms_label_ack * label_ack
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.06.19
/* GLOBAL : none
/* History :
/************************************************************************/
void mpls_lms_rel_atmlabel(mpls_lms_label_rel * label_rel,
mpls_lms_label_ack * label_ack)
{
MPLS_BOOL exit = MPLS_TRUE;
unsigned short vpi, vci, sit,t;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -