CNDP  22.08.0
cne_graph.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include <cne_common.h>

Go to the source code of this file.

Data Structures

struct  cne_graph_cluster_stats_param
 
struct  cne_graph_cluster_node_stats
 
struct  cne_node_register
 

Macros

#define CNE_GRAPH_NAMESIZE   64
 
#define CNE_NODE_NAMESIZE   64
 
#define CNE_GRAPH_OFF_INVALID   UINT32_MAX
 
#define CNE_NODE_ID_INVALID   UINT32_MAX
 
#define CNE_EDGE_ID_INVALID   UINT16_MAX
 
#define CNE_GRAPH_ID_INVALID   UINT16_MAX
 
#define CNE_GRAPH_FENCE   0xdeadbeef12345678ULL
 
#define CNE_GRAPH_BURST_SIZE_LOG2   8
 
#define cne_graph_foreach_node(count, off, graph, node)
 
#define CNE_NODE_SOURCE_F   (1ULL << 0)
 
#define CNE_NODE_INPUT_F   (1ULL << 1)
 
#define CNE_NODE_MASK_F   (CNE_NODE_SOURCE_F | CNE_NODE_INPUT_F)
 
#define CNE_NODE_REGISTER(node)
 

Typedefs

typedef uint32_t cne_graph_off_t
 
typedef uint32_t cne_node_t
 
typedef uint16_t cne_edge_t
 
typedef uint16_t cne_graph_t
 
typedef uint16_t(* cne_node_process_t) (struct cne_graph *graph, struct cne_node *node, void **objs, uint16_t nb_objs)
 
typedef int(* cne_node_init_t) (const struct cne_graph *graph, struct cne_node *node)
 
typedef void(* cne_node_fini_t) (const struct cne_graph *graph, struct cne_node *node)
 
typedef int(* cne_graph_cluster_stats_cb_t) (bool is_first, bool is_last, const struct cne_graph_cluster_node_stats *stats)
 

Functions

CNDP_API cne_graph_t cne_graph_create (const char *name, const char **patterns)
 
CNDP_API int cne_graph_destroy (cne_graph_t id)
 
CNDP_API cne_graph_t cne_graph_from_name (const char *name)
 
CNDP_API char * cne_graph_id_to_name (cne_graph_t id)
 
CNDP_API int cne_graph_export (const char *name, FILE *f)
 
CNDP_API int cne_graph_export_cb (const char *name, FILE *f, cne_graph_export_t *exp)
 
CNDP_API cne_graph_t cne_graph_max_count (void)
 
CNDP_API struct cne_graph * cne_graph_lookup (const char *name)
 
CNDP_API void cne_graph_dump (FILE *f, cne_graph_t id)
 
CNDP_API void cne_graph_list_dump (FILE *f)
 
CNDP_API void cne_graph_obj_dump (FILE *f, struct cne_graph *graph, bool all)
 
CNDP_API struct cne_node * cne_graph_node_get (cne_graph_t graph_id, cne_node_t node_id)
 
CNDP_API struct cne_node * cne_graph_node_get_by_name (const char *graph, const char *name)
 
CNDP_API struct cne_node * cne_graph_get_node_by_name (const struct cne_graph *graph, const char *node_name)
 
CNDP_API struct cne_graph_cluster_stats * cne_graph_cluster_stats_create (const struct cne_graph_cluster_stats_param *prm)
 
CNDP_API void cne_graph_cluster_stats_destroy (struct cne_graph_cluster_stats *stat)
 
CNDP_API void cne_graph_cluster_stats_get (struct cne_graph_cluster_stats *stat, bool skip_cb)
 
CNDP_API void cne_graph_cluster_stats_reset (struct cne_graph_cluster_stats *stat)
 
CNDP_API int cne_graph_stats_node_count (struct cne_graph_cluster_stats *stat)
 
cne_node_t __cne_node_register (const struct cne_node_register *node)
 
CNDP_API cne_node_t cne_node_clone (cne_node_t id, const char *name)
 
CNDP_API cne_node_t cne_node_from_name (const char *name)
 
CNDP_API char * cne_node_id_to_name (cne_node_t id)
 
CNDP_API cne_edge_t cne_node_edge_count (cne_node_t id)
 
CNDP_API cne_edge_t cne_node_edge_update (cne_node_t id, cne_edge_t from, const char **next_nodes, uint16_t nb_edges)
 
