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

📄 ldpque.c

📁 技术文件名称:MPLSv1.0软件模块测试规程
💻 C
📖 第 1 页 / 共 5 页
字号:
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"******!!! sorry,feclabel_req_queue is full !!!******\n");
  		printf("******!!! sorry,feclabel_req_queue is full !!!******");
    	return REQ_QUEUE_FULL;
  	}
  	/*为请求分配空间*/
  	MPLS_MEM_ALLOC(feclabel_lqe,(MPLS_LQE *),sizeof(MPLS_LQE),mem_mgr[IUMEM_LDP_FECLABEL_QUE_LQE]);
	if(feclabel_lqe == MPLS_NULL)
  	{
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"!!! sorry,can not allocate memory for feclabel_lqe !!!\n");
	  	printf("!!! sorry,can not allocate memory for feclabel_req_queue !!!");
	    return REQ_MEMORY_FAIL;
  	}

  	MPLS_MEM_ALLOC(req_index,(FECLABEL_REQ *),sizeof(FECLABEL_REQ),mem_mgr[IUMEM_LDP_FECLABEL_QUE]);
	if(req_index == MPLS_NULL)
  	{
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"!!! sorry,can not allocate memory for label_req_index !!!\n");
	  	printf("!!! sorry,can not allocate memory for feclabel_req_queue !!!");
	    return REQ_MEMORY_FAIL;
  	}
	req_index->req_type = req_type;
	MPLS_MEMCPY(&req_index->feclabel,req,sizeof(mplsLdpFecLabel));

  	/* 为请求初始化一个队列节点,分配空间,将其加入到相应队列的尾部 */
  	MPLS_INIT_LQE(*feclabel_lqe,req_index);
  	MPLS_INSERT_BEFORE(feclabel_req.req_queue,*feclabel_lqe);
	/*队列中请求个数增1*/
  	feclabel_req.req_num++;
  	/* 开始处理对头请求 */
 	mpls_process_feclabel_req();

	return REQ_QUEUE_OK;
}

/**PROC+********************************************************************/
/* Name:    mpls_process_feclabel_req                                      */
/* Author:	hu.yonghong                                                    */
/* Purpose: process request information for mpls feclabel request.         */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/* Note:    process the head req in queue                                  */
/**PROC-********************************************************************/
void mpls_process_feclabel_req()
{
  	FECLABEL_REQ     		*req_index;
  	mplsLdpFecLabel			feclabel;
  	
  	/* if some feclabel_req is processing or the feclabel_req queue is empty,return */
  	if((feclabel_req.req_in_progress == 1)||
     	((req_index = (FECLABEL_REQ *)MPLS_NEXT_IN_LIST(feclabel_req.req_queue)) == MPLS_NULL))
    	return ;

  	feclabel_req.req_in_progress = 1 ;
  	/* set timer */   
	MPLS_SET_TIMER(LBL_CONF_TIME,(void *)mpls_feclabelreq_queue_timeout,0,ldptime_q,feclabel_req.timerid);

  	req_index->feclabel.index = feclabel_req_index;
  	feclabel_req.index 	 = feclabel_req_index;
  	    
  	switch(req_index->req_type)
  	{
	  	case SEND_REQ:
	    /*	ASEND(FEC_LABEL_SEND_MSG, &req_index->feclabel, sizeof(mplsLdpFecLabel), sbForwardPid);  */
	    	send_mpls_fec_table(&req_index->feclabel,FEC_LABEL_SEND_MSG);
	    	#ifdef __BGS10_MPLS_DEBUG
		      printf( "****** send FEC_LABEL_SEND_MSG: sbForwardPid.module=%d *******\n",
		            sbForwardPid.module);
		    #endif
		    break;
		case RECV_REQ:
	    /*	ASEND(FEC_LABEL_RECEIVE_MSG, &req_index->feclabel, sizeof(mplsLdpFecLabel), sbForwardPid); */
	    	send_mpls_fec_table(&req_index->feclabel,FEC_LABEL_RECEIVE_MSG);
	    	#ifdef __BGS10_MPLS_DEBUG
		      printf( "****** send FEC_LABEL_RECEIVE_MSG: sbForwardPid.module=%d *******\n",
		            sbForwardPid.module);
		    #endif		
			break;
		case CLOSE_REQ:
		/*	ASEND(FEC_LABEL_CLOSE_MSG, &req_index->feclabel, sizeof(mplsLdpFecLabel), sbForwardPid);  */
		    send_mpls_fec_table(&req_index->feclabel,FEC_LABEL_CLOSE_MSG);
	    	#ifdef __BGS10_MPLS_DEBUG
		      printf( "****** send FEC_LABEL_CLOSSE_MSG: sbForwardPid.module=%d *******\n",
		            sbForwardPid.module);
		    #endif
		    break;
		default:
			break;
	}

  	feclabel_req_index++;
  	if(feclabel_req_index == MAX_LDP_FECLABEL_QUE)
      	feclabel_req_index = 0;

  	return;  

}

