replayGS_example.c

Reference Documentation

Platform
IntelĀ® PAC
Napatech SmartNIC
Content Type
Reference Information
Napatech Software Suite: examples/net/replayGS/replayGS_example.c File Reference
replayGS_example.c File Reference
#include <argparse.h>
#include <time.h>
#include <nt.h>

Go to the source code of this file.

Functions

static void StopApplication (int sig __attribute__((unused)))
 
static void DisplayProgramHeader (void)
 
static void DisplayProgramFooter (void)
 
static void PrintTimeStamp (uint64_t ts)
 Print a human readable time on the screen. More...
 
static uint64_t CalcOffset (uint64_t ts_start, uint64_t ts1, uint64_t ts2)
 Calculate the transmit offset. More...
 
static uint32_t GetAdapterTimestamp (int adapterNo, uint64_t *ts)
 Gets the timestamp from the adapter. More...
 
static uint32_t SetGlobalSync (int adapterNo, int portMask, uint64_t offset)
 Sets Global Sync. More...
 
static int GetTimeStamp (uint64_t *ts)
 Get the timestamp of the first packet in the file. More...
 
static int ParseStartTime (const char *dts, uint64_t *ts)
 Parse the start time. More...
 
static int printTransmissionStart (int adapter, uint64_t firstTS, uint64_t offset)
 Print the transmission start time on the screen. More...
 
int main (int argc, const char *argv[])
 

Macros

#define OPTION_FILE   (1<<1)
 
#define OPTION_PORTOFFSET   (1<<2)
 
#define OPTION_GSYNC   (1<<3)
 
#define OPTION_START   (1<<4)
 
#define OPTION_TIMESTAMP   (1<<5)
 

Variables

static const char * usageText []
 
static char * opt_file = NULL
 
static int opt_portOffset = -1
 
static char * opt_start = NULL
 
static int opt_time = 0
 
static int appRunning =1
 
static const char * progname
 Program name for the program itself. More...
 
static uint32_t optionMask = 0
 
static uint64_t gsyncAdapterTS = 0
 The timestamp of the adapter. More...
 
static uint64_t gsyncFirstTS = 0
 The timestamp of the first packet in the file. More...
 
static uint64_t gsyncSyncTS = 0
 The timestamp of the oldset timestamp of all the files that it sent synchronized. More...
 
static uint64_t gsyncStartTime = 0
 The start time for the transmit to begin. More...
 
static uint64_t gsyncOffset = 0
 The calculated transmit delay. More...
 
static uint64_t gsyncMaxTS = 0
 The timestamp of the last packet in the file. Used to calculate when the transmit is finish. More...
 
static int gsyncAdapter = 0
 The adapter number for the adapter used to transmit the file. More...
 
struct argparse_option arg_options []
 

Function Documentation

static void StopApplication ( int sig   __attribute__(unused))
static

Definition at line 230 of file replayGS_example.c.

Referenced by main().

static void DisplayProgramHeader ( void  )
static

Definition at line 245 of file replayGS_example.c.

Referenced by main().

static void DisplayProgramFooter ( void  )
static

Definition at line 260 of file replayGS_example.c.

Referenced by main().

static void PrintTimeStamp ( uint64_t  ts)
static

Print a human readable time on the screen.

This function is called to print a human readable time on the screen. Mainly used to print the transmit start time.

Parameters
[in]tsThe timestamp to print
Return values
NT_SUCCESSFunction succeded
!=NT_SUCCESS Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 277 of file replayGS_example.c.

Referenced by printTransmissionStart().

static uint64_t CalcOffset ( uint64_t  ts_start,
uint64_t  ts1,
uint64_t  ts2 
)
static

Calculate the transmit offset.

This function is called to calculate the transmit offset. CalcOffset calculates the global offset to set on an adapter in global sync mode. The clocks of the adapters used must be synchronized. All time stamps supplieds as parameters must be in 10-ns ticks. The offset is calculated such that transmission starts on ts_start.