CNDP_API cne_edge_t cne_node_edge_shrink (cne_node_t id, cne_edge_t size)
 
CNDP_API cne_node_t cne_node_edge_get (cne_node_t id, char *next_nodes[])
 
CNDP_API cne_node_t cne_node_max_count (void)
 
CNDP_API void cne_node_dump (FILE *f, cne_node_t id)
 
CNDP_API void cne_node_list_dump (FILE *f)
 
static __cne_always_inline int cne_node_is_invalid (cne_node_t id)
 
static __cne_always_inline int cne_edge_is_invalid (cne_edge_t id)
 
static __cne_always_inline int cne_graph_is_invalid (cne_graph_t id)
 
static __cne_always_inline int cne_graph_has_stats_feature (void)
 

Detailed Description

Graph architecture abstracts the data processing functions as "node" and "link" them together to create a complex "graph" to enable reusable/modular data processing functions.

This API enables graph framework operations such as create, lookup, dump and destroy on graph and node operations such as clone, edge update, and edge shrink, etc. The API also allows creation of the stats cluster to monitor per graph and per node stats.

Definition in file cne_graph.h.

Macro Definition Documentation

◆ CNE_GRAPH_NAMESIZE

#define CNE_GRAPH_NAMESIZE   64

Max length of graph name.

Examples
examples/cnet-graph/cnet-graph.c, and examples/cnet-quic/cnet-quic.c.

Definition at line 31 of file cne_graph.h.

◆ CNE_NODE_NAMESIZE

#define CNE_NODE_NAMESIZE   64

Max length of node name.

Definition at line 32 of file cne_graph.h.

◆ CNE_GRAPH_OFF_INVALID

#define CNE_GRAPH_OFF_INVALID   UINT32_MAX

Invalid graph offset.

Definition at line 33 of file cne_graph.h.

◆ CNE_NODE_ID_INVALID

#define CNE_NODE_ID_INVALID   UINT32_MAX

Invalid node id.

Definition at line 34 of file cne_graph.h.

◆ CNE_EDGE_ID_INVALID

#define CNE_EDGE_ID_INVALID   UINT16_MAX

Invalid edge id.

Definition at line 35 of file cne_graph.h.

◆ CNE_GRAPH_ID_INVALID

#define CNE_GRAPH_ID_INVALID   UINT16_MAX

◆ CNE_GRAPH_FENCE

#define CNE_GRAPH_FENCE   0xdeadbeef12345678ULL

Graph fence data.

Definition at line 37 of file cne_graph.h.

◆ CNE_GRAPH_BURST_SIZE_LOG2

#define CNE_GRAPH_BURST_SIZE_LOG2   8

Burst size in terms of log2 Object burst size of 256.

Definition at line 62 of file cne_graph.h.

◆ cne_graph_foreach_node

#define cne_graph_foreach_node (   count,
  off,
  graph,
  node 
)
Value:
for (count = 0, off = graph->nodes_start, node = CNE_PTR_ADD(graph, off); \
count < graph->nb_nodes; off = node->next, node = CNE_PTR_ADD(graph, off), count++)
#define CNE_PTR_ADD(ptr, x)
Definition: cne_common.h:235

Macro to browse cne_node object after the graph creation

Definition at line 329 of file cne_graph.h.

◆ CNE_NODE_SOURCE_F

#define CNE_NODE_SOURCE_F   (1ULL << 0)

Flag bits for cne_node_register.flags field Node type is source.

Definition at line 440 of file cne_graph.h.

◆ CNE_NODE_INPUT_F

#define CNE_NODE_INPUT_F   (1ULL << 1)

Node type is a input node not a source node

Definition at line 441 of file cne_graph.h.

◆ CNE_NODE_MASK_F

#define CNE_NODE_MASK_F   (CNE_NODE_SOURCE_F | CNE_NODE_INPUT_F)

Flag Mask value

Definition at line 442 of file cne_graph.h.

◆ CNE_NODE_REGISTER

