NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
psp_gw_flows.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024-2025 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef _PSP_GW_FLOWS_H_
27 #define _PSP_GW_FLOWS_H_
28 
29 #include <netinet/in.h>
30 #include <string>
31 #include <unordered_map>
32 
33 #include <rte_ether.h>
34 
35 #include <doca_dev.h>
36 #include <doca_flow.h>
37 
38 #include "psp_gw_config.h"
39 
40 static const int NUM_OF_PSP_SYNDROMES = 2; // ICV Fail, Bad Trailer
41 
42 struct psp_gw_app_config;
43 
47 struct psp_pf_dev {
48  doca_dev *dev;
49  uint16_t port_id;
50  doca_flow_port *port_obj;
51 
52  rte_ether_addr src_mac;
53  std::string src_mac_str;
54 
55  struct doca_flow_ip_addr src_pip; // Physical/Outer IP addr
56  std::string src_pip_str;
57 };
58 
63 struct psp_session_t {
64  rte_ether_addr dst_mac;
65 
66  struct doca_flow_ip_addr dst_pip; /* Physical/Outer IP addr */
67  struct doca_flow_ip_addr dst_vip; /* Virtual/Inner dest IP addr */
68  struct doca_flow_ip_addr src_vip; /* Virtual/Inner src IP addr */
69 
70  uint32_t spi_egress; /* Security Parameter Index on the wire - host-to-net */
71  uint32_t spi_ingress; /* Security Parameter Index on the wire - net-to-host */
72  uint32_t crypto_id; /* Internal shared-resource index */
73 
74  uint32_t psp_proto_ver; /* PSP protocol version used by this session */
75  uint64_t vc; /* Virtualization cookie, if enabled */
76 
77  doca_flow_pipe_entry *encap_encrypt_entry; /* DOCA Flow encap & encrypt entry */
78  doca_flow_pipe_entry *acl_entry; /* DOC AFlow ACL entry */
79  uint64_t pkt_count_egress; /* Count of encap_encrypt_entry */
80  uint64_t pkt_count_ingress; /* Count of acl_entry */
81 };
82 
88 public:
98 
103  virtual ~PSP_GatewayFlows(void);
104 
108  psp_pf_dev *pf(void)
109  {
110  return pf_dev;
111  }
112 
118  doca_error_t init(void);
119 
130  doca_error_t add_encrypt_entry(psp_session_t *session, const void *encrypt_key);
131 
140 
148 
153  void show_static_flow_counts(void);
154 
162  void show_session_flow_count(const session_key session_vips_pair, psp_session_t &session);
163 
164 private:
168  struct pipe_query;
169 
180  static void check_for_valid_entry(doca_flow_pipe_entry *entry,
181  uint16_t pipe_queue,
182  enum doca_flow_entry_status status,
183  enum doca_flow_entry_op op,
184  void *user_ctx);
185 
195  doca_error_t start_port(uint16_t port_id, doca_dev *port_dev, doca_flow_port **port);
196 
204 
210  void init_status(psp_gw_app_config *app_cfg);
211 
217  doca_error_t bind_shared_resources(void);
218 
224  doca_error_t configure_mirrors(void);
225 
240  doca_error_t add_single_entry(uint16_t pipe_queue,
241  doca_flow_pipe *pipe,
242  doca_flow_port *port,
243  const doca_flow_match *match,
244  const doca_flow_actions *actions,
245  const doca_flow_monitor *mon,
246  const doca_flow_fwd *fwd,
247  doca_flow_pipe_entry **entry);
248 
255  void format_encap_tunnel_data_ipv6(const psp_session_t *session, uint8_t *encap_data);
256 
263  void format_encap_tunnel_data_ipv4(const psp_session_t *session, uint8_t *encap_data);
264 
271  void format_encap_transport_data(const psp_session_t *session, uint8_t *encap_data);
272 
278  doca_error_t create_pipes(void);
279 
285  doca_error_t ingress_decrypt_pipe_create(void);
286 
292  doca_error_t ingress_sampling_pipe_create(void);
293 
301  doca_error_t ingress_acl_pipe_create(bool ipv4);
302 
309  doca_error_t syndrome_stats_pipe_create(void);
310 
317  doca_error_t egress_acl_pipe_create(bool ipv4);
318 
325  doca_error_t create_egress_dst_ip6_pipe(void);
326 
333  doca_error_t create_ingress_src_ip6_pipe(void);
334 
342  doca_error_t add_egress_dst_ip6_entry(psp_session_t *session, int dst_vip_id);
343 
351  doca_error_t add_ingress_src_ip6_entry(psp_session_t *session, int dst_vip_id);
352 
358  doca_error_t egress_sampling_pipe_create(void);
359 
365  doca_error_t rss_pipe_create(void);
366 
373  doca_error_t ingress_root_pipe_create(void);
374 
380  doca_error_t ingress_inner_classifier_pipe_create(void);
381 
387  doca_error_t fwd_to_wire_pipe_create(void);
388 
394  doca_error_t fwd_to_rss_pipe_create(void);
395 
401  doca_error_t set_sample_bit_pipe_create(void);
402 
410  doca_error_t empty_pipe_create(void);
411 
417  doca_error_t empty_pipe_create_not_sampled(void);
418 
427  std::pair<uint64_t, uint64_t> perform_pipe_query(pipe_query *query, bool suppress_output);
428 
429  // Application state data:
430 
432 
433  psp_pf_dev *pf_dev{};
434 
435  uint16_t vf_port_id{UINT16_MAX};
436 
437  doca_flow_port *vf_port{};
438 
439  bool sampling_enabled{false};
440 
441  std::vector<uint16_t> rss_queues;
442  doca_flow_fwd fwd_rss{};
443 
444  // Pipe and pipe entry application state:
445 
446  // general pipes
447  doca_flow_pipe *rss_pipe{};
448  doca_flow_pipe *ingress_root_pipe{};
449 
450  // net-to-host pipes
451  doca_flow_pipe *ingress_decrypt_pipe{};
452  doca_flow_pipe *ingress_sampling_pipe{};
453  doca_flow_pipe *ingress_inner_ip_classifier_pipe{};
454  doca_flow_pipe *ingress_acl_ipv4_pipe{};
455  doca_flow_pipe *ingress_acl_ipv6_pipe{};
456 
457  // host-to-net pipes
458  doca_flow_pipe *egress_acl_ipv4_pipe{};
459  doca_flow_pipe *egress_acl_ipv6_pipe{};
460  doca_flow_pipe *egress_sampling_pipe{};
461  doca_flow_pipe *egress_encrypt_pipe{};
462  doca_flow_pipe *syndrome_stats_pipe{};
463  doca_flow_pipe *empty_pipe{};
464  doca_flow_pipe *empty_pipe_not_sampled{};
465  doca_flow_pipe *fwd_to_wire_pipe{};
466  doca_flow_pipe *fwd_to_rss_pipe{};
467  doca_flow_pipe *set_sample_bit_pipe{};
468  doca_flow_pipe *egress_dst_ip6_pipe{};
469  doca_flow_pipe *ingress_src_ip6_pipe{};
470 
471  // static pipe entries
472  doca_flow_pipe_entry *default_rss_entry{};
473  doca_flow_pipe_entry *default_decrypt_entry{};
474  doca_flow_pipe_entry *default_ingr_sampling_entry{};
475  doca_flow_pipe_entry *egr_sampling_rss{};
476  doca_flow_pipe_entry *egr_sampling_drop{};
477  doca_flow_pipe_entry *default_ingr_acl_ipv4_entry{};
478  doca_flow_pipe_entry *default_ingr_acl_ipv6_entry{};
479  doca_flow_pipe_entry *ingress_ipv4_clasify_entry{};
480  doca_flow_pipe_entry *ingress_ipv6_clasify_entry{};
481  doca_flow_pipe_entry *root_jump_to_ingress_ipv6_entry{};
482  doca_flow_pipe_entry *root_jump_to_ingress_ipv4_entry{};
483  doca_flow_pipe_entry *root_jump_to_egress_ipv6_entry{};
484  doca_flow_pipe_entry *root_jump_to_egress_ipv4_entry{};
485  doca_flow_pipe_entry *vf_arp_to_rss{};
486  doca_flow_pipe_entry *vf_ns_to_rss{};
487  doca_flow_pipe_entry *vf_arp_to_wire{};
488  doca_flow_pipe_entry *uplink_arp_to_vf{};
489  doca_flow_pipe_entry *vf_ns_to_wire{};
490  doca_flow_pipe_entry *uplink_ns_to_vf{};
491  doca_flow_pipe_entry *syndrome_stats_entries[NUM_OF_PSP_SYNDROMES]{};
492  doca_flow_pipe_entry *empty_pipe_entry{};
493  doca_flow_pipe_entry *arp_empty_pipe_entry{};
494  doca_flow_pipe_entry *ns_empty_pipe_entry{};
495  doca_flow_pipe_entry *ipv4_empty_pipe_entry{};
496  doca_flow_pipe_entry *ipv6_empty_pipe_entry{};
497  doca_flow_pipe_entry *root_default_drop{};
498  doca_flow_pipe_entry *fwd_to_wire_entry{};
499  doca_flow_pipe_entry *fwd_to_rss_entry{};
500  doca_flow_pipe_entry *set_sample_bit_entry{};
501 
502  // commonly used setting to enable per-entry counters
503  struct doca_flow_monitor monitor_count {};
504 
505  // Shared resource IDs
506  uint32_t mirror_res_id_ingress{1};
507  uint32_t mirror_res_id_rss{2};
508  uint32_t mirror_res_id_drop{3};
509  uint32_t mirror_res_id_count{4};
510 
511  // Sum of all static pipe entries the last time
512  // show_static_flow_counts() was invoked.
513  uint64_t prev_static_flow_count{UINT64_MAX};
514 };
515 
516 #endif /* _PSP_GW_FLOWS_H_ */
struct doca_flow_port * init_doca_flow(uint16_t port_id, uint8_t rxq_num)
Definition: flow.c:37
static void check_for_valid_entry(struct doca_flow_pipe_entry *entry, uint16_t pipe_queue, enum doca_flow_entry_status status, enum doca_flow_entry_op op, void *user_ctx)
Definition: flow_common.c:50
The entity which owns all the doca flow shared resources and flow pipes (but not sessions).
Definition: psp_gw_flows.h:87
void show_session_flow_count(const session_key session_vips_pair, psp_session_t &session)
Shows flow counters for the given tunnel, if they have changed since the last invocation.
psp_pf_dev * pf(void)
Definition: psp_gw_flows.h:108
void show_static_flow_counts(void)
Shows flow counters for pipes which have a fixed number of entries, if any counter values have change...
doca_error_t add_ingress_acl_entry(psp_session_t *session)
Adds an ingress ACL entry for the given session to accept the combination of src_vip and SPI.
doca_error_t remove_encrypt_entry(psp_session_t *session)
Removes the indicated flow entry.
PSP_GatewayFlows(psp_pf_dev *pf, uint16_t vf_port_id, psp_gw_app_config *app_config)
Constructs the object. This operation cannot fail.
doca_error_t init(void)
Initialized the DOCA resources.
virtual ~PSP_GatewayFlows(void)
doca_error_t add_encrypt_entry(psp_session_t *session, const void *encrypt_key)
Adds a flow pipe entry to perform encryption on a new flow to the indicated peer. The caller is respo...
static uint16_t * rss_queues
Definition: flow_parser.c:114
static struct doca_flow_actions actions
Definition: flow_parser.c:107
static struct doca_flow_fwd fwd
Definition: flow_parser.c:109
static struct doca_flow_pipe_entry * entry[MAX_ENTRIES]
static struct app_gpu_cfg app_cfg
enum doca_error doca_error_t
DOCA API return codes.
doca_flow_entry_op
doca flow entry operation
Definition: doca_flow.h:146
doca_flow_entry_status
doca flow entry status
Definition: doca_flow.h:160
std::pair< std::string, std::string > session_key
Definition: psp_gw_config.h:79
static const int NUM_OF_PSP_SYNDROMES
Definition: psp_gw_flows.h:40
doca flow actions information
Definition: doca_flow.h:684
forwarding configuration
Definition: doca_flow.h:779
doca flow ip address
doca flow matcher information
Definition: doca_flow.h:491
doca monitor action configuration
Definition: doca_flow.h:968
describes the configuration of the PSP networking service on the local host.
Maintains the state of the host PF.
Definition: psp_gw_flows.h:47
struct doca_flow_ip_addr src_pip
Definition: psp_gw_flows.h:55
rte_ether_addr src_mac
Definition: psp_gw_flows.h:52
doca_dev * dev
Definition: psp_gw_flows.h:48
std::string src_mac_str
Definition: psp_gw_flows.h:53
doca_flow_port * port_obj
Definition: psp_gw_flows.h:50
std::string src_pip_str
Definition: psp_gw_flows.h:56
uint16_t port_id
Definition: psp_gw_flows.h:49
describes a PSP tunnel connection to a single address on a peer.
Definition: psp_gw_flows.h:63
uint64_t pkt_count_egress
Definition: psp_gw_flows.h:79
doca_flow_pipe_entry * encap_encrypt_entry
Definition: psp_gw_flows.h:77
uint32_t crypto_id
Definition: psp_gw_flows.h:72
rte_ether_addr dst_mac
Definition: psp_gw_flows.h:64
doca_flow_pipe_entry * acl_entry
Definition: psp_gw_flows.h:78
uint64_t pkt_count_ingress
Definition: psp_gw_flows.h:80
struct doca_flow_ip_addr src_vip
Definition: psp_gw_flows.h:68
uint32_t spi_ingress
Definition: psp_gw_flows.h:71
uint32_t psp_proto_ver
Definition: psp_gw_flows.h:74
uint32_t spi_egress
Definition: psp_gw_flows.h:70
struct doca_flow_ip_addr dst_pip
Definition: psp_gw_flows.h:66
struct doca_flow_ip_addr dst_vip
Definition: psp_gw_flows.h:67
uint64_t vc
Definition: psp_gw_flows.h:75