flowmatch_example_helper.cpp Source File

Reference Documentation

Platform
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.15
Napatech Software Suite: examples/flowmatch/flowmatch_example_helper.cpp Source File
flowmatch_example_helper.cpp
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 // Include this in order to access the Napatech API
44 #include <nt.h>
45 
46 #include <atomic>
47 #include <cstdlib>
48 #include <cstring>
49 #include <iostream>
50 
52 
53 namespace {
54 
55 std::atomic<bool> ApplicationRunning { true };
56 
57 } // Unnamed namespace
58 
60 {
61  return ApplicationRunning;
62 }
63 
64 void applicationStop(void)
65 {
66  ApplicationRunning = false;
67 }
68 
69 void handleErrorStatus(int status, const char* message)
70 {
71  if (status != NT_SUCCESS) {
72  char errorBuffer[NT_ERRBUF_SIZE];
73  NT_ExplainError(status, errorBuffer, sizeof(errorBuffer));
74  std::cerr << message << ": " << errorBuffer << std::endl;
75  std::exit(EXIT_FAILURE);
76  }
77 }
78 
79 void setHostLoopback(uint8_t port, bool enable)
80 {
81  int status;
82  NtConfig_t configRead;
83  NtConfig_t configWrite;
84  NtConfigStream_t hCfgStream;
85 
86  std::memset(&configRead, 0x0, sizeof(NtConfig_t));
87  std::memset(&configWrite, 0x0, sizeof(NtConfig_t));
88 
89  status = NT_ConfigOpen(&hCfgStream, "Learn_example_config_loopback");
90  handleErrorStatus(status, "NT_ConfigOpen() failed");
91 
93  configRead.u.portSettings_v2.portNo = port;
94 
95  status = NT_ConfigRead(hCfgStream, &configRead);
96  handleErrorStatus(status, "NT_ConfigRead() failed");
97 
99  configWrite.u.portSettings_v2.portNo = port;
100  configWrite.u.portSettings_v2.data = configRead.u.portSettings_v2.data;
101  configWrite.u.portSettings_v2.data.hostLoopback =
103 
104  status = NT_ConfigWrite(hCfgStream, &configWrite);
105  handleErrorStatus(status, "NT_ConfigWrite() failed");
106 
107  status = NT_ConfigClose(hCfgStream);
108  handleErrorStatus(status, "NT_ConfigClose() failed");
109 }