summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author童宗振 <[email protected]>2024-04-16 09:57:09 +0000
committer童宗振 <[email protected]>2024-04-16 09:57:09 +0000
commit134ef8b0b14ef76c6c0fec7e998196b19e73722a (patch)
tree4d77704cce1a6d6ad03be51441021392e8448296 /include
parent1f413abebc4c2b8b7b6457a717a9d9d7c6b74ae7 (diff)
Adjust file path
Diffstat (limited to 'include')
-rw-r--r--include/common.h54
-rw-r--r--include/config.h52
-rw-r--r--include/job_ctx.h21
-rw-r--r--include/kafka.h6
-rw-r--r--include/maat.h6
-rw-r--r--include/mocking.h6
-rw-r--r--include/trace_output.h6
7 files changed, 151 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h
new file mode 100644
index 0000000..93e0366
--- /dev/null
+++ b/include/common.h
@@ -0,0 +1,54 @@
+#pragma once
+#include "marsio.h"
+
+#include <zlog.h>
+
+#include <assert.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#ifndef MR_SYMBOL_MAX
+#define MR_SYMBOL_MAX 64
+#endif
+
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif /* likely */
+
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif /* unlikely */
+
+#define TELEMETRY_DIM(a) (sizeof(a) / sizeof((a)[0]))
+
+#define DP_TRACE_VERIFY(condition, fmt, ...) \
+ do \
+ { \
+ if (!(condition)) \
+ { \
+ dzlog_error(fmt, ##__VA_ARGS__); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
+#define DP_TRACE_NO_ROLE 0
+#define DP_TRACE_ROLE 1
+#define DP_TELEMETRY_ROLE 2
+
+extern struct mr_instance * mr_instance;
+
+static bool is_directory_exists(const char * path)
+{
+ struct stat info;
+ if (stat(path, &info) != 0)
+ return false;
+ return S_ISDIR(info.st_mode) == 1;
+}
+
+static bool is_file_exists(const char * path)
+{
+ return access(path, F_OK) == 0;
+} \ No newline at end of file
diff --git a/include/config.h b/include/config.h
new file mode 100644
index 0000000..de8778d
--- /dev/null
+++ b/include/config.h
@@ -0,0 +1,52 @@
+#pragma once
+#include "common.h"
+
+#include <event.h>
+#include <librdkafka/rdkafka.h>
+
+#include <limits.h>
+#include <sched.h>
+#include <stdint.h>
+
+struct config
+{
+ char absolute_path[PATH_MAX];
+
+ char config_path[PATH_MAX];
+ char dy_config_path[PATH_MAX];
+ char zlog_config_path[PATH_MAX];
+
+ cpu_set_t cpu_set_io;
+
+ // device Information
+ char * sled_ip;
+ char device_group[MR_SYMBOL_MAX];
+
+ // kafka
+ char topic_name[MR_SYMBOL_MAX];
+ char broker_list[1024];
+ char sasl_username[MR_SYMBOL_MAX];
+ char sasl_password[MR_SYMBOL_MAX];
+
+ // maat
+ unsigned int maat_log_level;
+ unsigned int maat_input_mode;
+ char table_schema[PATH_MAX];
+ char json_cfg_file[PATH_MAX];
+
+ char redis_server[MR_SYMBOL_MAX];
+ char redis_port_range[MR_SYMBOL_MAX];
+ int redis_db_idx;
+
+ // dp trace
+ char dp_trace_dir[PATH_MAX];
+ unsigned int dp_trace_file_max_size_in_KB;
+ unsigned int dp_trace_merge_timeout;
+ struct dp_trace_job_desc desc[DP_TRACE_JOB_NUM_MAX];
+};
+
+const struct config * config_create(const char * config_path, const char * dy_config_path);
+const struct config * global_config_get();
+void global_config_destroy();
+void config_load();
+void dynamic_config_load_and_apply(); \ No newline at end of file
diff --git a/include/job_ctx.h b/include/job_ctx.h
new file mode 100644
index 0000000..6ce69f4
--- /dev/null
+++ b/include/job_ctx.h
@@ -0,0 +1,21 @@
+#pragma once
+#include "marsio.h"
+#include <uuid/uuid.h>
+
+struct dp_trace_telemetry_desc
+{
+ uuid_t uuid;
+ char job_name[128];
+ struct dp_trace_job_desc job_desc;
+};
+
+void job_rule_apply(struct dp_trace_job_desc desc[], unsigned int nr_desc, uint8_t role);
+int job_id_to_index(job_bitmap_t job_id);
+job_bitmap_t index_to_job_id(unsigned int index);
+int is_job_id_used(job_bitmap_t job_id);
+uint8_t job_id_role_get(job_bitmap_t job_id);
+
+void telemetry_job_add_cb(const char * table_name, int table_id, const char * key, const char * table_line, void ** ad,
+ long argl, void * argp);
+void telemetry_job_del_cb(int table_id, void ** ad, long argl, void * argp);
+void telemetry_job_uuid_get(job_bitmap_t job_id, unsigned char * uu); \ No newline at end of file
diff --git a/include/kafka.h b/include/kafka.h
new file mode 100644
index 0000000..197c4f8
--- /dev/null
+++ b/include/kafka.h
@@ -0,0 +1,6 @@
+#pragma once
+#include <librdkafka/rdkafka.h>
+
+rd_kafka_t * kafka_handle_create(const char * brokerlist, const char * sasl_username, const char * sasl_passwd);
+rd_kafka_topic_t * kafka_topic_new(rd_kafka_t * rk, const char * topic, rd_kafka_topic_conf_t * conf);
+int kafka_produce(rd_kafka_topic_t * rkt, void * payload, size_t len); \ No newline at end of file
diff --git a/include/maat.h b/include/maat.h
new file mode 100644
index 0000000..ca9ea7d
--- /dev/null
+++ b/include/maat.h
@@ -0,0 +1,6 @@
+#pragma once
+
+#define MAAT_INPUT_JSON 0
+#define MAAT_INPUT_REDIS 1
+
+void dp_trace_maat_init(); \ No newline at end of file
diff --git a/include/mocking.h b/include/mocking.h
new file mode 100644
index 0000000..d509081
--- /dev/null
+++ b/include/mocking.h
@@ -0,0 +1,6 @@
+#pragma once
+#include <librdkafka/rdkafka.h>
+
+rd_kafka_t * __wrap_kafka_handle_create(const char * brokerlist, const char * sasl_username, const char * sasl_passwd);
+rd_kafka_topic_t * __wrap_kafka_topic_new(rd_kafka_t * rk, const char * topic, rd_kafka_topic_conf_t * conf);
+int __wrap_kafka_produce(rd_kafka_topic_t * rkt, void * payload, size_t len); \ No newline at end of file
diff --git a/include/trace_output.h b/include/trace_output.h
new file mode 100644
index 0000000..485e607
--- /dev/null
+++ b/include/trace_output.h
@@ -0,0 +1,6 @@
+#pragma once
+#include "common.h"
+
+void dp_trace_output_init();
+void * dp_trace_process_thread(void * arg);
+void dp_trace_pcapng_merger(job_bitmap_t job_id); \ No newline at end of file