datapath-windows/ovsext/BufferMgmt.c
/*
 * --------------------------------------------------------------------------
 * OvsAllocateFixSizeNBL --
 *
 *    Allocate fix size NBL which include
 *       NBL + NB + MBL + Data + Context
 *    Please note:
 *       * Forwarding Context is allocated, but forwarding detail information
 *       is not initailized.
 *       * The headroom can not be larger than OVS_DEFAULT_HEADROOM_SIZE(128
 *       byte).
 * --------------------------------------------------------------------------
 */


Allocate fix size NBL which include
NBL + NB + MBL + Data + Context
Please note:
Forwarding Context is allocated, but forwarding detail information
is not initailized.
The headroom can not be larger than OVS_DEFAULT_HEADROOM_SIZE(128
byte).
Allocate fix size NBL which include NBL + NB + MBL + Data + Context Please note : Forwarding Context is allocated but forwarding detail information is not initailized . The headroom can not be larger than OVS_DEFAULT_HEADROOM_SIZE ( 128 byte ) .
PNET_BUFFER_LIST
OvsAllocateFixSizeNBL(PVOID ovsContext,
                      UINT32 size,
                      UINT32 headRoom)
{
    PNET_BUFFER_LIST nbl = NULL;
    POVS_SWITCH_CONTEXT context = (POVS_SWITCH_CONTEXT)ovsContext;
    POVS_BUFFER_CONTEXT ctx;
    POVS_NBL_POOL ovsPool = &context->ovsPool;
    NDIS_STATUS status;
    UINT32 line;
    PNDIS_SWITCH_FORWARDING_DETAIL_NET_BUFFER_LIST_INFO info;
    if ((headRoom + size) > OVS_FIX_NBL_DATA_SIZE || size == 0) {
        line = __LINE__;
        goto allocate_done;
    }
    nbl = NdisAllocateNetBufferList(ovsPool->fixSizePool,
                                    (UINT16)sizeof (OVS_BUFFER_CONTEXT),
                                    (UINT16)OVS_DEFAULT_NBL_CONTEXT_FILL);
    if (nbl == NULL) {
        line = __LINE__;
        goto allocate_done;
    }
    nbl->SourceHandle = ovsPool->ndisHandle;
    status = context->NdisSwitchHandlers.
             AllocateNetBufferListForwardingContext(ovsPool->ndisContext, nbl);
    if (status != NDIS_STATUS_SUCCESS) {
        NdisFreeNetBufferList(nbl);
        nbl = NULL;
        line = __LINE__;
        goto allocate_done;
    }
    info = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL(nbl);
    ASSERT(info);
    info->IsPacketDataSafe = TRUE;
    info->SourcePortId = NDIS_SWITCH_DEFAULT_PORT_ID;
    status = NdisRetreatNetBufferDataStart(NET_BUFFER_LIST_FIRST_NB(nbl),
                                           size, 0, NULL);
    ASSERT(status == NDIS_STATUS_SUCCESS);
#ifdef DBG
    InterlockedIncrement((LONG volatile *)&ovsPool->fixNBLCount);
    OvsDumpNetBufferList(nbl);
    OvsDumpForwardingDetails(nbl);
#endif
    ctx = (POVS_BUFFER_CONTEXT)NET_BUFFER_LIST_CONTEXT_DATA_START(nbl);
    ASSERT(ctx);
    OvsInitNBLContext(ctx, OVS_BUFFER_FROM_FIX_SIZE_POOL |
                      OVS_BUFFER_PRIVATE_FORWARD_CONTEXT, size,
                      OVS_DPPORT_NUMBER_INVALID, 0);
    line = __LINE__;
allocate_done:
    OVS_LOG_LOUD("Allocate Fix NBL: %p, line: %d", nbl, line);
    return nbl;
}
PNET_BUFFER_LIST OvsAllocateFixSizeNBL ( PVOID ovsContext , UINT32 size , UINT32 headRoom ) { PNET_BUFFER_LIST nbl = NULL ; POVS_SWITCH_CONTEXT context = ( POVS_SWITCH_CONTEXT ) ovsContext ; POVS_BUFFER_CONTEXT ctx ; POVS_NBL_POOL ovsPool = & context -> ovsPool ; NDIS_STATUS status ; UINT32 line ; PNDIS_SWITCH_FORWARDING_DETAIL_NET_BUFFER_LIST_INFO info ; if ( ( headRoom + size ) > OVS_FIX_NBL_DATA_SIZE || size == 0 ) { line = __LINE__ ; goto allocate_done ; } nbl = NdisAllocateNetBufferList ( ovsPool -> fixSizePool , ( UINT16 ) sizeof ( OVS_BUFFER_CONTEXT ) , ( UINT16 ) OVS_DEFAULT_NBL_CONTEXT_FILL ) ; if ( nbl == NULL ) { line = __LINE__ ; goto allocate_done ; } nbl -> SourceHandle = ovsPool -> ndisHandle ; status = context -> NdisSwitchHandlers . AllocateNetBufferListForwardingContext ( ovsPool -> ndisContext , nbl ) ; if ( status != NDIS_STATUS_SUCCESS ) { NdisFreeNetBufferList ( nbl ) ; nbl = NULL ; line = __LINE__ ; goto allocate_done ; } info = NET_BUFFER_LIST_SWITCH_FORWARDING_DETAIL ( nbl ) ; ASSERT ( info ) ; info -> IsPacketDataSafe = TRUE ; info -> SourcePortId = NDIS_SWITCH_DEFAULT_PORT_ID ; status = NdisRetreatNetBufferDataStart ( NET_BUFFER_LIST_FIRST_NB ( nbl ) , size , 0 , NULL ) ; ASSERT ( status == NDIS_STATUS_SUCCESS ) ; #ifdef DBG InterlockedIncrement ( ( LONG volatile * ) & ovsPool -> fixNBLCount ) ; OvsDumpNetBufferList ( nbl ) ; OvsDumpForwardingDetails ( nbl ) ; #endif ctx = ( POVS_BUFFER_CONTEXT ) NET_BUFFER_LIST_CONTEXT_DATA_START ( nbl ) ; ASSERT ( ctx ) ; OvsInitNBLContext ( ctx , OVS_BUFFER_FROM_FIX_SIZE_POOL | OVS_BUFFER_PRIVATE_FORWARD_CONTEXT , size , OVS_DPPORT_NUMBER_INVALID , 0 ) ; line = __LINE__ ; allocate_done : OVS_LOG_LOUD ( " " , nbl , line ) ; return nbl ; }
OvsAllocateFixSizeNBL
OvsAllocateFixSizeNBL