The adapter implements the following logic in GSYNC mode. Let Tp denote the time stamp of a packet, t the current (running) time, and offset the GSYNC offset in the adapter.

Tp > t + offset : wait, do not send the packet yet Tp <= t + offset : send the packet

Replay calculates gsyncOffset a little differently, namely as

t - Tp = gsyncOffset

and hence

Tp = -gsyncOffset + t

If we insert this last equation into the right-hand side of the expression used in the adapter (Tp = t + offset), we get

Tp = t + offset = -gsyncOffset + t

and therefore

offset = -gsyncOffset

ReplayGS therefore uses the negated value of gsyncOffset as the offset value on the adapter.

Parameters
[in]ts_startThe start time of the transmit
[in]ts1Timestamp 1 from either the local file or from a file sent from another server
[in]ts2Timestamp 2 from either the local file or from a file sent from another server
Return values
NT_SUCCESSFunction succeded
!=NT_SUCCESS Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 338 of file replayGS_example.c.

Referenced by main().

static uint32_t GetAdapterTimestamp ( int  adapterNo,
uint64_t *  ts 
)
static

Gets the timestamp from the adapter.

This function is called to get the adapter timestamp

Parameters
[in]adapterNoAdapter number to get timestamp from
[out]tsPointer to the timestamp
Return values
NT_SUCCESSFunction succeded
!=NT_SUCCESS Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 359 of file replayGS_example.c.

Referenced by main(), and printTransmissionStart().

static uint32_t SetGlobalSync ( int  adapterNo,
int  portMask,
uint64_t  offset 
)
static

Sets Global Sync.

This function is called to enable or disable global sync

Parameters
[in]adapterNoAdapter number to get timestamp from
[in]portMaskBitmask for ports to enable
[in]offsetGlobal sync offset
Return values
NT_SUCCESSFunction succeded
!=NT_SUCCESS Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 407 of file replayGS_example.c.

Referenced by main().

static int GetTimeStamp ( uint64_t *  ts)
static

Get the timestamp of the first packet in the file.

This function is called to get the timestamp of the first packet in the file

Parameters
[out]tsPointer to variable holding the timestamp
Return values
0Function succeded
1Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 457 of file replayGS_example.c.

Referenced by main().

static int ParseStartTime ( const char *  dts,
uint64_t *  ts 
)
static

Parse the start time.

This function is called to parse the start time entered as input option

Parameters
[in]dtsPointer to string containing the start time
[out]tsPointer to variable to hold the converted start time
Return values
0Function succeded
-1Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 507 of file replayGS_example.c.

Referenced by main().

static int printTransmissionStart ( int  adapter,
uint64_t  firstTS,
uint64_t  offset 
)
static

Print the transmission start time on the screen.

This function is called to print the transmission start time on the screen.

Parameters
[in]adapterAdapter number
[in]firstTSThe time stamp of the first packet in the file
[in]offsetThe calculated transmit offset
Return values
NT_SUCCESSFunction succeded
!=NT_SUCCESS Function failed
Examples:
net/replayGS/replayGS_example.c.

Definition at line 574 of file replayGS_example.c.

Referenced by main().

int main ( int  argc,
const char *  argv[] 
)

Definition at line 594 of file replayGS_example.c.

Macro Definition Documentation

#define OPTION_FILE   (1<<1)
Examples:
net/replayGS/replayGS_example.c.

Definition at line 202 of file replayGS_example.c.

Referenced by main().

#define OPTION_PORTOFFSET   (1<<2)
Examples:
net/replayGS/replayGS_example.c.

Definition at line 203 of file replayGS_example.c.

Referenced by main().

#define OPTION_GSYNC   (1<<3)
Examples:
net/replayGS/replayGS_example.c.

Definition at line 204 of file replayGS_example.c.

Referenced by main().

#define OPTION_START   (1<<4)
Examples:
net/replayGS/replayGS_example.c.

Definition at line 205 of file replayGS_example.c.

Referenced by main().

#define OPTION_TIMESTAMP   (1<<5)
Examples:
net/replayGS/replayGS_example.c.

Definition at line 206 of file replayGS_example.c.

