📄 ldpsess.c
字号:
unsigned short checkSessionHello( mplsLdpSession_t * session )
{
unsigned short loop, helloExist;
ldpMibSessionIndexReq_t sesIndex_s;
mplsLdpSession_t * session1 = MPLS_NULL;
unsigned long old_sessionIndex;
old_sessionIndex = session->index;
helloExist = 0;
for (loop = 0; loop < SESSION_OWNED_HELLO; loop++)
{
if (session->helloArray[loop] > 0)
{
helloExist = 1;
session->index = SessionIndex--;
if( SessionIndex == 0 )
SessionIndex = mplsINDEX_MAX;
#ifdef SESSION_DEBUG
#ifdef __BGS10_MPLS_DEBUG
printf("====Module: %d, Session still have hello Adjacency====",
selfLdpPid.module);
#endif
#endif
break;
}
}
if ( helloExist == 0 ) /* session have no hello adjacency, delete session */
{
/* delete peer table */
if( delPeerTable( session ) == LDP_TRUE )
{
#ifdef SESSION_DEBUG
// #ifdef __BGS10_MPLS_DEBUG
printf("====checkSessionHello,Session %d,MODULE :%d DELETE PEER ====\n",session->ifIndex,
selfLdpPid.module);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"====checkSessionHello,Session %d,MODULE :%d DELETE PEER ====\n",session->ifIndex,
selfLdpPid.module);
// #endif
#endif
}
else
{
printf("====Session %d,checkSessionHello,MODULE :%d delete peer fail====\n",session->ifIndex,
selfLdpPid.module);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"Session %d,checkSessionHello,MODULE :%d delete peer fail\n",session->ifIndex,
selfLdpPid.module);
}
sesIndex_s.sessionIndex = session->index;
sesIndex_s.indexFlag = 1;
session1 = (mplsLdpSession_t *)MibSession(&sesIndex_s, LDP_DELETE);
if (session1 == MPLS_NULL)
{
printf("====Session %d,in checkSessionHello,Module: %d, Session delete error====\n",session->index,
selfLdpPid.module);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"in checkSessionHello,Module: %d, Session %d delete error\n",
selfLdpPid.module,session->index);
return LDP_FALSE;
}
else
{
printf("====Module: %d, DELETE SESSION====\n",
selfLdpPid.module);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"====Module: %d, DELETE SESSION====\n",
selfLdpPid.module);
session->subState = SUBIDLE;
}
/* delete peer table */
/* if( delPeerTable( session ) == LDP_TRUE )
{
#ifdef SESSION_DEBUG
// #ifdef __BGS10_MPLS_DEBUG
printf("====checkSessionHello,Session %d,MODULE :%d DELETE PEER ====\n",session->ifIndex,
selfLdpPid.module);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"====checkSessionHello,Session %d,MODULE :%d DELETE PEER ====\n",session->ifIndex,
selfLdpPid.module);
// #endif
#endif
}
else
{
printf("====Session %d,checkSessionHello,MODULE :%d delete peer fail====\n",session->ifIndex,
selfLdpPid.module);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"Session %d,checkSessionHello,MODULE :%d delete peer fail\n",session->ifIndex,
selfLdpPid.module);
}*/
}
else
{
for(loop = 0; loop < MPLSLDP_MAX; loop++)
{
if((MplsLdpHelloEntry[loop].RowStatus == VAL_RowStatus_active) &&
(MplsLdpHelloEntry[loop].sessionIndex == old_sessionIndex))
{
MplsLdpHelloEntry[loop].sessionIndex = session->index;
}
}
}
return helloExist;
}
/******************************************************************************/
/*function: ProcTcpConRetry */
/*Author: weng.qing hu.yonghong */
/*decription: */
/* check if tcp req exceed the threshhold */
/* if exceed, trap to nms(not implement),delete the session */
/* if not exceed, throttle off retry delay timer */
/* Transit Session state to NONEXISTENT, */
/* Transit Session subState to NONIDLE, */
/******************************************************************************/
void ProcTcpConRetry(mplsLdpSession_t * session)
{
unsigned short loop,mm;
mm = 0xffff;
for (loop=0; loop<allEntity.num; loop++)
if ((memcmp(&(allEntity.entity[loop].ldpId),&(session->entityLdpId),\
MPLS_LDPIDLEN) == 0)&&(allEntity.entity[loop].ifArray == session->ifIndex))
{
mm = loop;
break;
}
if(mm == 0xffff)
{
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"====Session %d,Module:%d ProcTcpConRetry, Entity LDPId not match====\n",
session->ifIndex,selfLdpPid.module);
printf("====Session %d,Module:%d ProcTcpConRetry, Entity LDPId not match====\n",session->ifIndex,
selfLdpPid.module);
return;
}
session->LocalPort = 0;
session->PeerPort = 0;
session->state = NONEXISTENT;
session->subState = NONIDLE;
if (session->role == ACTIVE)
{
session->tcpConRetry ++;
if (allEntity.entity[mm].failedInitSessionThreshold != 0)
if (session->tcpConRetry >= allEntity.entity[mm].failedInitSessionThreshold)
{
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"TCP CONNECT RETRY NUMBER EXCEDD THE CONFIGURE RETRY NUMBER!!!\n ");
printf("TCP CONNECT RETRY NUMBER EXCEDD THE CONFIGURE RETRY NUMBER!!!\n ");
return ;
}
if (session->tcpConRetry == 1)
{
/* first retry 15 senconds later */
MPLS_SET_TIMER(150,(void *)ProcSessTcpTimer,session,ldptime_q,session->tmidCon);
#ifdef SESSION_DEBUG
#ifdef __BGS10_MPLS_DEBUG
printf("==MODULE:%d !!!SET SessionTCPCONNECT 15s ==",
selfLdpPid.module);
#endif
#endif
}
else
{
/* later every 2 min later */
MPLS_SET_TIMER(1200,(void *)ProcSessTcpTimer,session,ldptime_q,session->tmidCon);
#ifdef SESSION_DEBUG
#ifdef __BGS10_MPLS_DEBUG
printf("==MODULE:%d !!!SET SessionTCPCONNECT 120s ==",
selfLdpPid.module);
#endif
#endif
}
#ifdef SESSION_DEBUG
#ifdef __BGS10_MPLS_DEBUG
printf("========MODULE :%d SET TCP Timer; %d =======\n",
selfLdpPid.module,session->tmidCon);
#endif
#endif
}
return;
}
/************************************************************************/
/* FUNCTION NAME : InitNegotiate() */
/* DESCRIPTION: : session initial negotiation */
/* INPUT : session, initMsg */
/* OUTPUT : loop detection data of the interface */
/* AUTHOR/DATE : shi.zhaohui 2002-1-16 */
/* GLOBAL : allEntity: entity table of the module */
/************************************************************************/
short InitNegotiate(mplsLdpSession_t *session, mplsLdpInitMsg_t *initMsg)
{
unsigned short maxPduLen;
ldpMibPeerIndexReq_t peerIndex;
mplsLdpPeer_t *peer = MPLS_NULL;
unsigned short ii, mm;
loopDetection_t sessionLoop; /* sbp 2002-1-30 for loop detection */
unsigned short time;
mm = 0xffff;
for (ii=0; ii<=allEntity.num; ii++)
if ((memcmp(&(allEntity.entity[ii].ldpId),&(session->entityLdpId),\
MPLS_LDPIDLEN) == 0)&&(allEntity.entity[ii].ifArray == session->ifIndex))
{
mm=ii;
break;
};
if (mm == 0xffff)
{
// #ifdef __BGS10_MPLS_DEBUG
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"==== InitNegotiate,MPLS LDP Entity SEARCH Fail!====\n");
printf("==== MPLS LDP Entity SEARCH Fail!====");
// #endif
return (LDP_FALSE);
}
/* 2001/09/04 Agilent test 20.tst */
if( (initMsg->csp.rcvLsrAddress != session->entityLdpId.lsrAddress)||
(initMsg->csp.rcvLsId != session->entityLdpId.labelSpace) )
{
sndnotifymsgproc(session,SREJNOHELLO, \
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
return LDP_FALSE;
}
/* 2001/09/04 end*/
peerIndex = session->peerLdpId;
peer = (mplsLdpPeer_t *)MibPeer(&peerIndex, LDP_SEARCH);
if (peer == MPLS_NULL)
{
// #ifdef __BGS10_MPLS_DEBUG
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"==== InitNegotiate,MPLS LDP PEER SEARCH Fail!====\n");
printf("==== MPLS LDP PEER SEARCH Fail!====");
// #endif
return LDP_FALSE;
}
/*
if (initMsg->baseMsg.msgLength > initMsg->csp.maxPduLen)
{
sndnotifymsgproc(session, BADMSGLEN,
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
return LDP_FALSE;
}
*/
if (initMsg->cspExists == 1)
{
/* Protocol Version */
if (initMsg->csp.protocolVersion != 1)
{
sndnotifymsgproc(session, BADPROTVER,
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
return LDP_FALSE;
}
session->protocolVersion = 1;
/* 协商keepaliveholdtime */
if(initMsg->csp.holdTime != 0)
time = (initMsg->csp.holdTime);
else
time = DEFAULT_LDP_KEEPALIVE_INTERVAL;
time = allEntity.entity[mm].keepAliveHoldTimer > time ? \
time : allEntity.entity[mm].keepAliveHoldTimer;
session->keepAliveHoldTime = time*LDP_MIN_TIME_INTERVAL;
session->keepAliveHoldTimeRemaining = time;
/* 协商label广播的方式 */
session->labelAdvertisement = allEntity.entity[mm].labelDistributionMethod;
/* modify by hyh */
if ((allEntity.entity[mm].labelDistributionMethod == DOWNSTREAMONDEMAND)\
&& (initMsg->csp.flags.flags.lad == DOWNSTRAMUNSOLICITED))
{
sndnotifymsgproc(session, SREJPARMADEVER,
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
session->labelAdvertisement = DOWNSTREAMONDEMAND;
}
if((allEntity.entity[mm].labelDistributionMethod == DOWNSTRAMUNSOLICITED)\
&& (initMsg->csp.flags.flags.lad == DOWNSTREAMONDEMAND))
{
sndnotifymsgproc(session, SREJPARMADEVER,
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
session->labelAdvertisement = DOWNSTRAMUNSOLICITED;
}
/* end */
/* loop detection */
/* sbp 2002-1-30 change the loopdetection from global to one interface */
sessionLoop = mplsLoopDetectEnableGet(allEntity.entity[mm].ifArray);
session->loopDetectionForPV = sessionLoop.loopDection;
session->pathVectorLimit = sessionLoop.pvLimit;
if( (initMsg->csp.flags.flags.ld == LDP_DISABLE)&&
(initMsg->csp.flags.flags.pvl != 0) )
{
sndnotifymsgproc(session, MALFORMTLVVAL,
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
return LDP_FALSE;
}
else if(initMsg->csp.flags.flags.ld == LDP_ENABLE) /* loop detect */
{
if((session->loopDetectionForPV == LOOPDETECT_PATHVECTOR) ||
(session->loopDetectionForPV == LOOPDETECT_HOPANDPV))
{
if( session->pathVectorLimit > initMsg->csp.flags.flags.pvl)
session->pathVectorLimit = initMsg->csp.flags.flags.pvl;
}
}
else if(initMsg->csp.flags.flags.ld == LDP_DISABLE)
{
session->loopDetectionForPV = LOOPDETECT_NONE;
lsrAttr.lsrAttribute.loopDetectionForPV = LOOPDETECT_NONE;
session->pathVectorLimit = 0;
}
/*如果两者不同,发送警告消息给网管???留以后做* /
/* MAX PDU LENGTH */
if (initMsg->csp.maxPduLen <= 255)
maxPduLen = MAX_PDU_LENGTH;
else
maxPduLen = initMsg->csp.maxPduLen;
if (maxPduLen < allEntity.entity[mm].maxPduLength)
session->maxPduLength = maxPduLen;
else
session->maxPduLength = allEntity.entity[mm].maxPduLength;
/* 2001/09/04 session pdu length negotiate */
if( session->maxPduLength >MAX_LDP_MSGLEN )
{
sndnotifymsgproc(session, SREJPARMMPDUL,
initMsg->baseMsg.msgId,initMsg->baseMsg.flags.flags.msgType);
return LDP_FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -