⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldppdu.c

📁 技术文件名称:MPLSv1.0软件模块测试规程
💻 C
📖 第 1 页 / 共 3 页
字号:
		            	if (encodedSize < 0)
		            	{
		               		printf("========MODULE :%d  Decode ldp_recv_tcp_msg.addrMsg Error =======\n",selfLdpPid.module);                                                    		               		
		               		break;
		            	}
		            	totalSize += encodedSize;
			    		startPtr  += encodedSize;
		
		                SessionFSM(session,MPLS_ADDR_MSGTYPE,&ldp_recv_tcp_msg.addrMsg);				
                        break;

			 		case MPLS_ADDRWITH_MSGTYPE:
			 		
			 			#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE Addrwith MSG =======\n",selfLdpPid.module);
						#endif	                    
            
						encodedSize = Mpls_decodeLdpAdrMsg(&ldp_recv_tcp_msg.addrWithMsg, startPtr,\
		                                    buffSize-MPLS_LDP_HDRSIZE-totalSize);
		            	if (encodedSize < 0)
		            	{
		               	    printf("========MODULE :%d  Decode ADDRWITHMsg Error =======\n",selfLdpPid.module);                                                    		               		
		               		break;
		            	}
		            	totalSize += encodedSize;
			    		startPtr  += encodedSize;
		
                        SessionFSM(session,MPLS_ADDRWITH_MSGTYPE,&ldp_recv_tcp_msg.addrWithMsg);
						break;
			 		
					case MPLS_LBLREQ_MSGTYPE:
			 		
			 			#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE Request MSG =======\n",selfLdpPid.module);
						#endif	                    
            
						encodedSize = Mpls_decodeLdpLblReqMsg(&ldp_recv_tcp_msg.lblReqMsg, startPtr,\
                                            buffSize-MPLS_LDP_HDRSIZE-totalSize);
		            	if (encodedSize < 0)
		            	{
		               		printf("========MODULE :%d  Decode LBLREQMsg Error =======\n",selfLdpPid.module);                                                    		               		
		               		break;
		            	}
		            	totalSize += encodedSize;
			    		startPtr  += encodedSize;

		            	SessionFSM(session,MPLS_LBLREQ_MSGTYPE,&ldp_recv_tcp_msg.lblReqMsg);				                    
						break;
			 		
					case MPLS_LBLMAP_MSGTYPE:
			 		
			 			#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE Mapping MSG =======\n",selfLdpPid.module);
						#endif	                    
            
						encodedSize = Mpls_decodeLdpLblMapMsg(&ldp_recv_tcp_msg.lblMapMsg,startPtr,\
		                                    buffSize-MPLS_LDP_HDRSIZE-totalSize);
		            	if (encodedSize < 0)
		            	{
		               		printf("========MODULE :%d  Decode LBLMAPMsg Error =======\n",selfLdpPid.module);   
		               		break;
		            	}
		            	
			    		totalSize += encodedSize;
			    		startPtr  += encodedSize;
		
                        SessionFSM(session,MPLS_LBLMAP_MSGTYPE,&ldp_recv_tcp_msg.lblMapMsg);
						break;
			 				
					case MPLS_LBLREL_MSGTYPE:

						#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE Release MSG =======\n",selfLdpPid.module);
						#endif	                    
            			 		
						encodedSize = Mpls_decodeLdpLbl_W_R_Msg(&ldp_recv_tcp_msg.lblRelMsg, 
		      		                   startPtr,buffSize-MPLS_LDP_HDRSIZE-totalSize);
		            	if (encodedSize < 0)
		            	{
		               		printf("========MODULE :%d  Decode LBLRELMsg Error =======\n",selfLdpPid.module);   
		               		break;
		            	}
		            	totalSize += encodedSize;
			    		startPtr  += encodedSize;

                        SessionFSM(session,MPLS_LBLREL_MSGTYPE,&ldp_recv_tcp_msg.lblRelMsg);    
						break;
			 		
					case MPLS_LBLWITH_MSGTYPE:
					
						#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE Lblwithdraw MSG =======\n",selfLdpPid.module);
						#endif	                    
            		                
						encodedSize = Mpls_decodeLdpLbl_W_R_Msg(&ldp_recv_tcp_msg.lblWithMsg, 
		      		                   startPtr,buffSize-MPLS_LDP_HDRSIZE-totalSize);
		            	if (encodedSize < 0)
		            	{
		               		printf("========MODULE :%d  Decode LBLWITHMsg Error =======\n",selfLdpPid.module);   
		               		break;
		            	}
		            	totalSize += encodedSize;
			    		startPtr  += encodedSize;
                        
                        SessionFSM(session,MPLS_LBLWITH_MSGTYPE,&ldp_recv_tcp_msg.lblWithMsg);    
					    break;
			 		
			 		case MPLS_LBLABORT_MSGTYPE:
			 		
			 			#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE Lblabort MSG =======\n",selfLdpPid.module);
						#endif	                    
            
                        encodedSize = Mpls_decodeLdpLblAbortMsg(&ldp_recv_tcp_msg.lblAbortMsg, 
		      		                   startPtr,buffSize-MPLS_LDP_HDRSIZE-totalSize);
		            	if (encodedSize < 0)
		            	{
		               		printf("========MODULE :%d  Decode LBLABORTMsg Error =======\n",selfLdpPid.module);   
		               		break;
		            	}
		            	totalSize += encodedSize;
			    		startPtr  += encodedSize;

                        SessionFSM(session,MPLS_LBLABORT_MSGTYPE,&ldp_recv_tcp_msg.lblAbortMsg);    
			 			break;
			 		
					default:
			 		    encodedSize = msgHead.msgLength+4;
	 					totalSize += encodedSize;
			    		startPtr  += encodedSize;
		            	#ifdef __BGS10_MPLS_DEBUG
							printf("========MODULE :%d  RECEIVE %x MSG =======\n",
									selfLdpPid.module,
									msgHead.flags.flags.msgType);
						#endif	                    
            			if(msgHead.flags.flags.uBit == 0)
            			{
            				encodedSize = MPLS_MSGTYPEERROR;
			 		    }
            			break;
			 		
		      	} /* switch */
		      	if ( encodedSize <= 0 )	
		      		break;
		    } /* while */
			    if ( encodedSize <= 0 )	
			    	break;
			    buffSize -= testHeaderDecode.pduLength+4;
			    if(buffSize > 0)
			    {
			    	encodedSize = Mpls_decodeLdpMsgHeader(&testHeaderDecode,startPtr,buffSize);
				    if (encodedSize < 0)
				    {
				        printf("========MODULE :%d  Failed while decoding HEADER =======\n",selfLdpPid.module);
				    	return LDP_FALSE;
				   	}
				   	startPtr += encodedSize;
				   	if (testHeaderDecode.pduLength > buffSize)
				   	{
				        printf("========MODULE :%d  Header Length is longer than buffsize ERROR =======\n",
				        		selfLdpPid.module);
				        return LDP_FALSE;
				   	}
			    }
		    }
		    break;
		default: break; 
	} /* end of switch(udptcpMsg->ProtocolType) */
	checkRetCode(encodedSize,session, msgHead);
    return LDP_TRUE;
}

