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

📄 ldpmib.c

📁 技术文件名称:MPLSv1.0软件模块测试规程
💻 C
📖 第 1 页 / 共 4 页
字号:
/********************************************************************/          
/*	Product Name:	MPLS PACK 1.0 									*/                                      	          
/*	Module  Name:	LDP    											*/						     
/*	File    Name:   LdpMib.c							        	*/          
/*	Author  Name:   hu.yonghong 									*/          
/*	Creat   Date:	2002-7-11 										*/
/*	Function    :	函数文件,集合了与MIB库查表有关的函数           */
/********************************************************************/  
#include "ldpvars.h"

/********************************************************************/          
/*							                                       	*/          
/*					1. 对MIB库动态表的操作函数						*/
/*														        	*/          
/********************************************************************/          

/* ******************************************************************** */
/* FUNCTION NAME : initldpdynmib( ) 			                        */
/* DESCRIPTION   : Dyanmic Data init 0                                  */
/* AUTHOR/DATE   : Shi.ZhaoHui / 2001.10.16                             */
/********************************************************************** */

/* 2003.12.30 shizhaohui session删除时,对其作清空操作 */

void initldpdynmib( )
{
    memset( (char *)MplsLdpPeerEntry, 0, sizeof( MplsLdpPeerTable ) );
    memset( (char *)MplsLdpHelloEntry, 0, sizeof( MplsLdpHelloTable ) );
    memset( (char *)MplsLdpSessionEntry, 0, sizeof( MplsLdpSessionTable ) );
    memset( (char *)MplsLdpSessionPeerAddrEntry, 0, sizeof( MplsLdpSessionPeerAddrTable ) );
    memset( (char *)MplsLdpEntityStatsEntry, 0, sizeof( MplsLdpEntityStatsTable ) );
    memset( (char *)MplsLdpSessionStatsEntry, 0, sizeof( MplsLdpSessionStatsTable ) );
}

/*  对Hello邻接表的置表、检索和删除操作
 */
mplsLdpHello_t *MibHello(void * input,unsigned char flag)
{
    MIB_LDPHELLO_REQ    	helloReq;
    mplsLdpHello_t 			*helloSet;
    ldpMibHelloIndexReq_t   * helloIndex;
    mplsLdpHello_t 			*hello = MPLS_NULL;
    
    helloReq.operateType        = flag;
    switch(flag)
    {
        case LDP_SET:    /*  置表  */
            helloSet = (mplsLdpHello_t *)input;
            memcpy(&(helloReq.req.set),helloSet,sizeof(mplsLdpHello_t));
			hello = func_helloset(&helloReq);
            break;
       
        case LDP_SEARCH:  /*  检索  */    
    
            helloIndex  = (ldpMibHelloIndexReq_t *)input;
            memcpy(&(helloReq.req.loc),helloIndex,\
                            sizeof(ldpMibHelloIndexReq_t ));
			hello = func_hellosearch(&helloReq);
            break;
            
        case LDP_DELETE:  /*  删除  */
        
            helloIndex  = (ldpMibHelloIndexReq_t *)input;
            memcpy(&(helloReq.req.del),helloIndex,\
                            sizeof(ldpMibHelloIndexReq_t ));
			hello = func_hellodel(&helloReq);
            break;
        
        default: break;
    }
    return hello;
}

/* ******************************************************************** */
/* FUNCTION NAME : func_helloset( ) 			                        */
/* DESCRIPTION   : set Dyanmic Data ldp To mib                          */
/* INPUT         : MIB_LDPHELLO_REQ *in, MIB_LDPHELLO_ACK *ack          */
/* OUTPUT        : No.                                 			        */
/* AUTHOR/DATE   : Shi.ZhaoHui / 2001.3.26                             */
/* GLOBAL        : none                                                 */
/* NOTE          :  ....                                                */
/********************************************************************** */

