This source file is an example of how to utilize host buffers allocated to a specific NUMA node using NTAPI. NUMA support is currently not available on FreeBSD, so this example only applies to Linux. The example uses host buffers on NUMA node 1 and receives data on port 0.
The following NTAPI functions are used:
A Napatech capture accelerator is need to run this example. The ntservice.ini must have at least one HostBuffersRx defined. Below is an example of a minimum ini-file. It will create a 32MB RX hostbuffer from NUMA node 1.
The following is required to use a host buffer from a specific NUMA node:
- #include/nt.h - Applications/Tools only need to include nt.h to obtain prototypes, macros etc. from NTAPI.
- Binding the current process to NUMA node 1 can be done in several ways:
- For Linux:
- Using sched_setaffinity() on Linux. This will require that it is known which CPU cores are located on NUMA node 1.
- Using numa_bind() from libnuma on Linux to bind to NUMA node 1.
- Using numactl on the command line to start the example on NUMA node 1. e.g numactl --cpubind=1 --membind=1 ./numa_example
- For Windows:
- Using GetNumaHighestNodeNumber, GetProcessAffinityMask and GetNumaNodeProcessorMask to find the numa node that the app/process is able to use. If the system is well known this step can be skipped.
- Using SetProcessAffinityMask to move the app/process to the wanted processor (numa node).
- For Linux:
- NT_Init(NTAPI_VERSION) - Initialize the NTAPI library. NTAPI_VERSION is a define that describes the version of the API described in the header files included by nt.h. NT_Init() will ask the NTAPI library to convert return data to the NTAPI_VERSION if possible. This will ensure that applications can run on NTAPI libraries of newer versions.
- NT_ConfigOpen() - Open a configuration stream.
- NT_NTPL() - Setup stream 1 to use NUMA node 1. This must be done before assigning a filter.
- NT_NTPL() - Assign traffic to the stream. A stream doesn't return data until traffic is assigned to it by a filter. Stream IDs might be shared between other streams.
- NT_ConfigClose() - Close the configuration stream.
- NT_NetRxOpen() - Open the stream using a stream ID. The stream ID must match the one used when creating the filter.
- NT_NetRxGet() is called with a timeout of 1000ms and will return NT_STATUS_TIMEOUT in case nothing is received within 1000ms and will return NT_SUCCESS if something is returned. Return values different from that is an indication of an error. Packets that are prior to the expected time are released via NT_NetRxRelease().
- NT_NetRxRelease() - Release a packet.
- NT_NetRxClose() - Close the stream when terminating.
- NT_NTPL() - Release the NTPL assignment made on the hostbuffer.
- NT_Done() - Close down the NTAPI library.
- NT_ExplainError() - Explain an error code returned by NTAPI functions.