CNDP  22.08.0
jcfg.h File Reference
#include <pthread.h>
#include <sched.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/queue.h>
#include <sys/un.h>
#include <bsd/sys/bitstring.h>
#include <json-c/json_object.h>
#include <json-c/json_tokener.h>
#include <json-c/json_util.h>
#include <json-c/json_visit.h>
#include <json-c/linkhash.h>
#include <cne_common.h>
#include <cne_log.h>
#include <cne_mmap.h>
#include <cne_thread.h>
#include <pktmbuf.h>

Go to the source code of this file.

Data Structures

struct  obj_value
 
struct  jcfg_hdr
 
struct  jcfg_opt
 
struct  jcfg_umem
 
struct  jcfg_lport
 
struct  jcfg_lgroup
 
struct  jcfg_thd
 
struct  jcfg_lport_group
 
struct  jcfg_user
 
struct  jcfg_list
 
struct  jcfg_data
 
union  jcfg_obj_t
 
struct  jcfg_info_s
 

Macros

#define APP_TAG   "application"
 
#define JCFG_TAG_NAMES
 
#define JCFG_COMMON_HDR(_t)
 
#define JCFG_LPORT_PMD_NAME   "pmd"
 
#define JCFG_LPORT_GROUP_NETDEV_NAMES_NAME   "netdevs"
 
#define jcfg_application_foreach(j, f, a)   jcfg_object_foreach(j, JCFG_APPLICATION_TYPE, f, a)
 
#define jcfg_num_applications(j)   jcfg_num_objects(j, JCFG_APPLICATION_TYPE)
 

Typedefs

typedef struct obj_value obj_value_t
 
typedef struct jcfg_hdr jcfg_hdr_t
 
typedef struct jcfg_opt jcfg_opt_t
 
typedef struct jcfg_umem jcfg_umem_t
 
typedef struct jcfg_lport jcfg_lport_t
 
typedef struct jcfg_lgroup jcfg_lgroup_t
 
typedef struct jcfg_thd jcfg_thd_t
 
typedef struct jcfg_lport_group jcfg_lport_group_t
 
typedef struct jcfg_user jcfg_user_t
 
typedef struct jcfg_list jcfg_list_t
 
typedef struct jcfg_data jcfg_data_t
 
typedef int jcfg_parse_cb_t(struct jcfg_info_s *jinfo, void *obj, void *arg, int idx)
 
typedef struct jcfg_info_s jcfg_info_t
 
typedef int jcfg_cb_t(jcfg_info_t *jinfo, void *obj, void *arg, int idx)
 

Enumerations

enum  jcfg_cb_type_t {
  JCFG_APPLICATION_TYPE , JCFG_DEFAULT_TYPE , JCFG_OPTION_TYPE , JCFG_UMEM_TYPE ,
  JCFG_LPORT_TYPE , JCFG_LGROUP_TYPE , JCFG_THREAD_TYPE , JCFG_LPORT_GROUP_TYPE ,
  JCFG_USER_TYPE , JCFG_MAX_TYPES
}
 
enum  obj_type_t
 
enum  {
}
 

Functions

CNDP_API int jcfg_object_foreach (jcfg_info_t *jinfo, jcfg_cb_type_t cbtype, jcfg_cb_t *func, void *arg)
 
CNDP_API void * jcfg_object_lookup (jcfg_info_t *jinfo, jcfg_cb_type_t cbtype, const char *name)
 
CNDP_API int jcfg_num_objects (jcfg_info_t *jinfo, jcfg_cb_type_t cbtype)
 
CNDP_API int jcfg_default_get (jcfg_info_t *jinfo, const char *name, uint64_t *val)
 
CNDP_API int jcfg_default_array_get (jcfg_info_t *jinfo, const char *name, obj_value_t **val_arr)
 
static int jcfg_default_get_bool (jcfg_info_t *jinfo, const char *name, uint32_t *v)
 