mplsLdpHello_t *func_helloset(MIB_LDPHELLO_REQ *in)
{
  short                 i,temp = -1;
  mplsOAMLdpMessage_t   oamldpmess;
  mplsLdpHello_t 		*hello = MPLS_NULL;
  
  for(i = 0; i < MPLSLDP_MAX; i++)
  {
      if((MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_active) &&
           (MplsLdpHelloEntry[i].entityLdpId.lsrAddress == in -> req.set.entityLdpId.lsrAddress) &&
           (MplsLdpHelloEntry[i].entityLdpId.labelSpace == in -> req.set.entityLdpId.labelSpace) &&
           (MplsLdpHelloEntry[i].ifIndex == in -> req.set.ifIndex) &&
           (MplsLdpHelloEntry[i].peerLdpId.lsrAddress == in -> req.set.peerLdpId.lsrAddress) &&
           (MplsLdpHelloEntry[i].peerLdpId.labelSpace == in -> req.set.peerLdpId.labelSpace))
      {
        in -> req.set.index = MplsLdpHelloEntry[i].index;
        memcpy((unsigned char *)&MplsLdpHelloEntry[i]+1,&(in -> req.set),sizeof(mplsLdpHello_t) );
        hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
        temp = 0;
        oamldpmess.msgtype = MPLS_MIB_LDP_HELLO ;
        oamldpmess.data.helloDataReq.operateType = 1;
        memcpy(&(oamldpmess.data.helloDataReq.req.set),&(in -> req.set),
                    sizeof(mplsLdpHello_t));
        /*MPLS_PSEND(MPLS_LDP_OAM_MESSAGE,&oamldpmess,sizeof(MIB_LDPHELLO_ACK)
        		+sizeof(mplsLdpOAMMessage)+sizeof(unsigned char),mlsmanagePid);*/
        mplsHelloRecv(&oamldpmess);   /* 2003-10-9 lixia add */ 
        break;
      }
  }
  if(temp == 0)
    return hello;

  for(i = 0; i < MPLSLDP_MAX; i++)
  {
      if(MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_null)
      {
            in -> req.set.index = HelloIndex;
            MplsLdpHelloEntry[i].RowStatus =  VAL_RowStatus_active;
            memcpy((unsigned char *)&MplsLdpHelloEntry[i]+1,&(in -> req.set),sizeof(mplsLdpHello_t) );
	        hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
            HelloIndex--;
		    if( HelloIndex == 0 )
			    HelloIndex = mplsINDEX_MAX;
			oamldpmess.msgtype = MPLS_MIB_LDP_HELLO ;
            oamldpmess.data.helloDataReq.operateType = 1;
            memcpy(&(oamldpmess.data.helloDataReq.req.set),&(in -> req.set),
                    sizeof(mplsLdpHello_t));
            /*MPLS_PSEND(MPLS_LDP_OAM_MESSAGE,&oamldpmess,sizeof(MIB_LDPHELLO_ACK)
        		+sizeof(mplsLdpOAMMessage)+sizeof(unsigned char),mlsmanagePid);*/
        	mplsHelloRecv(&oamldpmess);   /* 2003-10-9 lixia add */ 
            break;
      }
  }
  return hello;
}

