This source file show the procedure needed to get stream-id statistics that can be correlated with what the application receive.
The following NTAPI functions are used:
- This example does not work with the NT4E-STD accelerator
A Napatech capture accelerator is needed 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 0.
The following is required to perform real-time analysis on packets:
- #include/nt.h - Applications/Tools only need to include nt.h to obtain prototypes, macros etc. from NTAPI.
- 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 config stream in order to setup filter using the NT_NTPL() command and stream-id configuration.
- NT_StatOpen() - Open a statistics stream which will be used to get stream-id statistics.
- NT_NTPL() to inactivate the stream-id to ensure that no packets are forwarded to the stream-id until we are ready to handle them. A time stamp of when the stream-id is in-activated is returned. This time stamp is important because it tells us when to stop discarding packets.
- NT_StatRead() is called asking for a statistics reset when the next statistics update is performed.
- NT_NetRxOpen() - Open a stream. The stream ID must match the one used when creating the filter using the NT_NTPL() command. A stream doesn't return data until traffic is assigned to it by creating a filter. Stream IDs might be shared between other streams and it is possible to make several filters to one stream ID. Each filter can have a unique color in the ASSIGN. The "color" of the ASSIGN can be used to mark packets making it possible for the stream to determine if the packets it receives via NT_NetRxGet() as based on its assign or if the packet belongs to the other streams that also share the hostbuffer.
- NT_NTPL() - Assign traffic to a stream by creating a filter using a manually chosen stream ID. The stream ID must match the one used NT_NetRxOpen().
- NT_NTPL() to activate the stream-id because we are now ready to handle the traffic. It is important that wait with this step until all NT_NTPL() has been issued.
- NT_NetRxGet() and NT_NetRxRelease() - Receive and release packets. Packets received with a NT_NET_GET_PKT_TIMESTAMP() older than the time stamp returned in the "in-activation" ste are discarded newer packets are counted.
- When 10 packets has been received the stream-id is inactivated via NT_ConfigWrite() and the application will continue NT_NetRxGet() and NT_NetRxRelease() until NT_STATUS_TIMEOUT is returned.
- Delete the stream-id assignments via NT_NTPL().
- NT_NetRxClose() - Close the network stream.
- Get stream-id statistics via NT_StatRead() and check that the amount of packets counted by the application and statistics stream match.
- Close all other streams, NT_StatClose(), NT_ConfigClose().
- NT_Done() - Close down the NTAPI library.
- NT_ExplainError() - Explain an error code returned by NTAPI functions.