static int jcfg_default_get_u32 (jcfg_info_t *jinfo, const char *name, uint32_t *v)
 
static int jcfg_default_get_u16 (jcfg_info_t *jinfo, const char *name, uint16_t *v)
 
static int jcfg_default_get_string (jcfg_info_t *jinfo, const char *name, char **v)
 
CNDP_API int jcfg_option_get (jcfg_info_t *jinfo, const char *name, uint64_t *val)
 
CNDP_API int jcfg_option_array_get (jcfg_info_t *jinfo, const char *name, obj_value_t **val_arr)
 
static int jcfg_option_get_string (jcfg_info_t *jinfo, const char *name, char **v)
 
CNDP_API jcfg_info_tjcfg_parser (int flags, const char *s)
 
CNDP_API void jcfg_destroy (jcfg_info_t *jinfo)
 
CNDP_API int jcfg_decode (jcfg_info_t *jinfo, const char *key, void *arg)
 
CNDP_API int jcfg_socket_create (jcfg_info_t *jinfo, const char *runtime_dir)
 
CNDP_API void jcfg_socket_destroy (jcfg_info_t *jinfo)
 
CNDP_API int jcfg_add_decoder (const char *section, json_c_visit_userfunc *func)
 
CNDP_API int jcfg_del_decoder (const char *section)
 
CNDP_API json_c_visit_userfunc * jcfg_get_decoder (const char *section)
 
CNDP_API jcfg_data_tjcfg_get_data (jcfg_info_t *jinfo)
 
CNDP_API jcfg_umem_tjcfg_umem_by_index (jcfg_info_t *jinfo, int idx)
 
CNDP_API char * jcfg_lport_region (jcfg_lport_t *lport, uint32_t *objcnt)
 
CNDP_API int jcfg_json_string_set (jcfg_info_t *jinfo, const char *str)
 
CNDP_API struct json_object * jcfg_object_by_name (jcfg_info_t *jinfo, const char *key)
 
CNDP_API jcfg_lport_tjcfg_lport_by_index (jcfg_info_t *jinfo, int idx)
 
CNDP_API jcfg_thd_tjcfg_thd_by_index (jcfg_info_t *jinfo, int idx)
 
CNDP_API int jcfg_dump_object (struct json_object *obj)
 
CNDP_API int jcfg_dump_at (jcfg_info_t *jinfo, const char *key)
 
CNDP_API int jcfg_dump (jcfg_info_t *jinfo)
 
CNDP_API void jcfg_dump_info (void)
 

Detailed Description

JSON configuration using json-c

Definition in file jcfg.h.

Macro Definition Documentation

◆ APP_TAG

#define APP_TAG   "application"

The standard list of section names used in JCFG json-c files.

Definition at line 44 of file jcfg.h.

◆ JCFG_TAG_NAMES

#define JCFG_TAG_NAMES
Value:
{ \
APP_TAG, DEFAULT_TAG, OPTION_TAG, UMEM_TAG, LPORT_TAG, LGROUP_TAG, THREAD_TAG, \
LPORT_GROUP_TAG, USER_TAG, \
}

Macro to initialize a const char *tags[] type array for indexing with jcfg_tag_t.

Note
: make sure this matches the jcfg_cb_type_t enum order.

Definition at line 59 of file jcfg.h.

◆ JCFG_COMMON_HDR

#define JCFG_COMMON_HDR (   _t)
Value:
STAILQ_ENTRY(_t) next; \
char *name; \
char *desc; \
void *priv_; \
jcfg_cb_type_t cbtype

Common Header for all JCFG objects or groups The object callback type

Definition at line 124 of file jcfg.h.

◆ JCFG_LPORT_PMD_NAME

#define JCFG_LPORT_PMD_NAME   "pmd"

JCFG lport configuration names

Definition at line 183 of file jcfg.h.

◆ JCFG_LPORT_GROUP_NETDEV_NAMES_NAME

