File Network Stream

Reference Documentation

Platform
Intel® PAC
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.9
Napatech Software Suite: File Network Stream

Detailed Description

The File network stream is used for packet-by-packet offline analysis of the packets captured with the segment RX interface. See Segment interface for a description of how to accomplish this.

To open a file network stream, call the NT_NetFileOpen with the name of the captured file as argument. To get the next packet from the file network stream, call the NT_NetFileGet. Use the packet macros to access the packet data. When finished with the packet, call NT_NetFileRelease to release it again. When finished with the stream, call NT_NetFileClose to close it.

Supported files are native NT captured files, pcap and pcap-ng files. When using pcap or pcap-ng files, the received port information is always set to 0.

For an example on how to use the file network stream interface, see net/replay/replay_example.c.

Functions

int NT_NetFileOpen (NtNetStreamFile_t *hStream, const char *name, enum NtNetInterface_e netIntf, const char *file)
 Opens a capture file. More...
 
int NT_NetFileOpen_v2 (NtNetStreamFile_t *hStream, const char *name, enum NtNetInterface_e netIntf, const char *file, bool noConvert)
 Opens a capture file (extended version) More...
 
int NT_NetFileGet (NtNetStreamFile_t hStream, NtNetBuf_t *netBuf)
 Gets packets/segments from a file stream. More...
 
int NT_NetFileRelease (NtNetStreamFile_t hStream, NtNetBuf_t netBuf)
 Releases the network buffer. More...
 
int NT_NetFileClose (NtNetStreamFile_t hStream)
 Closes a file stream. More...
 
int NT_NetFileRead (NtNetStreamFile_t hStream, NtNetFileRead_t *data)
 Read information about a file stream. More...
 
int NT_NetFileOpen_Attr (NtNetStreamFile_t *hStream, const char *file, const NtNetFileAttr_t *attr)
 Opens a capture file. More...
 
void NT_NetFileOpenAttrInit (NtNetFileAttr_t *attr)
 Initialize NetFile stream attributes. More...
 
void NT_NetFileOpenAttrSetName (NtNetFileAttr_t *attr, const char *name)
 Sets the stream name attribute. More...
 
const char * NT_NetFileOpenAttrGetName (const NtNetFileAttr_t *attr)
 Returns the name attribute. More...
 
void NT_NetFileOpenAttrSetInterface (NtNetFileAttr_t *attr, enum NtNetInterface_e netIntf)
 Sets the interface type attribute. More...
 
enum NtNetInterface_e NT_NetTxOpenAttrGetInterface (NtNetTxAttr_t *attr)
 Returns the interface type attribute. More...
 
void NT_NetFileOpenAttrSetEnablePcapToNtConversion (NtNetFileAttr_t *attr, bool enableFlag)
 Enable or disable automatic conversion from PCAP to NT format. More...
 
bool NT_NetFileOpenAttrGetEnablePcapToNtConversion (const NtNetTxAttr_t *attr)
 Returns whether automatic conversion from PCAP to NT format is enabled. More...
 
int NT_NetFileOpenAttrSetConvertedTsType (NtNetFileAttr_t *attr, enum NtTimestampType_e convertedTsType)
 Sets the converted timstamp type attribute. More...
 
enum NtTimestampType_e NT_NetFileOpenAttrGetConvertedTsType (NtNetTxAttr_t *attr)
 Gets the converted timstamp type attribute. More...
 

Typedefs

typedef struct NtNetStreamFile_s * NtNetStreamFile_t
 

Function Documentation

int NT_NetFileOpen ( NtNetStreamFile_t hStream,
const char *  name,
enum NtNetInterface_e  netIntf,
const char *  file 
)

Opens a capture file.

This function is called to open a capture file, captured with a segment-based stream. The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail when opening the capture file.

Parameters
[out]hStreamReference to a NetFile_t stream pointer
[in]nameA stream friendly name - used in, for example, logging statements
[in]netIntfDeliver packets or segments
[in]fileThe capture file to open
Return values
NT_SUCCESSSuccess
!=NT_SUCCESSError - use NT_ExplainError for an error description
Examples:
net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.

Referenced by GetTimeStamp(), and main().

int NT_NetFileOpen_v2 ( NtNetStreamFile_t hStream,
const char *  name,
enum NtNetInterface_e  netIntf,
const char *  file,
bool  noConvert 
)

Opens a capture file (extended version)

This function is called to open a capture file, captured with a segment-based stream. The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail when opening the capture file.

Parameters
[out]hStreamReference to a NetFile_t stream pointer
[in]nameA stream friendly name - used in, for example, logging statements
[in]netIntfDeliver packets or segments
[in]fileThe capture file to open
[in]noConvertDo not convert PCAP files (Native PCAP tx for 4GA)
Return values
NT_SUCCESSSuccess
!=NT_SUCCESSError - use NT_ExplainError for an error description
int NT_NetFileGet ( NtNetStreamFile_t  hStream,
NtNetBuf_t netBuf 
)

Gets packets/segments from a file stream.

This function is called to retrieve packets or segments from a capture file

Note
This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
Parameters
[in]hStreamNetFile stream handle
[out]netBufPacket/segment container reference
Return values
NT_SUCCESS(0) Success
NT_STATUS_END_OF_FILEEOF indicator - See note
otherwiseError - use NT_ExplainError for an error description
Note
When NT_STATUS_END_OF_FILE is returned the internal file offset that been reset making it possible to call NT_NetFileGet() again without having to close and open the file, which improves performance when replaying a file continuously.
Examples:
net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.