/* ******************************************************************** */
/* FUNCTION NAME : func_hellosearch( )  		                        */
/* DESCRIPTION   : set Dyanmic Data ldp To mib                          */
/* INPUT         : MIB_LDPHELLO_REQ *in, MIB_LDPHELLO_ACK *ack          */
/* OUTPUT        : No.                                 			        */
/* AUTHOR/DATE   : Shi.ZhaoHui / 2001.3.26                             */
/* GLOBAL        : none                                                 */
/* NOTE          :  ....                                                */
/********************************************************************** */
mplsLdpHello_t *func_hellosearch(MIB_LDPHELLO_REQ *in)
{
    short           i;
    mplsLdpHello_t *hello = MPLS_NULL;
    
	switch (in -> req.loc.indexFlag )
	{
		case 1  :
		    if(( in -> req.loc.helloIndex < 0 )||( in -> req.loc.helloIndex > mplsINDEX_MAX ))
		    {
				#ifdef DEBUG_LDP
				    #ifdef __BGS10_MPLS_DEBUG
			  	        printf("!!! In func_search1, helloIndex error.");
			  	    #endif
			  	#endif
			  	return MPLS_NULL;
			}
		    for(i = 0; i < MPLSLDP_MAX; i++)
		    {
		        if((MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_active) &&
		           ( MplsLdpHelloEntry[i].index == in -> req.loc.helloIndex))
		        {
			        hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
			        break;
			    }
			}
		    #ifdef DEBUG_LDP
			    #ifdef __BGS10_MPLS_DEBUG
			        if(hello == MPLS_NULL)
			        	printf("!!! In func_search1, search data is not exist");
			    #endif
			#endif
			break;
		case 2 :
		    for(i = 0; i < MPLSLDP_MAX; i++)
		    {
		        if((MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_active) &&
		           (MplsLdpHelloEntry[i].entityLdpId.lsrAddress == in -> req.loc.unionIndex.entityLdpId.lsrAddress) &&
		           (MplsLdpHelloEntry[i].entityLdpId.labelSpace == in -> req.loc.unionIndex.entityLdpId.labelSpace) &&
		           (MplsLdpHelloEntry[i].ifIndex == in -> req.loc.unionIndex.ifIndex) &&
		           (MplsLdpHelloEntry[i].peerLdpId.lsrAddress == in -> req.loc.unionIndex.peerLdpId.lsrAddress) &&
		           (MplsLdpHelloEntry[i].peerLdpId.labelSpace == in -> req.loc.unionIndex.peerLdpId.labelSpace))
		        {
        			hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
			        break;
			    }
			}
			#ifdef DEBUG_LDP
			    #ifdef __BGS10_MPLS_DEBUG
			        if(hello == MPLS_NULL)
				        printf("!!! In func_search3, search data is not exist");
			    #endif
			#endif
			break;
		case 3 :
		    for(i = 0; i < MPLSLDP_MAX; i++)
		    {
		        if((MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_active) &&
		           (MplsLdpHelloEntry[i].helloPeerAddr == in -> req.loc.transAddr))
		        {
        			hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
			        break;;
			    }
			}
			#ifdef DEBUG_LDP
			    #ifdef __BGS10_MPLS_DEBUG
			        if(hello == MPLS_NULL)
				        printf("!!! In func_search3, search data is not exist");
			    #endif
			#endif
			break;		
		default:
			break;
	}
	return hello;
}

