This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tsg-service-chaining-…/common/include/utils.h
2024-07-17 15:47:48 +08:00

69 lines
2.2 KiB
C

#ifndef _UTILS_H
#define _UTILS_H
#ifdef __cplusplus
extern "C"
{
#endif
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define LOG_TAG_SCE "SCE"
#define LOG_TAG_POLICY "POLICY"
#define LOG_TAG_PKTIO "PACKET_IO"
#define LOG_TAG_RAWPKT "DATA_PACKET"
#define LOG_TAG_CTRLPKT "CTRL_PACKET"
#define LOG_TAG_SFMETRICS "SF_METRICS"
#define LOG_TAG_SFSTATUS "SF_STATUS"
#define LOG_TAG_UTILS "UTILS"
#define LOG_TAG_HEALTH_CHECK "HEALTH_CHECK"
#define LOG_TAG_TIMESTAMP "TIMESTAMP"
#define LOG_TAG_KAFKA "KAFKA"
#define ATOMIC_INC(x) __atomic_fetch_add(x, 1, __ATOMIC_RELAXED)
#define ATOMIC_DEC(x) __atomic_fetch_sub(x, 1, __ATOMIC_RELAXED)
#define ATOMIC_READ(x) __atomic_load_n(x, __ATOMIC_RELAXED)
#define ATOMIC_ZERO(x) __atomic_fetch_and(x, 0, __ATOMIC_RELAXED)
#define ATOMIC_ADD(x, y) __atomic_fetch_add(x, y, __ATOMIC_RELAXED)
#define ATOMIC_SET(x, y) __atomic_store_n(x, y, __ATOMIC_RELAXED)
#define likely(expr) __builtin_expect((expr), 1)
#define unlikely(expr) __builtin_expect((expr), 0)
#include <stdint.h>
#include <sys/types.h>
#include <netinet/in.h>
/******************************************************************************
* mutable_array
******************************************************************************/
struct mutable_array
{
uint64_t elems[128];
int num;
int size;
};
void mutable_array_init(struct mutable_array *array);
void mutable_array_add_elem(struct mutable_array *array, uint64_t elem);
void mutable_array_del_elem(struct mutable_array *array, uint64_t elem);
int mutable_array_is_full(struct mutable_array *array);
int mutable_array_count_elem(struct mutable_array *array);
int mutable_array_exist_elem(struct mutable_array *array, uint64_t elem);
int mutable_array_index_elem(struct mutable_array *array, int index);
/******************************************************************************
* device
******************************************************************************/
int get_ip_by_device_name(const char *dev_name, char *ip_str);
int get_mac_by_device_name(const char *dev_name, char *mac_str);
int str_to_mac(const char *mac_str, u_char mac[]);
#ifdef __cplusplus
}
#endif
#endif