205 lines
6.9 KiB
C
205 lines
6.9 KiB
C
/*
|
|
* Copyright (c) 1991-2016 by Celoxica Ltd.
|
|
*
|
|
* For licensing information please see the supplied COPYING file
|
|
*
|
|
*/
|
|
#ifndef CLX_LIBUTILS_H
|
|
#define CLX_LIBUTILS_H
|
|
|
|
#include <clx-lib-internal/clx.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
#include <net/ethernet.h>
|
|
#include <linux/in.h>
|
|
#include <linux/ip.h>
|
|
#include <linux/udp.h>
|
|
#include <net/if.h>
|
|
|
|
typedef struct clx_minmax {
|
|
uint64_t mm_min;
|
|
uint64_t mm_max;
|
|
} clx_minmax_t;
|
|
|
|
static inline void clxu_minmax_init(clx_minmax_t *mm)
|
|
{
|
|
mm->mm_min = -1UL;
|
|
mm->mm_max = 0;
|
|
}
|
|
|
|
static inline void clxu_minmax_update(clx_minmax_t *mm, const uint64_t val)
|
|
{
|
|
if (val < mm->mm_min)
|
|
mm->mm_min = val;
|
|
if (val > mm->mm_max)
|
|
mm->mm_max = val;
|
|
}
|
|
|
|
static inline int clxu_str_to_minmax(const char *str, clx_minmax_t *mm)
|
|
{
|
|
int err;
|
|
|
|
clx_return_val_if_fail(str, -EINVAL);
|
|
clx_return_val_if_fail(mm, -EINVAL);
|
|
|
|
err = clx_str_to_size(str, &mm->mm_min);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if (str[err] != ',')
|
|
return (&str[err] - str);
|
|
|
|
err = clx_str_to_size(&str[++err], &mm->mm_max);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
return (&str[err] - str);
|
|
}
|
|
|
|
#define CLX_MINMAX_FMT "%lu/%lu"
|
|
#define CLX_MINMAX_FMTf "%2.f/%2.f"
|
|
|
|
#define CLX_MINMAX_ARGS(_mm) (_mm)->mm_min, (_mm)->mm_max
|
|
|
|
#define CLX_RANGE_FMT "%lu,%lu,%lu,%s"
|
|
#define CLX_RANGE_ARGS(_r) (_r)->r_min, (_r)->r_max, (_r)->r_step, (_r)->r_step ? "linear" : "rand"
|
|
|
|
int clxu_get_mtu(const char *iface, unsigned *mtup);
|
|
int clxu_get_iface_addrs(const char *iface,
|
|
uint32_t *be_ipaddr, unsigned char *be_macaddr[ETH_ALEN]);
|
|
int clxu_arp_resolve(const char *iface_name, const uint32_t dest_ip,
|
|
unsigned char dest_mac[ETH_ALEN]);
|
|
|
|
typedef enum {
|
|
CLXU_STATS_FLAGS_FIRST_BIT = 0,
|
|
CLXU_STATS_FLAGS_LAST_BIT,
|
|
CLXU_STATS_FLAGS_STATS_GLOBAL_BIT,
|
|
CLXU_STATS_FLAGS_STATS_SAMPLE_BIT,
|
|
CLXU_STATS_FLAGS_STATS_BIT_NR,
|
|
} clxu_stats_flags_bit_t;
|
|
|
|
const char *clxu_stats_flags_bit_to_str(clxu_stats_flags_bit_t b);
|
|
|
|
typedef enum {
|
|
CLXU_STATS_FLAGS_FIRST = 1 << CLXU_STATS_FLAGS_FIRST_BIT,
|
|
CLXU_STATS_FLAGS_LAST = 1 << CLXU_STATS_FLAGS_LAST_BIT,
|
|
CLXU_STATS_FLAGS_STATS_GLOBAL = 1 << CLXU_STATS_FLAGS_STATS_GLOBAL_BIT,
|
|
CLXU_STATS_FLAGS_STATS_SAMPLE = 1 << CLXU_STATS_FLAGS_STATS_SAMPLE_BIT,
|
|
} clxu_stats_flags_t;
|
|
|
|
const char *clxu_stats_flags_to_str(clxu_stats_flags_t f);
|
|
const char *clxu_stats_flags_bit_to_str(clxu_stats_flags_bit_t f);
|
|
|
|
typedef enum {
|
|
CLXU_STATS_OUTPUT_HUMAN = 1 << 0,
|
|
CLXU_STATS_OUTPUT_PARSABLE = 1 << 1,
|
|
} clxu_stats_output_type_t;
|
|
|
|
typedef void clxu_stats_t;
|
|
|
|
int clxu_stats_str_to_flags(const char *str, clxu_stats_flags_t *flagsp);
|
|
|
|
int clxu_stats_alloc(const clx_pipeline_t *pipeline, clxu_stats_t **statsp);
|
|
void clxu_stats_free(clxu_stats_t *stats);
|
|
void clxu_stats_print(const clxu_stats_t *stats, clxu_stats_flags_t flags,
|
|
clxu_stats_output_type_t oflags);
|
|
|
|
int clxu_run_pipeline(clx_pipeline_t *pipeline,
|
|
int share, clx_pipeline_state_t state,
|
|
unsigned long stats_tick,
|
|
clxu_stats_output_type_t oflags,
|
|
clxu_stats_flags_t flags,
|
|
uint64_t wait_start);
|
|
|
|
int clxu_run_pipeline_from_json_node(const char *name, clx_json_node_t *root_node,
|
|
unsigned long stats_tick,
|
|
clxu_stats_output_type_t oflags,
|
|
clxu_stats_flags_t flags,
|
|
uint64_t wait_start);
|
|
|
|
int clxu_dump_json_buf_to_file(const char *json_buf, const char *path);
|
|
|
|
int clxu_pipeline_probe_raw_output(const char *pname, const char *elmname);
|
|
|
|
static inline void clxu_usage_quantities(void)
|
|
{
|
|
printf("\n");
|
|
printf("\t* All quantities may be postfixed with 'k' 'm' 'g' 'K' 'M' or 'G' when relevant\n");
|
|
}
|
|
|
|
static inline void clxu_usage_uri(void)
|
|
{
|
|
printf("\n");
|
|
printf("\t"USAGE_SECTION_FMT" is of the form 'PROTO://IPV4:UDPPORT[,VLANID]'\n", "URI");
|
|
printf("\t"USAGE_SECTION_FMT" maybe be one of:\n", "PROTO");
|
|
printf("\t\t%-16s: Offloaded UDP protocol\n", "udp");
|
|
printf("\t\t%-16s: Non-Offloaded (RAW) UDP protocol\n", "udp-raw");
|
|
}
|
|
|
|
static inline void clxu_usage_range(void)
|
|
{
|
|
printf("\n");
|
|
printf("\t"USAGE_SECTION_FMT" maybe be one of:\n", "RANGE");
|
|
printf("\t\t%-16s: fixed value\n", "MIN");
|
|
printf("\t\t%-16s: sequential value from MIN to MAX (inclusive), incremented by 1\n", "MIN-MAX");
|
|
printf("\t\t%-16s: sequential value from MIN to MAX (inclusive), incremented by STEP\n", "MIN-MAX,STEP");
|
|
printf("\t\t%-16s: same as above, implicit start from 0\n", "-MAX[,STEP]");
|
|
printf("\t\t%-16s: random value from MIN to MAX (inclusive)\n", "MIN~MAX");
|
|
printf("\t\t%-16s: same as above, implicit start from 0\n", "~MAX");
|
|
}
|
|
|
|
static inline void clxu_usage_datetime(void)
|
|
{
|
|
printf("\n");
|
|
printf("\t"USAGE_SECTION_FMT" may be formatted as:\n", "DATETIME");
|
|
printf("\t\t%-24s%s\n", "\"AAAA-MM-DD hh:mm:ss\"", "");
|
|
printf("\t\t%-24s%s\n", "\"AAAA-MM-DD hh:mm\"", "");
|
|
printf("\t\t%-24s%s\n", "\"AAAA-MM-DD\"", "");
|
|
printf("\t\t%-24s%s\n", "\"MM-DD hh:mm:ss\"", "");
|
|
printf("\t\t%-24s%s\n", "\"MM-DD hh:mm\"", "");
|
|
printf("\t\t%-24s%s\n", "\"MM-DD\"", "");
|
|
printf("\t\t%-24s%s\n", "\"hh:mm:ss\"", "");
|
|
printf("\t\t%-24s%s\n", "\"hh:mm:ss\"", "");
|
|
printf("\t\t%-24s%s\n", "\"hh:mm:ss\"", "");
|
|
printf("\t\t%-24s%s\n", "\"+ss\"", "");
|
|
printf("\n");
|
|
printf("\t\twhere:\n");
|
|
printf("\t\t - 'AAAA', 'MM' and 'DD' are the year, month and day\n");
|
|
printf("\t\t respectively (set to current date if not specified)\n");
|
|
printf("\t\t - 'hh', 'mm' and 'ss' are the hour, minutes and seconds\n");
|
|
printf("\t\t respectively (set to 0 if not specified)\n");
|
|
printf("\t\t - '+ss' is equivalent to \"now + X seconds\"\n");
|
|
}
|
|
|
|
static inline void clxu_usage_stats_flags(void)
|
|
{
|
|
unsigned i;
|
|
|
|
printf("\n");
|
|
printf("\t"USAGE_SECTION_FMT" may be the combination (comma separated) of:\n",
|
|
"SFLAGS");
|
|
printf("\n");
|
|
for (i = 0; i < CLXU_STATS_FLAGS_STATS_BIT_NR; i++)
|
|
printf("\t\t%-24s%s\n", clxu_stats_flags_bit_to_str(i), "");
|
|
}
|
|
|
|
static inline void clxu_usage_chklvl(void)
|
|
{
|
|
printf("\n");
|
|
printf("\t"USAGE_SECTION_FMT" may be one of:\n", "CHKLVL");
|
|
printf("\t\t0 : almost no checks (channels within boundaries)\n");
|
|
printf("\t\t1 : CHKLVL0 + header validated (buffer-size, channel sequence, channels)\n");
|
|
printf("\t\t2 : CHKLVL1 + global sequence validated (when possible, buffer big enough\n");
|
|
printf("\t\t3 : CHKLVL1 + data validated\n");
|
|
printf("\t\t4 : CHKLVL2 & CHKLVL3\n");
|
|
}
|
|
|
|
#endif /* CLX_LIBUTILS_H */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-file-style: "clx"
|
|
* End:
|
|
* vi: set cino=(0 tabstop=8 softtabstop=4 shiftwidth=4 expandtab:
|
|
*/
|