This source file is an example of how to transmit packets using the segment interface in NTAPI. The example will transmit 2500000 packets with a size of 1024 bytes from port 0. The packet contains an incrementing 32bit pattern.
The following NTAPI functions are used:
- The ntservice.ini must have at least one HostBuffersTx defined. Below is an example of a minimum ini-file. It will create a 4MB TX hostbuffer from NUMA node 0.
The following is required to transmit packages:
- #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_NetTxOpen() - Open a hostbuffer than can transmit packets to port 0.
- NT_NetTxGet() - Get an empty tx buffer. This will get a 1024 byte wire length packet buffer that will be sent onto port 0 when released.
- _nt_net_build_pkt_netbuf() - Initialize a view into the fiest packet of the segment.
- While there is still room in the segment:
- NT_NET_SET_PKT_CLEAR_DESCR_NT() - Zero the packet descriptor.
- NT_NET_SET_PKT_DESCR_TYPE_NT() - Set the packet descriptor type.
- NT_NET_UPDATE_PKT_L2_PTR() - Recalculate the pointer to the packet payload.
- NT_NET_SET_PKT_TXPORT() - Set the transmit port in the packet descriptor.
- NT_NET_SET_PKT_CAP_LENGTH() - Set the aligned packet buffer size. This macro automatically aligns and adds the descriptor length.
- NT_NET_SET_PKT_WIRE_LENGTH() - Set the payload length.
- NT_NET_SET_PKT_TXIGNORE() - If this is a padding packet, ignore the packet.
- _nt_net_get_next_packet() - Move the view to the next packet in the buffer. Loop.
- NT_NetTxRelease() - Release the tx packet buffer. Once a tx buffer is released it will be transmitted
- NT_NetTxClose() - Close the TX stream.
- NT_Done() - Close down the NTAPI library.