Example

Napatech Link-Capture™ Software Features

Platform
Intel® PAC
Napatech SmartNIC
Content Type
Feature Description
Capture Software Version
Link™ Capture Software 12.10

A short code example demonstrates how to calculate and configure the offset for transmit on time stamp.

TX configuration code example

This TX configuration code example is an excerpt from the file replay4ga_example.c, which is included in the product release package.

uint32_t status;
NtNetStreamFile_t hNetFile;     // Handle to the File stream
NtNetBuf_t hNetBufFile;         // Net buffer container. Used to return segments from the file stream
NtConfigStream_t hStream;       // Config stream handle
NtConfig_t configRead;          // Config stream data container
NtConfig_t configWrite;         // Config stream data container
struct NtNetBuf_s pktNetBuf;    // Packet netbuf structure.
uint8_t adapterNo ;             // Adapter no
uint64_t firstPacketTS=0;       // Timestamp of first packet
uint64_t adapterTS=0;           // Timestamp on the adapter
uint64_t timeDelta=0;           // Calculated time delta

// default setup
#define PORT        0

. . .

// Open the capture file to replay (captured with the capture example)
if((status = NT_NetFileOpen(&hNetFile, "FileStream", NT_NET_INTERFACE_SEGMENT, "capfile.ntcap")) != NT_SUCCESS) {
  // Error handling
}

// Read one segment from the file to get the first packet timestamp
if ((status = NT_NetFileGet(hNetFile, &hNetBufFile)) != NT_SUCCESS) {
  // Error handling
}
_nt_net_build_pkt_netbuf(hNetBufFile, &pktNetBuf);
firstPacketTS = NT_NET_GET_PKT_TIMESTAMP(&pktNetBuf) * 10; // Convert 10ns ticks to 1ns

// Close the file again. We will open it again later to actually transmit packets.
NT_NetFileClose(hNetFile);

// Open the config stream
if((status = NT_ConfigOpen(&hStream, "Replay")) != NT_SUCCESS) {
  // Error handling
}

. . .

// Read the adapter time
configRead.parm = NT_CONFIG_PARM_ADAPTER_TIMESTAMP;
configRead.u.timestampRead.adapter = adapterNo;
if ((status = NT_ConfigRead(hConfig, &configRead)) != NT_SUCCESS) {
  // Error handling
}
adapterTS = configRead.u.timestampRead.data.nativeUnixTs * 10; // Convert 10ns ticks to 1ns

// Calculate time delta - we add 1 second to give ourselves some headroom
timeDelta = (adapterTS - firstPacketTS) + 1000000000;

// Configure transmit on timestamp
configWrite.parm = NT_CONFIG_PARM_PORT_TRANSMIT_ON_TIMESTAMP;
configWrite.u.transmitOnTimestamp.portNo = (uint8_t) PORT;     // the TX port to configure
configWrite.u.transmitOnTimestamp.data.timeDelta = timeDelta;  // calculated offset in ns 
configWrite.u.transmitOnTimestamp.data.enable = true;          // enable transmit on time stamp
configWrite.u.transmitOnTimestamp.data.forceTxOnTs = true;     // ignore TxNow

if((status = NT_ConfigWrite(hStream, &configWrite)) != NT_SUCCESS) {
  // Error handling
}

. . .