/**PROC+********************************************************************/
/* Name:    mpls_feclabel_req_confirm                                            */
/* Author:	hu.yonghong                                                    */
/* Purpose: process request information for mpls cross-connect request.    */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/* Note:    insert the req in the queue tail,do processing                 */
/**PROC-********************************************************************/
void mpls_feclabel_req_confirm(void *in)
{
  	LBLREQ_CONF         *conf;
 
	#ifdef __BGS10_MPLS_DEBUG
	MPLS_ERR_LOG("======== mpls_feclabel_req_confirm ========"); 
	#endif
  	conf = (LBLREQ_CONF *)in;
  	/* 将响应与对头请求匹配,如匹配不上,表示响应有误,不理会,返回 */
  	if(feclabel_req.index != conf->index)
  	{
  		MPLS_ERR_LOG("======== mpls_feclabel_req_confirm %d,%d========",\
  		 feclabel_req.index,conf->index);
         DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"======== mpls_feclabel_req_confirm %x,%x========\n",\
  		 feclabel_req.index,conf->index);
	}
	/* 处理下一个请求*/
	mpls_feclabelreq_next();
	return ;
}

/**PROC+********************************************************************/
/* Name:    mpls_feclabelreq_queue_timeout                                       */
/* Author:	hu.yonghong                                                    */
/* Purpose: process when timeout.    									   */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/**PROC-********************************************************************/
#if 0
void mpls_feclabelreq_queue_timeout()
{
  	MPLS_LQE          *feclabel_lqe;
	int               rtcode;
	
	/* 将对头请求出队列,释放空间 */
    if(!MPLS_EMPTY_LIST(feclabel_req.req_queue))
    {
    	feclabel_lqe = MPLS_GET_FIRST_LQE(feclabel_req.req_queue);
  	MPLS_REMOVE_FROM_LIST(*feclabel_lqe);
	MPLS_MEM_FREE((feclabel_lqe->self),mem_mgr[IUMEM_LDP_FECLABEL_QUE]);
	MPLS_MEM_FREE((feclabel_lqe),mem_mgr[IUMEM_LDP_FECLABEL_QUE_LQE]);
  	/* 队列请求个数减一 */
  	feclabel_req.req_num--;
       	MPLS_ASSERT(feclabel_req.req_num >= 0);
  
  	/* 继续处理队列中的对头请求 */
  	mpls_reset_feclabel_req();  
  	mpls_process_feclabel_req();
    }
    return;

}
#endif
#if 1
void mpls_feclabelreq_queue_timeout()
{
  	MPLS_LQE          *feclabel_lqe;
	int               rtcode;
	
	/* 将对头请求出队列,释放空间 */
    if(!MPLS_EMPTY_LIST(feclabel_req.req_queue))
    {
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"mpls_feclabelreq_queue_timeout\n");
      	/* 继续处理队列中的对头请求 */
      	mpls_reset_feclabel_req();  
      	mpls_process_feclabel_req();
    }
    return;

}
#endif
/**PROC+********************************************************************/
/* Name:    mpls_feclabelreq_next                                                */
/* Author:	hu.yonghong                                                    */
/* Purpose: process next req in queue. 									   */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/**PROC-********************************************************************/
void mpls_feclabelreq_next()
{
  	MPLS_LQE          *feclabel_lqe;
	int               rtcode;
	
	/* 将对头请求出队列,释放空间 */
    if(!MPLS_EMPTY_LIST(feclabel_req.req_queue))
    {
    	feclabel_lqe = MPLS_GET_FIRST_LQE(feclabel_req.req_queue);
  	MPLS_REMOVE_FROM_LIST(*feclabel_lqe);
	MPLS_MEM_FREE((feclabel_lqe->self),mem_mgr[IUMEM_LDP_FECLABEL_QUE]);
	MPLS_MEM_FREE((feclabel_lqe),mem_mgr[IUMEM_LDP_FECLABEL_QUE_LQE]);
  	/* 队列请求个数减一 */
  	feclabel_req.req_num--;
       	MPLS_ASSERT(feclabel_req.req_num >= 0);
  
  	/* 取消定时器 */
  	if(feclabel_req.timerid>0)
      	{	
  		MPLS_CLEAR_TIMER(feclabel_req.timerid,ldptime_q,rtcode);
      		MPLS_ASSERT(rtcode == 1);
      		if(rtcode)
        feclabel_req.timerid = 0;
        }
  	/* 继续处理队列中的对头请求 */
  	mpls_reset_feclabel_req();  
  	mpls_process_feclabel_req();
}  
    return;
    
}  

