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

📄 ospf_vs_lib.c

📁 vxworks下ospf协议栈
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ospf_vs_lib.c - ospf virtual stack management library *//* Copyright 2000-2003 Wind River Systems, Inc. *//*modification history--------------------02c,02jun03,ram Changed native memory usage to OSPF memory partition02b,29may03,agi Modified RWOS calls to OSPF calls as part of RWOS removal 02a,08oct02,agi Fixed empty file compiler warning02,17sep01,kc  Moved ospfConfigurationTableInit() from ospf_init.c.01,07mar01jkw	 written.*//*DESCRIPTIONThis module implements the framework for OSPF Virtual Stacks.  Each stack isrepresented by an OSPF_GLOBAL_DATA structure defined intarget/src/wrn/ospf/ospf_vs_data.h.  Please see that file for informationon particular elements of that data structure.The system is an array of pointers to these structures stored in vsOspfTbl andindexed by an integer from 0 to OSPF_VSID_MAX.  There is a special stack, referredto as the management stack, which is defined as VS_MGMT_STACK_OSPF.  This isdefined in target/src/wrn/ospf/ospf_vs_lib.h.For tasks calling into the stack we provide a current Ospf Virtual Stacknumber concept via a task variable called myTaskNum.  This variable can begotten or set via a set of routines in this module.  Routines called in thecontext of a task (though NEVER tNetTask) it is possible to reference elementsof the stack's virtual stack like this:.CSospfVsTbl[myTaskNum]->stackGlobalYouWantToLookAt*//* this include is here to fix the "empty file" compiler warning */#include "vxWorks.h"/* * This huge ifdef means that the file gets run through the compiler but is * empty in the case where we're building the stack without  * __OSPF_VIRTUAL_STACK__ support. */#ifdef __OSPF_VIRTUAL_STACK__/* includes */#include "ospf_vs_lib.h"#include "ospf_vs_data.h"/* defines *//* globals */int myStackNum = 0; /* Task local stack number. */OSPF_GLOBAL_DATA* ospfVsTbl[OSPF_VSID_MAX];SEM_ID ospfVsTblLock;OSPF_VSID mgmtStackId;/********************************************************************************* ospfVirtualStackLibInit - initialize the Ospf Virtual Stack system** This routine initializes all the global data required by the ospf virtual stack* system.** RETURNS: OK or ERROR if any resources are unavailable.**/STATUS ospfVirtualStackLibInit    (    )    {    int count;    /*     * Create a semaphore to protect our table.     */    ospfVsTblLock = semBCreate(SEM_Q_PRIORITY, SEM_FULL);    if (ospfVsTblLock == NULL)        return (ERROR);    for (count = 0; count < OSPF_VSID_MAX; count++)        {        ospfVsTbl[count] = NULL;        }    return (OK);    }/********************************************************************************* ospfVirtualStackCreate - creates an instance of an ospf virtual stack** This routine creates an instance of a Ospf Virtual Stack and returns a pointer* to the OSPF_VSID on successful completion.  Once this routine returns the* desired initialization sequence may be called to start the appropriate* protocols and initialize the network data structures.** The stack index (i.e.  0 1 2 ...) is assigned.** RETURNS: OK or ERROR. If ERROR is returned the <pOSPF_VSID> contents are* not valid.**/STATUS ospfVirtualStackCreate    (    OSPF_VSID* pOSPF_VSID 		/* Buffer for storing virtual stack identifier */    )    {    int ospfVsIndex, i;    char tempName[OSPF_VS_NAME_MAX + 1];    /* Lock out access until creation is complete or error is returned. */    semTake(ospfVsTblLock, WAIT_FOREVER);    /* Find the first empty slot. */    for (ospfVsIndex = 0; ospfVsIndex < OSPF_VSID_MAX; ospfVsIndex++)        {        if (ospfVsTbl[ospfVsIndex] == NULL)            break; /* Hey, we found one! */        }    if (ospfVsIndex == OSPF_VSID_MAX)        {        semGive(ospfVsTblLock);        return (ERROR);        }        sprintf(tempName, "%d", ospfVsIndex);    /* null-terminate it, just in case... */    *(tempName + OSPF_VS_NAME_MAX) = EOS;    /* Check that a stack with the same name doesn't already exist */    for (i = 0; i < OSPF_VSID_MAX; i++)        {        if (ospfVsTbl[i] == NULL)  /* empty slot */            continue;        if (strcmp(ospfVsTbl[i]->pName, tempName) == 0)            {            semGive(ospfVsTblLock);            return ERROR;            }        }    /* Allocate our global structure.  */    *pOSPF_VSID = ospfVsTbl[ospfVsIndex] = (OSPF_GLOBAL_DATA *)buffer_malloc        (sizeof(OSPF_GLOBAL_DATA));    if (ospfVsTbl[ospfVsIndex] == NULL)        {        semGive(ospfVsTblLock);        return (ERROR);        }    /* Clear out the structure to NULL */    memset ((char *)*pOSPF_VSID,0, sizeof(OSPF_GLOBAL_DATA));    /*     * Make the name the OSPF VS number.     */    ospfVsTbl[ospfVsIndex]->pName = (char *)&ospfVsTbl[ospfVsIndex]->name;    memcpy(tempName, ospfVsTbl[ospfVsIndex]->pName, sizeof(tempName));    semGive(ospfVsTblLock);    return (OK);    }/********************************************************************************* ospfVirtualStackInit - initialize an ospf virtual stack** This routine performs the default initialization of an OSPF Virtual stack* created with the ospfVirtualStackCreate() routine. When this routine* completes, the OSPF protocol will be initialized and* the corresponding data structures for the stack will be valid.** RETURNS: OK, or ERROR if initialization fails.*/STATUS ospfVirtualStackInit    (    OSPF_VSID ospfVsId	  /* Stack identifier from ospfVirtualStackCreate() routine */    )    {    int ospfVsIndex;     /* Verify stack identifier. Exit if not found. */    semTake(ospfVsTblLock, WAIT_FOREVER);    for (ospfVsIndex = 0; ospfVsIndex < OSPF_VSID_MAX; ospfVsIndex++)        if (ospfVsTbl[ospfVsIndex] == ospfVsId)            break;    if (ospfVsIndex == OSPF_VSID_MAX)        {        semGive(ospfVsTblLock);        return (ERROR);        }    semGive(ospfVsTblLock);    return (OK);    }/********************************************************************************* ospfVirtualStackDelete - delete an ospf virtual stack** This routine deletes the ospf virtual stack referenced by the OSPF_VSID passed to it.** RETURNS: OK or ERROR if the OSPF_VSID passed to the call was in some way invalid**/STATUS ospfVirtualStackDelete    (    OSPF_VSID ospfVsId /* VID returned by virtualStackCreate */    )    {    int ospfVsIndex;    semTake(ospfVsTblLock, WAIT_FOREVER);    for (ospfVsIndex = 0; ospfVsIndex < OSPF_VSID_MAX; ospfVsIndex++)        if (ospfVsTbl[ospfVsIndex] == ospfVsId)            break; /* Hey, we found it! */    /* Check that we did find it. */    if (ospfVsIndex == OSPF_VSID_MAX)        {        semGive(ospfVsTblLock);

⌨️ 快捷键说明

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