#define JCFG_LPORT_GROUP_NETDEV_NAMES_NAME   "netdevs"

JCFG lport group configuration names

Definition at line 246 of file jcfg.h.

◆ jcfg_application_foreach

#define jcfg_application_foreach (   j,
  f,
 
)    jcfg_object_foreach(j, JCFG_APPLICATION_TYPE, f, a)

Helper macros for each type of object to iterate over.

Definition at line 393 of file jcfg.h.

◆ jcfg_num_applications

#define jcfg_num_applications (   j)    jcfg_num_objects(j, JCFG_APPLICATION_TYPE)

Helper macros for getting the number of object in a section

Definition at line 444 of file jcfg.h.

Typedef Documentation

◆ obj_value_t

typedef struct obj_value obj_value_t

JCFG Object information

◆ jcfg_hdr_t

typedef struct jcfg_hdr jcfg_hdr_t

A template structure to be used as a generic overlay to the jcfg objects.

◆ jcfg_opt_t

typedef struct jcfg_opt jcfg_opt_t

JCFG option structure

◆ jcfg_umem_t

typedef struct jcfg_umem jcfg_umem_t

UMEM information for JCFG

◆ jcfg_lport_t

typedef struct jcfg_lport jcfg_lport_t

JCFG lport information

◆ jcfg_lgroup_t

typedef struct jcfg_lgroup jcfg_lgroup_t

JCFG lgroup for lcore allocations

◆ jcfg_thd_t

typedef struct jcfg_thd jcfg_thd_t

JCFG Thread information

◆ jcfg_lport_group_t

JCFG lport group information

◆ jcfg_user_t

typedef struct jcfg_user jcfg_user_t

A user defined object type

◆ jcfg_list_t

typedef struct jcfg_list jcfg_list_t

Simple structure to hold an array of object in a list.

The list array uses realloc() to grow the list.

◆ jcfg_data_t

typedef struct jcfg_data jcfg_data_t

Main structure to hold all of the jcfg configuration information

◆ jcfg_parse_cb_t

typedef int jcfg_parse_cb_t(struct jcfg_info_s *jinfo, void *obj, void *arg, int idx)

JCFG Parser callback function prototype. Called once for each parsed object in the JSON file.

Parameters
jinfoThe jcfg information structure pointer
objThe object (application, thread, lport, ...) pointer
argThe argument for the callback passed in by the user.
idxThe index pointer in the JSON configuration relative to the group being parsed.
Returns
0 on success or -1 on error

Definition at line 329 of file jcfg.h.

◆ jcfg_info_t

typedef struct jcfg_info_s jcfg_info_t

The JCFG basic information structure

◆ jcfg_cb_t

typedef int jcfg_cb_t(jcfg_info_t *jinfo, void *obj, void *arg, int idx)

Object callback functions

Parameters
jinfoThe jcfg information structure pointer
objThe object (application, thread, lport, ...) pointer
argThe argument for the callback passed in by the user.
idxThe index pointer in the JSON configuration relative to the group being parsed.
Returns
0 on success or -1 on error

Definition at line 371 of file jcfg.h.

Enumeration Type Documentation

◆ jcfg_cb_type_t

Enumeration of jcfg process callback types

Enumerator
JCFG_APPLICATION_TYPE 

Application Callback flag

JCFG_DEFAULT_TYPE 

Default option Callback flag

JCFG_OPTION_TYPE 

Options Callback flag

JCFG_UMEM_TYPE 

UMEM Callback flag

JCFG_LPORT_TYPE 

LPORT Callback flag

JCFG_LGROUP_TYPE 

LGROUP Callback flag

JCFG_THREAD_TYPE 

Thread Callback flag

JCFG_LPORT_GROUP_TYPE 

LPORT GROUP Callback flag

JCFG_USER_TYPE 

User Callback flag

JCFG_MAX_TYPES 

Maximum tag types

Definition at line 68 of file jcfg.h.

