bypass_info_example.c Source File

Reference Documentation

Platform
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.15
Napatech Software Suite: examples/bypass/info/bypass_info_example.c Source File
bypass_info_example.c
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  * @example bypass/info/bypass_info_example.c
44  * @section bypass_info_example_description Description
45  *
46  * This source file is an example of how to retrieve bypass port information using the @ref InfoStream
47  * "Info stream" interface in NTAPI.
48  * *
49  * The following NTAPI functions are used:
50  * - @ref NT_Init()
51  * - @ref NT_InfoOpen()
52  * - @ref NT_InfoRead()
53  * - @ref NT_InfoClose()
54  * - @ref NT_Done()
55  * - @ref NT_ExplainError()
56  *
57  * <hr>
58  * @section bypass_info_example_prerequisites Prerequisites
59  * A working system is needed with a Napatech accelerator - a Napatech bypass accelerator is preferred.
60  *
61  * @section bypass_info_example_flow Program flow
62  * @{
63  * The following is required to perform read operations on
64  * the @ref InfoStream "Info stream":
65  *
66  * - \#include/nt.h - Applications/Tools only need to include @ref
67  * nt.h to obtain prototypes, macros etc. from NTAPI.
68  * - @ref NT_Init(@ref NTAPI_VERSION) - Initialize the NTAPI
69  * library. @ref NTAPI_VERSION is a define that describes the version
70  * of the API described in the header files included by @ref
71  * nt.h. NT_Init() will ask the NTAPI library to convert return data
72  * to the @ref NTAPI_VERSION if possible. This will ensure that
73  * applications can run on NTAPI libraries of newer versions.
74  *
75  * - @ref NT_InfoOpen() - Open an info stream.
76  * - @ref NT_InfoRead() - Read info stream.
77  * - @ref NT_InfoClose() - Close the stream when terminating.
78  * - @ref NT_Done() - Close down the NTAPI library.
79  * - @ref NT_ExplainError() - Explain an error code returned by NTAPI functions.
80  *
81  *<hr>
82  * @}
83  */
84 
85 // Include this in order to access the Napatech API
86 #include <nt.h>
87 
88 #if defined(__linux__) || defined(__FreeBSD__)
89  #include <unistd.h>
90 #endif
91 
92 #include <stdlib.h>
93 #include <stdio.h>
94 #include <errno.h>
95 
96 
97 //
98 // main()
99 //
100 int main(void)
101 {
102  NtError_t status;
103  char errBuf[NT_ERRBUF_SIZE];
104  //
105  NtInfoStream_t hInfo;
106  //
107  NtInfo_t infoSystem;
108  NtInfo_t infoAdapter;
109  NtInfo_t infoPort;
110  //
111  unsigned int adapter;
112  unsigned int port;
113  //
114  const char* aBpWdt[] = {"Inactive", "Active"};
115  const char* aBpFlags[] = {"Off", "On"};
116  const char* aBpState[] = {"Unknown", "Normal", "Bypass"};
117  //
118  //
119  //
120 
121  // Initialize NTAPI library
122  if ((status = NT_Init(NTAPI_VERSION)) != NT_SUCCESS) {
123  NT_ExplainError(status, errBuf, sizeof(errBuf));
124  fprintf(stderr, "ERROR: NT_Init failed. Code 0x%x = %s\n", status, errBuf);
125  return status;
126  }
127 
128  // Open the information stream
129  if ((status = NT_InfoOpen(&hInfo, "bypass_info_example")) != NT_SUCCESS) {
130  NT_ExplainError(status, errBuf, sizeof(errBuf));
131  fprintf(stderr, ">>> Error: NT_InfoOpen failed. Code 0x%x = %s\n", status, errBuf);
132  return status;
133  }
134 
135  // Read system information
136  infoSystem.cmd = NT_INFO_CMD_READ_SYSTEM;
137  if ((status = NT_InfoRead(hInfo, &infoSystem)) != NT_SUCCESS) {
138  NT_ExplainError(status, errBuf, sizeof(errBuf));
139  fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
140  return status;
141  }
142 
143  printf("System: %d.%d.%d.%d\n\n", infoSystem.u.system.data.version.major,
144  infoSystem.u.system.data.version.minor,
145  infoSystem.u.system.data.version.patch,
146  infoSystem.u.system.data.version.tag);
147  printf("Adapters: %u\n", infoSystem.u.system.data.numAdapters);
148  printf("Ports: %u\n", infoSystem.u.system.data.numPorts);
149  printf("\n");
150 
151  for (adapter = 0; adapter < infoSystem.u.system.data.numAdapters; adapter++) {
152  infoAdapter.cmd = NT_INFO_CMD_READ_ADAPTER_V7;
153  infoAdapter.u.adapter_v7.adapterNo = (uint8_t)adapter;
154  if ((status = NT_InfoRead(hInfo, &infoAdapter)) != 0) {
155  NT_ExplainError(status, errBuf, sizeof(errBuf));
156  fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
157  return status;
158  }
159  printf("Adapter %u (%u ports):\n", infoAdapter.u.adapter_v7.adapterNo, infoAdapter.u.adapter_v7.data.numPorts);
160 
161  for (port = 0; port < infoAdapter.u.adapter_v7.data.numPorts; port++) {
162  infoPort.cmd = NT_INFO_CMD_READ_PORT_V10;
163  infoPort.u.port_v10.portNo = (uint8_t)(infoAdapter.u.adapter_v7.data.portOffset + port);
164  if ((status = NT_InfoRead(hInfo, &infoPort)) != 0) {
165  NT_ExplainError(status, errBuf, sizeof(errBuf));
166  fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
167  return status;
168  }
169 
170  printf("Port %u (adapter #%u port #%u):\n", infoPort.u.port_v10.portNo, infoPort.u.port_v10.data.adapterNo, port);
171 
173  printf(" Bypass port feature is present\n");
174  if ((status = NT_InfoRead(hInfo, &infoPort)) != 0) {
175  NT_ExplainError(status, errBuf, sizeof(errBuf));
176  fprintf(stderr, ">>> Error: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
177  return status;
178  }
179 
180  printf(" Bypass port belongs to adapter #%u portset #%u\n", infoPort.u.port_v10.data.adapterNo, infoPort.u.port_v10.data.bypass.bypassPortsetNo);
181  printf(" Bypass port is currently in %s state\n", aBpState[infoPort.u.port_v10.data.bypass.currentBypassPortState]);
182  printf(" Bypass port watchdog is %s\n", aBpWdt[(infoPort.u.port_v10.data.bypass.bypassPortWatchdogTimeout==0?0:1)]);
183  printf(" Bypass port onPowerFail detect trigger is %s\n", aBpFlags[((infoPort.u.port_v10.data.bypass.bypassTriggerModes & NT_BYPASS_TRIGGER_PWRFAIL)==0?0:1)]);
184  }
185  printf("\n");
186  }
187  printf("\n");
188  }
189 
190  printf("\n");
191 
192  // Close down the NTAPI library
193  NT_Done();
194 
195  return 0;
196 }
197 
198 //
199 // EOF
200 //