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

📄 lms.c

📁 路由器协议平台mpls协议的设计与实现源代码。
💻 C
📖 第 1 页 / 共 4 页
字号:
    short				p;
    unsigned char 		* head = MPLS_NULL;
	
	p = -1;
    for(t = 0; t <local_label_busy_flags.interface_num; t ++ )
	{
		if((label_rel -> module == local_label_busy_flags.interface[t].module)&&
		  (label_rel -> port == local_label_busy_flags.interface[t].port))
		{
			p = t;
			break;
		}
	}
	if(p < 0)
	{
		label_ack->ack 	=	MPLS_FAIL;
		return;
	}
	head = &(local_label_busy_flags.busyAtmLabelFlags[p][0]);
	
	vpi = label_rel->label.atm_label.label.flags.vpi;
	vci = label_rel->label.atm_label.label.flags.vci;
	sit = vpi*(local_label_busy_flags.maxvci[p]+1)+vci+1;
	exit = mpls_rel_label_busy(sit, head);
	if(exit != MPLS_FALSE)
	{
    	label_ack->ack 	=	MPLS_FAIL;
	}
	else
	{
	    label_ack->ack 	=	MPLS_SUCCESS;
	    if(local_label_busy_flags.interface[p].session_index != 0)
	    {
	        /* notify ldp , has label is use */
	        SndNotMsg(local_label_busy_flags.interface[p].session_index,\
	        		  LBLRESRCAVA,0,0);
	        local_label_busy_flags.interface[p].session_index = 0;
	    }
	}
	return;
}

/***********************************************************************/
/* FUNCTION NAME  : mpls_lms_rel_genlabel()
/* DESCRIPTION:   : release gen label
/*  INPUT         : unsigned long  genlbl
/*  OUTPUT        : unsigned char
/*  AUTHOR/DATE   : shi.zhaohui/ 02.06.19
/*  GLOBAL        : none
/* History        : 02-12-12 szh mod for avoid error
/************************************************************************/

unsigned char   mpls_lms_rel_genlabel(unsigned long  genlbl )
{
    genlabel_link   *templbl, *nextlbl;

    if(genlabel_head == MPLS_NULL)
    {
        return MPLS_TRUE;
    }
    else
    {
        templbl = genlabel_head;
        if(genlbl < genlabel_head->minlabel)
        {
   /*     	MPLS_ASSERT(0);    */
        	return MPLS_TRUE;
        }
        do
        {
//			printf("release gen label: %d",genlbl);
            nextlbl = templbl;
            if((genlbl <= nextlbl -> maxlabel)&&(genlbl >= nextlbl -> minlabel)) /* to avoid rel label does not exist */
            {
                apartgenlbl(genlbl,nextlbl);
                if(genlabel_busy_flag == 1)
                {
                    /* inform ldp can hunt label */
                    genlabel_busy_flag = 0;
                }
                break;
            }
            else
            {
                if(genlbl < nextlbl -> minlabel) /* to avoid continuing comparison */
                {
                   printf("label does not belong to any segment.");
                   break;
                }
                templbl = (genlabel_link *)nextlbl -> next;
            }
        }while(templbl != MPLS_NULL);
    }
    return MPLS_TRUE;
}

