stream_net.h Source File

Reference Documentation

Platform
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.14
Napatech Software Suite: include/ntapi/stream_net.h Source File
stream_net.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2025 Napatech A/S.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Napatech A/S nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NAPATECH A/S BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *
29 
30  */
31 
32 /**
33  * @file
34  *
35  * This is header file of the network stream interface
36  */
37 #ifndef __STREAM_NET_H__
38 #define __STREAM_NET_H__
39 
40 #if !defined(__NT_H__)
41  #error: My interface file is 'nt.h'. Please include that via #include "nt.h" directly.
42 #endif
43 
44 /** @addtogroup NetworkStream
45  *
46  * Network streams are used to receive and transmit data packets to
47  * and from the adapters. They are an extension build on top of the
48  * hardware-based host buffers.
49  * Three types of network streams exist:
50  * @li @ref StreamRx is used to receive data
51  * @li @ref StreamTx is used to transmit data
52  * @li @ref StreamFile is used to receive data to a file
53  *
54  * @note The streams are not thread safe so using the network stream API
55  * must be performed without concurrent access to the stream.
56  */
57 
58 /** @addtogroup StreamRx
59  * The RX network stream is used for both capture and in-line
60  * scenarios. The capture scenarios can deliver packets either
61  * packet-by-packet or as segments. The segment delivery is used for
62  * store to disk scenarios followed by offline analysis via the
63  * file-based network stream.
64  *
65  * @section PacketInterface Packet Interface
66  *
67  * The main interface is the packet interface. The packet interface is
68  * an interface for applications to do packet-by-packet
69  * processing. Please note that this approach will move some CPU load
70  * from the application to the driver compared to the segment
71  * interface. To open an RX network stream using the packet interface,
72  * call the @ref NT_NetRxOpen function with the interface type set to
73  * @ref NtNetInterface_e::NT_NET_INTERFACE_PACKET
74  * "NT_NET_INTERFACE_PACKET". To receive a packet, call @ref NT_NetRxGet
75  * and use the @ref PacketMacros "packet macros" to access the
76  * data. When finished with the packet, call @ref NT_NetRxRelease to release
77  * it again. When finished with the stream, call @ref NT_NetRxClose to close
78  * it.
79  *
80  * For an example on how to use the packet interface see @ref
81  * net/analysis/analysis_example.c "net/analysis/analysis_example.c".
82  *
83  * @section SegmentInterface Segment Interface
84  *
85  * The segment interface is only intended to be used for writing data
86  * to the disc and to do this the application will have to add a file
87  * header, provided by the system, to the beginning of the file. To read
88  * back data from the file, the application will have to use the
89  * @ref StreamFile to open the file and process the saved data packet
90  * by packet. To open an RX network stream using the segment interface,
91  * call the @ref NT_NetRxOpen function with the interface type set to
92  * @ref NtNetInterface_e::NT_NET_INTERFACE_SEGMENT
93  * "NT_NET_INTERFACE_SEGMENT". To receive a segment, call @ref NT_NetRxGet
94  * and use the @ref SegmentMacros "segment macros" to access the
95  * data. When finished with the segment, call @ref NT_NetRxRelease to release
96  * it again. When finished with the stream, call @ref NT_NetRxClose to
97  * close it.
98  *
99  * For an example on how to use the segment interface see @ref
100  * net/capture/capture_example.c "net/capture/capture_example.c".
101  *
102  * @section DataSharing Data Sharing
103  *
104  * Data sharing is a feature that will allow multiple applications to
105  * access the same shared host buffer.
106  *
107  * Data sharing is supported at the host buffer level. This allows
108  * multiple applications to access the same host buffer, at the
109  * same time, and individually decide if they want to use the packet
110  * interface or the segment interface. Data sharing is zero copy but
111  * will take up some extra CPU power to handle the synchronization of
112  * the host buffers. The service daemon is responsible for handling the
113  * host buffer exchange with the hardware and the data sharing is
114  * transparent to the application.
115  *
116  * In-line network streams cannot be shared and any attempt to open an
117  * existing in-line stream fails with an error return value.
118  *
119  * @note Be aware that the slowest application sets the speed. This
120  * means that a packet/segment will not be returned to the hardware
121  * before all applications that share the host buffer have
122  * processed it. To avoid this use @ref MainDocMainFeaturesTraffic_ReceiveHb_HostBufferAllowance
123  *
124  * @section DataMerging Data Merging
125  *
126  * Data merging is used for merging data packets received from
127  * multiple host buffers into one stream. This feature is used to merge
128  * data from multiple ports on multiple adapters, or multiple host buffers from one
129  * in-line adapter. The Napatech Software Suite supports
130  * merging of data from up to 42 host buffers, making it possible to
131  * merge data from 42 NT adapters. See the @ref NtplOverview "NTPL" for a
132  * description on how to configure data merging.
133  *
134  * @note Data merging is only possible for packet streams.
135  * @par
136  * @note Timesynchronisation is required when merging from different adapters (see @ref MainDocMainFeaturesVirtPort_AdapterMerge).
137  */
138 
139 /** @addtogroup StreamTx
140  * The TX network stream is used for transmitting data. Packets sent
141  * via this stream will be interleaved with traffic from in-line
142  * streams or other transmit streams.
143  *
144  * To open a TX network stream, call the @ref NT_NetTxOpen function. To
145  * get an empty packet, call the @ref NT_NetTxGet function with the
146  * desired length of the packet. The length includes the 4 bytes for
147  * the Ethernet CRC. Now fill data into the buffer and use the
148  * @ref TxMacros "TX Macros" for setting the desired time stamp, force CRC
149  * generation, etc. When finished with the packet, call @ref NT_NetTxRelease
150  * to release and transmit it. When finished with the stream, call @ref
151  * NT_NetTxClose to close it.
152  *
153  * For an example on how to use the packet interface, see @ref
154  * net/transmit_packet/transmit_packet_example.c "net/transmit/transmit_example.c".
155  *
156  * With NT3GA FPGAs Tx mode selection is an adapter global configuration - controlled by the actual FPGA image functionality and the profile ini-option.\n
157  * With NT4GA FPGAs the configuration granularity has changed - Tx mode selection can be set up/configured dynamically on individual streams.\n
158  * To facilitate this change - new options have been introduced into NTAPI (NT_NetTxOpen).
159  *
160  * Tx streams are normally "per port Tx mode" - meaning that one host buffer is allocated per (Tx) port set in the (Tx) portMask specfied to NT_NetTxOpen.
161  * Each allocated host buffer will be paired to a specific Tx port and the txPort field in the standard packet descriptor will have no meaning/effect.
162  *
163  * Adapter-based multi-port transmit buffer mode (named after its option/flag) will allocate one host buffer per adapter that has (Tx) ports set in the (Tx) portMask specified to NetTxOpen.
164  * Each host buffer allocated will be paired to a specific adapter - and that host buffer will be able to transmit on all the ports mentioned in the portMask on the adapter it is paired with.
165  * The Tx port will be selected by the txPort field in each packet descriptor.
166  *
167  * Adapter-based multi-port transmit buffer mode is selected by a new option (called flags) that is introduced to the attributes used by NTAPI function NT_NetTxOpen_Attr().
168  * The new NT_NETTX_OPEN_FLAGS_ADAPTER_MULTI_PORT_BUFFER flag/attribute is set up using NT_NetTxOpenAttrSetFlags().
169  *
170  * With NT4GA Test & Measurement FPGAs the following can be controlled per transmitted packet: timestamp injection, FCS calculation, Layer 3 checksum calculation and Layer 4 checksum calculation.
171  * See @ref test_and_measurement_4ga_introduction "4GA Test and Measurement features" for a detailed description.
172  */
173 
174 /** @addtogroup StreamFile
175  * The File network stream is used for packet-by-packet offline
176  * analysis of the packets captured with the segment RX interface. See
177  * @ref SegmentInterface "Segment interface" for a description of how
178  * to accomplish this.
179  *
180  * To open a file network stream, call the @ref NT_NetFileOpen with the
181  * name of the captured file as argument. To get the next packet from
182  * the file network stream, call the @ref NT_NetFileGet. Use the
183  * @ref PacketMacros "packet macros" to access the packet data. When
184  * finished with the packet, call @ref NT_NetFileRelease to release it
185  * again. When finished with the stream, call @ref NT_NetFileClose to close
186  * it.
187  *
188  * Supported files are native NT captured files, pcap and pcap-ng files.
189  * When using pcap or pcap-ng files, the received port information is always
190  * set to 0.
191  *
192  * For an example on how to use the file network stream interface, see
193  * @ref net/replay/replay_example.c "net/replay/replay_example.c".
194  *
195  */
196 
197 /**
198  * The network interface types.
199  * Used to select PACKET or NETWORK interface.
200  */
202  NT_NET_INTERFACE_UNKNOWN=0, //!< Unknown interface
203  NT_NET_INTERFACE_PACKET, //!< Packet interface
204  NT_NET_INTERFACE_SEGMENT //!< Segment interface
205 };
206 
207 
208 #ifndef DOXYGEN_INTERNAL_ONLY
209 /**
210  * Internal structures used in @ref NtNetBuf_s
211  */
212 typedef struct NtNetBufData_s* NtNetBufData_t; //!< Confidential data
213 typedef struct NtNetBufPkt_s* NtNetBufPkt_t; //!< Packet data
214 typedef struct NtNetBufHdr_s* NtNetBufHdr_t; //!< Header data
215 #endif
216 
217 
218 /**
219  * This structure is used by the @ref NetworkStream Get/Release functions and provides a handle to the returned data.
220  * The layout of the structure is confidential and must only be accessed via @ref DataMacros.
221  * The layout of the structure might change between major releases of NTAPI.
222  */
223 typedef struct NtNetBuf_s {
224 #ifndef DOXYGEN_INTERNAL_ONLY
225  int version; //!< The version of the NetworkData header
226  NtNetBufData_t hData; //!< A handle to confidential data
227  NtNetBufPkt_t hPkt; //!< A handle to packet data
228  NtNetBufHdr_t hHdr; //!< A handle to header data
229  uint64_t length; //!< Data field length
230  enum NtNetInterface_e netIf; //!< The network interface
231  enum NtTimestampType_e tsType; //!< The time stamp type
232 #endif
233  uint8_t portOffset; //!< The port offset - used to identify logical ports
234 #ifndef DOXYGEN_INTERNAL_ONLY
235  uint8_t Reserved1[3];
236  uint8_t adapterNo; //!< The adapter from which the data originated
237  uint8_t Reserved2[3];
238  int8_t egressPort; //!< The destination port (in-line)
239  uint8_t Reserved3[3];
240  uint8_t* colorMap; //!< The filter color map table
241 #define _FEED2STREAM_SHL_ 4
242  int* streamInfo; //!< A pointer to indexed stream IDs - used by macros
243  uint32_t pkts;
244 #endif
245  uintptr_t arg0; //!< User specific meta data container 0
246  uintptr_t arg1; //!< User specific meta data container 1
247  uintptr_t arg2; //!< User specific meta data container 2
248 } *NtNetBuf_t;
249 
250 /** @addtogroup StreamRx
251  *@{
252  */
253 
254 /**
255  * Possible NetRx stream commands
256  */
258  NT_NETRX_READ_CMD_UNKNOWN=0, //!< Unknown read command
259  NT_NETRX_READ_CMD_GET_FILE_HEADER, //!< Gets the file header for the stream
260  NT_NETRX_READ_CMD_STREAM_DROP, //!< Returns the drop counters for each stream - the counters increment when packets are dropped because of the host buffer allowance (hysteresis) being activated
261  NT_NETRX_READ_CMD_STREAM_TIME, //!< Returns the current stream time
262  NT_NETRX_READ_CMD_PCAP_FCS, //!< Returns whether packets with pcap descriptors include ethernet FCS
263  NT_NETRX_READ_CMD_GET_RING_CONTROL, //!< Return control of the host buffer ring of a stream Dangerous!! (Napatech internal use only - may change without further notice)
264  NT_NETRX_READ_CMD_GET_HB_INFO //!< Gets the info on the host buffers used by the stream
265 };
266 
267 /**
268  * TX stream descriptor modes.
269  * Used for configuring required variables for TX.
270  */
272  NT_NETTX_DESCRIPTOR_MODE_STD, //!< TX with standard descriptors
273  NT_NETTX_DESCRIPTOR_MODE_DYN1, //!< TX with DYN1 descriptors
274  NT_NETTX_DESCRIPTOR_MODE_DYN2, //!< TX with DYN2 descriptors
275  NT_NETTX_DESCRIPTOR_MODE_DYN3, //!< TX with DYN3 descriptors
276  NT_NETTX_DESCRIPTOR_MODE_DYN4, //!< TX with DYN4 descriptors
277 };
278 
279 /**
280  * File header return structure.
281  * Note: This header can only be read when all NTPL assignments have completed.
282  */
284  uint8_t data[128]; //!< The actual file header
285  int32_t size; //!< The size of the file header
286 };
287 
288 /**
289  * Stream drop counter return structure
290  */
292  uint64_t pktsDropped; //!< Packets dropped because the application is affected by the host buffer allowance (hysteresis)
293  uint64_t octetsDropped; //!< Bytes dropped because the application is affected by the host buffer allowance (hysteresis)
294 };
295 
296 /**
297  * Stream time
298  */
300  uint64_t ts; //!< Current stream time. Can be used when NT_NetRxGet() returns timeout to get the time of the stream.
301 };
302 
303 /**
304  * PCAP information
305  */
307  uint32_t fcs; //!< Returns non-zero if FCS is included in packets with PCAP descriptors.
308 };
309 
310 /**
311  * Expose buffer info to the user (Napatech internal use only - may change without further notice)
312  */
314  volatile uint64_t* pRead;
315  volatile uint64_t* pWrite;
316  uint8_t* ring;
317  uint64_t size;
318  uint64_t mask;
319 };
320 
321 /**
322  * RX Host buffer info
323  */
325  uint32_t numAddedHostBuffers; //!< The number of host buffers added by the driver
326  uint32_t numAssignedHostBuffers; //!< The number of host buffers assigned and also the depth of the array
327  struct NtNetRxHb_s {
328  uint64_t timestamp; //!< The current host buffer time
329  size_t size; //!< The size of the host buffer (4GA only)
330  size_t available; //!< Amount of the host buffer available to the adapter (4GA only)
331  size_t dequeued; //!< Reserved for future use
332  size_t pending; //!< Amount of the host buffer pending for the application to read (4GA only)
333  size_t inlinePending; //!< Reserved for future use
334  enum NtNetHostBufferLayout_e layout; //!< The host buffer layout
335  int index; //!< The host buffer index. Unique throughout the system
336  } aHostBuffer[128];
337 };
338 
339 /**
340  * NetRx structure. Network RX data is read via this structure via @ref NT_NetRxRead().
341  */
342 typedef struct NtNetRx_s {
343  enum NtNetRxCmd_e cmd; //!< The read command - specified what to read from NetRx
344  /**
345  * Union of all possible return structures from NetRxRead()
346  */
347  union NtNetRx_u {
348  struct NtNetRxFileHeader_s fileheader; //!< The structure to use for @ref NtNetRx_s::cmd==NT_NETRX_READ_CMD_GET_FILE_HEADER
349  struct NtNetRxStreamDrop_s streamDrop; //!< The structure to use for @ref NtNetRx_s::cmd==NT_NETRX_READ_CMD_STREAM_DROP
350  struct NtNetRxStreamTime_s streamTime; //!< The structure to use for @ref NtNetRx_s::cmd==NT_NETRX_READ_CMD_STREAM_TIME
351  struct NtNetRxPcapInfo_s pcap; //!< The structure to use for @ref NtNetRx_s::cmd==NT_NETRX_READ_CMD_PCAP_INFO
352  struct NtNetRxHbRing_s ringControl; //!< The structure to use for @ref NtNetRx_s::cmd==NT_NETRX_READ_CMD_GET_RING_CONTROL
353  struct NtNetRxHbInfo_s hbInfo; //!< The structure to use for @ref NtNetRx_s::cmd==NT_NETRX_READ_CMD_GET_HB_INFO
354  } u ;
355 } NtNetRx_t;
356 
357 /**
358  * Possible NetTx stream commands
359  */
361  NT_NETTX_READ_CMD_UNKNOWN=0, //!< Unknown read command
362  NT_NETTX_READ_CMD_GET_HB_INFO, //!< Gets the info on the host buffers used by the stream
363  NT_NETTX_READ_CMD_GET_RING_CONTROL, //!< Get the control of the host buffer ring. Dangerous!! (Napatech internal use only - may change without further notice)
364 };
365 
366 /**
367  * TX Host buffer info
368  */
370  unsigned int numHostBuffers; //!< The number of host buffers used by the stream and also the depth of the array
371  struct NtNetTxHb_s {
372  size_t size; //!< The size of the host buffer
373  size_t available; //!< Amount of the host buffer available to the application
374  size_t dequeued; //!< Amount of the host buffer dequeued by the application
375  size_t released; //!< Amount of the host buffer released waiting to be transmitted
376  enum NtNetHostBufferLayout_e layout; //!< The host buffer layout
377  int index; //!< The host buffer index. Unique throughout the system.
378  uint64_t portMask; //!< The port-mask the host buffer can utilize
379  } aHostBuffer[128];
380 };
381 
382 /**
383  * Expose host buffer info (Napatech internal use only - may change without further notice)
384  */
386  volatile uint64_t* pRead;
387  volatile uint64_t* pWrite;
388  uint8_t* ring;
389  uint64_t size;
390  uint16_t minTxPktSize; //!< The min transmit packet size of this port
391  uint16_t maxTxPktSize; //!< The max transmit packet size of this port
392  uint8_t port; //!< The port this ring is attached to
393  //TODO: Maybe expose what descriptors can be used?
394 };
395 
396 /**
397  * NetTx structure. Network TX data is read via this structure via @ref NT_NetTxRead().
398  */
399 typedef struct NtNetTx_s {
400  enum NtNetTxCmd_e cmd; //!< The read command - specified what to read from NetTx
401  /**
402  * Union of all possible return structures from NetTxRead()
403  */
404  union NtNetTx_u {
405  struct NtNetTxHbInfo_s hbInfo; //!< Information about the host buffers used
406  struct NtNetTxHbRing_s ringControl; //!< Control of the host buffer ring (Napatech internal use only - may change without further notice)
407  } u ;
408 } NtNetTx_t;
409 
410 
411 /**
412  * NtNetTxFragment structure. A TX packet may be scattered in a list of fragments,
413  * which is put together and added to the TX hostbuffer via @ref NT_NetTxAddPacket().
414  */
415 typedef struct NtNetTxFragment_s
416 {
417  uint8_t* data;
418  uint16_t size;
420 
421 /**
422  * Possible NetFileRead commands
423  */
425  NT_NETFILE_READ_INFO_UNKNOWN_CMD=0, //!< Unknown read command
426  NT_NETFILE_READ_COMPAT_0, //!< Read information about the NetFile stream
427  NT_NETFILE_READ_FILETYPE_CMD, //!< Read information about the opened file type
428  NT_NETFILE_READ_DESCRIPTOR_CMD, //!< Read information about the descriptor and timestamp format used
429  NT_NETFILE_READ_INFO_CMD_V1, //!< Read information about the NetFile stream
430 };
431 
432 /**
433  * NetFile stream Info return structure
434  */
435 
436 typedef struct NtNetFileReadInfo_v1_s {
437  uint64_t lastTimestamp; //!< The time stamp in the last packet in last segment read using the function @ref NT_NetFileGet
438  uint64_t numberOfOctets; //!< Number of octets read from Netfile so far
439  uint32_t numberOfPackets; //!< Number of packets read from Netfile so far
440  uint64_t firstTimestamp; //!< The time stamp in the first packet in first segment read using the function @ref NT_NetFileGet
442 
443 typedef enum {
444  NT_NETFILE_TYPE_UNKNOWN, //!< The opened file is a unknown
445  NT_NETFILE_TYPE_NT, //!< The opened file is a Napatech capture file
446  NT_NETFILE_TYPE_PCAP, //!< The opened file is a PCAP capture file
447  NT_NETFILE_TYPE_PCAP_NG, //!< The opened file is a PCAP NG capture file
449 
450 typedef struct NtNetFileReadDesc_s
451 {
452  enum NtTimestampType_e tsType; //!< Timestamp format used in packet data
453  enum NtPacketDescriptorType_e desc; //!< Descriptor used in packet data
455 
456 /* Include commands for backward compatibility */
457 #if !defined(_NT_NTAPI_NO_COMPAT)
458 #include "stream_net_compat.h"
459 #endif
460 
461 /**
462  * NetFileRead stream structure - network File data is read via this structure via @ref NT_NetFileRead()
463  */
464 typedef struct NtNetFileRead_s {
465  enum NtNetFileReadCmd_e cmd; //!< The read command - specified what to read from NetFile
466  /**
467  * Union of all possible return structures from NT_NetFileRead()
468  */
470  struct NtNetFileReadInfo_v1_s info_v1; //!< Information about the NetFile. Used by NT_NETFILE_READ_INFO_CMD
471  struct NtNetFileReadDesc_s desc; //!< Information about the descriptor and timestamp format used. Used by NT_NETFILE_READ_DESCRIPTOR_CMD
472  NtNetFileType_e fileType; //!< Information about the type of the opened file
473 #if !defined(_NT_NTAPI_NO_COMPAT)
474  /* Commands for backward compatibility */
475  struct NtNetFileReadInfo_s info; //!< Information about the NetFile. Used by NT_NETFILE_READ_INFO_CMD
476 #endif
477  } u ;
479 
480 /**
481  * The Network RX stream handle - used for both in-line and capture streams
482  */
483 typedef struct NtNetStreamRx_s* NtNetStreamRx_t;
484 
485 /**
486  * Parameter structure for NT_NetRxOpen_Attr/NT_NetRxOpen_v3/NT_NetRxOpenMulti_v3.
487  * Use NT_NetRxOpenAttrInit() and NT_NetRxOpenAttrSet*() functions to define content.
488  */
489 #define __SIZEOF_NT_NETRX_ATTR (128)
492  long int __align;
493 };
495 
496 /**
497  * Parameter structure for NT_NetTxOpen_Attr/NT_NetTxOpen_v3/NT_NetTxOpenMulti_v3.
498  * Use NT_NetTxOpenAttrInit() and NT_NetTxOpenAttrSet*() functions to define content.
499  */
500 #define __SIZEOF_NT_NETTX_ATTR (128)
503  long int __align;
504 };
506 
507 /**
508  * Parameter structure for NT_NetFileOpen_Attr.
509  * Use NT_NetFileOpenAttrInit() and NT_NetFileOpenAttrSet*()
510  * functions to define content.
511  */
512 #define __SIZEOF_NT_NETFILE_ATTR (128)
515  long int __align;
516 };
518 
519 /**
520  * Flags for NT_NetRxOpen_v2+/NT_NetRxOpenMulti_v2+
521  *
522  * Obsolete: please use enum NtNetRxOpenFlags_e below
523  */
524 #define NT_NETRX_NONE (0)
525 #define NT_NETRX_READONLY_STREAM (1LL<<0)
526 
527 /**
528  *
529  */
533 };
534 
535 /**
536  * @brief Opens in-line or capture host buffer(s) and returns a NtNetStreamRx_t handle
537  *
538  * This function is called to retrieve a handle to an in-line or capture network stream.
539  *
540  * In-line network streams cannot be shared and any attempt to open an existing in-line stream fails with an error return value.
541  *
542  * @note It is important to start calling NT_NetRxGet() and NT_NetRxRelease() soon
543  * after this call to avoid packet drop. Host buffers are assigned/released to the streamid within
544  * NT_NetRxGet() and NT_NetRxRelease().
545  *
546  * @param[out] hStream Reference to a NtNetStreamRx_t stream pointer
547  * @param[in] name Stream friendly name - used in, for example, logging statements
548  * @param[in] netIntf Interface type - segment or packet
549  * @param[in] streamId The network stream ID to open - can be opened a number of times which will cause sharing of the host buffers in the streamId
550  * @param[in] hostBufferAllowance Drop level for the host buffer allowance (hysteresis), -1 means disabled
551  *
552  * @retval NT_SUCCESS Success
553  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
554  */
555 int NT_NetRxOpen(NtNetStreamRx_t* hStream, const char* name, enum NtNetInterface_e netIntf, uint32_t streamId, int hostBufferAllowance);
556 
557 /**
558  * @brief Opens in-line or capture host buffer(s) and returns a NtNetStreamRx_t handle
559  *
560  * This function is called to retrieve a handle to an in-line or capture network stream with flags.
561  *
562  * In-line network streams cannot be shared and any attempt to open an existing in-line stream fails with an error return value.
563  *
564  * @note It is important to start calling NT_NetRxGet() and NT_NetRxRelease() soon
565  * after this call to avoid packet drop. Host buffers are assigned/released to the streamid within
566  * NT_NetRxGet() and NT_NetRxRelease().
567  *
568  * The flags shall be either NT_NETRX_OPEN_FLAGS_NONE or the bitwise-inclusive OR of one or more of the other
569  * flags in the following table:
570  *
571  * Flag | Description
572  * ------------------------------------|-------------
573  * NT_NETRX_OPEN_FLAGS_NONE | No flags set, equivalent to passing '0' as flag.
574  * NT_NETRX_OPEN_FLAGS_READONLY_STREAM | Using this option will cause a write to data returned by NT_NetRxGet to fail with a segmentation fault.
575  *
576  * @param[out] hStream Reference to a NtNetStreamRx_t stream pointer
577  * @param[in] name Stream friendly name - used in, for example, logging statements
578  * @param[in] netIntf Interface type - segment or packet
579  * @param[in] streamId The network stream ID to open - can be opened a number of times which will cause sharing of the host buffers in the streamId
580  * @param[in] hostBufferAllowance Drop level for the host buffer allowance (hysteresis), -1 means disabled
581  * @param[in] flags Flags for the stream OR'd together, or zero for no flags.
582  *
583  * @retval NT_SUCCESS Success
584  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
585  */
586 int NT_NetRxOpen_v2(NtNetStreamRx_t* hStream, const char* name, enum NtNetInterface_e netIntf, uint32_t streamId, int hostBufferAllowance, int flags);
587 
588 /**
589  * @brief Initialize RX stream attributes
590  *
591  * The attributes are initialized to the following default values: \n
592  * name = NULL \n
593  * netIntf = NT_NET_INTERFACE_UNKNOWN \n
594  * hostBufferAllowance = -1 \n
595  * flags = NT_NETRX_OPEN_FLAGS_NONE \n
596  *
597  * @param[out] attr Pointer to the attributes structure
598  */
600 
601 /**
602  * @brief Sets the stream name attribute
603  *
604  * @param[in] attr Pointer to the attributes structure
605  * @param[in] name Stream friendly name - used in, for example, logging statements
606  */
607 void NT_NetRxOpenAttrSetName(NtNetRxAttr_t* attr, const char* name);
608 
609 /**
610  * @brief Returns the name attribute
611  * @return The name attribute
612  */
613 const char* NT_NetRxOpenAttrGetName(const NtNetRxAttr_t* attr);
614 
615 /**
616  * @brief Sets the interface type attribute
617  *
618  * @param[in] attr Pointer to the attributes structure
619  * @param[in] netIntf Interface type - segment or packet
620  */
622 
623 /**
624  * @brief Returns the interface type attribute
625  * @return The interface type attribute
626  */
628 
629 /**
630  * @brief Sets the host buffer allowance attribute
631  *
632  * @param[in] attr Pointer to the attributes structure
633  * @param[in] hostBufferAllowance Drop level for the host buffer allowance (hysteresis), -1 means disabled
634  */
635 void NT_NetRxOpenAttrSetHostBufferAllowance(NtNetRxAttr_t* attr, int hostBufferAllowance);
636 
637 /**
638  * @brief Returns the buffer allowance attribute
639  * @return The buffer allowance attribute
640  */
642 
643 /**
644  * @brief Sets the flags attribute
645  *
646  * The flags shall be either NT_NETRX_NONE or the bitwise-inclusive OR of one or more of the other
647  * flags in the following table - see enum ::NtNetRxOpenFlags_e
648  *
649  * Flag | Description
650  * -------------------------|-------------
651  * NT_NETRX_NONE | No flags set, equivalent to passing '0' as flag.
652  * NT_NETRX_READONLY_STREAM | Using this option will cause a write to data returned by NT_NetRxGet to fail with a segmentation fault.
653  *
654  * @param[in] attr Pointer to the attributes structure
655  * @param[in] flags Drop level for the host buffer allowance (hysteresis), -1 means disabled
656  */
657 void NT_NetRxOpenAttrSetFlags(NtNetRxAttr_t* attr, int flags);
658 
659 /**
660  * @brief Returns the flags attribute
661  * @return The flags attribute - see enum ::NtNetRxOpenFlags_e
662  */
663 int NT_NetRxOpenAttrGetFlags(const NtNetRxAttr_t* attr);
664 
665 /**
666  * @brief Opens in-line or capture host buffer(s) and returns a NtNetStreamRx_t handle
667  *
668  * This function is called to retrieve a handle to an in-line or capture network stream with flags.
669  * @note It is important to start calling NT_NetRxGet() and NT_NetRxRelease() soon
670  * after this call to avoid packet drop. Host buffers are assigned/released to the streamid within
671  * NT_NetRxGet() and NT_NetRxRelease().
672  *
673  * @param[out] hStream Reference to a NtNetStreamRx_t stream pointer
674  * @param[in] streamId The network stream ID to open - can be opened a number of times which will cause sharing of the host buffers in the streamId
675  * @param[in] attr Attributes of the stream
676  *
677  * @retval NT_SUCCESS Success
678  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
679  */
680 int NT_NetRxOpen_Attr(NtNetStreamRx_t* hStream, uint32_t streamId, const NtNetRxAttr_t* attr);
681 
682 /**
683  * @brief Opens in-line or capture host buffer(s) and returns a NtNetStreamRx_t handle
684  *
685  * This function is called to retrieve a handle to an in-line or capture network streams. If
686  * multiple stream-ids are opened the data from them will be time stamp merged. Note multiple
687  * stream-ids can only be used with the packet interface.
688  * @note It is important to start calling NT_NetRxGet() and NT_NetRxRelease() soon
689  * after this call to avoid packet drop. Host buffers are assigned/released to the streamid within
690  * NT_NetRxGet() and NT_NetRxRelease().
691  *
692  * @param[out] hStream Reference to a NtNetStreamRx_t stream pointer
693  * @param[in] name Stream friendly name - used in, for example, logging statements
694  * @param[in] netIntf Interface type - Can only be packet if multiple are opened
695  * @param[in] paStreamId Array containing the network stream IDs to open. A maximum of 8 streams can be specified.
696  * @param[in] numStreamIds The number of stream-ids in the paStreamId array
697  * @param[in] hostBufferAllowance Drop level for the host buffer allowance (hysteresis), -1 means disabled
698  *
699  * @retval NT_SUCCESS Success
700  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
701  */
702 int NT_NetRxOpenMulti(NtNetStreamRx_t* hStream, const char* name, enum NtNetInterface_e netIntf, uint32_t* paStreamId, unsigned int numStreamIds, int hostBufferAllowance);
703 
704 /**
705  * @brief Opens in-line or capture host buffer(s) and returns a NtNetStreamRx_t handle
706  *
707  * This function is called to retrieve a handle to an in-line or capture network streams with flags.
708  * If multiple stream-ids are opened the data from them will be time stamp merged. Note multiple
709  * stream-ids can only be used with the packet interface.
710  * @note It is important to start calling NT_NetRxGet() and NT_NetRxRelease() soon
711  * after this call to avoid packet drop. Host buffers are assigned/released to the streamid within
712  * NT_NetRxGet() and NT_NetRxRelease().
713  *
714  * The flags shall be either NT_NETRX_NONE or the bitwise-inclusive OR of one or more of the other
715  * flags in the following table (see enum ::NtNetRxOpenFlags_e):
716  *
717  * Flag | Description
718  * -------------------------|-------------
719  * NT_NETRX_NONE | No flags set, equivalent to passing '0' as flag.
720  * NT_NETRX_READONLY_STREAM | Using this option will cause a write to data returned by NT_NetRxGet to fail with a segmentation fault.
721  *
722  * @param[out] hStream Reference to a NtNetStreamRx_t stream pointer
723  * @param[in] name Stream friendly name - used in, for example, logging statements
724  * @param[in] netIntf Interface type - Can only be packet if multiple are opened
725  * @param[in] paStreamId Array containing the network stream IDs to open. A maximum of 8 streams can be specified.
726  * @param[in] numStreamIds The number of stream-ids in the paStreamId array
727  * @param[in] hostBufferAllowance Drop level for the host buffer allowancei (hysteresis), -1 means disabled
728  * @param[in] flags Flags for the stream OR'd together, or zero for no flags.
729  *
730  * @retval NT_SUCCESS Success
731  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
732  */
733 int NT_NetRxOpenMulti_v2(NtNetStreamRx_t* hStream, const char* name, enum NtNetInterface_e netIntf, uint32_t* paStreamId, unsigned int numStreamIds, int hostBufferAllowance, int flags);
734 
735 /**
736  * @brief Opens in-line or capture host buffer(s) and returns a NtNetStreamRx_t handle
737  *
738  * This function is called to retrieve a handle to an in-line or capture network streams with flags.
739  * If multiple stream-ids are opened the data from them will be time stamp merged. Note multiple
740  * stream-ids can only be used with the packet interface.
741  * @note It is important to start calling NT_NetRxGet() and NT_NetRxRelease() soon
742  * after this call to avoid packet drop. Host buffers are assigned/released to the streamid within
743  * NT_NetRxGet() and NT_NetRxRelease().
744  *
745  * @param[out] hStream Reference to a NtNetStreamRx_t stream pointer
746  * @param[in] paStreamId Array containing the network stream IDs to open. A maximum of 8 streams can be specified.
747  * @param[in] numStreamIds The number of stream-ids in the paStreamId array
748  * @param[in] attr Attributes of the stream(s)
749  *
750  * @retval NT_SUCCESS Success
751  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
752  */
753 int NT_NetRxOpenMulti_Attr(NtNetStreamRx_t* hStream, uint32_t* paStreamId, unsigned int numStreamIds, const NtNetRxAttr_t* attr);
754 
755 /**
756  * @brief Gets data from an in-line or capture stream
757  *
758  * This function is called to retrieve packets/segments from a in-line or capture stream.
759  *
760  * The calling process is suspended when no data is immediately available.
761  * The suspension is done in one of two ways, depending on the system clock resolution:
762 
763  * 1) If the system clock resolution is <= 1 uSec, sleep calls are used. The timeout value
764  * is divided into sleep intervals (with intervals approximating the segment timeout on the adapter).
765  * It then periodically polls for data.
766 
767  * 2) using events. If the system cannot do uSec sleeps, then the suspension mechanism used is event
768  * based. It puts the calling process to sleep waiting for an event. On data receival an event is sent
769  * and the process is woken up.
770  *
771  * @param[in] hStream Network RX stream handle
772  * @param[out] netBuf Segment/packet container reference, is set to NULL if return value is not NT_SUCCESS
773  * @param[in] timeout The timeout in milliseconds. The call will return when any data is available, or when the timeout is reached.
774  * A timeout of -1 will wait indefinitely if using the packet mode. In segment mode the waiting is always capped
775  * to the next HostBufferPollInterval (ntservice.ini), which is 100 usecs by default, at which point an empty
776  * segment is returned, if no data arrived. So in segment mode, any timeout larger than HostBufferPollInterval
777  * (including -1) has no effect.
778  *
779  * @note This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
780  * @note When the segment interface is used this function can return empty segments only containing a time stamp update, hence if NT_NET_GET_SEGMENT_LENGTH() return 0 only NT_NET_GET_SEGMENT_TIMESTAMP() can be used.
781  * The time stamp update will make it possible for users to merge packets in segments from different stream ids.
782  *
783  * @retval NT_SUCCESS Data has been returned and must be released again via NT_NetRxRelease()
784  * @retval NT_STATUS_TIMEOUT No data has been returned and a timeout has occured
785  * @retval NT_STATUS_TRYAGAIN The resource is temporarily unavailable because of reconfiguration - call NT_NetRxGet() again
786  * @retval Error Use @ref NT_ExplainError for an error description
787  */
788 int NT_NetRxGet(NtNetStreamRx_t hStream, NtNetBuf_t* netBuf, int timeout);
789 
790 /**
791  * @brief Gets data from an in-line or capture stream
792  *
793  * This function is called to retrieve packets from a in-line or capture stream. The function will
794  * automatically release the previous packet when called, hence it is not possible to keep packets and if necessary
795  * the packets must be copied to a safe buffer before calling the function to get the next packet.
796  *
797  * @param[in] hStream Network RX stream handle
798  * @param[out] netBuf Segment/packet container reference, is set to NULL if return value is not NT_SUCCESS
799  * @param[in] timeout The timeout in milliseconds. The call will return when this timeout is reached unless data is available. A timeout of -1 will wait indefinitely for a new buffer.
800  *
801  * @note This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
802  *
803  * @retval NT_SUCCESS Data has been returned and will be valid until the next @ref NT_NetRxGetNextPacket() call
804  * @retval NT_STATUS_TIMEOUT No data has been returned and a timeout has occured
805  * @retval NT_STATUS_TRYAGAIN The resource is temporarily unavailable because of reconfiguration - call NT_NetRxGetNextPacket() again
806  * @retval Error Use @ref NT_ExplainError for an error description
807  */
808 int NT_NetRxGetNextPacket(NtNetStreamRx_t hStream, NtNetBuf_t* netBuf, int timeout);
809 
810 /**
811  * @brief Reads data from the stream
812  *
813  * This function will read on-line generated data from the stream, for example, a file header
814  *
815  * @param[in] hStream NetRx stream handle
816  * @param[in] cmd NetRx read structure
817  *
818  * @retval NT_SUCCESS Success
819  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
820  */
821 int NT_NetRxRead(NtNetStreamRx_t hStream, NtNetRx_t* cmd);
822 
823 
824 /**
825  * @brief Releases network buffer
826  *
827  * This function will release the netBuf data obtained via NT_NetRxGet(). The data within
828  * netBuf will on an in-line profile be sent to the adapter upon release even in the case where
829  * the NTPL assignment has been terminated.
830  *
831  * @note This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
832  *
833  * @param[in] hStream NetRx stream handle
834  * @param[in] netBuf Net buffer received via NT_NetRxGet()
835  *
836  * @retval NT_SUCCESS Success
837  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
838  */
839 int NT_NetRxRelease(NtNetStreamRx_t hStream, NtNetBuf_t netBuf);
840 
841 /**
842  * @brief Closes an in-line or capture stream
843  *
844  * This function is called to close an in-line or capture stream
845  *
846  * @param[in] hStream In-line or capture stream handle to close
847  *
848  * @retval NT_SUCCESS Success
849  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
850  */
851 int NT_NetRxClose(NtNetStreamRx_t hStream);
852 
853 /** @} */
854 
855 
856 /** @addtogroup StreamTx
857  *@{
858  */
859 /**
860  * Network TX stream handle - used for TX streams
861  */
862 typedef struct NtNetStreamTx_s* NtNetStreamTx_t;
863 
864 /**
865  * Network TX packet options
866  */
868  NT_NETTX_PACKET_OPTION_UNKNOWN=0, //!< Unknown option
869  NT_NETTX_PACKET_OPTION_DEFAULT, //!< Gets a TX buffer with a pre-configured packet descriptor. Use this option to transmit L2 data. This option uses packetSize as wire length.
871  NT_NETTX_PACKET_OPTION_RAW, //!< Gets a raw TX packet buffer without packet descriptor. Care needs to be taken when using this option. Use this option in replay scenarios where packets already have a correct descriptor, e.g. data recorded using @ref StreamFile. Uses packetSize as the stored length. With this option packetSize must be a multiple of 8 (NT3GA only).
872  NT_NETTX_SEGMENT_OPTION_RAW, //!< Gets a raw TX segment buffer. Care needs to be taken when using this option. Use this option in replay scenarios where the segment length is known prior to calling @ref NT_NetTxGet. Use packetSize as the segment length. The port parameter in @ref NT_NetTxGet is used to control that the segment returned belongs to the adapter on which the port resides. It is required that the txPort in the packet descriptors within the segment are set before releasing the segment. If the host buffer layout is NT_NET_HOSTBUFFER_LAYOUT_SLABS, the slabs are automatically terminated when this option is used.
873  NT_NETTX_PACKET_OPTION_DYN, //!< Gets a TX buffer with a pre-configured dynamic packet descriptor. Use this option to transmit L2 data. This option uses packetSize as wire length. Set DescriptorMode before using this option.
874 };
875 
876 /**
877  * Network TX NUMA HB options for NUMA-parameter in NT_NetTxOpen()
878  */
880  NT_NETTX_NUMA_ANY_HB=0xFFFFFFFE, //!< (=-2) Allocate TX host buffer from any TX host buffer pool
881  NT_NETTX_NUMA_ADAPTER_HB=0xFFFFFFFF, //!< (=-1) Allocate TX host buffer from TX-host buffer pool on that NUMA node where the adapter of the TX-port is located
882 };
883 
884 /**
885  * Flags for NT_NetTxOpen_Attr()
886  */
888  NT_NETTX_OPEN_NONE=0, //!< No NtNetTxOpen flags (Obsolete)
889  NT_NETTX_OPEN_FLAGS_NONE=0, //!< No NtNetTxOpen flags
890  NT_NETTX_OPEN_FLAGS_ADAPTER_MULTI_PORT_BUFFER=(1LL<<0), //!< Allocate one TX host buffer per adapter that has ports set in NT_NetTXOpen portmask - if unset allocate one TX host buffer per port that is set in NT_NetTXOpen portmask
891  NT_NETTX_OPEN_FLAGS_SEGMENT_UNALIGN_MODE=(1LL<<1), //!< Arbitrary raw segment sizes can be operated on that will be placed back to back
892 };
893 
894 /**
895  * @brief Opens a TX host buffer and returns a NtNetStreamTx_t handle
896  *
897  * This function, which is superseded by NT_NetTxOpen_v3(), is called
898  * to retrieve a TX stream handle.
899  *
900  * Note that the TX stream on capture-only adapters (NT4E Capture, NT4E_STD Capture and NT20E Capture)
901  * will have very limited transmit capabilities. They will not be able to transmit at line rate
902  * and their transmit sizes and statistics will also be limited. Packets larger than 2000 bytes
903  * will sliced to the size of 2000 bytes.
904  *
905  * @param[out] hStream Reference to a NtNetStreamTx_t stream pointer
906  * @param[in] name Stream friendly name - used in, for example, logging statements
907  * @param[in] portMask Bitmask for ports this stream will use for transmitting
908  * @param[in] NUMA NUMA node on which the host buffer is be located (NOTE: Special options in NtNetTxOpenNumaOption_e)
909  * @param[in] minHostBufferSize Minimum size of host buffer needed in <em>MBytes</em>. The
910  * smallest host buffer found that is larger or equal to minHostBufferSize
911  * is used and the size of the host buffer is set to minHostBufferSize. If
912  * set to 0, the first host buffer found is used regardsless of the size.
913  *
914  * @retval NT_SUCCESS Success
915  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
916  */
917 int NT_NetTxOpen(NtNetStreamTx_t* hStream, const char* name, uint64_t portMask, uint32_t NUMA, uint32_t minHostBufferSize);
918 
919 /**
920  * @brief Opens a TX host buffer and returns a NtNetStreamTx_t handle (extended version)
921  *
922  * This function, which is superseded by NT_NetTxOpen_v3(), is similar
923  * to the NT_NetTxOpen() function. The main difference is that it has
924  * two additional parameters, the descriptor type and the timestamp
925  * format.
926  *
927  * This function will only work with 4GA adapters.
928  *
929  * @param[out] hStream Reference to a NtNetStreamTx_t stream pointer
930  * @param[in] name Stream friendly name - used in, for example, logging statements
931  * @param[in] portMask Bitmask for ports this stream will use for transmitting
932  * @param[in] NUMA NUMA node on which the host buffer is be located (NOTE: Special options in NtNetTxOpenNumaOption_e)
933  * @param[in] minHostBufferSize Minimum size of host buffer needed in <em>MBytes</em>. The smallest host
934  * buffer found that is larger or equal to minHostBufferSize is used and the
935  * size of the host buffer is set to minHostBufferSize. If set to 0, the
936  * first host buffer found is used regardsless of the size.
937  * @param[in] descriptor Descriptor type to use when transmitting.
938  * @param[in] ts Timestamp format to use when transmitting.
939  *
940  * @retval NT_SUCCESS Success
941  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
942  */
943 int NT_NetTxOpen_v2(NtNetStreamTx_t* hStream, const char* name, uint64_t portMask, uint32_t NUMA, uint32_t minHostBufferSize, enum NtPacketDescriptorType_e descriptor, enum NtTimestampType_e ts);
944 
945 /**
946  * @brief Opens a TX host buffer and returns a NtNetStreamTx_t handle (extended version)
947  *
948  * This function is similar to the NT_NetTxOpen_v2() function. The
949  * main difference is that the minimum hostbuffer size is specified in
950  * bytes to support a hostbuffer size less than one megabyte.
951  *
952  * This function will only work with 4GA adapters.
953  *
954  * @param[out] hStream Reference to a NtNetStreamTx_t stream pointer
955  * @param[in] name Stream friendly name - used in, for example, logging statements
956  * @param[in] portMask Bitmask for ports this stream will use for transmitting
957  * @param[in] NUMA NUMA node on which the host buffer is be located (NOTE: Special options in NtNetTxOpenNumaOption_e)
958  * @param[in] minHostBufferSize Minimum size of host buffer needed in <em>bytes</em>. The smallest host
959  * buffer found that is larger or equal to minHostBufferSize is used and the
960  * size of the host buffer is set to minHostBufferSize. If set to 0, the
961  * first host buffer found is used regardsless of the size.
962  * @param[in] descriptor Descriptor type to use when transmitting.
963  * @param[in] ts Timestamp format to use when transmitting.
964  *
965  * @retval NT_SUCCESS Success
966  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
967  *
968  * NOTE:
969  * When using NT_NetTxOpen() >= 3: ntservice ini-option System.NtapiNetTxSegmentRawAlignMode can be used to control NT_NetTxGet()/NT_NetTxRelease() behaviour for NT_NETTX_SEGMENT_OPTION_RAW mode.
970  * System.NtapiNetTxSegmentRawAlignMode = 1 will retain previous NTAPI default behaviour where RAW segment mode always operates on a whole (aligned) underlying slab (segment) typically (1,2,4 MB - dictated by FPGA)
971  * System.NtapiNetTxSegmentRawAlignMode = 0 will enable NT4GA to operate on arbitrary raw segment sizes that will be placed back to back
972  * System.NtapiNetTxSegmentRawAlignMode = -1 will apply the decided default value for the current driver release. This default value (applied with -1) can change across driver releases.
973  */
974 int NT_NetTxOpen_v3(NtNetStreamTx_t* hStream, const char* name, uint64_t portMask, uint32_t NUMA, uint64_t minHostBufferSize, enum NtPacketDescriptorType_e descriptor, enum NtTimestampType_e ts);
975 
976 /**
977  * @brief Initialize TX stream attributes
978  *
979  * The attributes are initialized to the following default values: \n
980  * name = NULL \n
981  * portMask = 0 \n
982  * NUMA = NT_NETTX_NUMA_ADAPTER_HB \n
983  * minHostBufferSize = 0 \n
984  * descriptor = NT_PACKET_DESCRIPTOR_TYPE_NT \n
985  * timestampType = NT_TIMESTAMP_TYPE_NATIVE_UNIX \n
986  *
987  * @param[out] attr Pointer to the attributes structure
988  */
990 
991 /**
992  * @brief Sets the stream name attribute
993  *
994  * @param[in] attr Pointer to the attributes structure
995  * @param[in] name Stream friendly name - used in, for example, logging statements
996  */
997 void NT_NetTxOpenAttrSetName(NtNetTxAttr_t* attr, const char* name);
998 
999 /**
1000  * @brief Returns the name attribute
1001  * @return The name attribute
1002  */
1003 const char* NT_NetTxOpenAttrGetName(const NtNetTxAttr_t* attr);
1004 
1005 /**
1006  * @brief Sets the descriptor mode attribute
1007  *
1008  * @param[in] attr Pointer to the attributes structure
1009  * @param[in] portMask Descriptor mode
1010  *
1011  * @retval NT_SUCCESS Success
1012  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1013  */
1015 
1016 /**
1017  * @brief Returns the descriptor mode attribute
1018  * @return The descriptor mode attribute
1019  */
1021 
1022 /**
1023  * @brief Sets the port mask attribute
1024  *
1025  * @param[in] attr Pointer to the attributes structure
1026  * @param[in] portMask Bitmask for ports this stream will use for transmitting
1027  */
1028 void NT_NetTxOpenAttrSetPortMask(NtNetTxAttr_t* attr, uint64_t portMask);
1029 
1030 /**
1031  * @brief Returns the port mask attribute
1032  * @return The port mask attribute
1033  */
1035 
1036 /**
1037  * @brief Sets the numa attribute
1038  *
1039  * @param[in] attr Pointer to the attributes structure
1040  * @param[in] NUMA NUMA node on which the host buffer is be located (NOTE: Special options in enum ::NtNetTxOpenNumaOption_e)
1041  */
1042 void NT_NetTxOpenAttrSetNUMA(NtNetTxAttr_t* attr, uint32_t NUMA);
1043 
1044 /**
1045  * @brief Returns the numa attribute
1046  * @return The numa attribute
1047  */
1048 uint32_t NT_NetTxOpenAttrGetNUMA(NtNetTxAttr_t* attr);
1049 
1050 /**
1051  * @brief Sets the flags attribute
1052  *
1053  * @param[in] attr Pointer to the attributes structure
1054  * @param[in] flags Flags - see enum ::NtNetTxOpenFlags_e
1055  *
1056  * flags shall be either NT_NETTX_OPEN_FLAGS_NONE (0) or the bitwise-inclusive OR of one or more of the other flags in enum ::NtNetTxOpenFlags_e
1057  *
1058  * When using ntservice ini-option System.NtapiNetTxSegmentRawAlignMode == -1, NT_NETTX_OPEN_FLAGS_SEGMENT_UNALIGN_MODE will determine the segment
1059  * alignment mode.
1060  */
1061 void NT_NetTxOpenAttrSetFlags(NtNetTxAttr_t* attr, uint32_t flags);
1062 
1063 /**
1064  * @brief Returns the flags attribute
1065  * @return The flags attribute - see enum ::NtNetTxOpenFlags_e
1066  */
1067 uint32_t NT_NetTxOpenAttrGetFlags(NtNetTxAttr_t* attr);
1068 
1069 /**
1070  * @brief Sets the minimum host buffer size attribute
1071  *
1072  * @param[in] attr Pointer to the attributes structure
1073  * @param[in] minHostBufferSize Minimum size of host buffer needed in bytes. The smallest host buffer found that is larger or equal to minHostBufferSize is used and the size of the host buffer is set to minHostBufferSize. If set to 0, the first host buffer found is used regardsless of the size.
1074  */
1075 void NT_NetTxOpenAttrSetMinHostbufferSize(NtNetTxAttr_t* attr, uint64_t minHostBufferSize);
1076 
1077 /**
1078  * @brief Returns the minimum host buffer size attribute
1079  * @return The minimum host buffer size attribute
1080  */
1082 
1083 /**
1084  * @brief Sets the descriptor type attribute
1085  *
1086  * @param[in] attr Pointer to the attributes structure
1087  * @param[in] descriptor Descriptor type to use when transmitting.
1088  */
1090 
1091 /**
1092  * @brief Returns the descriptor type attribute
1093  * @return The descriptor type attribute
1094  */
1096 
1097 /**
1098  * @brief Sets bit position in packet descriptor for the Timestamp Inject command bit
1099  *
1100  * @param[in] attr Pointer to the attributes structure
1101  * @param[in] enable Enable/disable use of bits in packet descriptor.
1102  * @param[in] pos Position of bit. Maximum value is 191.
1103 
1104  *
1105  * @retval NT_SUCCESS Success
1106  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1107  */
1108 int NT_NetTxOpenAttrSetTxtDescriptorPosTimestampInject(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1109 
1110 /**
1111  * @brief Gets bit position in packet descriptor for the Timestamp Inject command bit
1112  *
1113  * @param[in] attr Pointer to the attributes structure
1114  * @param[in] enable Output pointer to enable/disable use of bit in packet descriptor.
1115  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1116  */
1117 void NT_NetTxOpenAttrGetTxtDescriptorPosTimestampInject(NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1118 
1119 //-----------
1120 /**
1121  * @brief Sets bit position in packet descriptor for the FCS control command bit
1122  *
1123  * @param[in] attr Pointer to the attributes structure
1124  * @param[in] enable Enable/disable use of bits in packet descriptor.
1125  * When disabled all FCS is recalculated for packets.
1126  * When enabled FCS recalculation is controlled by
1127  * the packet descriptor bit in position pos.
1128  * @param[in] pos Position of bit. Maximum value is 191.
1129 
1130  *
1131  * @retval NT_SUCCESS Success
1132  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1133  */
1134 int NT_NetTxOpenAttrSetTxtDescriptorPosFcs(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1135 
1136 /**
1137  * @brief Gets bit position in packet descriptor for the FCS control command bit
1138  *
1139  * @param[in] attr Pointer to the attributes structure
1140  * @param[in] enable Output pointer to enable/disable use of bit in packet descriptor.
1141  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1142  */
1143 void NT_NetTxOpenAttrGetTxtDescriptorPosFcs(NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1144 
1145 //-----------
1146 /**
1147  * @brief Sets the timestamp type attribute
1148  *
1149  * @param[in] attr Pointer to the attributes structure
1150  * @param[in] timestampType Timestamp format to use when transmitting.
1151  */
1152 void NT_NetTxOpenAttrSetTimestampType(NtNetTxAttr_t* attr, enum NtTimestampType_e timestampType);
1153 
1154 /**
1155  * @brief Returns the timestamp type attribute
1156  * @return The timestamp type attribute
1157  */
1159 
1160 /**
1161  * @brief Set bit position in packet descriptor for layer 3 offset bits.
1162  *
1163  * @param[in] attr Pointer to the attributes structure.
1164  * @param[in] enable Enable/disable use of bits in packet descriptor.
1165  * @param[in] pos Position of bits. Maximum value is 191.
1166  *
1167  * @retval NT_SUCCESS Success
1168  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1169  */
1170 int NT_NetTxOpenAttrSetDescriptorPosLayer3Offset(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1171 
1172 /**
1173  * @brief Get bit position in packet descriptor for layer 3 offset bits.
1174  *
1175  * @param[in] attr Pointer to the attributes structure.
1176  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1177  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1178  */
1179 void NT_NetTxOpenAttrGetDescriptorPosLayer3Offset(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1180 
1181 /**
1182  * @brief Set bit position in packet descriptor for layer 4 offset bits.
1183  *
1184  * @param[in] attr Pointer to the attributes structure.
1185  * @param[in] enable Enable/disable use of bits in packet descriptor.
1186  * @param[in] pos Position of bits. Maximum value is 191.
1187  *
1188  * @retval NT_SUCCESS Success
1189  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1190  */
1191 int NT_NetTxOpenAttrSetDescriptorPosLayer4Offset(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1192 
1193 /**
1194  * @brief Get bit position in packet descriptor for layer 4 offset bits.
1195  *
1196  * @param[in] attr Pointer to the attributes structure.
1197  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1198  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1199  */
1200 void NT_NetTxOpenAttrGetDescriptorPosLayer4Offset(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1201 
1202 /**
1203  * @brief Set bit position in packet descriptor for frame type bits.
1204  *
1205  * @param[in] attr Pointer to the attributes structure.
1206  * @param[in] enable Enable/disable use of bits in packet descriptor.
1207  * @param[in] pos Position of bits. Maximum value is 191.
1208  *
1209  * @retval NT_SUCCESS Success
1210  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1211  */
1212 int NT_NetTxOpenAttrSetDescriptorPosFrameType(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1213 
1214 /**
1215  * @brief Get bit position in packet descriptor for frame type bits.
1216  *
1217  * @param[in] attr Pointer to the attributes structure.
1218  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1219  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1220  */
1221 void NT_NetTxOpenAttrGetDescriptorPosFrameType(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1222 
1223 /**
1224  * @brief Set bit position in packet descriptor for checksum command bits.
1225  *
1226  * @param[in] attr Pointer to the attributes structure.
1227  * @param[in] enable Enable/disable use of bits in packet descriptor.
1228  * @param[in] pos Position of bits. Maximum value is 191.
1229  *
1230  * @retval NT_SUCCESS Success
1231  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1232  */
1233 int NT_NetTxOpenAttrSetDescriptorPosChecksumCmd(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1234 
1235 /**
1236  * @brief Get bit position in packet descriptor for checksum command bits.
1237  *
1238  * @param[in] attr Pointer to the attributes structure.
1239  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1240  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1241  */
1242 void NT_NetTxOpenAttrGetDescriptorPosChecksumCmd(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1243 
1244 /**
1245  * @brief Set bit position in packet descriptor for TX ignore bit.
1246  *
1247  * See Standard Descriptor for "TX ignore bit" description.
1248  *
1249  * @param[in] attr Pointer to the attributes structure.
1250  * @param[in] enable Enable/disable use of bit in packet descriptor.
1251  * @param[in] pos Position of bits. Maximum value is 191.
1252  *
1253  * @retval NT_SUCCESS Success
1254  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1255  */
1256 int NT_NetTxOpenAttrSetDescriptorPosIgnoreBit(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1257 
1258 /**
1259  * @brief Get bit position in packet descriptor for TX ignore bit.
1260  *
1261  * @param[in] attr Pointer to the attributes structure.
1262  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1263  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1264  */
1265 void NT_NetTxOpenAttrGetDescriptorPosIgnoreBit(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1266 
1267 /**
1268  * @brief Set bit position in packet descriptor for TX now bit.
1269  *
1270  * See Standard Descriptor for "TX now bit" description.
1271  *
1272  * @param[in] attr Pointer to the attributes structure.
1273  * @param[in] enable Enable/disable use of bit in packet descriptor.
1274  * @param[in] pos Position of bits. Maximum value is 191.
1275  *
1276  * @retval NT_SUCCESS Success
1277  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1278  */
1279 int NT_NetTxOpenAttrSetDescriptorPosTxNowBit(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1280 
1281 /**
1282  * @brief Get bit position in packet descriptor for TX now bit.
1283  *
1284  * @param[in] attr Pointer to the attributes structure.
1285  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1286  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1287  */
1288 void NT_NetTxOpenAttrGetDescriptorPosTxNowBit(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1289 
1290 /**
1291  * @brief Set bit position in packet descriptor for TX set clock bit.
1292  *
1293  * See Standard Descriptor for "TX set clock bit" description.
1294  *
1295  * @param[in] attr Pointer to the attributes structure.
1296  * @param[in] enable Enable/disable use of bit in packet descriptor.
1297  * @param[in] pos Position of bits. Maximum value is 191.
1298  *
1299  * @retval NT_SUCCESS Success
1300  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1301  */
1302 int NT_NetTxOpenAttrSetDescriptorPosClockBit(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1303 
1304 /**
1305  * @brief Get bit position in packet descriptor for TX set clock bit.
1306  *
1307  * @param[in] attr Pointer to the attributes structure.
1308  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1309  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1310  */
1311 void NT_NetTxOpenAttrGetDescriptorPosClockBit(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1312 
1313 /**
1314  * @brief Set bit position in packet descriptor for TX set port bit.
1315  *
1316  * See Standard Descriptor for "TX set port bit" description.
1317  *
1318  * @param[in] attr Pointer to the attributes structure.
1319  * @param[in] enable Enable/disable use of bit in packet descriptor.
1320  * @param[in] pos Position of bits. Maximum value is 191.
1321  *
1322  * @retval NT_SUCCESS Success
1323  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1324  */
1325 int NT_NetTxOpenAttrSetDescriptorPosPortBit(NtNetTxAttr_t* attr, bool enable, uint32_t pos);
1326 
1327 /**
1328  * @brief Get bit position in packet descriptor for TX set port bit.
1329  *
1330  * @param[in] attr Pointer to the attributes structure.
1331  * @param[in] enable Output pointer to enable/disable use of bits in packet descriptor.
1332  * @param[in] pos Output pointer to position of bits. Value will not be set if disabled.
1333  */
1334 void NT_NetTxOpenAttrGetDescriptorPosPortBit(const NtNetTxAttr_t* attr, bool* enable, uint32_t* pos);
1335 
1336 /**
1337  * @brief Set mode for use of wire length in packet descriptor
1338  *
1339  * @param[in] attr Pointer to the attributes structure.
1340  * @param[in] enable flag to enable/disable use wire length in packet descriptor.
1341  */
1343 
1344 /**
1345  * @brief get mode for use of wire length in packet descriptor
1346  *
1347  * @param[in] attr Pointer to the attributes structure.
1348  * @param[in] enable Output pointer flag indicating use of wire length in packet descriptor.
1349  */
1350 int NT_NetTxOpenAttrGetDescriptorUseWireLength(const NtNetTxAttr_t* attr, bool* enable);
1351 
1352 
1353 /**
1354  * @brief Opens a TX host buffer and returns a NtNetStreamTx_t handle (extended version)
1355  *
1356  * This function is called to retrieve a TX stream handle.
1357  * This function will only work with 4GA adapters.
1358  *
1359  * @param[out] hStream Reference to a NtNetStreamTx_t stream pointer
1360  * @param[in] attr Pointer to stream attributes
1361  *
1362  * @retval NT_SUCCESS Success
1363  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1364  */
1365 int NT_NetTxOpen_Attr(NtNetStreamTx_t* hStream, const NtNetTxAttr_t* attr);
1366 /**
1367  * @brief Gets a TX port buffer
1368  *
1369  * This function is called to acquire a TX buffer
1370  *
1371  * @note This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
1372  *
1373  * @param[in] hStream Network TX stream handle
1374  * @param[out] netBuf Segment/packet container reference
1375  * @param[in] port Port to receive a TX buffer from
1376  * @param[in] packetSize Size of the packet to transmit including 4-byte CRC.
1377  * @param[in] packetOption Option to control the properties of the buffer, see @ref NtNetTxPacketOption_e for details
1378  * @param[in] timeout Time in milliseconds to wait for a new buffer - a timeout of -1 will wait indefinitely for a new buffer
1379  *
1380  * @retval NT_SUCCESS Success
1381  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1382  */
1383 int NT_NetTxGet(NtNetStreamTx_t hStream, NtNetBuf_t* netBuf, uint32_t port, size_t packetSize, enum NtNetTxPacketOption_e packetOption, int timeout);
1384 
1385 /**
1386  * @brief Releases the network buffer
1387  *
1388  * This function releases the netBuf data obtained via NT_TxGet
1389  *
1390  * @note This function has no mutex protection and can therefore the same hStream cannot be used by multiple threads
1391  *
1392  * @param[in] hStream Network TX stream handle
1393  * @param[in] netBuf Net buffer is received via NT_TxGet
1394  *
1395  * @retval NT_SUCCESS Success
1396  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1397  */
1398 int NT_NetTxRelease(NtNetStreamTx_t hStream, NtNetBuf_t netBuf);
1399 
1400 /**
1401  * @brief Reads data from the stream
1402  *
1403  * This function will read Tx related info
1404  *
1405  * @param[in] hStream NetTx stream handle
1406  * @param[in] cmd NetTx read structure
1407  *
1408  * @retval NT_SUCCESS Success
1409  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1410  */
1411 int NT_NetTxRead(NtNetStreamTx_t hStream, NtNetTx_t* cmd);
1412 
1413 /**
1414  * @brief Closes a TX stream
1415  *
1416  * This function is called to close a TX stream
1417  *
1418  * @param[in] hStream The TX stream handle to close
1419  *
1420  * @retval NT_SUCCESS Success
1421  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1422  */
1423 int NT_NetTxClose(NtNetStreamTx_t hStream);
1424 
1425 /**
1426  * @brief AddPacket to a TX stream
1427  *
1428  * This function is called to put together scattered fragments of a packet and add it to a TX stream
1429  *
1430  * @note This function has no mutex protection and cannot be used by multiple threads on the same stream, hStream.
1431  *
1432  * @param[in] hStream Network TX stream handle
1433  * @param[in] port Port to add packet into host buffer
1434  * @param[in] fragments The scattered list of packet fragments
1435  * @param[in] fragmentCount The number of scattered fragments in the list
1436  * @param[in] timeout Time in milliseconds to wait for a packet buffer - a timeout of -1 will wait indefinitely for a packet buffer
1437  *
1438  * @retval NT_SUCCESS Success
1439  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1440  */
1441 int NT_NetTxAddPacket(NtNetStreamTx_t hStream, uint32_t port, NtNetTxFragment_t* fragments, uint32_t fragmentCount, int timeout );
1442 
1443 //
1444 
1445 
1446 /** @page HwL3L4Checksum HW IP/UDP/TCP checksum
1447  * @{
1448  * The NT40E2-4, NT20E2, NT4E2 adapters and NT4E in-line adapters support IPv4, UDP and TCP
1449  * calculations in hardware on transmit.\n
1450  * In order to use the feature, the packet descriptor must be configured prior to calling
1451  * @ref NT_NetTxRelease().\n
1452  * <b>Note:</b> The feature only works on non-fragmented packets.\n\n
1453  * Here is an example on the configuration required before transmitting a packet.
1454  *
1455  @verbatim
1456 
1457  struct IPv4Header_s {
1458  uint16_t ip_hl: 4;
1459  uint16_t ip_v: 4;
1460  uint16_t ip_tos: 8;
1461  uint16_t ip_len;
1462 
1463  uint32_t ip_id:16;
1464  uint32_t ip_frag_off:16;
1465 #define IP_DONT_FRAGMENT 0x4000
1466 #define IP_MORE_FRAGMENTS 0x2000
1467 
1468  uint32_t ip_ttl:8;
1469  uint32_t ip_prot:8;
1470  uint32_t ip_crc:16;
1471 
1472  uint32_t ip_src;
1473  uint32_t ip_dest;
1474 }; //20 bytes
1475 
1476 struct UDPHeader_s {
1477  uint32_t udp_src:16;
1478  uint32_t udp_dest:16;
1479 
1480  uint32_t udp_len:16;
1481  uint32_t udp_crc:16;
1482 }; // 8 bytes
1483 
1484 
1485  NT_NET_SET_PKT_IS_IP(hNetBuf, 1);
1486  NT_NET_SET_PKT_IS_UDP(hNetBuf, 1);
1487  NT_NET_SET_PKT_IP_CSUM_OK(hNetBuf, 1);
1488  NT_NET_SET_PKT_UDP_CSUM_OK(hNetBuf, 1);
1489  if(NT_NET_GET_PKT_DESCRIPTOR_TYPE(hNetBuf) == NT_PACKET_DESCRIPTOR_TYPE_NT_EXTENDED) {
1490  NT_NET_SET_PKT_ISL(hNetBuf, 0);
1491  NT_NET_SET_PKT_VLAN_COUNT(hNetBuf, 0);
1492  NT_NET_SET_PKT_MPLS_COUNT(hNetBuf, 0);
1493  NT_NET_SET_PKT_L2_FRAME_TYPE(hNetBuf, NT_L2_FRAME_TYPE_ETHER_II);
1494  NT_NET_SET_PKT_L3_FRAME_TYPE(hNetBuf, NT_L3_FRAME_TYPE_IPv4);
1495  NT_NET_SET_PKT_L4_FRAME_TYPE(hNetBuf, NT_L4_FRAME_TYPE_UDP);
1496  NT_NET_SET_PKT_L3_LENGTH(hNetBuf, sizeof(struct IPv4Header_s)>>2);
1497  NT_NET_SET_PKT_L4_LENGTH(hNetBuf, sizeof(struct UDPHeader_s)>>2);
1498  NT_NET_SET_PKT_CALC_L3_CHECKSUM(hNetBuf, 1);
1499  NT_NET_SET_PKT_CALC_L4_CHECKSUM(hNetBuf, 1);
1500  }
1501  @endverbatim
1502 
1503  @} */
1504 
1505 /** @page PacketBasedTransmit Packet based transmit
1506  * @{
1507  *
1508  * For packet based transmit see the example @ref transmit_packet_example.c "net/transmit/transmit_packet_example.c"
1509  @} */
1510 
1511 /** @page SegmentBasedTransmit Segment based transmit
1512  * @{
1513  *
1514  * For segment based transmit see the example @ref transmit_segment_example.c "net/transmit_segment/transmit_segment_example.c"
1515  @} */
1516 
1517 /** @} */
1518 
1519 
1520 /** @addtogroup StreamFile
1521  *@{
1522  */
1523 /**
1524  * Network file stream handle - used for file streams
1525  */
1526 typedef struct NtNetStreamFile_s* NtNetStreamFile_t;
1527 
1528 /**
1529  * @brief Opens a capture file
1530  *
1531  * This function is called to open a capture file, captured with a segment-based stream.
1532  * The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail
1533  * when opening the capture file.
1534  *
1535  * @param[out] hStream Reference to a NetFile_t stream pointer
1536  * @param[in] name A stream friendly name - used in, for example, logging statements
1537  * @param[in] netIntf Deliver packets or segments
1538  * @param[in] file The capture file to open
1539  *
1540  * @retval NT_SUCCESS Success
1541  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1542  */
1543 int NT_NetFileOpen(NtNetStreamFile_t* hStream, const char* name, enum NtNetInterface_e netIntf, const char* file);
1544 
1545 /**
1546 * @brief Opens a capture file (extended version)
1547 *
1548 * This function is called to open a capture file, captured with a segment-based stream.
1549 * The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail
1550 * when opening the capture file.
1551 *
1552 * @param[out] hStream Reference to a NetFile_t stream pointer
1553 * @param[in] name A stream friendly name - used in, for example, logging statements
1554 * @param[in] netIntf Deliver packets or segments
1555 * @param[in] file The capture file to open
1556 * @param[in] noConvert Do not convert PCAP files (Native PCAP tx for 4GA)
1557 *
1558 * @retval NT_SUCCESS Success
1559 * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1560 */
1561 int NT_NetFileOpen_v2(NtNetStreamFile_t* hStream, const char* name, enum NtNetInterface_e netIntf, const char* file, bool noConvert);
1562 
1563 /**
1564  * @brief Gets packets/segments from a file stream
1565  *
1566  * This function is called to retrieve packets or segments from a capture file
1567  *
1568  * @note This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
1569  *
1570  * @param[in] hStream NetFile stream handle
1571  * @param[out] netBuf Packet/segment container reference
1572  *
1573  * @retval NT_SUCCESS (0) Success
1574  * @retval NT_STATUS_END_OF_FILE EOF indicator - See note
1575  * @retval otherwise Error - use @ref NT_ExplainError for an error description
1576  * @note When NT_STATUS_END_OF_FILE is returned the internal file offset that been reset making it possible to
1577  * call NT_NetFileGet() again without having to close and open the file, which improves performance when
1578  * replaying a file continuously.
1579  */
1580 int NT_NetFileGet(NtNetStreamFile_t hStream, NtNetBuf_t* netBuf);
1581 
1582 /**
1583  * @brief Releases the network buffer
1584  *
1585  * This function will release the netBuf data obtained via NT_FileGet
1586  *
1587  * @note This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
1588  *
1589  * @param[in] hStream NetStreamFile stream handle
1590  * @param[in] netBuf The network buffer is received via NT_FileGet
1591  *
1592  * @retval NT_SUCCESS Success
1593  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1594  */
1595 int NT_NetFileRelease(NtNetStreamFile_t hStream, NtNetBuf_t netBuf);
1596 
1597 /**
1598  * @brief Closes a file stream
1599  *
1600  * This function is called to close a file stream
1601  *
1602  * @param[in] hStream The file stream handle to close
1603  *
1604  * @retval NT_SUCCESS Success
1605  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1606  */
1607 int NT_NetFileClose(NtNetStreamFile_t hStream);
1608 
1609 /**
1610  * @brief Read information about a file stream
1611  *
1612  * This function is called to read information about a file stream
1613  *
1614  * @param[in] hStream The file stream handle
1615  * @param[in,out] data Structure containing command and returned data
1616  *
1617  * @retval NT_SUCCESS Success
1618  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1619  */
1620 int NT_NetFileRead(NtNetStreamFile_t hStream, NtNetFileRead_t* data);
1621 
1622 /**
1623 * @brief Opens a capture file
1624 *
1625 * This function is called to open a capture file, captured with a segment-based stream.
1626 * The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail
1627 * when opening the capture file.
1628 *
1629 * @param[out] hStream Reference to a NetFile_t stream pointer
1630 * @param[in] file The capture file to open
1631 * @param[in] attr Attributes of the stream
1632 *
1633 * @retval NT_SUCCESS Success
1634 * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
1635 */
1636 int NT_NetFileOpen_Attr(NtNetStreamFile_t* hStream, const char* file, const NtNetFileAttr_t* attr);
1637 
1638 /**
1639  * @brief Initialize NetFile stream attributes
1640  *
1641  * The attributes are initialized to the following default values: \n
1642  * name = NULL \n
1643  * netIntf = NT_NET_INTERFACE_SEGMENT \n
1644  * pcapToNtConversion = True \n
1645  * convertedTsType = NT_TIMESTAMP_TYPE_NATIVE_UNIX \n
1646  *
1647  * @param[in] attr Pointer to the attributes structure
1648  *
1649  */
1651 
1652 /**
1653  * @brief Sets the stream name attribute
1654  *
1655  * @param[in] attr Pointer to the attributes structure
1656  * @param[in] name Stream friendly name - used in, for example, logging statements
1657  */
1658 void NT_NetFileOpenAttrSetName(NtNetFileAttr_t* attr, const char* name);
1659 
1660 /**
1661  * @brief Returns the name attribute
1662  *
1663  * @param[in] attr Pointer to the attributes structure
1664  *
1665  * @return The name attribute
1666  */
1667 const char* NT_NetFileOpenAttrGetName(const NtNetFileAttr_t* attr);
1668 
1669 /**
1670  * @brief Sets the interface type attribute
1671  *
1672  * @param[in] attr Pointer to the attributes structure
1673  * @param[in] netIntf Interface type - segment or packet
1674  */
1676 
1677 /**
1678  * @brief Returns the interface type attribute
1679  *
1680  * @param[in] attr Pointer to the attributes structure
1681  *
1682  * @return The interface type attribute
1683  */
1685 
1686 
1687 /**
1688  * @brief Enable or disable automatic conversion from PCAP to NT format
1689  *
1690  * @param[in] attr Pointer to the attributes structure
1691  * @param[in] enableFlag True enables automatic conversion from PCAP to NT
1692  * format for 3GA. Automatic conversion does not
1693  * apply to 4GA, which has native support for PCAP.
1694  */
1696  bool enableFlag);
1697 
1698 /**
1699  * @brief Returns whether automatic conversion from PCAP to NT format is enabled
1700  *
1701  * @param[in] attr Pointer to the attributes structure
1702  *
1703  * @return A boolean where True denotes that automatic conversion from
1704  * PCAP to NT format is enabled (only applicable to 3GA).
1705  */
1707 
1708 /**
1709  * @brief Sets the converted timstamp type attribute
1710  *
1711  * This attribute is only used, when a PCAP file is converted to
1712  * an NT capture file.
1713  *
1714  * Valid values are:
1715  * NT_TIMESTAMP_TYPE_NATIVE_UNIX
1716  * NT_TIMESTAMP_TYPE_UNIX_NANOTIME
1717  *
1718  * @param[in] attr Pointer to the attributes structure
1719  * @param[in] convertedTsType Converted timestamp type
1720  */
1722 
1723 /**
1724  * @brief Gets the converted timstamp type attribute
1725  *
1726  * @param[in] attr Pointer to the attributes structure
1727  *
1728  * @return the converted Timestamp Type attribute
1729  */
1731 
1732 /** @} */
1733 
1734 /**
1735  * MACROs to access network data
1736  */
1737 
1738 /**
1739  * Layer 2 types
1740  */
1742  NT_L2_FRAME_TYPE_ETHER_II=0, //!< Ether type II frame
1743  NT_L2_FRAME_TYPE_LLC, //!< LLC frame
1744  NT_L2_FRAME_TYPE_SNAP, //!< SNAP frame
1745  NT_L2_FRAME_TYPE_NOVELL_RAW //!< Novell Raw frame
1746 };
1747 
1748 /**
1749  * Layer 3 types
1750  */
1752  NT_L3_FRAME_TYPE_IPv4=0, //!< IPv4 frame
1753  NT_L3_FRAME_TYPE_IPv6, //!< IPV6 frame
1754  NT_L3_FRAME_TYPE_IPX, //!< IPX frame
1755  NT_L3_FRAME_TYPE_OTHER, //!< Other frame
1756 };
1757 
1758 /**
1759  * Layer 4 frame types
1760  */
1762  NT_L4_FRAME_TYPE_TCP=0, //!< TCP frame
1763  NT_L4_FRAME_TYPE_UDP, //!< UDP frame
1764  NT_L4_FRAME_TYPE_ICMP, //!< ICMP frame
1765  NT_L4_FRAME_TYPE_OTHER, //!< Other frame
1766  NT_L4_FRAME_TYPE_GRE, //!< GRE frame
1767  NT_L4_FRAME_TYPE_SCTP, //!< SCTP frame
1768  NT_L4_FRAME_TYPE_IPV4, //!< IPV4 in IP frame
1769  NT_L4_FRAME_TYPE_IPV6, //!< IPV6 in IP frame
1770 };
1771 
1772 /**
1773  * Layer 4 port types
1774  */
1776  NT_L4_PORT_OTHER=0, //!< Other port
1777  NT_L4_PORT_GTPV0_U, //!< GTPV0_U port
1778  NT_L4_PORT_GTPV1V2_C, //!< GTPV1V2_C port
1779  NT_L4_PORT_GTPV1_U //!< GTPV1_U port
1780 };
1781 
1782 /**
1783  * Frame tunnel types
1784  */
1786  NT_TUNNELTYPE_OTHER=0, //!< Other data type
1787  NT_TUNNELTYPE_GTPV0_U, //!< GTPV0_U data type
1788  NT_TUNNELTYPE_GTPV1V2_C, //!< GTPV1V2_C data type
1789  NT_TUNNELTYPE_GTPV1_U_SIGNAL, //!< GTPV1_U_SIGNAL type
1790  NT_TUNNELTYPE_GTPV1_U_GPDU, //!< GTPV1_U_GPDU data type
1791  NT_TUNNELTYPE_IPINIP, //!< IPINIP data type
1792 };
1793 
1794 /**
1795  * L3 fragmentation
1796  */
1798  NT_L3_FRAGMENT_TYPE_NONE, //!< L3 not fragmented
1799  NT_L3_FRAGMENT_TYPE_FIRST, //!< L3 first fragment
1800  NT_L3_FRAGMENT_TYPE_MIDDLE, //!< L3 middle fragment
1801  NT_L3_FRAGMENT_TYPE_LAST, //!< L3 last fragment
1802 };
1803 
1804 /** @addtogroup NetworkStream
1805  *@{
1806  */
1807 
1808 /**
1809  * @defgroup MetaDataMacros User meta data container
1810  * @{
1811  * The following macros get and set user defined meta data.
1812  * Use these fields as house-keeping storage. No NTAPI function use these meta containers for anything.
1813  *
1814  */
1815 
1816 /** @def NT_NET_GET_USER_META_ARG0
1817  * @brief Returns the meta data arg0 uintptr_t value
1818  * @param[in] "_hNetBuf_" NetBuf pointer
1819  * @hideinitializer
1820  */
1821 #define NT_NET_GET_USER_META_ARG0(_hNetBuf_) ((_hNetBuf_)->arg0)
1822 
1823 /** @def NT_NET_GET_USER_META_ARG1
1824  * @brief Returns the meta data arg1 uintptr_t value
1825  * @param[in] "_hNetBuf_" NetBuf pointer
1826  * @hideinitializer
1827  */
1828 #define NT_NET_GET_USER_META_ARG1(_hNetBuf_) ((_hNetBuf_)->arg1)
1829 
1830 /** @def NT_NET_GET_USER_META_ARG2
1831  * @brief Returns the meta data arg2 uintptr_t value
1832  * @param[in] "_hNetBuf_" NetBuf pointer
1833  * @hideinitializer
1834  */
1835 #define NT_NET_GET_USER_META_ARG2(_hNetBuf_) ((_hNetBuf_)->arg2)
1836 
1837 /** @def NT_NET_SET_USER_META_ARG0
1838  * @brief Set the meta data arg0 uintptr_t value
1839  * @param[in] "_hNetBuf_" NetBuf pointer
1840  * @param[in] value An uintptr_t sized value
1841  * @hideinitializer
1842  */
1843 #define NT_NET_SET_USER_META_ARG0(_hNetBuf_, value) ((_hNetBuf_)->arg0 = (value))
1844 
1845 /** @def NT_NET_SET_USER_META_ARG1
1846  * @brief Set the meta data arg1 uintptr_t value
1847  * @param[in] "_hNetBuf_" NetBuf pointer
1848  * @param[in] value An uintptr_t sized value
1849  * @hideinitializer
1850  */
1851 #define NT_NET_SET_USER_META_ARG1(_hNetBuf_, value) ((_hNetBuf_)->arg1 = (value))
1852 
1853 /** @def NT_NET_SET_USER_META_ARG2
1854  * @brief Set the meta data arg2 uintptr_t value
1855  * @param[in] "_hNetBuf_" NetBuf pointer
1856  * @param[in] value An uintptr_t sized value
1857  * @hideinitializer
1858  */
1859 #define NT_NET_SET_USER_META_ARG2(_hNetBuf_, value) ((_hNetBuf_)->arg2 = (value))
1860 
1861 /** @} */
1862 
1863 /** @defgroup DataMacros Network macros
1864  * @{
1865  * The network stream delivers data to the application. In order to access data
1866  * content, such as packet length or packet receive time stamp, a set of macros is
1867  * provided. These macros are divided into 2 major groups:
1868  * - @ref SegmentMacros
1869  * - @ref PacketMacros
1870  *
1871  * The @ref SegmentMacros are used with the segment-based interface
1872  * The @ref PacketMacros are used with the packet-based interface
1873  */
1874 
1875 /** @defgroup SegmentMacros Segment macros
1876  * @{
1877  * The following is only possible on segment-based streams
1878  */
1879 
1880 /** @def NT_NET_GET_SEGMENT_PTR
1881  * @brief Returns the segment pointer
1882  * @param[in] "_hNetBuf_" Segment container reference
1883  * @hideinitializer
1884  */
1885 #define NT_NET_GET_SEGMENT_PTR(_hNetBuf_) ((_hNetBuf_)->hHdr)
1886 
1887 /** @def NT_NET_GET_SEGMENT_LENGTH
1888  * @brief Returns the segment length
1889  * @param[in] "_hNetBuf_" Segment container reference
1890  * @hideinitializer
1891  */
1892 #define NT_NET_GET_SEGMENT_LENGTH(_hNetBuf_) ((size_t)(_hNetBuf_)->length)
1893 
1894 /** @def NT_NET_GET_SEGMENT_PKTS
1895  * @brief Returns the number of packets in a segment
1896  *
1897  * This macro is only supported on NT4GA adapters configured to static segment
1898  * size emulation mode. On NT4GA adapters configured to dynamic segment size
1899  * this macro will always return 0.
1900  * @param[in] "_hNetBuf_" Segment container reference
1901  * @hideinitializer
1902  */
1903 #define NT_NET_GET_SEGMENT_PKTS(_hNetBuf_) ((size_t)(_hNetBuf_)->pkts)
1904 
1905 /** @def NT_NET_GET_SEGMENT_TIMESTAMP
1906  * @brief The time stamp of the first packet in the segment
1907  * @param[in] "_hNetBuf_" Segment container reference
1908  * @hideinitializer
1909  */
1910 #define NT_NET_GET_SEGMENT_TIMESTAMP(_hNetBuf_) NT_NetGetSegmentTimestamp((_hNetBuf_)->hHdr)
1911 uint64_t NT_NetGetSegmentTimestamp(void* pDescr);
1912 
1913 /** @def NT_NET_GET_SEGMENT_TIMESTAMP_TYPE
1914  * @brief The time stamp type
1915  * @param[in] "_hNetBuf_" Segment container reference
1916  * @hideinitializer
1917  */
1918 #define NT_NET_GET_SEGMENT_TIMESTAMP_TYPE(_hNetBuf_) ((_hNetBuf_)->tsType)
1919 
1920 /** @def NT_NET_SET_SEGMENT_LENGTH
1921  * @brief Sets the segment length
1922  *
1923  * This is used when generating a TX segment and should be used with care.
1924  * @param[in,out] "_hNetBuf_" Segment container reference
1925  * @param[in] "_length_" Length of the segment
1926  * @hideinitializer
1927  */
1928 #define NT_NET_SET_SEGMENT_LENGTH(_hNetBuf_, _length_) do {(_hNetBuf_)->length=_length_;} while(0)
1929 
1930 
1931 /** @defgroup SegmentFunctions Functions to handle segment data
1932  * @{
1933  * These inline C functions are only valid when "PacketDescriptor" in ntservice.ini file has been set to any value than PCAP
1934  * and @ref NT_NET_GET_PKT_DESCRIPTOR_TYPE returns @ref NT_PACKET_DESCRIPTOR_TYPE_NT_EXTENDED or @ref NT_PACKET_DESCRIPTOR_TYPE_NT
1935  */
1936 /**
1937  * @brief Inline C function to create a segment NtNetBuf_t
1938  *
1939  * This function is used when creating segments in application memory, e.g.
1940  * when constructing a transmit segment
1941  *
1942  * @param[in] size Size of the memory provided by the "mem" pointer
1943  * @param[in] mem Pointer to the segment memory allocated
1944  * @param[in] portOffset Segments are per adapter and ports are relative to the port offset. The port offset can be found in @ref NtInfoAdapter_v6_s::portOffset. If 0 is provided then the possible values in @ref NT_NET_SET_PKT_TXPORT can only be from 0 to 3.
1945  * @param[out] segNetBuf Destination segment NtNetBuf_t structure
1946  *
1947  */
1948 static NT_INLINE void _nt_net_create_segment_netbuf(uint64_t size, void* mem, uint8_t portOffset, struct NtNetBuf_s* segNetBuf)
1949 {
1950  memset(segNetBuf, 0, sizeof(struct NtNetBuf_s));
1951  segNetBuf->length=size;
1952  segNetBuf->portOffset=portOffset;
1953  segNetBuf->hHdr=(NtNetBufHdr_t)(mem);
1954  segNetBuf->hPkt=(NtNetBufPkt_t)(mem);
1955  *((uint64_t*)mem+0)=0;
1956  *((uint64_t*)mem+1)=0;
1957  *((uint64_t*)mem+2)=0;
1958  *((uint64_t*)mem+3)=0;
1959 }
1960 
1961 /**
1962  * @brief Inline C function to use when traversing segments. The
1963  * function will update the NetBuf to the next packet
1964  * in the segment.
1965  *
1966  * @param[in] segNetBuf Segment NtNetBuf_s * structure
1967  * @param[in] segLength Length of the segment - used to know when there is no more data
1968  * @param[out] pktNetBuf Packet NtNetBuf_s * structure
1969  *
1970  * @retval Returns the amount of data left in the segment
1971  */
1972 static NT_INLINE uint64_t _nt_net_get_next_packet(struct NtNetBuf_s* segNetBuf, uint64_t segLength, struct NtNetBuf_s* pktNetBuf)
1973 {
1974  if(segLength) {
1975  uint8_t* nextPacket = (uint8_t*)pktNetBuf->hHdr + NT_NET_GET_PKT_CAP_LENGTH(pktNetBuf);
1976  uint8_t* endSegm = (uint8_t*)segNetBuf->hHdr + segLength;
1977  // If this was the last packet then do not traverse any further
1978  if (nextPacket >= endSegm) {
1979  return 0;
1980  }
1981  pktNetBuf->hHdr=(NtNetBufHdr_t)nextPacket;
1982  pktNetBuf->hPkt=(NtNetBufPkt_t)(nextPacket + NT_NET_GET_PKT_DESCR_LENGTH(pktNetBuf));
1983  return (uint64_t)(endSegm - nextPacket);
1984  } else {
1985  return 0;
1986  }
1987 }
1988 
1989 /**
1990  * @brief Inline C function to build a packet based NtNetBuf_t
1991  * from a segment based NtNetBuf_t
1992  *
1993  * @param[in] segNetBuf Segment NtNetBuf_t structure
1994  * @param[out] pktNetBuf Destination packet NtNetBuf_t structure
1995  *
1996  */
1997 static NT_INLINE void _nt_net_build_pkt_netbuf(struct NtNetBuf_s* segNetBuf, struct NtNetBuf_s* pktNetBuf)
1998 {
1999  memcpy((void*)pktNetBuf, (void*)segNetBuf, sizeof(struct NtNetBuf_s));
2000  pktNetBuf->hHdr=(NtNetBufHdr_t)(segNetBuf->hHdr);
2001  pktNetBuf->hPkt=(NtNetBufPkt_t)((uint8_t*)segNetBuf->hHdr+NT_NET_GET_PKT_DESCR_LENGTH(segNetBuf));
2002 }
2003 
2004 /**
2005  * @brief Inline C function to initialize a segment NtNetBuf_t structure
2006  * using any received segment buffer.
2007  *
2008  * This function is used when a new NtNetBuf_t handle is needed for a provided segment
2009  * buffer, e.g. when copying segments
2010  *
2011  * @param[in] size Size of the segment pointed to by the "segment" pointer
2012  * @param[in] segment Pointer to the segment
2013  * @param[in] portOffset Segments are per adapter and ports are relative to the port offset. The port offset of the adapter of which the segment originates from most be copied/stored in parallel, or known by some other means, and specified here. If 0 is used here local ports will be seen as logical ports.
2014  * @param[out] segNetBuf Segment NtNetBuf_t structure to initialize
2015  *
2016  */
2017 static NT_INLINE void _nt_net_initialize_segment_netbuf(uint64_t size, void* segment, uint8_t portOffset, struct NtNetBuf_s* segNetBuf)
2018 {
2019  memset(segNetBuf, 0, sizeof(struct NtNetBuf_s));
2020  segNetBuf->length=size;
2021  segNetBuf->portOffset=portOffset;
2022  segNetBuf->hHdr=(NtNetBufHdr_t)(segment);
2023  segNetBuf->hPkt=(NtNetBufPkt_t)(segment);
2024 }
2025 
2026 
2027 /** @} */
2028 
2029 /** @} */
2030 
2031 /** @} */
2032 /** @} */
2033 /** @} */
2034 
2035 
2036 #ifndef DOXYGEN_INTERNAL_ONLY
2037 #define NT_MAKE_STRUCTURE_ID( __structureType, __structureName ) \
2038  ((uint32_t)((__structureType << 16) | sizeof(__structureName)))
2039 
2040 /**
2041  * File header. This data must be placed in the beginning of a
2042  * file when storing data to disk.
2043  */
2044 #define NT_FILE_HEADER0_COOKIE 0xDEADBEAF
2045 // Ensure that the following is packed equally on 32 and 64bit
2046 #pragma pack(push, 1)
2047 typedef struct NtFileHeader0_s {
2048  /**
2049  * StructureID is used to identify the header structure type
2050  */
2051  uint32_t structid; //!< The segment descriptor version
2052  uint64_t align; //!< Alignment to ensure the cookie is located at offset 12
2053  /**
2054  * Cookie to validate the header
2055  */
2056  uint32_t cookie; //!< Cookie = 0xDEADBEAF. Must be located at offset 12 to be able to detect if the file starts with a packet. The cookie will be located where storedLength is found in a packet.
2057  /**
2058  * The time stamp type used to time stamp the segments - very useful in offline mode
2059  */
2060  uint8_t tsType; //!< Timestamp type that is supplied with 'TimeValidAt'
2061  /**
2062  * Port offset. All packets in the segment have a per adapter specific port index
2063  * and by adding this portOffset, the system-wide port is retrieved.
2064  */
2065  uint8_t portOffset; //!< Port offset - use to calculate the logical port number
2066  /**
2067  * Color lookup.
2068  * Contains the customer color ID mapping to HW IDs.
2069  */
2070  uint8_t colorMap[64]; //!< Filter color map table
2071  uint8_t reserved[46]; //!< Reserved. Total structure size must be 128 bytes.
2072 } NtFileHeader0_t;
2073 
2074 // Disable packing
2075 #pragma pack(pop)
2076 #define NT_STID_FILE_HEADER0 NT_MAKE_STRUCTURE_ID(1, NtFileHeader0_t)
2077 #endif
2078 #endif /* __STREAM_NET_H__ */
2079 
2080 //
2081 // EOF
2082 //