/*************************************************************************************/
/* 函数	  			: DelHello                      								 */
/* 功能				: 删除Hello连接												     */
/* 输入		        : mplsLdpHello_t *hello			                                 */
/* 作者		        : hu.yonghong  2002-7-3  													 */
/*************************************************************************************/
short DelHello(mplsLdpHello_t *hello)
{
	ldpMibHelloIndexReq_t       helIndex,helIndex1;
	mplsLdpHello_t 				*hello1 = MPLS_NULL;
	mplsLdpHello_t 				*hello2 = MPLS_NULL;
	ldpMibSessionIndexReq_t     sesIndex_s;
	mplsLdpSession_t            * session = MPLS_NULL;
	ldpMibPeerIndexReq_t		peerIndex;
	mplsLdpPeer_t				*peer = MPLS_NULL;
	unsigned char				jj,kk;
	unsigned short				tmid;
	unsigned short              ii;
	mplsLdpEntity_t				*pEntity = MPLS_NULL;
	
	/* 检查hello所对应的session表项 */
	sesIndex_s.sessionIndex = hello->sessionIndex;
	sesIndex_s.indexFlag    = 1; 							
	session = (mplsLdpSession_t *)MibSession(&sesIndex_s, LDP_SEARCH);
	
	if (session == MPLS_NULL)
	{
       	session_error++;
       	sesserror_index = hello->sessionIndex;
       	/* 如果session不存在,删除这个hello表项,hyh add */
    	helIndex.helloIndex = hello->index;
    	helIndex.indexFlag = 1;
    	hello2 = (mplsLdpHello_t *)MibHello(&helIndex, LDP_DELETE);
    	if (hello2 == MPLS_NULL)
        {
        	#ifdef MPLS_ERR_PRINT
                DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"==== Delete Hello Table error ,index %x====\n",hello->index);
        		printf("==== Delete Hello Table error ====");
        	#endif
    		return LDP_FALSE;
        }    
    	#ifdef __BGS10_MPLS_DEBUG
    		printf("==== Delete Hello Table ====");
    	#endif
	    return LDP_TRUE;
    }

	/* 检查session表项是否只包含这一个hello */
	for (jj = 0; jj < SESSION_OWNED_HELLO; jj++)
	{	
		if (session->helloArray[jj] == hello->index)
		{
			/*如果删的是session的第一个hello,则更新session到第二个hello上*/
			if((jj == 0)&&(session->helloArray[1]!=0))
			{
				helIndex1.helloIndex = session->helloArray[1];
				helIndex1.indexFlag = 1;
				hello1 = (mplsLdpHello_t *)MibHello(&helIndex1, LDP_SEARCH);
				if (hello1 == MPLS_NULL)
					return LDP_FALSE;
				session->nexthopaddr = hello1->nexthopAddr;
				session->ifIndex = hello1->ifIndex;
				/*更新peer*/
				peerIndex		   = session->peerLdpId;
			    peer = (mplsLdpPeer_t *)MibPeer(&peerIndex, LDP_SEARCH);
			    if(peer == MPLS_NULL)
			    	return LDP_FALSE;
			    peer->ifIndex = session->ifIndex;

			}
			/*更新session的helloIndex*/
			if(jj < SESSION_OWNED_HELLO-1)
			{
				for(kk = jj;kk<SESSION_OWNED_HELLO-1;kk++)
				{	
					session->helloArray[kk] = session->helloArray[kk+1];
				}	
			}
			session->helloArray[SESSION_OWNED_HELLO-1] = 0;			
			break;			
		}
    }
	/* 恢复helloSendTimer值 */
	pEntity = ldp_search_entity_index(hello->EntityIndex);
	if(pEntity != MPLS_NULL)
	{
		pEntity->helloSendTimer = pEntity->helloHoldTimer * LDP_MIN_TIME_INTERVAL/3;
	}
	
	/* 删除这个hello表项 */
	helIndex.helloIndex = hello->index;
	helIndex.indexFlag = 1;
	hello2 = (mplsLdpHello_t *)MibHello(&helIndex, LDP_DELETE);
	if (hello2 == MPLS_NULL)
    {
    	#ifdef MPLS_ERR_PRINT
            DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_SESSION,"==== Delete Hello Table 2 error ,index %x====\n",hello->index);
    		printf("==== Delete Hello Table error ====");
    	#endif
		return LDP_FALSE;
    }    
	#ifdef __BGS10_MPLS_DEBUG
		printf("==== Delete Hello Table ====");
	#endif

	
	/* 如所有的hello都删掉,则进入session状态机,消息是Time out  */
	if(session->helloArray[0] == 0)	
		SessionFSM(session,HELLOTIMEOUT,NULL);
	return LDP_TRUE;

}


