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