#include <arpa/inet.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <sched.h>
#include <stddef.h>
#include <openssl/pem.h>
#include "picotls.h"
#include "picotls/openssl.h"
#include "quicly.h"
#include "quicly/defaults.h"
#include "quicly/streambuf.h"
#include "cnet-quic.h"
static struct cnet_info cnet_info;
struct cnet_info *cinfo = &cnet_info;
#define foreach_thd_lport(_t, _lp) \
for (int _i = 0; _i < _t->lport_cnt && (_lp = _t->lports[_i]); _i++, _lp = _t->lports[_i])
static inline int
add_graph_pattern(graph_info_t *gi, const char *pattern)
{
if ((gi->cnt + 1) > gi->nb_patterns) {
gi->cnt++;
gi->patterns = realloc(gi->patterns, ((gi->cnt + 1) * sizeof(char *)));
if (!gi->patterns)
}
gi->patterns[gi->nb_patterns++] = strdup(pattern);
gi->patterns[gi->nb_patterns] = NULL;
return 0;
}
static int
initialize_graph(
jcfg_thd_t *thd, graph_info_t *gi)
{
int ret;
snprintf(graph_name,
sizeof(graph_name),
"cnet_%d",
cne_id());
cne_printf(
"[magenta]Graph Name[]: '[orange]%s[]', [magenta]Thread name [orange]%s[]\n",
graph_name, thd->name);
if (ret < 0)
CNE_ERR_GOTO(err,
"Unable to find %s option name\n", thd->name);
CNE_ERR_GOTO(err,
"Thread %s does not have any graph patterns\n", thd->name);
for (
int i = 0; i < pattern_array->
array_sz; i++) {
if (add_graph_pattern(gi, pattern_array->arr[i]->
str))
goto err;
}
foreach_thd_lport (thd, lport) {
snprintf(node_name,
sizeof(node_name),
"eth_rx-%u", lport->
lpid);
if (add_graph_pattern(gi, node_name))
goto err;
}
CNE_ERR_GOTO(err,
"cne_graph_create(): graph_id '%s' for uid %u\n", graph_name,
cne_id());
if (!gi->graph)
CNE_ERR_GOTO(err,
"cne_graph_lookup(): graph '%s' not found\n", graph_name);
this_stk->graph = gi->graph;
free(gi->patterns);
return 0;
err:
free(gi->patterns);
return -1;
}
void
thread_func(void *arg)
{
graph_info_t *gi;
pthread_t pid = pthread_self();
int tid;
CNE_RET(
"pthread_setaffinity_np('%s') failed\n", thd->name);
}
if (pthread_barrier_wait(&cinfo->barrier) > 0)
CNE_RET(
"cnet_stk_initialize('%s') failed\n", thd->name);
if (tid >= cne_countof(cinfo->graph_info))
CNE_ERR_GOTO(err,
"Number of threads cannot be >= %d\n", cne_countof(cinfo->graph_info));
gi = &cinfo->graph_info[tid];
if (initialize_graph(thd, gi))
if (open_quic_channel() < 0)
return;
err:
(void)pthread_barrier_wait(&cinfo->barrier);
}
static int
{
foreach_thd_lport (thd, lport) {
cne_printf(
" [magenta]lport [red]%d[] - '[cyan]%s[]'", lport->
lpid, lport->name);
CNE_ERR("pktdev_close() returned error\n");
}
}
return 0;
}
static void
my_quit(struct cnet_info *ci)
{
if (ci) {
jcfg_thread_foreach(ci->jinfo, _thread_quit, ci);
}
}
static void
__on_exit(int val, void *arg, int exit_type)
{
struct cnet_info *ci = arg;
switch (exit_type) {
switch (val) {
case SIGUSR1:
break;
case SIGINT:
cne_printf_pos(99, 1,
"\n>>> [cyan]Terminating with signal [green]%d[]\n", val);
break;
default:
cne_printf_pos(99, 1,
"\n>>> [cyan]Terminating with signal [red]%d[]\n", val);
break;
}
break;
cne_printf_pos(99, 1,
"\n>>> [cyan]Terminating with status [green]%d[]\n", val);
break;
cne_printf_pos(99, 1,
"\n>>> [cyan]User called exit, with [red]%d[]\n", val);
break;
default:
cne_printf_pos(99, 1,
"\n>>> [cyan]Unknow Exit type %d[]\n", exit_type);
break;
}
my_quit(ci);
}
static int
initialize(void)
{
uint16_t nb_conf = 0;
CNE_DEBUG(
"pktmbuf_t size %ld, udata64 offset %ld\n",
sizeof(
pktmbuf_t),
pkt_conf[nb_conf++].port_id = lportid;
return 0;
}
static int
cli_tree(void)
{
}
int
main(int argc, char **argv)
{
int cnt, signals[] = {SIGINT, SIGTERM, SIGUSR1};
memset(&cnet_info, 0, sizeof(struct cnet_info));
if (
cne_init() < 0 || (cnt = parse_args(argc, argv)) < 0)
argc -= cnt;
argv += cnt;
if (
cne_on_exit(__on_exit, cinfo, signals, cne_countof(signals)) < 0)
cne_printf(
"\n*** [yellow]quic-echo[], [blue]PID[]: [green]%d[] [blue]lcore[]: [green]%d[]\n",
if (!cinfo->cnet)
usleep(1000);
if (initialize())
if (quicly_main(argc, argv) < 0)
if (pthread_barrier_wait(&cinfo->barrier) > 0)
if (pthread_barrier_destroy(&cinfo->barrier))
usleep(250000);
cne_printf(
">>> [cyan]CNET-QUIC Application Exiting[]: [green]Bye![]\n");
return 0;
err:
if (pthread_barrier_destroy(&cinfo->barrier))
CNE_ERR("Failed to destroy barrier\n");
leave:
cne_printf(
"\n*** [cyan]CNET-QUIC Application[], [blue]PID[]: [green]%d[] failed\n", getpid());
return -1;
}
CNDP_API void cli_start(const char *msg)
CNDP_API int cli_setup_with_tree(cli_tree_t tree)
CNDP_API void cli_destroy(void)
CNDP_API int cli_create(struct cli_cfg *cfg)
CNDP_API int cli_create_with_defaults(struct cli_cfg *cfg)
CNDP_API int cne_id(void)
CNDP_API int cne_init(void)
CNDP_API int cne_on_exit(on_exit_fn_t exit_fn, void *arg, int *signals, int nb_signals)
#define offsetof(TYPE, MEMBER)
CNDP_API int cne_graph_destroy(cne_graph_t id)
CNDP_API cne_graph_t cne_graph_create(const char *name, const char **patterns)
CNDP_API struct cne_graph * cne_graph_lookup(const char *name)
#define CNE_GRAPH_ID_INVALID
#define CNE_GRAPH_NAMESIZE
static void cne_graph_walk(struct cne_graph *graph)
#define CNE_ERR_GOTO(lbl,...)
CNDP_API int cne_printf_pos(int16_t r, int16_t c, const char *fmt,...)
CNDP_API int cne_printf(const char *fmt,...)
CNDP_API int cne_lcore_id(void)
void cne_timer_subsystem_init(void)
CNDP_API struct cnet * cnet_create(void)
Create cnet structure and use default value, will call cnet_config_create().
CNDP_API int cnet_add_cli_cmds(void)
Called to initialize the CLI commands for the CNET structure.
CNDP_API void cnet_stop(void)
Stop and free resources of the cnet structure.
CNDP_API int cnet_stk_initialize(struct cnet *cnet)
Initialize the stack instance.
CNDP_API int cnet_eth_node_config(struct pkt_eth_node_config *cfg, uint16_t cnt)
CNDP_API int jcfg_option_array_get(jcfg_info_t *jinfo, const char *name, obj_value_t **val_arr)
CNDP_API int metrics_destroy(void)
CNDP_API int pktdev_close(uint16_t lport_id)
CNDP_API uint16_t pktdev_port_count(void)