short SendLdpHello(mplsLdpEntity_t *pEntity)
{
	mplsLdpHeader_t     pduHeader;
	unsigned short  	pduSize;
	unsigned short 		jj;
	short               kk;
	long 				sizeTemp;
	mplsLdpInterface_t  *pIntface = NULL;

	/* a. PDU头的参数设置 */
	pduHeader.protocolVersion = pEntity->protocolVersion;							
	pduHeader.lsrAddress 	  = pEntity->ldpId.lsrAddress;
	pduHeader.labelSpace 	  = pEntity->ldpId.labelSpace;
	pduSize = MPLS_LDP_HDRSIZE;										

	/* b. 构造hello消息 */
	InitHelloMsg(&(ldp_snd_msg.helloMsg));
	ldp_snd_msg.helloMsg.baseMsg.msgId = messageId[HELLO_M];
	AddMsgId(HELLO_M);
	ldp_snd_msg.helloMsg.chp.holdTime  = (unsigned short)(pEntity->helloHoldTimer);			    
    if(pEntity->transportAddr != 0)
    {
        ldp_snd_msg.helloMsg.trAdrTlvExists = 1;
        ldp_snd_msg.helloMsg.trAdr.address = pEntity->transportAddr;	        	
    }
#if 0
    ldp_snd_msg.helloMsg.csnTlvExists = 1;
    ldp_snd_msg.helloMsg.csn.seqNumber = pEntity->csn;
#endif
	sizeTemp = Mpls_encodeLdpHelloMsg(&(ldp_snd_msg.helloMsg),\
				(pduBuffer + pduSize), (MAX_PDU_LENGTH - pduSize));
	if (sizeTemp < 0)
	{
	    printf("Hello  encode  error!");
	    return  LDP_FALSE;
	}
	pduSize += sizeTemp; 

	/* c. 构造PDU的header */				
	pduHeader.pduLength	= (unsigned short)(pduSize - MPLS_TLVFIXLEN);
	sizeTemp = Mpls_encodeLdpMsgHeader(&pduHeader, pduBuffer, MPLS_LDP_HDRSIZE);
	if (sizeTemp < 0)
	{
	    printf("PduHeader  encode  error!");
	    return  LDP_FALSE;
	}	

	/* d. 发送UDP包 */
	pIntface = (mplsLdpInterface_t *)LDP_ENTITY_SEARCH_IF(pEntity);
	if(pIntface == NULL)
		return LDP_FALSE;
	udptcpMsg.ProtType	    = PROT_UDP;
	udptcpMsg.LocalIpaddr   = pIntface->ifIpAddress;
	udptcpMsg.PeerIpaddr 	= UDP_MULTICAST_ADDRESS;
	memcpy(udptcpMsg.pdu,pduBuffer,pduSize);
	udptcpMsg.pdulen		= pduSize;
	sizeTemp                = pduSize + LDPMSG_COMMHEADSIZE;
	#ifdef DEBUG_LDP_HELLO
		printf("======== SEND HELLO MSG ==========");
	#endif
/*	MPLS_PSEND(MSG_SEND_REQ,&udptcpMsg,sizeTemp,udptcpPid);    */
	if(eppc_init_status()) 
    {
	    send_ldpmsg_to_eppc(3, &udptcpMsg, 0);
	}
	
	#if 0
	/* 设置hello发送定时器 */
	MPLS_SET_TIMER(pEntity->helloSendTimer,
					(void *)SendLdpHello,
					pEntity,
					ldptime_q,
					pEntity->hellotmd);
	#endif
	pEntity->hellotmd = pEntity->helloSendTimer;

    return  LDP_TRUE;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -