NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
psp_gw_utils.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_UTILS_H_
27 #define _PSP_GW_UTILS_H_
28 
29 #include <inttypes.h>
30 #include <string>
31 
32 #include <rte_byteorder.h>
33 #include <rte_ether.h>
34 
35 #include "doca_flow_net.h"
36 #include "psp_gw_config.h"
37 
38 /* set IPv6 address in array */
39 #define SET_IP6_ADDR(addr, a, b, c, d) \
40  do { \
41  addr[0] = a; \
42  addr[1] = b; \
43  addr[2] = c; \
44  addr[3] = d; \
45  } while (0)
46 
50 std::string mac_to_string(const rte_ether_addr &mac_addr);
51 
58 bool is_empty_mac_addr(const rte_ether_addr &addr);
59 
63 std::string ipv4_to_string(rte_be32_t ipv4_addr);
64 
68 std::string ipv6_to_string(const uint32_t ipv6_addr[]);
69 
73 std::string ip_to_string(const struct doca_flow_ip_addr &ip_addr);
74 
82 bool is_ip_equal(struct doca_flow_ip_addr *ip_a, struct doca_flow_ip_addr *ip_b);
83 
92 doca_error_t parse_ip_addr(const std::string &ip_str,
93  doca_flow_l3_type enforce_l3_type,
94  struct doca_flow_ip_addr *ip_addr);
95 
102 void copy_ip_addr(const struct doca_flow_ip_addr &src, struct doca_flow_ip_addr &dst);
103 
111 psp_gw_peer *lookup_vip_pair(std::vector<psp_gw_peer> *peers, ip_pair &vip_pair);
112 
113 #endif /* _PSP_GW_UTILS_H_ */
uintptr_t addr
static uint64_t *restrict src
Definition: dpaintrin.h:230
enum doca_error doca_error_t
DOCA API return codes.
doca_flow_l3_type
doca flow layer 3 packet type
bool is_ip_equal(struct doca_flow_ip_addr *ip_a, struct doca_flow_ip_addr *ip_b)
Compare DOCA Flow IP address struct, return true if addresses are equal.
doca_error_t parse_ip_addr(const std::string &ip_str, doca_flow_l3_type enforce_l3_type, struct doca_flow_ip_addr *ip_addr)
Parse an IP address string into a DOCA Flow IP address struct.
std::string ipv4_to_string(rte_be32_t ipv4_addr)
Converts an IPv4 address to a C++ string.
psp_gw_peer * lookup_vip_pair(std::vector< psp_gw_peer > *peers, ip_pair &vip_pair)
Search for a peer in a vector of peers that holds the same IP pair.
bool is_empty_mac_addr(const rte_ether_addr &addr)
Tests whether a MAC address has been set (is non-zero)
std::string mac_to_string(const rte_ether_addr &mac_addr)
Converts a MAC/ethernet address to a C++ string.
void copy_ip_addr(const struct doca_flow_ip_addr &src, struct doca_flow_ip_addr &dst)
Copy an IP address struct.
std::string ip_to_string(const struct doca_flow_ip_addr &ip_addr)
Converts a DOCA Flow IP address struct to a C++ string.
std::string ipv6_to_string(const uint32_t ipv6_addr[])
Converts an IPv6 address to a C++ string.
doca flow ip address
Describes a peer which is capable of exchanging traffic flows over a PSP tunnel.
Definition: psp_gw_config.h:98