/**PROC+********************************************************************/
/* Name:    mpls_reset_feclabel_req                                              */
/* Author:	hu.yonghong                                                    */
/* Purpose: Reset request information for mpls cross-connect request.      */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/*                                                                         */
/**PROC-********************************************************************/
void mpls_reset_feclabel_req()
{
  	/* Reset request information for the cross-connect request. */
  	feclabel_req.req_in_progress = 0;
  	feclabel_req.index = 0;
  	feclabel_req.timerid = 0;
  	return;
} 


/**************************************************************************/
/*同FEC的缓冲函数                                                         */
/**************************************************************************/

/**PROC+********************************************************************/
/* Name:    mpls_fec_req_append                                             */
/* Author:	hu.yonghong                                                    */
/* Purpose: add request information in queue                               */
/*          for mpls cross-connect request.                                */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/* Note:    insert the req in the queue tail,do processing                 */
/**PROC-********************************************************************/
short mpls_fec_req_append(void *req)
{
  	FecMsg		    *FecReq;
  	MPLS_LQE        *fec_lqe = MPLS_NULL;

  	/* 判断队列是否满? */  
  	if(fec_req.req_num >= MAX_LDP_FEC_QUE)
  	{
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"******!!! append sorry,fec_req_queue is full !!!******\n");
  		printf("******!!! sorry,fec_req_queue is full !!!******");
    	return REQ_QUEUE_FULL;
  	}
  	/*为请求分配空间*/
  	MPLS_MEM_ALLOC(fec_lqe,(MPLS_LQE *),sizeof(MPLS_LQE),mem_mgr[IUMEM_LDP_FEC_QUE_LQE]);
	if(fec_lqe == MPLS_NULL)
  	{
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"!!! sorry,can not allocate memory for fec_lqe 2 !!!\n");
	  	printf("!!! sorry,can not allocate memory for fec_req_queue !!!");
	    return REQ_MEMORY_FAIL;
  	}

  	MPLS_MEM_ALLOC(FecReq,(FecMsg *),sizeof(FecMsg),mem_mgr[IUMEM_LDP_FEC_QUE]);
	if(FecReq == MPLS_NULL)
  	{
        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"!!! sorry,can not allocate memory for FecReq !!!\n");
	  	printf("!!! sorry,can not allocate memory for fec_req_queue !!!");
	    return REQ_MEMORY_FAIL;
  	}
	MPLS_MEMCPY(FecReq,req,sizeof(FecMsg));

  	/* 为请求初始化一个队列节点,分配空间,将其加入到相应队列的尾部 */
  	MPLS_INIT_LQE(*fec_lqe,FecReq);
  	MPLS_INSERT_BEFORE(fec_req.req_queue,*fec_lqe);
	/*队列中请求个数增1*/
  	fec_req.req_num++;
  	/* 开始处理对头请求 */
    if(fec_req.req_in_progress == 0)
 	    mpls_process_fec_req();

	return REQ_QUEUE_OK;
}

/**PROC+********************************************************************/
/* Name:    mpls_process_fec_req                                      */
/* Author:	hu.yonghong                                                    */
/* Purpose: process request information for mpls fec request.         */
/* Returns: Nothing.                                                       */
/* Params:  None.                                                          */
/* Note:    process the head req in queue                                  */
/**PROC-********************************************************************/
void mpls_process_fec_req()
{
  	FecMsg     		*FecReq;
  	FecAckMsg       Fec_Ack;
  	
  	/* if some fec_req is processing or the fec_req queue is empty,return */
  	if((fec_req.req_in_progress == 1)||
     	((FecReq = (FecMsg *)MPLS_NEXT_IN_LIST(fec_req.req_queue)) == MPLS_NULL))
    	return ;

  	fec_req.req_in_progress = 1 ;
  	if(fec_req_index == MAX_LDP_FEC_QUE)
      	fec_req_index = 0;
  	fec_req_index++;

  	/* set timer */   
	MPLS_SET_TIMER(FEC_CONF_TIME,(void *)mpls_fecreq_queue_timeout,0,ldptime_q,fec_req.timerid);

 	MPLS_MEMSET(&Fec_Ack,0,sizeof(FecAckMsg));
 	MPLS_MEMCPY(&(Fec_Ack.FecAck),FecReq,sizeof(FecMsg));
  	Fec_Ack.index    = fec_req_index;
  	fec_req.index 	= fec_req_index;
    #ifdef __BGS10_MPLS_DEBUG
 	printf("ldp MPLS_FEC_STUDY to fec,timerid %u,index %d",fec_req.timerid,fec_req_index);    
 	#endif   
	ASEND(MPLS_FEC_RESP,&Fec_Ack,sizeof(FecAckMsg),fecPid);

⌨️ 快捷键说明

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