Referenced by GetTimeStamp(), and main().

int NT_NetFileRelease ( NtNetStreamFile_t  hStream,
NtNetBuf_t  netBuf 
)

Releases the network buffer.

This function will release the netBuf data obtained via NT_FileGet

Note
This function has no mutex protection, therefore the same hStream cannot be used by multiple threads
Parameters
[in]hStreamNetStreamFile stream handle
[in]netBufThe network buffer is received via NT_FileGet
Return values
NT_SUCCESSSuccess
!=NT_SUCCESSError - use NT_ExplainError for an error description
Examples:
net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.

Referenced by main().

int NT_NetFileClose ( NtNetStreamFile_t  hStream)

Closes a file stream.

This function is called to close a file stream

Parameters
[in]hStreamThe file stream handle to close
Return values
NT_SUCCESSSuccess
!=NT_SUCCESSError - use NT_ExplainError for an error description
Examples:
net/readcapfile/readcapfile_example.c, net/replay/replay_example.c, net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.

Referenced by GetTimeStamp(), and main().

int NT_NetFileRead ( NtNetStreamFile_t  hStream,
NtNetFileRead_t data 
)

Read information about a file stream.

This function is called to read information about a file stream

Parameters
[in]hStreamThe file stream handle
[in,out]dataStructure containing command and returned data
Return values
NT_SUCCESSSuccess
!=NT_SUCCESSError - use NT_ExplainError for an error description
Examples:
net/replay4GA/replay4ga_example.c, and net/replayGS/replayGS_example.c.

Referenced by main().

int NT_NetFileOpen_Attr ( NtNetStreamFile_t hStream,
const char *  file,
const NtNetFileAttr_t attr 
)

Opens a capture file.

This function is called to open a capture file, captured with a segment-based stream. The capture file must have an NT, PCAP or PCAP-NG file header otherwise it will fail when opening the capture file.

Parameters
[out]hStreamReference to a NetFile_t stream pointer
[in]fileThe capture file to open
[in]attrAttributes of the stream
Return values
NT_SUCCESSSuccess
!=NT_SUCCESSError - use NT_ExplainError for an error description

Referenced by main().

void NT_NetFileOpenAttrInit ( NtNetFileAttr_t attr)

Initialize NetFile stream attributes.

The attributes are initialized to the following default values:
name = NULL
netIntf = NT_NET_INTERFACE_SEGMENT
pcapToNtConversion = True
convertedTsType = NT_TIMESTAMP_TYPE_NATIVE_UNIX

Parameters
[in]attrPointer to the attributes structure

Referenced by main().

void NT_NetFileOpenAttrSetName ( NtNetFileAttr_t attr,
const char *  name 
)

Sets the stream name attribute.

Parameters
[in]attrPointer to the attributes structure
[in]nameStream friendly name - used in, for example, logging statements

Referenced by main().

const char* NT_NetFileOpenAttrGetName ( const NtNetFileAttr_t attr)

Returns the name attribute.

Parameters
[in]attrPointer to the attributes structure
Returns
The name attribute
void NT_NetFileOpenAttrSetInterface ( NtNetFileAttr_t attr,
enum NtNetInterface_e  netIntf 
)

Sets the interface type attribute.

Parameters
[in]attrPointer to the attributes structure
[in]netIntfInterface type - segment or packet

Referenced by main().

enum NtNetInterface_e NT_NetTxOpenAttrGetInterface ( NtNetTxAttr_t attr)

Returns the interface type attribute.

Parameters
[in]attrPointer to the attributes structure
Returns
The interface type attribute
void NT_NetFileOpenAttrSetEnablePcapToNtConversion ( NtNetFileAttr_t attr,
bool  enableFlag 
)

Enable or disable automatic conversion from PCAP to NT format.

Parameters
[in]attrPointer to the attributes structure
[in]enableFlagTrue enables automatic conversion from PCAP to NT format for 3GA. Automatic conversion does not apply to 4GA, which has native support for PCAP.

Referenced by main().

bool NT_NetFileOpenAttrGetEnablePcapToNtConversion ( const NtNetTxAttr_t attr)

Returns whether automatic conversion from PCAP to NT format is enabled.

Parameters
[in]attrPointer to the attributes structure
Returns
A boolean where True denotes that automatic conversion from PCAP to NT format is enabled (only applicable to 3GA).
int NT_NetFileOpenAttrSetConvertedTsType ( NtNetFileAttr_t attr,
enum NtTimestampType_e  convertedTsType 
)

Sets the converted timstamp type attribute.

This attribute is only used, when a PCAP file is converted to an NT capture file.

Valid values are: NT_TIMESTAMP_TYPE_NATIVE_UNIX NT_TIMESTAMP_TYPE_UNIX_NANOTIME

Parameters
[in]attrPointer to the attributes structure
[in]convertedTsTypeConverted timestamp type

Referenced by main().

enum NtTimestampType_e NT_NetFileOpenAttrGetConvertedTsType ( NtNetTxAttr_t attr)

Gets the converted timstamp type attribute.

Parameters
[in]attrPointer to the attributes structure
Returns
the converted Timestamp Type attribute

Typedef Documentation

typedef struct NtNetStreamFile_s* NtNetStreamFile_t

Network file stream handle - used for file streams

Definition at line 1499 of file stream_net.h.