◆ obj_type_t

enum obj_type_t

Known types of objects we can have in a JSON file for JCFG.

Definition at line 87 of file jcfg.h.

◆ anonymous enum

anonymous enum

Flags used for jcfg_info_t.flags value

Enumerator
JCFG_INFO_VERBOSE 

Enable VERBOSE printout after parsing json data

JCFG_DEBUG_DECODING 

Debug the JCGF decoding of json text

JCFG_DEBUG_PARSING 

Debug the JCGF parsing of json text

JCFG_INFO_STRICT_FLAG 

Force strict JSON parsing, no JSON-C support

JCFG_PARSE_FILE 

Get JSON text from a file

JCFG_PARSE_SOCKET 

Get the JSON text from a socket or local domain socket

JCFG_PARSE_STRING 

Use the string as the JSON text data

Definition at line 346 of file jcfg.h.

Function Documentation

◆ jcfg_object_foreach()

CNDP_API int jcfg_object_foreach ( jcfg_info_t jinfo,
jcfg_cb_type_t  cbtype,
jcfg_cb_t func,
void *  arg 
)

Foreach routines for each object type.

Parameters
jinfoThe jcfg information structure pointer
cbtypeThe jcfg_cb_type_t enum value.
funcThe function to callback for each object.
argThe user supplied argument passed to the func function
Returns
0 on success or -1 on error

◆ jcfg_object_lookup()

CNDP_API void* jcfg_object_lookup ( jcfg_info_t jinfo,
jcfg_cb_type_t  cbtype,
const char *  name 
)

Object section lookup by name routines.

Parameters
jinfoThe jcfg information structure pointer
cbtypeThe JCFG Tag Type enum value
nameThe name string for the object in the JSON group being searched.
Returns
The object pointer or NULL if not found or error

◆ jcfg_num_objects()

CNDP_API int jcfg_num_objects ( jcfg_info_t jinfo,
jcfg_cb_type_t  cbtype 
)

Count the number of objects in a given group or type (lport, thread, ...)

Parameters
jinfoThe jcfg information structure pointer
cbtypeThe type of the object to count
Returns
The number of object in the given type.

◆ jcfg_default_get()

CNDP_API int jcfg_default_get ( jcfg_info_t jinfo,
const char *  name,
uint64_t *  val 
)

Get the value of the defaults section given of the same name

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
valLocation to place the found object data.
Returns
obj_type_t (boolean, string or int) on success and val is valid or -1 on error

◆ jcfg_default_array_get()

CNDP_API int jcfg_default_array_get ( jcfg_info_t jinfo,
const char *  name,
obj_value_t **  val_arr 
)

Get the array of the defaults section given of the same name

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the array to search for in the default list.
val_arrLocation to place the found object data array.
Returns
0 on success and val_arr is valid or -1 on error

◆ jcfg_default_get_bool()

static int jcfg_default_get_bool ( jcfg_info_t jinfo,
const char *  name,
uint32_t *  v 
)
inlinestatic

Get the value of the default section given of the same name for a boolean value

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
vLocation to place the found object data.
Returns
0 on success and val is valid or -1 on error

Definition at line 494 of file jcfg.h.

◆ jcfg_default_get_u32()

static int jcfg_default_get_u32 ( jcfg_info_t jinfo,
const char *  name,
uint32_t *  v 
)
inlinestatic

Get the value of the default section given of the same name for a u32 bit value

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
vLocation to place the found object data.
Returns
0 on success and val is valid or -1 on error
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

Definition at line 517 of file jcfg.h.

◆ jcfg_default_get_u16()

static int jcfg_default_get_u16 ( jcfg_info_t jinfo,
const char *  name,
uint16_t *  v 
)
inlinestatic

Get the value of the default section given the name for a u16 bit value

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
vLocation to place the found object data.
Returns
0 on success and val is valid or -1 on error

Definition at line 540 of file jcfg.h.