/* ******************************************************************** */
/* FUNCTION NAME : func_hellodel( ) 			                        */
/* DESCRIPTION   : search Dyanmic Data from mib                         */
/* INPUT         : MIB_LDPHELLO_REQ *in, MIB_LDPHELLO_ACK *ack          */
/* OUTPUT        : No.                                 			        */
/* AUTHOR/DATE   : Shi.ZhaoHui / 2001.3.26                             */
/* GLOBAL        : none                                                 */
/* NOTE          :  ....                                                */
/********************************************************************** */
mplsLdpHello_t *func_hellodel(MIB_LDPHELLO_REQ *in )
{
    short           i;
    mplsLdpHello_t *hello;
    mplsOAMLdpMessage_t   oamldpmess;
	switch ( in -> req.del.indexFlag )
	{
		case 1  :
		    if(( in -> req.del.helloIndex < 0 )||( in -> req.del.helloIndex > mplsINDEX_MAX ))
		    {
				#ifdef DEBUG_LDP
				    #ifdef __BGS10_MPLS_DEBUG
			  	        printf("!!! In func_hellodel1, helloIndex error.");
			  	    #endif
			  	#endif
			  	return MPLS_NULL;
			}
		    for(i = 0; i < MPLSLDP_MAX; i++)
		    {
		        if((MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_active) &&
		           ( MplsLdpHelloEntry[i].index == in -> req.del.helloIndex))
		        {
		            MplsLdpHelloEntry[i].RowStatus =  VAL_RowStatus_null;
        			hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
			        oamldpmess.msgtype = MPLS_MIB_LDP_HELLO ;
		            oamldpmess.data.helloDataReq.operateType = 3;
		            /*oamldpmess.data.helloDataReq.req.del.indexFlag = 1;
					oamldpmess.data.helloDataReq.req.del.helloIndex = 
							(unsigned long)MplsLdpHelloEntry[i].ifIndex;
		            MPLS_PSEND(MPLS_LDP_OAM_MESSAGE,&oamldpmess,sizeof(MIB_LDPHELLO_ACK)
		        		+sizeof(mplsLdpOAMMessage)+sizeof(unsigned char),mlsmanagePid);*/
		            memcpy(&(oamldpmess.data.helloDataReq.req.set),hello,
		                    sizeof(mplsLdpHello_t));
		           /* MPLS_PSEND(MPLS_LDP_OAM_MESSAGE,&oamldpmess,sizeof(MIB_LDPHELLO_ACK)
		        		+sizeof(mplsLdpOAMMessage)+sizeof(unsigned char),mlsmanagePid); */
		        	mplsHelloRecv(&oamldpmess);   /* 2003-10-9 lixia add */ 
		        		
			        break;
			    }
			}
			#ifdef DEBUG_LDP
			    #ifdef __BGS10_MPLS_DEBUG
			        if(hello == MPLS_NULL)
				        printf("!!! In func_search1, del data is not exist");
			    #endif
			#endif
			break;
		case 2 :
		    for(i = 0; i < MPLSLDP_MAX; i++)
		    {
		        if((MplsLdpHelloEntry[i].RowStatus ==  VAL_RowStatus_active) &&
		           ( MplsLdpHelloEntry[i].entityLdpId.lsrAddress == in -> req.del.unionIndex.entityLdpId.lsrAddress) &&
		           ( MplsLdpHelloEntry[i].entityLdpId.labelSpace == in -> req.del.unionIndex.entityLdpId.labelSpace) &&
		           ( MplsLdpHelloEntry[i].ifIndex == in -> req.del.unionIndex.ifIndex) &&
		           ( MplsLdpHelloEntry[i].peerLdpId.lsrAddress == in -> req.del.unionIndex.peerLdpId.lsrAddress) &&
		           ( MplsLdpHelloEntry[i].peerLdpId.labelSpace == in -> req.del.unionIndex.peerLdpId.labelSpace))
		        {
		            MplsLdpHelloEntry[i].RowStatus =  VAL_RowStatus_null;
        			hello = (mplsLdpHello_t *)(&MplsLdpHelloEntry[i].entityLdpId);
			        oamldpmess.msgtype = MPLS_MIB_LDP_HELLO ;
		            oamldpmess.data.helloDataReq.operateType = 3;
		            /*oamldpmess.data.helloDataReq.req.del.indexFlag = 2;
					oamldpmess.data.helloDataReq.req.del.helloIndex = 
							(unsigned long)MplsLdpHelloEntry[i].ifIndex;
		            MPLS_PSEND(MPLS_LDP_OAM_MESSAGE,&oamldpmess,sizeof(MIB_LDPHELLO_ACK)
		        		+sizeof(mplsLdpOAMMessage)+sizeof(unsigned char),mlsmanagePid);*/
		            memcpy(&(oamldpmess.data.helloDataReq.req.set),hello,
		                    sizeof(mplsLdpHello_t));
		         /*   MPLS_PSEND(MPLS_LDP_OAM_MESSAGE,&oamldpmess,sizeof(MIB_LDPHELLO_ACK)
		        		+sizeof(mplsLdpOAMMessage)+sizeof(unsigned char),mlsmanagePid);*/
		        	mplsHelloRecv(&oamldpmess);   /* 2003-10-9 lixia add */ 
			        break;
			    }
			}
			#ifdef DEBUG_LDP
			    #ifdef __BGS10_MPLS_DEBUG
			        if(hello == MPLS_NULL)
				        printf("!!! In func_search2, del data is not exist");
			    #endif
		    #endif
			break;
		default:
			break;
	}
	return hello;
}

/*  对Session表的置表、检索和删除操作  
 */

mplsLdpSession_t  *MibSession(void * input, unsigned char flag)
{

⌨️ 快捷键说明

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