bypass_info_example.c Source File

Reference Documentation

Platform
Intel® PAC
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.10
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 2023 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 "NP-0405 Napatech Software license
18  * agreement.pdf"
19  *
20  * 4. Redistributions of source code must retain this copyright notice,
21  * list of conditions and the following disclaimer.
22  *
23  * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTIES, EXPRESS OR
24  * IMPLIED, AND NAPATECH DISCLAIMS ALL IMPLIED WARRANTIES INCLUDING ANY
25  * IMPLIED WARRANTY OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, OR OF
26  * FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT NOT PROHIBITED BY
27  * APPLICABLE LAW, IN NO EVENT SHALL NAPATECH BE LIABLE FOR PERSONAL INJURY,
28  * OR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES WHATSOEVER,
29  * INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, CORRUPTION OR
30  * LOSS OF DATA, FAILURE TO TRANSMIT OR RECEIVE ANY DATA OR INFORMATION,
31  * BUSINESS INTERRUPTION OR ANY OTHER COMMERCIAL DAMAGES OR LOSSES, ARISING
32  * OUT OF OR RELATED TO YOUR USE OR INABILITY TO USE NAPATECH SOFTWARE OR
33  * SERVICES OR ANY THIRD PARTY SOFTWARE OR APPLICATIONS IN CONJUNCTION WITH
34  * THE NAPATECH SOFTWARE OR SERVICES, HOWEVER CAUSED, REGARDLESS OF THE THEORY
35  * OF LIABILITY (CONTRACT, TORT OR OTHERWISE) AND EVEN IF NAPATECH HAS BEEN
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME JURISDICTIONS DO NOT ALLOW
37  * THE EXCLUSION OR LIMITATION OF LIABILITY FOR PERSONAL INJURY, OR OF
38  * INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY TO YOU.
39  *
40  *
41 
42  */
43 /**
44  * @example bypass/info/bypass_info_example.c
45  * @section bypass_info_example_description Description
46  *
47  * This source file is an example of how to retrieve bypass port information using the @ref InfoStream
48  * "Info stream" interface in NTAPI.
49  * *
50  * The following NTAPI functions are used:
51  * - @ref NT_Init()
52  * - @ref NT_InfoOpen()
53  * - @ref NT_InfoRead()
54  * - @ref NT_InfoClose()
55  * - @ref NT_Done()
56  * - @ref NT_ExplainError()
57  *
58  * <hr>
59  * @section bypass_info_example_prerequisites Prerequisites
60  * A working system is needed with a Napatech accelerator - a Napatech bypass accelerator is preferred.
61  *
62  * @section bypass_info_example_flow Program flow
63  * @{
64  * The following is required to perform read operations on
65  * the @ref InfoStream "Info stream":
66  *
67  * - \#include/nt.h - Applications/Tools only need to include @ref
68  * nt.h to obtain prototypes, macros etc. from NTAPI.
69  * - @ref NT_Init(@ref NTAPI_VERSION) - Initialize the NTAPI
70  * library. @ref NTAPI_VERSION is a define that describes the version
71  * of the API described in the header files included by @ref
72  * nt.h. NT_Init() will ask the NTAPI library to convert return data
73  * to the @ref NTAPI_VERSION if possible. This will ensure that
74  * applications can run on NTAPI libraries of newer versions.
75  *
76  * - @ref NT_InfoOpen() - Open an info stream.
77  * - @ref NT_InfoRead() - Read info stream.
78  * - @ref NT_InfoClose() - Close the stream when terminating.
79  * - @ref NT_Done() - Close down the NTAPI library.
80  * - @ref NT_ExplainError() - Explain an error code returned by NTAPI functions.
81  *
82  *<hr>
83  * @}
84  */
85 
86 // Include this in order to access the Napatech API
87 #include <nt.h>
88 
89 #if defined(__linux__) || defined(__FreeBSD__)
90  #include <unistd.h>
91 #endif
92 
93 #include <stdlib.h>
94 #include <stdio.h>
95 #include <errno.h>
96 
97 
98 //
99 // main()
100 //
101 int main(void)
102 {
103  NtError_t status;
104  char errBuf[NT_ERRBUF_SIZE];
105  //
106  NtInfoStream_t hInfo;
107  //
108  NtInfo_t infoSystem;
109  NtInfo_t infoAdapter;
110  NtInfo_t infoPort;
111  //
112  unsigned int adapter;
113  unsigned int port;
114  //
115  const char* aBpWdt[] = {"Inactive", "Active"};
116  const char* aBpFlags[] = {"Off", "On"};
117  const char* aBpState[] = {"Unknown", "Normal", "Bypass"};
118  //
119  //
120  //
121 
122  // Initialize NTAPI library
123  if ((status = NT_Init(NTAPI_VERSION)) != NT_SUCCESS) {
124  NT_ExplainError(status, errBuf, sizeof(errBuf));
125  fprintf(stderr, "ERROR: NT_Init failed. Code 0x%x = %s\n", status, errBuf);
126  return status;
127  }
128 
129  // Open the information stream
130  if ((status = NT_InfoOpen(&hInfo, "bypass_info_example")) != NT_SUCCESS) {
131  NT_ExplainError(status, errBuf, sizeof(errBuf));
132  fprintf(stderr, ">>> Error: NT_InfoOpen failed. Code 0x%x = %s\n", status, errBuf);
133  return status;
134  }
135 
136  // Read system information
137  infoSystem.cmd = NT_INFO_CMD_READ_SYSTEM;
138  if ((status = NT_InfoRead(hInfo, &infoSystem)) != NT_SUCCESS) {
139  NT_ExplainError(status, errBuf, sizeof(errBuf));
140  fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
141  return status;
142  }
143 
144  printf("System: %d.%d.%d.%d\n\n", infoSystem.u.system.data.version.major,
145  infoSystem.u.system.data.version.minor,
146  infoSystem.u.system.data.version.patch,
147  infoSystem.u.system.data.version.tag);
148  printf("Adapters: %u\n", infoSystem.u.system.data.numAdapters);
149  printf("Ports: %u\n", infoSystem.u.system.data.numPorts);
150  printf("\n");
151 
152  for (adapter = 0; adapter < infoSystem.u.system.data.numAdapters; adapter++) {
153  infoAdapter.cmd = NT_INFO_CMD_READ_ADAPTER_V6;
154  infoAdapter.u.adapter_v6.adapterNo = (uint8_t)adapter;
155  if ((status = NT_InfoRead(hInfo, &infoAdapter)) != 0) {
156  NT_ExplainError(status, errBuf, sizeof(errBuf));
157  fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
158  return status;
159  }
160  printf("Adapter %u (%u ports):\n", infoAdapter.u.adapter_v6.adapterNo, infoAdapter.u.adapter_v6.data.numPorts);
161 
162  for (port = 0; port < infoAdapter.u.adapter_v6.data.numPorts; port++) {
163  infoPort.cmd = NT_INFO_CMD_READ_PORT_V9;
164  infoPort.u.port_v9.portNo = (uint8_t)(infoAdapter.u.adapter_v6.data.portOffset + port);
165  if ((status = NT_InfoRead(hInfo, &infoPort)) != 0) {
166  NT_ExplainError(status, errBuf, sizeof(errBuf));
167  fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
168  return status;
169  }
170 
171  printf("Port %u (adapter #%u port #%u):\n", infoPort.u.port_v9.portNo, infoPort.u.port_v9.data.adapterNo, port);
172 
174  printf(" Bypass port feature is present\n");
175  if ((status = NT_InfoRead(hInfo, &infoPort)) != 0) {
176  NT_ExplainError(status, errBuf, sizeof(errBuf));
177  fprintf(stderr, ">>> Error: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf);
178  return status;
179  }
180 
181  printf(" Bypass port belongs to adapter #%u portset #%u\n", infoPort.u.port_v9.data.adapterNo, infoPort.u.port_v9.data.bypass.bypassPortsetNo);
182  printf(" Bypass port is currently in %s state\n", aBpState[infoPort.u.port_v9.data.bypass.currentBypassPortState]);
183  printf(" Bypass port watchdog is %s\n", aBpWdt[(infoPort.u.port_v9.data.bypass.bypassPortWatchdogTimeout==0?0:1)]);
184  printf(" Bypass port onPowerFail detect trigger is %s\n", aBpFlags[((infoPort.u.port_v9.data.bypass.bypassTriggerModes & NT_BYPASS_TRIGGER_PWRFAIL)==0?0:1)]);
185  }
186  printf("\n");
187  }
188  printf("\n");
189  }
190 
191  printf("\n");
192 
193  // Close down the NTAPI library
194  NT_Done();
195 
196  return 0;
197 }
198 
199 //
200 // EOF
201 //