/***********************************************************************/
/* FUNCTION NAME  : apartgenlbl()
/* DESCRIPTION:   : apart one gen label area into two gen label
/*  INPUT         : unsigned long  genlbl, genlabel_link  *apartlbl
/*  OUTPUT        : void
/*  AUTHOR/DATE   : shi.zhaohui/ 02.06.19
/*  GLOBAL        : none
/* History        :
/* wengqing 2002.12.25 modify release label block
/************************************************************************/
unsigned char    apartgenlbl(unsigned long  genlbl, genlabel_link  *apartlbl)
{
    genlabel_link    *templbl, *newlbl, *temp1lbl;


    if(genlbl == MPLS_LABEL_MIN)
	{
            genlbl_min_busy = 0;
        }
        if((genlbl == apartlbl -> maxlabel)&&
          (genlbl == apartlbl -> minlabel))
        {
        if(apartlbl->front)
        	apartlbl->front->next = apartlbl->next;
        if(apartlbl->next)
        	apartlbl->next->front = apartlbl->front;
        if(apartlbl == genlabel_head)
        	genlabel_head = apartlbl->next;
        apartlbl->minlabel = 0;
	    apartlbl->maxlabel = 0;
	    apartlbl->front    = MPLS_NULL;
	    apartlbl->next     = MPLS_NULL;
        /*    free(apartlbl);   */
            MPLS_MEM_FREE(apartlbl, genlblmem);
        apartlbl = MPLS_NULL;
        }
        else /* apart this label  */
        {
            if(genlbl == apartlbl -> maxlabel)
            {
                apartlbl -> maxlabel = apartlbl -> maxlabel - 1;
            }
            else if(genlbl == apartlbl -> minlabel)
            {
                apartlbl -> minlabel = apartlbl -> minlabel + 1;
            }
            else
            {
        	newlbl = MPLS_NULL;
                MPLS_MEM_ALLOC(newlbl,(genlabel_link *),sizeof(genlabel_link),genlblmem);
                if(newlbl == MPLS_NULL)
                {
                    printf(" no apply enough memory(lms) !!!!");
                    #ifdef MPLS_LMS_DEBUG
                        MPLS_ASSERT(newlbl);
                    #endif
                    return MPLS_MEMORY_ERROR;
                }
                  newlbl -> next = apartlbl ->next;
                /*hyh*/
                if(apartlbl ->next)
                    apartlbl ->next->front = newlbl;
                /**/
            apartlbl ->next = newlbl;
            newlbl -> front = apartlbl;
                newlbl -> maxlabel = apartlbl -> maxlabel;
                newlbl -> minlabel = genlbl + 1;
                apartlbl -> maxlabel = genlbl - 1;
             }
        }
        return MPLS_TRUE;
}


/*****************************************************************************/
/* mpls_ifindex2module(MPLS_IFINDEX2MOD_REQ * mpls_ifindex2mod_req,          */
/*                     MPLS_IFINDEX2MOD_ACK * mpls_ifindex2mod_ack)          */
/* may for global use                                                        */
/* hyh 2003-3-24 modify mpls_ifindex2module,get port from MplsPortDataTable */
/* szh mod 2003-8-29  改成从MplsPortDataTable1中取数据是为了避免当有配置发生变化
时,MplsPortDataTable是发消息到MFU要数据,在发消息时此表是清空的,如果这个时候LDP
建路会发生错误这种情况。 当MplsPortDataTable从MFU要全数据后再更改MplsPortDataTable1*/
/*****************************************************************************/
void mpls_ifindex2module(MPLS_IFINDEX2MOD_REQ * mpls_ifindex2mod_req,
                              MPLS_IFINDEX2MOD_ACK * mpls_ifindex2mod_ack,
                              unsigned short        ModorPortorIf)
{
  unsigned short    port;
  unsigned short    mod;
  unsigned short  i,j;

  mod   = mpls_ifindex2mod_req->ifIndex / MPLS_NIC_MAX_IF;

  mpls_ifindex2mod_ack->ack = MPLS_FAIL;
  if(mpls_ifindex2mod_req->mpls_platform == MPLS_PLATFORM_M1000)
  {
    if(mpls_ifindex2mod_req->mpls_protocol_type ==
        MPLS_LABEL_SWITCH_PROTOCOL_ATM)
    {
      mpls_ifindex2mod_ack->mod  = 0;
    }
  }
  else if(mpls_ifindex2mod_req->mpls_platform == MPLS_PLATFORM_BX)
  {
    if(mpls_ifindex2mod_req->mpls_protocol_type ==
        MPLS_LABEL_SWITCH_PROTOCOL_ATM)
    {
      mpls_ifindex2mod_ack->mod  = mod+1;
    }
  }
  else if(mpls_ifindex2mod_req->mpls_platform == MPLS_PLATFORM_AX)
  {
    if(mpls_ifindex2mod_req->mpls_protocol_type ==
        MPLS_LABEL_SWITCH_PROTOCOL_ATM)
    {
      mpls_ifindex2mod_ack->mod  = mod+6;
    }
  }
  else if(mpls_ifindex2mod_req->mpls_platform == MPLS_PLATFORM_M2000)
  {
    if(mpls_ifindex2mod_req->mpls_protocol_type ==
        MPLS_LABEL_SWITCH_PROTOCOL_ATM)
    {
      if(mpls_ifindex2mod_req->ifIndex == 15||mpls_ifindex2mod_req->ifIndex == 16)
          mpls_ifindex2mod_ack->mod  = 0; /* MMU */
      else    
          mpls_ifindex2mod_ack->mod  = mod+5;
    }
  }
  
  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_MPU) ||
     (MplsPortDataTable1.mplsModule[i].cardType>=MPLS_CARDTYPE_LIC1 &&
      MplsPortDataTable1.mplsModule[i].cardType<=MPLS_CARDTYPE_LIC10))
      #endif
     {
         for(j=0; j<MplsPortDataTable1.mplsModule[i].num; j++)
         {
             if(mpls_ifindex2mod_req->ifIndex==MplsPortDataTable1.mplsModule[i].portData[j].ifIndex)
             {
                 mpls_ifindex2mod_ack -> ack = MPLS_SUCCESS;
                 mpls_ifindex2mod_ack->port  = MplsPortDataTable1.mplsModule[i].portData[j].port;
                 break;
             }
         }
     }
     if(mpls_ifindex2mod_ack -> ack == MPLS_SUCCESS)
        break;
  }
             
  return ;
}