Referenced by main().

Variable Documentation

const char* usageText[]
static
Initial value:
= {
"The replay example can replay a data file stored with the \"capture\" example.\n"
"The packets will be transmitted according to the TxPort field in the\n"
"packet descriptors. The TxPort field is relative to port0 on the adapter\n"
"provided the packets and therefore it is needed to select a port0 offset\n"
"via the option \"-p\".\n"
"The replay rate will be identical to the rate at which the packets were received.\n"
"\n"
"Syntax:\n"
"\n"
"replayGS -f <file> [-p <port offset>] [-g <timestamp>] [-s <starttime>] [-t] [--help] \n"
"\nCommands:\n",

Definition at line 167 of file replayGS_example.c.

Referenced by main().

char* opt_file = NULL
static
Examples:
net/replayGS/replayGS_example.c.

Definition at line 181 of file replayGS_example.c.

Referenced by GetTimeStamp(), and main().

int opt_portOffset = -1
static
Examples:
net/replayGS/replayGS_example.c.

Definition at line 182 of file replayGS_example.c.

Referenced by main().

char* opt_start = NULL
static
Examples:
net/replayGS/replayGS_example.c.

Definition at line 183 of file replayGS_example.c.

Referenced by main().

int opt_time = 0
static
Examples:
net/replayGS/replayGS_example.c.

Definition at line 184 of file replayGS_example.c.

Referenced by main().

int appRunning =1
static

Definition at line 186 of file replayGS_example.c.

Referenced by main(), and StopApplication().

const char* progname
static

Program name for the program itself.

Definition at line 187 of file replayGS_example.c.

Referenced by DisplayProgramHeader(), and main().

uint32_t optionMask = 0
static
Examples:
net/replayGS/replayGS_example.c.

Definition at line 189 of file replayGS_example.c.

Referenced by main().

uint64_t gsyncAdapterTS = 0
static

The timestamp of the adapter.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 191 of file replayGS_example.c.

Referenced by main().

uint64_t gsyncFirstTS = 0
static

The timestamp of the first packet in the file.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 192 of file replayGS_example.c.

Referenced by main().

uint64_t gsyncSyncTS = 0
static

The timestamp of the oldset timestamp of all the files that it sent synchronized.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 193 of file replayGS_example.c.

Referenced by main().

uint64_t gsyncStartTime = 0
static

The start time for the transmit to begin.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 194 of file replayGS_example.c.

Referenced by main().

uint64_t gsyncOffset = 0
static

The calculated transmit delay.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 195 of file replayGS_example.c.

Referenced by main().

uint64_t gsyncMaxTS = 0
static

The timestamp of the last packet in the file. Used to calculate when the transmit is finish.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 196 of file replayGS_example.c.

Referenced by main().

int gsyncAdapter = 0
static

The adapter number for the adapter used to transmit the file.

Examples:
net/replayGS/replayGS_example.c.

Definition at line 197 of file replayGS_example.c.

Referenced by main().

struct argparse_option arg_options[]
Initial value:
= {
OPT_STRING( 'f', "file", &opt_file, "Specifies the file to replay.", NULL, 0, 0, "file name"),
OPT_INTEGER('p', "port", &opt_portOffset, "Port offset to port0 on the adapter on which the data\n"
"should be replayed.", NULL, 0, 0, "offset"),
OPT_UINT64('g', NULL, &gsyncSyncTS, "Enable global synchronization mode.\n"
"Earliest 10-ns ticks time stamp to synchronize with", NULL, 0, 0, "timestamp"),
OPT_STRING('s', NULL, &opt_start, "Absolute transmission begin time stamp.\n"
"Format: YYYY/MM/DD-HH:MM:SS, HH:MM:SS or HH:MM", NULL, 0, 0, "starttime"),
OPT_BOOLEAN('t', NULL, &opt_time, "Find the first time stamp (in 10-ns ticks) in the capture file.", NULL, 0, 0, NULL),
}

Table of valid options.

Definition at line 211 of file replayGS_example.c.