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

📄 lms.c

📁 路由器协议平台mpls协议的设计与实现源代码。
💻 C
📖 第 1 页 / 共 4 页
字号:
/********************************************************************/
/*	Product Name:	mpls                                           	*/
/*	Module  Name:	protocol   										*/
/*	File    Name:   lms.c	    						        	*/
/*	Author  Name:   weng.qing               						*/
/*	Creat   Date:	01/01/2002										*/
/*	Version		:	1.0                                         	*/
/*	Function    :	mpls label manager function                     */
/*  History     :   szh mod 2002-6-18 16:09                         */
/*                  02-12-12 szh mod for avoid error                */
/* wengqing 2002.12.25 modify get_gen_label and rel_gen_label       */ 
/* szh 2003-1-9  init genlabel_head and modify apartgenlbl          */
/* szh 2003-2-10 add protect exceed data limit in mpls_lms_init     */
/* hyh 2003-3-24 modify mpls_ifindex2module,get port from MplsPortDataTable */
/* szh 2003-3-25 在运行版本中去掉assert()                           */
/* 2003.06.09 shizhaohui 增加APC类型的单板                          */
/* 2003-8-13 szhmod 修改函数rel_busy_flag的错误                     */
/* szh mod 2003-8-29  改成从MplsPortDataTable1中取数据是为了避免当有配
置发生变化时,MplsPortDataTable是发消息到MFU要数据,在发消息时此表是清
空的,如果这个时候LDP建路会发生错误这种情况。 当MplsPortDataTable从MFU
要全数据后再更改MplsPortDataTable1                                  */
/*   2003-11-12 szh mod MplsPortDataTable1代替MplsPortDataTable
/*2003.11.27 Lixia 如果VPI=0,VCI=32,那么从34开始                   */
/* 2003-12-1 szh mod MplsPortDataTable to MplsPortDataTable1 in func mpls_lms_init
/* 2003-12-10 lixia add for debug mpls */
/* 2004-2-4 szh add 修改获取vpi,vci标签值的方法
/********************************************************************/

#include "lms.h"
#include "lmsfunc.h"
#include "mplsni.h"
#include "mpls_mgr.h"
#include "mpls.h"
#include "ldpvars.h"

/************************************************************************/
/*  for atm label v2.1.3 per LIC 14k vcs, so 16k is enough									 */
/*  not support configuration change																				 */
/************************************************************************/
mpls_label_busy_flags			local_label_busy_flags;

genlabel_link                   *genlabel_head=MPLS_NULL;

unsigned char                   genlabel_busy_flag = 0, genlbl_min_busy = 0;

mplsPort_t               MplsPortDataTable, MplsPortDataTable1;
PROTO_MEM_MGR                   genlblmem;

/*
void mpls_lms_init()
{
	MPLS_MEMSET(&local_label_busy_flags,  0,
							sizeof(mpls_label_busy_flags));

	local_label_busy_flags.interface_num  = 2;
	local_label_busy_flags.interface[0]   = 1;
	local_label_busy_flags.maxvci[0]      = 127;

	local_label_busy_flags.interface[1]   = 7;
	local_label_busy_flags.maxvci[1]      = 127;

	return;
}
*/