/***********************************************************************/
/* FUNCTION NAME  : rel_busy_flag()
/* DESCRIPTION:   : when module alarm, delete the internal-module label range
/*  INPUT         : unsigned char module
/*  OUTPUT        : void
/*  AUTHOR/DATE   : weng.qing/ 03.06.23
/*  GLOBAL        : local_label_busy_flags
/* History        :
/* 2003-8-13 szh mod i被重复使用,再定义一个变量t
/************************************************************************/
void rel_busy_flag(unsigned char module, unsigned char port)
{
    unsigned short  i, flag = 0, tuple, t;
    
    i = 0xffff;
    if(port == 0)
    {
        for(t = 0; t < local_label_busy_flags.interface_num; t++)
        {
            if((local_label_busy_flags.interface[t].module == module)&&
            (local_label_busy_flags.interface[t].port == 0))
            {
                i = t;
                break;
            }
        }
    }  
    else if(port == 1)
    {
    if(mplsOamLocalPlatformType==MPLS_OAM_PLATFORM_M1000) 
    {
    	module += 4;
    }
     for(t = 0; t < local_label_busy_flags.interface_num; t++)
     {
        if((local_label_busy_flags.interface[t].module == 0)&&
            (local_label_busy_flags.interface[t].port == module))
        {
            i = t;
            break;
        }
     }
    }
    if(i != 0xffff)
    {
        memcpy(&local_label_busy_flags.interface[i],&local_label_busy_flags.interface[i+1],\
               (local_label_busy_flags.interface_num-i-1)*sizeof(mpls_lms_atm_interface));
        memcpy(&local_label_busy_flags.minvci[i],&local_label_busy_flags.minvci[i+1],\
               (local_label_busy_flags.interface_num-i-1)*sizeof(unsigned short));
        memcpy(&local_label_busy_flags.minvpi[i],&local_label_busy_flags.minvpi[i+1],\
               (local_label_busy_flags.interface_num-i-1)*sizeof(unsigned short));
        memcpy(&local_label_busy_flags.maxvci[i],&local_label_busy_flags.maxvci[i+1],\
               (local_label_busy_flags.interface_num-i-1)*sizeof(unsigned short));
        memcpy(&local_label_busy_flags.maxvpi[i],&local_label_busy_flags.maxvpi[i+1],\
               (local_label_busy_flags.interface_num-i-1)*sizeof(unsigned short));
        memcpy(&local_label_busy_flags.busyAtmLabelFlags[i][0], \
               &local_label_busy_flags.busyAtmLabelFlags[i+1][0],\
               (local_label_busy_flags.interface_num-i-1)*sizeof(unsigned char)*2*1024);        
        local_label_busy_flags.interface_num--;
    }
}


void  mpls_ldp_configtbl( )
{
    if(MplsPortDataTable.num>0)
    {
        MPLS_MEMSET(&MplsPortDataTable1, 0, sizeof(mplsPort_t));
        MPLS_MEMCPY(&MplsPortDataTable1, &MplsPortDataTable,sizeof(mplsPort_t));
    }
    return;    
}    
    

⌨️ 快捷键说明

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