◆ jcfg_default_get_string()

static int jcfg_default_get_string ( jcfg_info_t jinfo,
const char *  name,
char **  v 
)
inlinestatic

Get the value of the default section given of the same name for a string value

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
vLocation to place the found object data.
Returns
0 on success and val is valid or -1 on error

Definition at line 563 of file jcfg.h.

◆ jcfg_option_get()

CNDP_API int jcfg_option_get ( jcfg_info_t jinfo,
const char *  name,
uint64_t *  val 
)

Get the value of the options section given of the same name

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
valLocation to place the found object data.
Returns
obj_type_t (boolean, string or int) on success and val is valid or -1 on error

◆ jcfg_option_array_get()

CNDP_API int jcfg_option_array_get ( jcfg_info_t jinfo,
const char *  name,
obj_value_t **  val_arr 
)

Get the array of the options section given of the same name

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the array to search for in the default list.
val_arrLocation to place the found object data array.
Returns
0 on success and val_arr is valid or -1 on error
Examples
examples/cnet-graph/cnet-graph.c, and examples/cnet-quic/cnet-quic.c.

◆ jcfg_option_get_string()

static int jcfg_option_get_string ( jcfg_info_t jinfo,
const char *  name,
char **  v 
)
inlinestatic

Get the value of the options section given of the same name for a string value

Parameters
jinfoThe jcfg information structure pointer
nameThe string name of the object to search for in the default list.
vLocation to place the found object data.
Returns
0 on success and val is valid or -1 on error

Definition at line 614 of file jcfg.h.

◆ jcfg_parser()

CNDP_API jcfg_info_t* jcfg_parser ( int  flags,
const char *  s 
)

Load and parse a json-c or json file, socket or string.

Parameters
flagsFlags used to configure jcfg JSON parsing.
sThe json-c or json file or string to load and parse.
Returns
The pointer to jcfg_info_t or NULL on error.
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, examples/l3fwd-graph/parse-args.c, and examples/phil/parse-args.c.

◆ jcfg_destroy()

CNDP_API void jcfg_destroy ( jcfg_info_t jinfo)

Free the jcfg structure

Parameters
jinfoPointer to jcfg_info_t structure to free.

◆ jcfg_decode()

CNDP_API int jcfg_decode ( jcfg_info_t jinfo,
const char *  key,
void *  arg 
)

Decode the Application JSON file.

Parameters
jinfoThe jcfg_info_t pointer from jcfg_create()
keyThe key to search for in the JSON data, if NULL use the root JSON object If Key is given then a user defined function must be provided.
argArgument to use in func callback. If arg is NULL then jinfo is passed to callback.
Returns
0 on success or -1 on error

◆ jcfg_socket_create()

CNDP_API int jcfg_socket_create ( jcfg_info_t jinfo,
const char *  runtime_dir 
)

Create the thread and socket to listen for json configuration

Parameters
jinfoThe struct jcfg_info pointer from jcfg_create().
runtime_dirThe path to the runtime directory can be NULL to use the default path
Returns
0 on success or -1 on error

◆ jcfg_socket_destroy()

CNDP_API void jcfg_socket_destroy ( jcfg_info_t jinfo)

Destroy the thread which is waiting for json configuration

Parameters
jinfoThe struct jcfg_info pointer

◆ jcfg_add_decoder()

CNDP_API int jcfg_add_decoder ( const char *  section,
json_c_visit_userfunc *  func 
)

Add a decoder for the user part of the json-C file.

Parameters
sectionThe section name to use for locating the JSON section to decode.
funcThe json_c_visit_userfunc pointer
Returns
0 on success or -1 on error

◆ jcfg_del_decoder()

CNDP_API int jcfg_del_decoder ( const char *  section)

Delete a decoder from the list

Parameters
sectionThe section name to use for locating the JSON section to decode.
Returns
0 on success or -1 on error

◆ jcfg_get_decoder()

