32 #include <rte_ethdev.h>
35 #include <google/protobuf/util/json_util.h>
36 #include <grpc/support/log.h>
37 #include <grpcpp/grpcpp.h>
38 #include <grpcpp/server_builder.h>
68 if (signum == SIGINT || signum == SIGTERM) {
69 DOCA_LOG_INFO(
"Signal %d received, preparing to exit", signum);
81 int main(
int argc,
char **argv)
85 int exit_status = EXIT_SUCCESS;
89 app_config.dpdk_config.port_config.nb_queues = 2;
90 app_config.dpdk_config.port_config.switch_mode =
true;
91 app_config.dpdk_config.port_config.enable_mbuf_metadata =
true;
92 app_config.dpdk_config.port_config.isolated_mode =
true;
93 app_config.dpdk_config.reserve_main_thread =
true;
98 app_config.net_config.crypt_offset = UINT32_MAX;
99 app_config.net_config.default_psp_proto_ver = UINT32_MAX;
101 app_config.ingress_sample_meta_indicator = 0x65656565;
102 app_config.egress_sample_meta_indicator = 0x43434343;
103 app_config.return_to_vf_indicator = 0x78787878;
113 std::string dev_probe_str;
115 struct doca_log_backend *sdk_log;
141 const char *eal_args[] = {
"",
"-a00:00.0",
"-c",
app_config.core_mask.c_str(),
"--file-prefix", pid_str.c_str()};
142 int n_eal_args =
sizeof(eal_args) /
sizeof(eal_args[0]);
143 int rc = rte_eal_init(n_eal_args, (
char **)eal_args);
151 exit_status = EXIT_FAILURE;
155 if (
app_config.net_config.crypt_offset == UINT32_MAX) {
168 if (
app_config.net_config.default_psp_proto_ver == UINT32_MAX) {
180 exit_status = EXIT_FAILURE;
184 dev_probe_str = std::string(
"dv_flow_en=2,"
188 "repr_matching_en=0,"
195 exit_status = EXIT_FAILURE;
202 app_config.dpdk_config.port_config.nb_ports = rte_eth_dev_count_avail();
214 exit_status = EXIT_FAILURE;
224 exit_status = EXIT_FAILURE;
230 DOCA_LOG_INFO(
"Port %d: Detected PF MAC addr: %s, IP addr: %s, total ports: %d",
236 vf_port_id = pf_dev.
port_id + 1;
242 exit_status = EXIT_FAILURE;
248 std::vector<psp_gw_peer> remotes_to_connect;
254 exit_status = EXIT_FAILURE;
268 RTE_LCORE_FOREACH_WORKER(lcore_id)
273 std::string server_address =
app_config.local_svc_addr;
274 if (server_address.empty()) {
275 server_address =
"0.0.0.0";
277 if (server_address.find(
":") == std::string::npos) {
280 grpc::ServerBuilder builder;
281 builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
282 builder.RegisterService(&
psp_svc);
283 auto server_instance = builder.BuildAndStart();
285 if (!server_instance) {
286 DOCA_LOG_ERR(
"Failed to initialize gRPC server (%s)", server_address.c_str());
287 exit_status = EXIT_FAILURE;
288 goto workers_cleanup;
290 DOCA_LOG_WARN(
"Server listening on %s", server_address.c_str());
300 remotes_to_connect =
app_config.net_config.peers;
315 if (server_instance) {
316 server_instance->Shutdown();
317 server_instance.reset();
322 RTE_LCORE_FOREACH_WORKER(lcore_id)
325 rte_eal_wait_lcore(lcore_id);
The entity which owns all the doca flow shared resources and flow pipes (but not sessions).
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 init(void)
Initialized the DOCA resources.
Implementation of the PSP_Gateway service.
doca_error_t show_flow_counts(void)
Displays the counters of all tunnel sessions that have changed since the previous invocation.
static constexpr uint16_t DEFAULT_HTTP_PORT_NUM
size_t try_connect(std::vector< psp_gw_peer > &peers)
Attempt to establish tunnels to each of the passed peers. On success, a given peer is removed from th...
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
doca_error_t dpdk_queues_and_ports_init(struct application_dpdk_config *app_dpdk_config)
void dpdk_queues_and_ports_fini(struct application_dpdk_config *app_dpdk_config)
DOCA_EXPERIMENTAL doca_error_t doca_argp_destroy(void)
ARG Parser destroy.
#define DOCA_DEVINFO_IPV4_ADDR_SIZE
Length of IPv4 address.
DOCA_STABLE doca_error_t doca_devinfo_get_ipv6_addr(const struct doca_devinfo *devinfo, uint8_t *ipv6_addr, uint32_t size)
Get the IPv6 address of a DOCA devinfo.
DOCA_STABLE doca_error_t doca_devinfo_get_ipv4_addr(const struct doca_devinfo *devinfo, uint8_t *ipv4_addr, uint32_t size)
Get the IPv4 address of a DOCA devinfo.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
#define DOCA_DEVINFO_IPV6_ADDR_SIZE
Length of IPv6 address.
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
DOCA_EXPERIMENTAL doca_error_t doca_dpdk_port_probe(struct doca_dev *dev, const char *devargs)
Attach a DPDK port specified by DOCA device.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_standard(void)
Create default, non configurable backend for application messages.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_WARN(format,...)
Generates a WARNING application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_create_with_file_sdk(FILE *fptr, struct doca_log_backend **backend)
Create a logging backend with a FILE* stream for SDK messages.
DOCA_EXPERIMENTAL doca_error_t doca_log_backend_set_sdk_level(struct doca_log_backend *backend, uint32_t level)
Set the log level limit for SDK logging backends.
std::string to_string(storage::control::message_type type)
DOCA_LOG_REGISTER(PSP_GATEWAY)
int main(int argc, char **argv)
static void signal_handler(int signum)
Signal handler function (SIGINT and SIGTERM signals)
static constexpr uint32_t DEFAULT_CRYPT_OFFSET_IPV6
static const uint32_t DEFAULT_PSP_VERSION
static constexpr uint32_t DEFAULT_CRYPT_OFFSET_VC_ENABLED_IPV6
static constexpr uint32_t DEFAULT_CRYPT_OFFSET_VC_ENABLED_IPV4
static constexpr uint32_t DEFAULT_CRYPT_OFFSET_IPV4
doca_error_t psp_gw_parse_config_file(psp_gw_app_config *app_config)
Parses the configuration JSON file that was passed to the application.
doca_error_t psp_gw_argp_exec(int &argc, char *argv[], psp_gw_app_config *app_config)
Parses command-line arguments to the application.
std::string mac_to_string(const rte_ether_addr &mac_addr)
Converts a MAC/ethernet address to a C++ string.
std::string ip_to_string(const struct doca_flow_ip_addr &ip_addr)
Converts a DOCA Flow IP address struct to a C++ string.
enum doca_flow_l3_type type
The parameters needed by each L-Core's main loop.
PSP_GatewayImpl * psp_svc
PSP_GatewayFlows * psp_flows
describes the configuration of the PSP networking service on the local host.
Maintains the state of the host PF.
struct doca_flow_ip_addr src_pip