stream_flow.h Source File

Reference Documentation

Platform
Intel® PAC
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.10
Napatech Software Suite: include/ntapi/stream_flow.h Source File
stream_flow.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2023 Napatech A/S.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Napatech A/S nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NAPATECH A/S BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *
29 
30  */
31 
32 /**
33  * @file
34  *
35  * This is header file of the flow stream interface
36  */
37 #ifndef __STREAM_FLOW_H__
38 #define __STREAM_FLOW_H__
39 
40 #if !defined(__NT_H__)
41  #error: My interface file is 'nt.h'. Please include that via #include "nt.h" directly.
42 #endif
43 
44 /** @addtogroup FlowStream
45  * @{
46  * Flow streams are used to program and delete flows as well as receiving flow status
47  * and information records on adapters that support stateful flow tracking.
48  *
49  * A flow stream must be opened before flows can be programmed. This is accomplished
50  * with the @ref NT_FlowOpen_Attr functions which takes a NtFlowAttr_t attribute
51  * structure and returns a handle to the flow stream.
52  *
53  * Three types of records can be present in a flow stream:
54  *
55  * @ref NtFlow_t records for flow programming using @ref NT_FlowWrite
56  *
57  * @ref NtFlowInfo_t records with flow information read using @ref NT_FlowRead. These
58  * records are only generated if flow programming sets the gfi bit.
59  *
60  * @ref NtFlowStatus_t records with async flow programming result read using @ref NT_FlowStatusRead.
61  * Generation of these records depends on ntservice.ini settings.
62  *
63  * To ensure optimal performance an application that both wishes to read and write flows
64  * should alternate between @ref NT_FlowWrite, @ref NT_FlowRead and @ref NT_FlowStatusRead.
65  */
66 
67 
68 /**
69  * Flow stream handle
70  */
71 typedef struct NtFlowStream_s* NtFlowStream_t;
72 
73 /** \cond */
74 #define __SIZEOF_NT_FLOW_ATTR 128
75 union __nt_flow_attr {
76  char __size[__SIZEOF_NT_FLOW_ATTR];
77  long int __align;
78 };
79 typedef union __nt_flow_attr NtFlowAttr_t;
80 /** \endcond */
81 
82 /**
83  * @brief Flow programming structure
84  *
85  * This structure is used when programming flows with the @ref NT_FlowWrite
86  * function.
87  */
88 typedef struct NtFlow_s {
89  uint8_t keyData[40]; /*!< Raw key data array as defined by the NTPL KeyDef command */
90  uint64_t id; /*!< 64-bit user defined ID */
91  uint32_t color; /*!< 32-bit flow color */
92  uint8_t overwrite:1; /*!< Enable overwrite filter action */
93  uint8_t streamId:7; /*!< Marks the stream id if overwrite filter action is enabled.
94  Unused if overwrite is not enabled */
95  uint8_t ipProtocolField; /*!< Next-protocol field from the IP header. Can be extracted from
96  outer or inner IP header or not at all
97  (see @ref NtplKeyType "KeyType NTPL Command") */
98  uint8_t keyId; /*!< Key ID as used in the @ref NtplKeyType "KeyType NTPL Command" */
99  uint8_t keySetId; /*!< Ket Set id as used in the NTPL filter */
100  uint8_t op:4; /*!< Flow programming operation (1: learn, 0: un-learn) */
101  uint8_t gfi:1; /*!< Generate flow info record (1: generate, 0: do not generate) */
102  uint8_t tau:1; /*!< TCP auto unlearn (1: auto unlearn enable, 0: auto unlearn disable) */
103 } NtFlow_t;
104 
105 /**
106  * @brief Flow information structure
107  *
108  * This structure contains state for a particular flow. If flow programming
109  * had the gfi bit set, the flow information structure is
110  * returned on the flow stream when the flow is terminated or timed out.
111  */
112 typedef struct NtFlowInfo_s {
113  uint64_t packetsA; /*!< Packet counter for set A */
114  uint64_t octetsA; /*!< Byte/octet counter for set A */
115  uint64_t packetsB; /*!< Packet counter for set B */
116  uint64_t octetsB; /*!< Byte/octet counter for set B */
117  uint64_t ts; /*!< Time stamp in UNIX_NS format of last seen packet */
118  uint64_t id; /*!< The 64-bit user defined ID from the flow programming operation */
119  uint16_t flagsA; /*!< Bitwise OR of TCP flags for packets in set A */
120  uint16_t flagsB; /*!< Bitwise OR of TCP flags for packets in set B */
121  uint8_t cause; /*!< Unlearn cause (0: Software, 1: Timeout, 2: TCP flow termination */
122 } NtFlowInfo_t;
123 
124 
125 #define NT_FLOW_STAT_LDS 0x1 /*< Learn done status flag */
126 #define NT_FLOW_STAT_LFS 0x2 /*< Learn fail status flag */
127 #define NT_FLOW_STAT_LIS 0x4 /*< Learn ignore status flag */
128 #define NT_FLOW_STAT_UDS 0x8 /*< Un-learn done status flag */
129 #define NT_FLOW_STAT_UIS 0x10 /*< Un-learn ignore status flag */
130 
131 /**
132  * @brief Flow status structure
133  *
134  * This structure contains the status for a particular flow (Un-)learning
135  * operation. A series of flags indicates whether the operation was successful
136  * or not.
137  */
138 typedef struct NtFlowStatus_s {
139  uint64_t id; /*< 64-bit user defined flow id */
140  uint32_t flags; /*< Flags indicating the status of the operation */
142 
143 /**
144  * @brief Initialize flow stream attributes
145  *
146  * See NT_FlowOpen_Attr for further description
147  *
148  * @param attr Pointer to the attributes structure
149  */
150 void NT_FlowOpenAttrInit(NtFlowAttr_t *attr);
151 
152 /**
153  * @brief Set adapter number attribute
154  *
155  * @param attr Pointer to the attributes structure
156  * @param adapterNo Adapter number the stream should be associated to
157  */
158 void NT_FlowOpenAttrSetAdapterNo(NtFlowAttr_t *attr, uint8_t adapterNo);
159 
160 /**
161  * @brief Return the adapter number attribute
162  *
163  * See NT_FlowOpen_Attr for further description
164  *
165  * @return The adapter number attribute
166  */
167 uint8_t NT_FlowOpenAttrGetAdapterNo(NtFlowAttr_t *attr);
168 
169 /**
170  * @brief Set flow stream flags
171  *
172  * Currently no flags are defined so calls of this
173  * function shall be avoided
174  *
175  * @param attr Pointer to attriute structure
176  * @param flags Flow stream flags
177  */
178 void NT_FlowOpenAttrSetFlags(NtFlowAttr_t *attr, uint32_t flags);
179 
180 /**
181  * @brief Get flow stream flags
182  *
183  * @param attr Pointer to attriute structure
184  * @return Flow stream flags
185  */
186 uint32_t NT_FlowOpenAttrGetFlags(NtFlowAttr_t *attr);
187 
188 /**
189  * @brief Opens a flow programming stream and returns a stream handle
190  *
191  * This function opens a flow stream which is used for fast programming of the flow
192  * matcher present on adapters that support the flow matching feature. A flow stream
193  * should only be opened after all relevant NTPL statements configuring the flow matcher
194  * has been executed.
195  *
196  * The default sequence for opening a flow stream is:
197  *
198  * NtFlowAttr_t attr;
199  *
200  * NT_FlowOpenAttrInit(&attr);
201  *
202  * NT_FlowOpenAttrSetAdapterNo(&attr, adapter_no);
203  *
204  * int status = NT_FlowOpen_Attr(&_stream, "name", &attr);
205  *
206  * @param[out] hStream Reference to the NtFlowStream_t stream pointer
207  * @param[in] name Name of the stream
208  * @param[in] attr Pointer to the flow stream attributes
209  */
210 int NT_FlowOpen_Attr(NtFlowStream_t* hStream, const char *name, NtFlowAttr_t* attr);
211 
212 /**
213  * @brief Closes a flow stream
214  *
215  * This function closes and frees resources belonging to a flow stream
216  *
217  * @param[in] hStream Flow stream handle to be closed
218  * @retval NT_SUCCESS Success
219  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
220  */
221 int NT_FlowClose(NtFlowStream_t hStream);
222 
223 /**
224  * @brief Programs a flow into an adapter
225  *
226  * This function is used to program flows into the adapter associated
227  * with the stream handle. The flow data must be written into the @ref NtFlow_t
228  * structure by the caller before calling this function.
229  *
230  * Returns NT_ERROR_INVALID_PARAMETER if NtFlow_t:
231  * - tau = 1 and gfi = 0
232  * - overwrite is set and any of 7 most significant bit in color is set
233  * - overwrite is not set but streamId is different from 0
234  *
235  * @param[in] hStream The flow stream handle obtained in @ref NT_FlowOpen_Attr
236  * @param[in] flow Pointer to the flow data structure
237  * @param[in] timeout Timeout in ms before failing to program the flow (-1 = retry indefinitely)
238  * @retval NT_SUCCESS The flow was successfully programmed
239  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
240  */
241 int NT_FlowWrite(NtFlowStream_t hStream, NtFlow_t* flow, int timeout);
242 
243 /**
244  * @brief Read a flow information record
245  *
246  * This function will attempt to read a flow information record. If a record
247  * is available in the stream it will be returned in the record pointed
248  * to by "info".
249  *
250  * @param[in] hStream The flow stream handle obtained in @ref NT_FlowOpen_Attr
251  * @param[out] info Pointer to flow info structure the record is returned in
252  * @param[in] timeout Timeout in ms before failing to program the flow (-1 = retry indefinitely)
253  * @retval NT_SUCCESS A flow information record was successfully read
254  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
255  */
256 int NT_FlowRead(NtFlowStream_t hStream, NtFlowInfo_t* info, int timeout);
257 
258 /**
259  * @brief Read a flow status record
260  *
261  * This function will attempt to read a flow status record. A status record
262  * is an async result response for an NT_FlowWrite. If a record
263  * is available in the stream it will be returned in the record pointed
264  * to by "status".
265  *
266  * There are 5 types of status records:
267  *
268  * LearnDone which signals a succesful flow program operation
269  *
270  * LearnFail which signals an unsuccesful flow program operation
271  *
272  * LearnIgnore which signals an ignored flow program operation (flow already exists)
273  *
274  * UnlearnDone which signals a succesful flow unlearn operation
275  *
276  * UnlearnIgnore which signals an ignored flow unlearn operation (flow doesn't exists)
277  *
278  * Generation of status records can be enabled/disabled individually in ntservice.ini
279  *
280  *
281  * @param[in] hStream The flow stream handle obtained in @ref NT_FlowOpen_Attr
282  * @param[out] status Pointer to flow status structure the record is returned in
283  * @retval NT_SUCCESS A flow status record was successfully read
284  * @retval NT_STATUS_TRYAGAIN No flow status records available at this time
285  * @retval !=NT_SUCCESS Error - use @ref NT_ExplainError for an error description
286  */
288 
289 /**
290  * @}
291  */
292 
293 #endif