CNDP_API json_c_visit_userfunc* jcfg_get_decoder ( const char *  section)

Get a decoder by section name

Parameters
sectionThe section name to use for locating the JSON section to decode.
Returns
The json_c_visit_userfunc pointer if found else NULL

◆ jcfg_get_data()

CNDP_API jcfg_data_t* jcfg_get_data ( jcfg_info_t jinfo)

Return the internal data pointer in struct jcfg.

Parameters
jinfoThe jcfg_info_t pointer for the JCFG configuration
Returns
NULL on error or pointer to jcfg_data_t structure.

◆ jcfg_umem_by_index()

CNDP_API jcfg_umem_t* jcfg_umem_by_index ( jcfg_info_t jinfo,
int  idx 
)

Return the UMEM pointer for the given ID value.

Parameters
jinfoThe jcfg information structure pointer.
idxThe ID or index value to locate.
Returns
NULL if id is invalid or the jcfg_umem_t pointer.

◆ jcfg_lport_region()

CNDP_API char* jcfg_lport_region ( jcfg_lport_t lport,
uint32_t *  objcnt 
)

Return the memory address of the region in UMEM area.

Parameters
lportThe jcfg_lport_t pointer for the lport.
objcntThe uint32_t variable to place the number of objcnt in the region.
Returns
The address for the lport region
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, and examples/l3fwd-graph/parse-args.c.

◆ jcfg_json_string_set()

CNDP_API int jcfg_json_string_set ( jcfg_info_t jinfo,
const char *  str 
)

Set the JSON string data for parsing later

Parameters
jinfoThe pointer created from jcfg_create().
strThe pointer to JSON text, can be NULL to free resources.
Returns
0 on success or -1 on error

◆ jcfg_object_by_name()

CNDP_API struct json_object* jcfg_object_by_name ( jcfg_info_t jinfo,
const char *  key 
)

Return the JSON object pointer for the given jcfg_info_t pointer.

Parameters
jinfoThe jcfg_info_t pointer containing the JSON root object
keyThe key to search for in the JOSN object, can be NULL.
Returns
NULL on error or JSON object pointer, if key is NULL return root object.

◆ jcfg_lport_by_index()

CNDP_API jcfg_lport_t* jcfg_lport_by_index ( jcfg_info_t jinfo,
int  idx 
)

Return the lport pointer for the given ID value.

Parameters
jinfoThe jcfg information structure pointer.
idxThe ID or index value to locate.
Returns
NULL if id is invalid or the jcfg_lport_t pointer.
Examples
examples/cndpfwd/acl-func.c, and examples/cndpfwd/main.c.

◆ jcfg_thd_by_index()

CNDP_API jcfg_thd_t* jcfg_thd_by_index ( jcfg_info_t jinfo,
int  idx 
)

Return the thread pointer for the given ID value.

Parameters
jinfoThe jcfg information structure pointer.
idxThe ID or index value to locate.
Returns
NULL if id is invalid or the jcfg_thd_t pointer.

◆ jcfg_dump_object()

CNDP_API int jcfg_dump_object ( struct json_object *  obj)

Dump out the json_object, by walking the object tree.

Parameters
objStart dumping at this object
Returns
0 on success or -1 on error

◆ jcfg_dump_at()

CNDP_API int jcfg_dump_at ( jcfg_info_t jinfo,
const char *  key 
)

Dump out the json_object by key, by walking the object tree.

Parameters
jinfoThe jcfg_info_t pointer holding the json root object
keyStart dumping at this key
Returns
0 on success or -1 on error

◆ jcfg_dump()

CNDP_API int jcfg_dump ( jcfg_info_t jinfo)

Dump out the json_object from the root, by walking the object tree.

Parameters
jinfoThe jcfg_info_t pointer holding the json root object
Returns
0 on success or -1 on error

◆ jcfg_dump_info()

CNDP_API void jcfg_dump_info ( void  )

Dump out some information about jcfg structures