/***********************************************************************/
/* FUNCTION NAME  : mpls_lms_init()
/* DESCRIPTION:   : atm label init
/*  INPUT         : void
/*  OUTPUT        : void
/*  AUTHOR/DATE   : shi.zhaohui
/*  GLOBAL        : none
/* History        :
/* 2003-12-1 szh mod MplsPortDataTable to MplsPortDataTable1 
/* 2004-2-4 szh add 对current vpivci的赋值
/************************************************************************/
void    mpls_lms_init()
{
    unsigned char   module;
    unsigned short  i, j, t, temp;
    short           res;

    /* init in other place */
    /*  MPLS_MEMSET(&local_label_busy_flags, 0,sizeof(mpls_label_busy_flags)); */

    if(local_label_busy_flags.interface_num == 0) /* first get config data */
    {
        for(i = 0, j = 0; i < MplsPortDataTable1.num; i++)
        {
        #ifdef __INSTALL_V22
        if(((MplsPortDataTable1.mplsModule[i].cardType >=MPLS_CARDTYPE_LIC1)
              &&(MplsPortDataTable1.mplsModule[i].cardType <=MPLS_APCLIC_END))||
           ((MplsPortDataTable1.mplsModule[i].cardType >=MPLS_CARDTYPE_GEI)
            &&(MplsPortDataTable1.mplsModule[i].cardType <=MPLS_GEICARD_END))||
           ((MplsPortDataTable1.mplsModule[i].cardType >=MPLS_CARDTYPE_MPU)
            &&(MplsPortDataTable1.mplsModule[i].cardType <=MPLS_MPU_END)))             
        #else
        if((MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC1)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC2)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC3)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC4)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC5)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC6)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC7)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC8)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC9)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC10)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_MPU))
      #endif        
        {   
            for(t = 0; t < MplsPortDataTable1.mplsModule[i].num; t++)
            {
                local_label_busy_flags.interface[j].module =
                MplsPortDataTable1.mplsModule[i].module ;
                local_label_busy_flags.interface[j].port =
                MplsPortDataTable1.mplsModule[i].portData[t].port;
                local_label_busy_flags.minvci[j] =
                MplsPortDataTable1.mplsModule[i].portData[t].atmfAtmLayerMinSvccVci;
                local_label_busy_flags.maxvci[j] =
                (0x01 << MplsPortDataTable1.mplsModule[i].portData[t].atmInterfaceMaxActiveVciBits) -1;
                local_label_busy_flags.minvpi[j] = 0;
                local_label_busy_flags.maxvpi[j] =
                MplsPortDataTable1.mplsModule[i].portData[t].atmfAtmLayerMaxSvccVpi;
                local_label_busy_flags.currhuntvpi[j] = 0;
                local_label_busy_flags.currhuntvci[j] = local_label_busy_flags.minvci[j];
                j++;
                local_label_busy_flags.interface_num++;
                /* add protect exceed data limit szh 2003-2-10 */
                if(local_label_busy_flags.interface_num>=MPLS_LDP_INTERFACE_NUMBER)
                {
                    DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"first get config data too much !!!!\n ");
                    printf(" get config data too much !!!! ");
                    return;
                }    
            }
         }    
        }
    }
    else /* online get new config data */
    {
        if(local_label_busy_flags.interface_num>=MPLS_LDP_INTERFACE_NUMBER)
        {
            DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"online get config data too much !!!!\n ");
            printf(" get config data too much !!!! ");
            return;
        }
        for(i = 0; i < MplsPortDataTable1.num; i++)
        {
        #ifdef __INSTALL_V22
        if(((MplsPortDataTable1.mplsModule[i].cardType >=MPLS_CARDTYPE_LIC1)
              &&(MplsPortDataTable1.mplsModule[i].cardType <=MPLS_APCLIC_END))||
           ((MplsPortDataTable1.mplsModule[i].cardType >=MPLS_CARDTYPE_GEI)
            &&(MplsPortDataTable1.mplsModule[i].cardType <=MPLS_GEICARD_END))||
           ((MplsPortDataTable1.mplsModule[i].cardType >=MPLS_CARDTYPE_MPU)
            &&(MplsPortDataTable1.mplsModule[i].cardType <=MPLS_MPU_END)))
        #else
        if((MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC1)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC2)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC3)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC4)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC5)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC6)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC7)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC8)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC9)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_LIC10)||
           (MplsPortDataTable1.mplsModule[i].cardType == MPLS_CARDTYPE_MPU))
      #endif        
        {    
            for(j = 0; j < MplsPortDataTable1.mplsModule[i].num; j++)
            {
                res =  lms_searchport(MplsPortDataTable1.mplsModule[i].module,
                                  MplsPortDataTable1.mplsModule[i].portData[j].port);
                if(res == -1)
                {
                    temp = local_label_busy_flags.interface_num;
                    local_label_busy_flags.interface[temp].module =
                    MplsPortDataTable1.mplsModule[i].module ;
                    local_label_busy_flags.interface[temp].port =
                    MplsPortDataTable1.mplsModule[i].portData[j].port;
                    local_label_busy_flags.minvci[temp] =
                    MplsPortDataTable1.mplsModule[i].portData[j].atmfAtmLayerMinSvccVci;
                    local_label_busy_flags.maxvci[temp] =
                    (0x01 << MplsPortDataTable1.mplsModule[i].portData[j].atmInterfaceMaxActiveVciBits) -1;
                    local_label_busy_flags.minvpi[temp] = 0;
                    local_label_busy_flags.maxvpi[temp] =
                    MplsPortDataTable1.mplsModule[i].portData[j].atmfAtmLayerMaxSvccVpi;
                    local_label_busy_flags.currhuntvpi[temp] = 0;
                    local_label_busy_flags.currhuntvci[temp] = local_label_busy_flags.minvci[temp];
                    MPLS_MEMSET(&(local_label_busy_flags.busyAtmLabelFlags[temp][0]), 0, 2048*sizeof(unsigned char));
                    local_label_busy_flags.interface_num++;
                    if(local_label_busy_flags.interface_num>=MPLS_LDP_INTERFACE_NUMBER)
                    {
                        DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"online 2 get config data too much !!!!\n ");
                        printf(" get config data too much !!!! ");
                        return;
                    }
                }
                else
                {
                    local_label_busy_flags.interface[res].module =
                    MplsPortDataTable1.mplsModule[i].module;
                    local_label_busy_flags.interface[res].port =
                    MplsPortDataTable1.mplsModule[i].portData[j].port;
                    local_label_busy_flags.minvci[res] =
                    MplsPortDataTable1.mplsModule[i].portData[j].atmfAtmLayerMinSvccVci;
                    local_label_busy_flags.maxvci[res] =
                    (0x01 << MplsPortDataTable1.mplsModule[i].portData[j].atmInterfaceMaxActiveVciBits) -1;
                    local_label_busy_flags.minvpi[res] = 0;
                    local_label_busy_flags.maxvpi[res] =
                    MplsPortDataTable1.mplsModule[i].portData[j].atmfAtmLayerMaxSvccVpi;
                }
            }
         }   
        }
    }
}

