bypass_info_example.c

Reference Documentation

product_line_custom
Napatech SmartNIC
category
Reference Information

Go to the documentation of this file.

1/* 2 * %NT_SOFTWARE_LICENSE% 3 */ 4/** 5 * @example bypass/info/bypass_info_example.c 6 * @section bypass_info_example_description Description 7 * 8 * This source file is an example of how to retrieve bypass port information using the @ref InfoStream 9 * "Info stream" interface in NTAPI. 10 * * 11 * The following NTAPI functions are used: 12 * - @ref NT_Init() 13 * - @ref NT_InfoOpen() 14 * - @ref NT_InfoRead() 15 * - @ref NT_InfoClose() 16 * - @ref NT_Done() 17 * - @ref NT_ExplainError() 18 * 19 * <hr> 20 * @section bypass_info_example_prerequisites Prerequisites 21 * A working system is needed with a Napatech accelerator - a Napatech bypass accelerator is preferred. 22 * 23 * @section bypass_info_example_flow Program flow 24 * @{ 25 * The following is required to perform read operations on 26 * the @ref InfoStream "Info stream": 27 * 28 * - \#include/nt.h - Applications/Tools only need to include @ref 29 * nt.h to obtain prototypes, macros etc. from NTAPI. 30 * - @ref NT_Init(@ref NTAPI_VERSION) - Initialize the NTAPI 31 * library. @ref NTAPI_VERSION is a define that describes the version 32 * of the API described in the header files included by @ref 33 * nt.h. NT_Init() will ask the NTAPI library to convert return data 34 * to the @ref NTAPI_VERSION if possible. This will ensure that 35 * applications can run on NTAPI libraries of newer versions. 36 * 37 * - @ref NT_InfoOpen() - Open an info stream. 38 * - @ref NT_InfoRead() - Read info stream. 39 * - @ref NT_InfoClose() - Close the stream when terminating. 40 * - @ref NT_Done() - Close down the NTAPI library. 41 * - @ref NT_ExplainError() - Explain an error code returned by NTAPI functions. 42 * 43 *<hr> 44 * @} 45 */ 46 47 48// std includes 49 50#if defined(__linux__) || defined(__FreeBSD__) 51 #include <unistd.h> 52#endif 53 54#include <stdlib.h> 55#include <stdio.h> 56#include <errno.h> 57 58// NT includes 59#include "nt.h" 60 61 62// 63// main() 64// 65int main(void) 66{ 67 uint32_t status; 68 char errBuf[NT_ERRBUF_SIZE]; 69 // 70 NtInfoStream_t hInfo; 71 // 72 NtInfo_t infoSystem; 73 NtInfo_t infoAdapter; 74 NtInfo_t infoPort; 75 // 76 unsigned int adapter; 77 unsigned int port; 78 // 79 const char* aBpWdt[] = {"Inactive", "Active"}; 80 const char* aBpFlags[] = {"Off", "On"}; 81 const char* aBpState[] = {"Unknown", "Normal", "Bypass"}; 82 // 83 // 84 // 85 86 // Initialize NTAPI library 87 if ((status = NT_Init(NTAPI_VERSION)) != NT_SUCCESS) { 88 NT_ExplainError(status, errBuf, sizeof(errBuf)); 89 fprintf(stderr, "ERROR: NT_Init failed. Code 0x%x = %s\n", status, errBuf); 90 return status; 91 } 92 93 // Open the information stream 94 if ((status = NT_InfoOpen(&hInfo, "bypass_info_example")) != NT_SUCCESS) { 95 NT_ExplainError(status, errBuf, sizeof(errBuf)); 96 fprintf(stderr, ">>> Error: NT_InfoOpen failed. Code 0x%x = %s\n", status, errBuf); 97 return status; 98 } 99 100 // Read system information 101 infoSystem.cmd = NT_INFO_CMD_READ_SYSTEM; 102 if ((status = NT_InfoRead(hInfo, &infoSystem)) != NT_SUCCESS) { 103 NT_ExplainError(status, errBuf, sizeof(errBuf)); 104 fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf); 105 return status; 106 } 107 108 printf("System: %d.%d.%d.%d\n\n", infoSystem.u.system.data.version.major, 109 infoSystem.u.system.data.version.minor, 110 infoSystem.u.system.data.version.patch, 111 infoSystem.u.system.data.version.tag); 112 printf("Adapters: %u\n", infoSystem.u.system.data.numAdapters); 113 printf("Ports: %u\n", infoSystem.u.system.data.numPorts); 114 printf("\n"); 115 116 for (adapter = 0; adapter < infoSystem.u.system.data.numAdapters; adapter++) { 117 infoAdapter.cmd = NT_INFO_CMD_READ_ADAPTER_V6; 118 infoAdapter.u.adapter_v6.adapterNo = (uint8_t)adapter; 119 if ((status = NT_InfoRead(hInfo, &infoAdapter)) != 0) { 120 NT_ExplainError(status, errBuf, sizeof(errBuf)); 121 fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf); 122 return status; 123 } 124 printf("Adapter %u (%u ports):\n", infoAdapter.u.adapter_v6.adapterNo, infoAdapter.u.adapter_v6.data.numPorts); 125 126 for (port = 0; port < infoAdapter.u.adapter_v6.data.numPorts; port++) { 127 infoPort.cmd = NT_INFO_CMD_READ_PORT_V9; 128 infoPort.u.port_v9.portNo = (uint8_t)(infoAdapter.u.adapter_v6.data.portOffset + port); 129 if ((status = NT_InfoRead(hInfo, &infoPort)) != 0) { 130 NT_ExplainError(status, errBuf, sizeof(errBuf)); 131 fprintf(stderr, "ERROR: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf); 132 return status; 133 } 134 135 printf("Port %u (adapter #%u port #%u):\n", infoPort.u.port_v9.portNo, infoPort.u.port_v9.data.adapterNo, port); 136 137 if ( infoPort.u.port_v9.data.capabilities.featureMask & NT_PORT_FEATURE_BYPASS) { 138 printf(" Bypass port feature is present\n"); 139 if ((status = NT_InfoRead(hInfo, &infoPort)) != 0) { 140 NT_ExplainError(status, errBuf, sizeof(errBuf)); 141 fprintf(stderr, ">>> Error: NT_InfoRead failed. Code 0x%x = %s\n", status, errBuf); 142 return status; 143 } 144 145 printf(" Bypass port belongs to adapter #%u portset #%u\n", infoPort.u.port_v9.data.adapterNo, infoPort.u.port_v9.data.bypass.bypassPortsetNo); 146 printf(" Bypass port is currently in %s state\n", aBpState[infoPort.u.port_v9.data.bypass.currentBypassPortState]); 147 printf(" Bypass port watchdog is %s\n", aBpWdt[(infoPort.u.port_v9.data.bypass.bypassPortWatchdogTimeout==0?0:1)]); 148 printf(" Bypass port onPowerFail detect trigger is %s\n", aBpFlags[((infoPort.u.port_v9.data.bypass.bypassTriggerModes & NT_BYPASS_TRIGGER_PWRFAIL)==0?0:1)]); 149 } 150 printf("\n"); 151 } 152 printf("\n"); 153 } 154 155 printf("\n"); 156 157 // Close down the NTAPI library 158 NT_Done(); 159 160 return 0; 161} 162 163// 164// EOF 165//