#define CNE_NODE_REGISTER (   node)
Value:
CNE_INIT(cne_node_register_##node) \
{ \
node.parent_id = CNE_NODE_ID_INVALID; \
node.id = __cne_node_register(&node); \
}
#define CNE_INIT(func)
Definition: cne_common.h:189
cne_node_t __cne_node_register(const struct cne_node_register *node)
#define CNE_NODE_ID_INVALID
Definition: cne_graph.h:34

Register a static node.

The static node is registered through the constructor scheme, thereby, it can be used in a multi-process scenario.

Parameters
nodeValid node pointer with name, process function, and next_nodes.

Definition at line 468 of file cne_graph.h.

Typedef Documentation

◆ cne_graph_off_t

typedef uint32_t cne_graph_off_t

Graph offset type.

Definition at line 39 of file cne_graph.h.

◆ cne_node_t

typedef uint32_t cne_node_t

Node id type.

Definition at line 40 of file cne_graph.h.

◆ cne_edge_t

typedef uint16_t cne_edge_t

Edge id type.

Definition at line 41 of file cne_graph.h.

◆ cne_graph_t

typedef uint16_t cne_graph_t

Graph id type.

Definition at line 42 of file cne_graph.h.

◆ cne_node_process_t

typedef uint16_t(* cne_node_process_t) (struct cne_graph *graph, struct cne_node *node, void **objs, uint16_t nb_objs)

Node stats within cluster of graphs Node process function.

The function invoked when the worker thread walks on nodes using cne_graph_walk().

Parameters
graphPointer to the graph object.
nodePointer to the node object.
objsPointer to an array of objects to be processed.
nb_objsNumber of objects in the array.
Returns
Number of objects processed.
See also
cne_graph_walk()

Definition at line 94 of file cne_graph.h.

◆ cne_node_init_t

typedef int(* cne_node_init_t) (const struct cne_graph *graph, struct cne_node *node)

Node initialization function.

The function invoked when the user creates the graph using cne_graph_create()

Parameters
graphPointer to the graph object.
nodePointer to the node object.
Returns
  • 0: Success. -<0: Failure.
See also
cne_graph_create()

Definition at line 113 of file cne_graph.h.

◆ cne_node_fini_t

typedef void(* cne_node_fini_t) (const struct cne_graph *graph, struct cne_node *node)

Node finalization function.

The function invoked when the user destroys the graph using cne_graph_destroy().

Parameters
graphPointer to the graph object.
nodePointer to the node object.
See also
cne_graph_destroy()

Definition at line 128 of file cne_graph.h.

◆ cne_graph_cluster_stats_cb_t

typedef int(* cne_graph_cluster_stats_cb_t) (bool is_first, bool is_last, const struct cne_graph_cluster_node_stats *stats)

Graph cluster stats callback.

Parameters
is_firstFlag to denote that stats are of the first node.
is_lastFlag to denote that stats are of the last node.
statsNode cluster stats data.
Returns
  • 0: Success. -<0: Failure.

Definition at line 144 of file cne_graph.h.

Function Documentation

◆ cne_graph_create()

CNDP_API cne_graph_t cne_graph_create ( const char *  name,
const char **  patterns 
)

Create Graph.

Create memory reel, detect loops and find isolated nodes.

Parameters
nameUnique name for this graph.
patternsGraph node patterns, must be NULL terminated.
Returns
Unique graph id on success, CNE_GRAPH_ID_INVALID otherwise.
Examples
examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, and examples/l3fwd-graph/fwd.c.

◆ cne_graph_destroy()

CNDP_API int cne_graph_destroy ( cne_graph_t  id)

Destroy Graph.

Free Graph memory reel.

Parameters
idid of the graph to destroy.
Returns
0 on success, error otherwise.
Examples
examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, and examples/l3fwd-graph/fwd.c.

◆ cne_graph_from_name()

CNDP_API cne_graph_t cne_graph_from_name ( const char *  name)

Get graph id from graph name.

Parameters
nameName of the graph to get id.
Returns
Graph id on success, CNE_GRAPH_ID_INVALID otherwise.

◆ cne_graph_id_to_name()

CNDP_API char* cne_graph_id_to_name ( cne_graph_t  id)

Get graph name from graph id.

Parameters
idid of the graph to get name.
Returns
Graph name on success, NULL otherwise.

◆ cne_graph_export()

CNDP_API int cne_graph_export ( const char *  name,
FILE *  f 
)

Export the graph as graphviz dot file

Parameters
nameName of the graph to export.
fFile pointer to export the graph.
Returns
0 on success, error otherwise. Set of functions to be called to help format the graph export data

◆ cne_graph_export_cb()

CNDP_API int cne_graph_export_cb ( const char *  name,
FILE *  f,
cne_graph_export_t *  exp 
)

Export the graph information to a file and use the export functions to help build the data.

Parameters
nameThe name of the graph to export.
fThe file pointer to write the exported data, can be NULL and will use stdout.
expThe export function structure pointer.
Returns
0 on success or negative errno number on failure.

EBADF - exp function return an error. EINVAL - exp function or name is NULL. ENOENT - Did not find the graph named.

◆ cne_graph_max_count()

CNDP_API cne_graph_t cne_graph_max_count ( void  )

Get maximum number of graph available.

Returns
Maximum graph count.

◆ cne_graph_lookup()

CNDP_API struct cne_graph* cne_graph_lookup ( const char *  name)

Get graph object from its name.

Typical usage of this API is to get graph objects in the worker thread and call cne_graph_walk() in a loop.

Parameters
nameName of the graph.
Returns
Graph pointer on success, NULL otherwise.
See also
cne_graph_walk()
Examples
examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, and examples/l3fwd-graph/fwd.c.

◆ cne_graph_dump()

CNDP_API void cne_graph_dump ( FILE *  f,
cne_graph_t  id 
)

Dump the graph information to file.

Parameters
fFile pointer to dump graph info.
idGraph id to get graph info.

◆ cne_graph_list_dump()

CNDP_API void cne_graph_list_dump ( FILE *  f)

Dump all graph information to file

Parameters
fFile pointer to dump graph info.

◆ cne_graph_obj_dump()

CNDP_API void cne_graph_obj_dump ( FILE *  f,
struct cne_graph *  graph,
bool  all 
)

Dump graph information along with node info to file

Parameters
fFile pointer to dump graph info.
graphGraph pointer to get graph info.
alltrue to dump nodes in the graph.

◆ cne_graph_node_get()

CNDP_API struct cne_node* cne_graph_node_get ( cne_graph_t  graph_id,
cne_node_t  node_id 
)

Get node object with in graph from id.

Parameters
graph_idGraph id to get node pointer from.
node_idNode id to get node pointer.
Returns
Node pointer on success, NULL otherwise.

◆ cne_graph_node_get_by_name()

CNDP_API struct cne_node* cne_graph_node_get_by_name ( const char *  graph,
const char *  name 
)

Get node pointer with in graph from name.

Parameters
graphGraph name to get node pointer from.
nameNode name to get the node pointer.
Returns
Node pointer on success, NULL otherwise.

◆ cne_graph_get_node_by_name()

CNDP_API struct cne_node* cne_graph_get_node_by_name ( const struct cne_graph *  graph,
const char *  node_name 
)

Get node pointer within graph.

Parameters
graphPointer to the graph to locate the node.
node_nameNode name to get the node pointer.
Returns
Node pointer on success, NULL otherwise.

◆ cne_graph_cluster_stats_create()

CNDP_API struct cne_graph_cluster_stats* cne_graph_cluster_stats_create ( const struct cne_graph_cluster_stats_param prm)

Create graph stats cluster to aggregate runtime node stats.

Parameters
prmParameters including file pointer to dump stats, Graph pattern to create cluster and callback function.
Returns
Valid pointer on success, NULL otherwise.
Examples
examples/l3fwd-graph/fwd.c.

◆ cne_graph_cluster_stats_destroy()

CNDP_API void cne_graph_cluster_stats_destroy ( struct cne_graph_cluster_stats *  stat)

Destroy cluster stats.

Parameters
statValid cluster pointer to destroy.
Examples
examples/l3fwd-graph/fwd.c.

◆ cne_graph_cluster_stats_get()

CNDP_API void cne_graph_cluster_stats_get ( struct cne_graph_cluster_stats *  stat,
bool  skip_cb 
)

Get stats to application.

Parameters
[out]statCluster status.
skip_cbtrue to skip callback function invocation.
Examples
examples/l3fwd-graph/fwd.c.

◆ cne_graph_cluster_stats_reset()

CNDP_API void cne_graph_cluster_stats_reset ( struct cne_graph_cluster_stats *  stat)

Reset cluster stats to zero.

Parameters
statValid cluster stats pointer.

◆ cne_graph_stats_node_count()

CNDP_API int cne_graph_stats_node_count ( struct cne_graph_cluster_stats *  stat)

Return the number of nodes in cluster.

Parameters
statValid cluster stats pointer.
Returns
Number of nodes in cluster or -1 if stat pointer is NULL.

◆ __cne_node_register()

cne_node_t __cne_node_register ( const struct cne_node_register node)

Register new packet processing node. Nodes can be registered dynamically via this call or statically via the CNE_NODE_REGISTER macro.

Parameters
nodeValid node pointer with name, process function and next_nodes.
Returns
Valid node id on success, CNE_NODE_ID_INVALID otherwise.
See also
CNE_NODE_REGISTER()

◆ cne_node_clone()

CNDP_API cne_node_t cne_node_clone ( cne_node_t  id,
const char *  name 
)

Clone a node from static node(node created from CNE_NODE_REGISTER).

Parameters
idStatic node id to clone from.
nameName of the new node. The library prepends the parent node name to the user-specified name. The final node name will be, "parent node name" + "-" + name.
Returns
Valid node id on success, CNE_NODE_ID_INVALID otherwise.

◆ cne_node_from_name()

CNDP_API cne_node_t cne_node_from_name ( const char *  name)

Get node id from node name.

Parameters
nameValid node name. In the case of the cloned node, the name will be "parent node name" + "-" + name.
Returns
Valid node id on success, CNE_NODE_ID_INVALID otherwise.

◆ cne_node_id_to_name()

CNDP_API char* cne_node_id_to_name ( cne_node_t  id)

Get node name from node id.

Parameters
idValid node id.
Returns
Valid node name on success, NULL otherwise.

◆ cne_node_edge_count()

CNDP_API cne_edge_t cne_node_edge_count ( cne_node_t  id)

Get the number of edges(next-nodes) for a node from node id.

Parameters
idValid node id.
Returns
Valid edge count on success, CNE_EDGE_ID_INVALID otherwise.

◆ cne_node_edge_update()

CNDP_API cne_edge_t cne_node_edge_update ( cne_node_t  id,
cne_edge_t  from,
const char **  next_nodes,
uint16_t  nb_edges 
)

Update the edges for a node from node id.

Parameters
idValid node id.
fromIndex to update the edges from. CNE_EDGE_ID_INVALID is valid, in that case, it will be added to the end of the list.
next_nodesName of the edges to update.
nb_edgesNumber of edges to update.
Returns
Valid edge count on success, 0 otherwise.

◆ cne_node_edge_shrink()

CNDP_API cne_edge_t cne_node_edge_shrink ( cne_node_t  id,
cne_edge_t  size 
)

Shrink the edges to a given size.

Parameters
idValid node id.
sizeNew size to shrink the edges.
Returns
New size on success, CNE_EDGE_ID_INVALID otherwise.

◆ cne_node_edge_get()

CNDP_API cne_node_t cne_node_edge_get ( cne_node_t  id,
char *  next_nodes[] 
)

Get the edge names from a given node.

Parameters
idValid node id.
[out]next_nodesBuffer to copy the edge names. The NULL value is allowed in that case, the function returns the size of the array that needs to be allocated.
Returns
When next_nodes == NULL, it returns the size of the array else number of item copied.

◆ cne_node_max_count()

CNDP_API cne_node_t cne_node_max_count ( void  )

Get maximum nodes available.

Returns
Maximum nodes count.

◆ cne_node_dump()

CNDP_API void cne_node_dump ( FILE *  f,
cne_node_t  id 
)

Dump node info to file.

Parameters
fFile pointer to dump the node info.
idNode id to get the info.

◆ cne_node_list_dump()

CNDP_API void cne_node_list_dump ( FILE *  f)

Dump all node info to file.

Parameters
fFile pointer to dump the node info.

◆ cne_node_is_invalid()

static __cne_always_inline int cne_node_is_invalid ( cne_node_t  id)
static

Test the validity of node id.

Parameters
idNode id to check.
Returns
1 if valid id, 0 otherwise.

Definition at line 607 of file cne_graph.h.

◆ cne_edge_is_invalid()

static __cne_always_inline int cne_edge_is_invalid ( cne_edge_t  id)
static

Test the validity of edge id.

Parameters
idEdge node id to check.
Returns
1 if valid id, 0 otherwise.

Definition at line 622 of file cne_graph.h.

◆ cne_graph_is_invalid()

static __cne_always_inline int cne_graph_is_invalid ( cne_graph_t  id)
static

Test the validity of graph id.

Parameters
idGraph id to check.
Returns
1 if valid id, 0 otherwise.

Definition at line 637 of file cne_graph.h.

◆ cne_graph_has_stats_feature()

static __cne_always_inline int cne_graph_has_stats_feature ( void  )
static

Test stats feature support.

Returns
1 if stats enabled, 0 otherwise.

Definition at line 649 of file cne_graph.h.