INFO: This is an 3GA and 4GA inline example. A more advanced 4GA inline example can be found in examples/net/vlandemo/.
This source file is an example of how to run in an inline scenario. The example will discard every 2nd packet.
The following NTAPI functions are used:
An Napatech inline accelerator with at least one RX host buffer per port defined. Below is an example of a minimum ini-file. It will create two 32MB RX hostbuffers from NUMA node 0. The source and destination is determined by the filter. Use a traffic generator to apply traffic to one of the ports.
The following is required to run in an inline scenario:
- #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_InfoOpen() - Detect the adapter generation and if TX is available.
- NT_ConfigOpen() - Open a config stream in order to setup filter using the NT_NTPL() command.
- 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(). On 4GA adapters and above, the Setup NTPL statement must be used to forward the packets from the stream to the output tx port (as opposed to the older form on 3Garch adapters where this could be done in the Assign statement). To indicate whether a packet should be dropped, we use the DYN3 descriptors and indicate that the wirelength is used.
- Optional step. Wait until we start seeing packets that are hit by the NTPL assign command. This is done to avoid getting packets that are not fully classified by the stream. 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_NetRxGet(), discard every 2nd packet and NT_NetRxRelease() - Receive packets, discard every 2nd and release packets. The Packet macros are used to find the packet length ant the timestamp of the packet:
- NT_NET_GET_PKT_WIRE_LENGTH() - Get length of the packet to store.
- NT_NET_GET_PKT_TIMESTAMP() - The time the packet was delivered.
- NT_NET_SET_PKT_TXIGNORE() - Don't send the current packet (3GArch).
- NT_NET_GET_PKT_DESCR_PTR() - Get the packet descriptor header (4GArch). In the 4GArch, we set the wire length to 0 in order to discard the packet as opposed to using the NT_NET_SET_PKT_TXIGNORE().
- NT_NetRxClose() - Close the stream when terminating. This will close the stream and release the NTPL assignment made on the hostbuffer.