short lms_searchport(unsigned char module,  unsigned short port)
{
    unsigned short  i, flag = 0, tuple;

    for(i = 0; i < local_label_busy_flags.interface_num; i++)
    {
        if((local_label_busy_flags.interface[i].module == module)&&
            (local_label_busy_flags.interface[i].port == port))
        {
            tuple = i;
            flag = 1;
            break;
        }
    }
    if(flag != 0)
    {
        return tuple;
    }
    else
        return -1; /* new config module */
}


/***********************************************************************/
/* FUNCTION NAME  : mpls_genlbl_mem_init()
/* DESCRIPTION:   : gen label init
/*  INPUT         : void
/*  OUTPUT        : void
/*  AUTHOR/DATE   : shi.zhaohui  2002/07/10
/*  GLOBAL        : none
/* History        :
/************************************************************************/
void  mpls_genlbl_mem_init()
{
    MPLS_MEMSET(&genlblmem, 0, sizeof(PROTO_MEM_MGR));
    genlblmem.alloc_type = ALLOC_TYPE_FROM_MMQ;
    genlblmem.mmq_max = LMS_ALLOC_UNITS;
    genlblmem.mmq_size = sizeof(genlabel_link);
    /* wengqing modify for memory manager init 2002.12.25 */
    if(MPLS_INIT_MMGR(genlblmem) != LMS_ALLOC_UNITS)
    /*if(&genlblmem == MPLS_NULL)*/
    {
        printf(" no apply gen label memory !!!!");
        #ifdef MPLS_LMS_DEBUG
        MPLS_ASSERT(&genlblmem);
        #endif
    }
    genlabel_head = MPLS_NULL;    
   return ;
}

/***********************************************************************/
/* FUNCTION NAME  : mpls_check_label_busy()
/* DESCRIPTION:   :
/*  INPUT         : unsigned long sit, unsigned char * head
/*  OUTPUT        : bool
/*  AUTHOR/DATE   : weng.qing
/*  GLOBAL        : none
/* History        :
/************************************************************************/
MPLS_BOOL mpls_check_label_busy( unsigned long sit, unsigned char * head)
{
	unsigned long			byte_sit ;
	unsigned long			bit_sit	 ;
	unsigned char			* base;

	byte_sit		=		(sit>>3);
	base				=   head+byte_sit;
	bit_sit			=   sit - (byte_sit<<3);

	if(!(*(base)&(0x80>>bit_sit)))
	{
		(*base) |= (0x80>>bit_sit);
		return MPLS_FALSE;
	}
	else
		return MPLS_TRUE;
}

/***********************************************************************/
/* FUNCTION NAME  : mpls_rel_label_busy()
/* DESCRIPTION:   :
/*  INPUT         : unsigned long sit, unsigned char * head
/*  OUTPUT        : bool
/*  AUTHOR/DATE   : weng.qing
/*  GLOBAL        : none
/* History        :
/************************************************************************/
MPLS_BOOL mpls_rel_label_busy( unsigned long sit, unsigned char * head)
{
	unsigned long			byte_sit ;
	unsigned long			bit_sit	 ;
	unsigned char			* base;


	byte_sit		=		(sit>>3);
	base				=   head+byte_sit;
	bit_sit			=   sit - (byte_sit<<3);

	(*base) &= ~(0x80>>bit_sit);
	return MPLS_FALSE;

}

/***********************************************************************/
/* FUNCTION NAME  : mpls_get_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

⌨️ 快捷键说明

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