📄 lms.c
字号:
/************************************************************************/
void mpls_get_lms_label( mpls_lms_label_req * label_req,
mpls_lms_label_ack * label_ack )
{
unsigned long gen_label;
MPLS_ASSERT(label_req != MPLS_NULL);
MPLS_ASSERT(label_ack != MPLS_NULL);
if(label_req -> flags == MPLS_LABEL_PER_PLATFORM)
{
gen_label = mpls_lms_get_genlabel();
if(gen_label != 0)
{
label_ack -> ack = MPLS_SUCCESS;
label_ack -> label.type = MPLS_LABEL_PER_PLATFORM;
label_ack -> label.general_label.label.flags.gen_lbl = gen_label;
label_ack -> label.general_label.label.flags.res = 0;
}
else
{
label_ack -> ack = MPLS_FAIL;
}
}
else if(label_req -> flags & MPLS_LABEL_PER_INTERFACE)
{
mpls_lms_get_atmlabel( label_req, label_ack);
}
return;
}
/***********************************************************************/
/* FUNCTION NAME : mpls_rel_lms_label()
/* DESCRIPTION: : send all message from prot_tcp
/* INPUT : mpls_lms_label_req * label_req,
mpls_lms_label_ack * label_ack
/* OUTPUT : void
/* AUTHOR/DATE : weng.qing/ 02.06.19
/* GLOBAL : none
/* History : shi.zhaohui mod
/************************************************************************/
void mpls_rel_lms_label( mpls_lms_label_rel * label_rel,
mpls_lms_label_ack * label_ack )
{
unsigned char result;
MPLS_ASSERT(label_rel != MPLS_NULL);
MPLS_ASSERT(label_ack != MPLS_NULL);
if(label_rel -> flags == MPLS_LABEL_PER_PLATFORM)
{
result = mpls_lms_rel_genlabel(label_rel -> label.general_label.label.flags.gen_lbl);
if(result == MPLS_TRUE)
{
label_ack -> ack = MPLS_SUCCESS;
}
}
else if(label_rel -> flags & MPLS_LABEL_PER_INTERFACE)
{
mpls_lms_rel_atmlabel(label_rel, label_ack);
}
return;
}
/***********************************************************************/
/* FUNCTION NAME : mpls_lms_get_atmlabel()
/* DESCRIPTION: : hunt atm label process
/* INPUT : mpls_lms_label_req * label_req,
mpls_lms_label_ack * label_ack
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.06.19
/* GLOBAL : none
/* History :
/************************************************************************/
void mpls_lms_get_atmlabelold(mpls_lms_label_req * label_req,
mpls_lms_label_ack * label_ack)
{
unsigned short t, increment, sit, vpi, vci;
short p;
MPLS_BOOL exit = MPLS_TRUE;
unsigned char * head = MPLS_NULL;
p = -1;
for(t = 0; t <local_label_busy_flags.interface_num; t ++ )
{
if((label_req -> module == local_label_busy_flags.interface[t].module)&&
(label_req -> port == local_label_busy_flags.interface[t].port))
{
p = t;
break;
}
}
if(p < 0)
{
label_ack->ack = MPLS_FAIL;
return;
}
if(label_req->label_range_num == 0) /* inter port */
{
/* 2002-12-19 szh mod for avoid error no label */
if(local_label_busy_flags.maxvpi[p]==0xffff)
{
label_ack->ack = MPLS_FAIL;
return;
}
head = &(local_label_busy_flags.busyAtmLabelFlags[p][0]);
for(vpi = local_label_busy_flags.minvpi[p];
vpi <= local_label_busy_flags.maxvpi[p];
vpi ++)
{
vci = local_label_busy_flags.minvci[p];
sit = vpi*(local_label_busy_flags.maxvci[p]+1)+vci+1;
increment = 1;
for( ; vci <= local_label_busy_flags.maxvci[p];
vci += increment)
{
exit = mpls_check_label_busy(sit, head);
if( exit == MPLS_FALSE )
break;
sit += increment;
}
if( exit == MPLS_FALSE )
break;
}
}
else
{
head = &(local_label_busy_flags.busyAtmLabelFlags[p][0]);
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 )
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;
}
/* 2004-2-3 szh add 获取vpi,vci值从小到大依次获得,用完后再从头获取 */
void mpls_lms_get_atmlabel(mpls_lms_label_req * label_req,
mpls_lms_label_ack * label_ack)
{
unsigned short t, increment, sit, vpi, vci;
short p;
MPLS_BOOL exit = MPLS_TRUE;
unsigned char * head = MPLS_NULL, recnewhuntflag = 1;
p = -1;
for(t = 0; t <local_label_busy_flags.interface_num; t ++ )
{
if((label_req -> module == local_label_busy_flags.interface[t].module)&&
(label_req -> port == local_label_busy_flags.interface[t].port))
{
p = t;
break;
}
}
if(p < 0)
{
label_ack->ack = MPLS_FAIL;
return;
}
if(label_req->label_range_num == 0) /* inter port */
{
/* 2002-12-19 szh mod for avoid error no label */
if(local_label_busy_flags.maxvpi[p]==0xffff)
{
label_ack->ack = MPLS_FAIL;
return;
}
/* 增加保护,如果记录的当前标签值超过配置范围改成配置范围的最小值,从头查找 */
if((local_label_busy_flags.currhuntvpi[p]<local_label_busy_flags.minvpi[p])||
(local_label_busy_flags.currhuntvpi[p]>local_label_busy_flags.maxvpi[p]))
{
local_label_busy_flags.currhuntvpi[p]=local_label_busy_flags.minvpi[p];
printf("lms.c, add protect, internal port vpi exceed limit!!!");
}
if((local_label_busy_flags.currhuntvci[p]<local_label_busy_flags.minvci[p])||
(local_label_busy_flags.currhuntvci[p]>local_label_busy_flags.maxvci[p]))
{
local_label_busy_flags.currhuntvci[p]=local_label_busy_flags.minvci[p];
printf("lms.c, add protect, internal port vci exceed limit!!!");
}
head = &(local_label_busy_flags.busyAtmLabelFlags[p][0]);
if((local_label_busy_flags.currhuntvpi[p] == local_label_busy_flags.minvpi[p]) &&
(local_label_busy_flags.currhuntvci[p] == local_label_busy_flags.minvci[p]))
{
recnewhuntflag = 0;
}
for(vpi = local_label_busy_flags.currhuntvpi[p];
vpi <= local_label_busy_flags.maxvpi[p];
vpi ++)
{
vci = local_label_busy_flags.currhuntvci[p];
sit = vpi*(local_label_busy_flags.maxvci[p]+1)+vci+1;
increment = 1;
for( ; vci <= local_label_busy_flags.maxvci[p];
vci += increment)
{
exit = mpls_check_label_busy(sit, head);
if( exit == MPLS_FALSE )
{
local_label_busy_flags.currhuntvci[p] = vci+increment;
if(vci == local_label_busy_flags.maxvci[p])
{
local_label_busy_flags.currhuntvci[p] =
local_label_busy_flags.minvci[p];
local_label_busy_flags.currhuntvpi[p] = vpi+1;
if(vpi == local_label_busy_flags.maxvpi[p])
{
local_label_busy_flags.currhuntvpi[p] =
local_label_busy_flags.minvpi[p];
}
}
break;
}
sit += increment;
}
if( exit == MPLS_FALSE )
break;
}
/* 没有查到而且需要从头再查一遍 */
if((exit != MPLS_FALSE) && (recnewhuntflag == 1))
{
printf(" inter port, renew search vpi,vci !!!!");
for(vpi = local_label_busy_flags.minvpi[p];
vpi <= local_label_busy_flags.maxvpi[p];
vpi ++)
{
vci = local_label_busy_flags.minvci[p];
sit = vpi*(local_label_busy_flags.maxvci[p]+1)+vci+1;
increment = 1;
for( ; vci <= local_label_busy_flags.maxvci[p];
vci += increment)
{
exit = mpls_check_label_busy(sit, head);
if( exit == MPLS_FALSE )
{
local_label_busy_flags.currhuntvci[p] = vci+increment;
if(vci == local_label_busy_flags.maxvci[p])
{
local_label_busy_flags.currhuntvci[p] =
local_label_busy_flags.minvci[p];
local_label_busy_flags.currhuntvpi[p] = vpi+1;
if(vpi == local_label_busy_flags.maxvpi[p])
{
local_label_busy_flags.currhuntvpi[p] =
local_label_busy_flags.minvpi[p];
}
}
break;
}
sit += increment;
}
if( exit == MPLS_FALSE )
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -