Napatech Software Suite: service/streams/path_delay.h Source File servicestreams path_delay.h Go to the documentation of this file. 1 /** 2 * 3 * Copyright 2025 Napatech A/S. All Rights Reserved. 4 * 5 * 1. Copying, modification, and distribution of this file, or executable 6 * versions of this file, is governed by the terms of the Napatech Software 7 * license agreement under which this file was made available. If you do not 8 * agree to the terms of the license do not install, copy, access or 9 * otherwise use this file. 10 * 11 * 2. Under the Napatech Software license agreement you are granted a 12 * limited, non-exclusive, non-assignable, copyright license to copy, modify 13 * and distribute this file in conjunction with Napatech SmartNIC's and 14 * similar hardware manufactured or supplied by Napatech A/S. 15 * 16 * 3. The full Napatech Software License Agreement is included in this 17 * distribution, please see "NA-0009 Software License Agreement.pdf" 18 * 19 * 4. Redistributions of source code must retain this copyright notice, 20 * list of conditions and the following disclaimer. 21 * 22 * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, EXPRESS OR 23 * IMPLIED, AND NAPATECH DISCLAIMS ALL IMPLIED WARRANTIES INCLUDING ANY 24 * IMPLIED WARRANTY OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, OR OF 25 * FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY 26 * APPLICABLE LAW, IN NO EVENT SHALL NAPATECH BE LIABLE FOR PERSONAL INJURY, 27 * OR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES WHATSOEVER, 28 * INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, CORRUPTION OR 29 * LOSS OF DATA, FAILURE TO TRANSMIT OR RECEIVE ANY DATA OR INFORMATION, 30 * BUSINESS INTERRUPTION OR ANY OTHER COMMERCIAL DAMAGES OR LOSSES, ARISING 31 * OUT OF OR RELATED TO YOUR USE OR INABILITY TO USE NAPATECH SOFTWARE OR 32 * SERVICES OR ANY THIRD PARTY SOFTWARE OR APPLICATIONS IN CONJUNCTION WITH 33 * THE NAPATECH SOFTWARE OR SERVICES, HOWEVER CAUSED, REGARDLESS OF THE THEORY 34 * OF LIABILITY (CONTRACT, TORT OR OTHERWISE) AND EVEN IF NAPATECH HAS BEEN 35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME JURISDICTIONS DO NOT ALLOW 36 * THE EXCLUSION OR LIMITATION OF LIABILITY FOR PERSONAL INJURY, OR OF 37 * INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY TO YOU. 38 * 39 * 40 41 */ 42 43 /** 44 * @file 45 */ 46 #ifndef _PATH_DELAY_H_ 47 #define _PATH_DELAY_H_ 48 49 /** @addtogroup MainDocMainFeaturesPathDelay 50 * @{ 51 @section path_delay_overview Overview 52 53 An adapter uses time stamps for time-stamping incoming packets, and 54 for sending packets at the correct time. When receiving a packet 55 there is a delay from the time that a packet (frame) arrives and until 56 the adapter time-stamps it. This delay is called the RX path delay. 57 When transmitting a packet there is a delay from the time that the 58 adapter releases a packet (frame) and until it is transmitted. This 59 delay is called the TX path delay. 60 61 An application can retrieve the path delay from the driver. 62 A path delay is an integer value in nanoseconds. The delay 63 information may not always be available, and an application must be 64 ready to handle that situation. 65 66 When delay information is available, the application can subtract the 67 RX path delay from the time stamp in a packet descriptor to calculate 68 when an incoming packet (frame) arrived at the port. When using 69 global sync mode, the application can adjust for the TX path delay 70 when calculating the value of the single TX clock origin. 71 72 To use the feature properly, an application must query the delay when 73 the link speed changes, or a NIM module is inserted. The system 74 provides suitable <em>events</em> for this purpose, 75 see @ref sec_link_speed_nim_module_update. 76 77 78 @section path_delay_api API 79 80 An application can use the information stream to retrieve the path 81 delays for a port. 82 83 - The information stream provides access to path delays. An 84 application must use the @ref NtInfo_t structure and set the 85 <tt>cmd</tt> member to @ref NT_INFO_CMD_READ_PATH_DELAY command and 86 the @ref NtInfoCmdPortPathDelay_s command structure to retrieve the 87 path delay for a port. The application should set the 88 <tt>direction</tt> member to NT_PATH_DELAY_RX_DIR or 89 NT_PATH_DELAY_TX_DIR to retrieve the RX and TX path delays, 90 respectively. Section @ref sec_example_program contains a simple 91 example program that retrieves the RX and TX delays for port number 92 zero. 93 94 - RX and TX path delays are kept separate in the API. This means that 95 an application cannot retrieve both types of delays for a given port 96 at the same time. 97 98 - The API returns a delay value and a status code via the @ref 99 NtInfoPortPathDelay_s structure. The member <tt>status</tt> 100 provides the status code, and the <tt>member</tt> is the returned 101 delay. The status code is an enumeration @ref NtPathDelayStatus_e 102 that indicates whether the delay value is valid. The returned value 103 is an integer, which is the path delay in nanoseconds. 104 105 - The returned delay is a single value that is the sum of the adapter 106 and the NIM module contributions, or in some cases only the adapter 107 delay without the NIM module delay. An application must use the 108 status code to interpret the delay value correctly. Section @ref 109 sec_status_codes describes the meaning of the return codes. 110 111 - Status code NT_PATH_DELAY_SUCCESS means the link is up, and the 112 driver has recognized the adapter/FPGA and the installed NIM 113 modules. The returned delay value is the sum of the adapter and NIM 114 module delays. 115 116 - Status codes NT_PATH_DELAY_LINK_DOWN and NT_PATH_DELAY_NOT_SUPPORTED 117 mean the delay value is unavailable. If the staus code is 118 NT_PATH_DELAY_LINK_DOWN, an application may try to retrieve the 119 delay value later, or it can catch the NT_EVENT_PORT_LINK_UP event. 120 121 - Status code NT_PATH_DELAY_UNKNOWN_NIM means the link is up, and the 122 driver has recognized the adapter/FPGA but not the NIM module. The 123 returned delay value is without the NIM module delay. 124 125 @note Observe the @ref path_delay_limitations "limitations" in the 126 current implementation. 127 128 @subsection sec_status_codes Path Delay Status Codes 129 130 The status code is the <tt>status</tt> member of the @ref 131 NtInfoPortPathDelay_s structure. 132 133 <table width="100%" border="1" cellspacing="0" cellpadding="1"> 134 <caption align="top">Path Delay Status Codes</caption> 135 <tr> 136 <td width="15%" align="center" style='background:#BFBFBF'>@b Code</td> 137 <td align="center" style='background:#BFBFBF'>@b Meaning</td> 138 </tr> 139 <tr> 140 <td>NT_PATH_DELAY_LINK_DOWN</td> 141 <td>Link is down, no delay to return, 142 not even if the NIM module is optical.</td> 143 </tr> 144 <tr> 145 <td>NT_PATH_DELAY_NOT_SUPPORTED</td> 146 <td>No delay available for the FPGA version. 147 It is undefined whether the NIM module is known.</td> 148 </tr> 149 <tr> 150 <td>NT_PATH_DELAY_SUCCESS</td> 151 <td>Link is up and FPGA and NIM modules are known.</td> 152 </tr> 153 <tr> 154 <td>NT_PATH_DELAY_UNKNOWN_NIM</td> 155 <td>NIM is unknown but the FPGA version is known. 156 The returned delay does not contain any contribution 157 from the NIM module.</td> 158 </tr> 159 </table> 160 161 @subsection sec_link_speed_nim_module_update Detecting Link Speed Change or New NIM Module 162 163 The path delay depends on the link speed and NIM module type, and an 164 application must retrieve the delay whenever the link speed changes, 165 or the NIM module is replaced. This is also true if the same NIM is 166 removed and reinserted. 167 168 An application can catch the NT_EVENT_PORT_NIM_REMOVED and 169 NT_EVENT_PORT_NIM_INSERTED events to detect replacement of a NIM 170 module, but although a NIM is a requisite for a network link, it 171 is not until the link is up, and the link speed is set, that the 172 correct path delay is available. Remember that the path delay depends 173 on the NIM module type and link speed. An application can, and 174 <em>must</em>, detect whenever a link goes down, and when the link is 175 up again; the application must retrieve the path delay (again). An 176 application can detect a change of the link speed indirectly by 177 catching the events NT_EVENT_PORT_LINK_DOWN and NT_EVENT_PORT_LINK_UP, 178 and retrieve the path delay when the link is up again. 179 180 Note that the solution does not provide a way for an application to 181 identify the first network packet that pertains to a new link speed. 182 An application must implement logic for that purpose itself. Since 183 the solution requires a link is up for the delay to be available, 184 there is a small time period following a link down event, where 185 packets may arrive without the application knowing the correct 186 (receive) delay; the application can either disregard the delay or 187 postpone processing of the packets until the delay has been retrieved. 188 189 @note A user may consider disabling auto negotiation to avoid 190 externally imposed link speed changes, however even with auto 191 negotiation @e enabled, a link will go down and come back up when the 192 speed changes, which gives an application the possibility to detect 193 the change. 194 195 196 @section path_delay_limitations Limitations 197 198 The version number mentioned in this section can be found by running 199 the <tt>adapterinfo</tt> command. The version number is the third 200 number series in the line that begins with <tt>FPGA ID</tt>. The 201 following command line gives an example that illustrates a version 202 number of 47. 203 204 @verbatim 205 # /opt/napatech3/bin/adapterinfo | grep "^FPGA " 206 FPGA ID: 200-9220-47-01-00 207 @endverbatim 208 209 The current implementation has the following limitation: 210 211 - GEN1 capture adapters are not supported. The system returns 212 NT_PATH_DELAY_NOT_SUPPORTED for GEN1 capture adapters. 213 214 215 @section sec_example_program Example Program 216 217 @code 218 // Save in get_path_delay.c and build with 219 // cc -I/opt/napatech3/include -L/opt/napatech3/lib -lntapi \ 220 // -g -o get_path_delay get_path_delay.c 221 222 #include "nt.h" 223 #include <stdio.h> 224 #include <assert.h> 225 226 static NtInfoStream_t hInfo = NULL; 227 228 static const char *status2text(enum NtPathDelayStatus_e status) 229 { 230 switch (status) { 231 case NT_PATH_DELAY_SUCCESS: 232 return "SUCCESS"; 233 case NT_PATH_DELAY_NOT_SUPPORTED: 234 return "NOT_SUPPORTED"; 235 case NT_PATH_DELAY_LINK_DOWN: 236 return "LINK_DOWN"; 237 case NT_PATH_DELAY_UNKNOWN_NIM: 238 return "UNKNOWN_NIM"; 239 default: 240 assert(0); 241 } 242 } 243 244 int main() 245 { 246 const uint8_t logicalPortNo = 0; 247 NtInfo_t info; 248 char errBuf[1024]; 249 int status; 250 251 // Initialize NTAPI 252 if ((status = NT_Init(NTAPI_VERSION)) != NT_SUCCESS) { 253 NT_ExplainError(status, errBuf, sizeof(errBuf)); 254 fprintf(stderr, ">>> Error: NT_Init failed. Code 0x%x = %s\n", 255 status, errBuf); 256 return 1; 257 } 258 259 // Open information stream 260 if ((status = NT_InfoOpen(&hInfo, "CONFIG")) != NT_SUCCESS) { 261 NT_ExplainError(status, errBuf, sizeof(errBuf)); 262 fprintf(stderr, ">>> Error: NT_InfoOpen failed. Code 0x%x = %s\n", 263 status, errBuf); 264 return 1; 265 } 266 267 // Read RX path delay for port `logicalPortNo' 268 info.cmd = NT_INFO_CMD_READ_PATH_DELAY; 269 info.u.pathDelay.portNo = logicalPortNo; 270 info.u.pathDelay.direction = NT_PATH_DELAY_RX_DIR; 271 272 if ((status = NT_InfoRead(hInfo, &info)) != NT_SUCCESS) { 273 NT_ExplainError(status, errBuf, sizeof(errBuf)); 274 fprintf(stderr, ">>> Error: NT_InfoRead failed. Code 0x%x = %s\n", 275 status, errBuf); 276 return 1; 277 } 278 279 (void)printf("RX port path delay for port %u: status = %s; delay = %d\n", 280 info.u.pathDelay.portNo, 281 status2text(info.u.pathDelay.data.status), 282 info.u.pathDelay.data.delay); 283 284 // Read TX path delay for port `logicalPortNo' 285 info.u.pathDelay.direction = NT_PATH_DELAY_TX_DIR; 286 if ((status = NT_InfoRead(hInfo, &info)) != NT_SUCCESS) { 287 NT_ExplainError(status, errBuf, sizeof(errBuf)); 288 fprintf(stderr, ">>> Error: NT_InfoRead failed. Code 0x%x = %s\n", 289 status, errBuf); 290 return 1; 291 } 292 (void)printf("TX port path delay for port %u: status = %s; delay = %d\n", 293 info.u.pathDelay.portNo, 294 status2text(info.u.pathDelay.data.status), 295 info.u.pathDelay.data.delay); 296 return 0; 297 } 298 @endcode 299 300 *@} 301 **/ 302 303 #include "nt.h" /* Cannot include stream_info.h directly */ 304 int getPathDelay(NtInfo_t *); 305 306 #endif DN-0449 Napatech Software Suite Reference Documentation (v. 3.29.38.15-72ea8b4e)Copyright © 2025 Napatech A/S