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-…/platform/include/packet_trace.h

136 lines
6.7 KiB
C
Raw Normal View History

#ifndef _PACKET_TRACE_H
#define _PACKET_TRACE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include "utils.h"
#include "policy.h"
#include <marsio.h>
/*
* SCE packet trace info format
*
* PACKET_TRACE_ON_NEW : "(Packet I/O) new packet"
* PACKET_TRACE_ON_FREE : "(Packet I/O) free packet"
* PACKET_TRACE_ON_CTRL : "(Session Synchronization) ${MSG}"
*
* Service Function Path (SFP) https://datatracker.ietf.org/doc/html/rfc7665
*
* PACKET_TRACE_ON_POLICY : "(Policy) rule_list: [${Rule_ID1}, ${Rule_ID2}, ...], SFP_list: [${SF_ID1}, ${SF_ID2}, ...]"
* PACKET_TRACE_ON_CHAIN : "(Forwarder) SF_id: ${SF_ID}, fwd_type: ${FWD_TYPE}, pkt_dir: ${PKT_DIR}, pkt_type: ${PKT_TYPE}, state: ${STATE} ${ACTION}"
*
* ${FWD_TYPE}
* steering
* mirroring
*
* ${PKT_DIR}
* I2E
* E2I
*
* ${PKT_TYPE}
* raw
* decrypted
*
* ${STATE}
* success
* failure
*
* ${ACTION}
* bypass
* block
* re-dispatch block
* re-dispatch bypass
* re-dispatch bypass(health SF limit)
*
* bypass(default)
* bypass(invalid policy)
*/
static inline int rule_id_tostring(struct mutable_array *rule_ids, char *buffer, int size)
{
int used = 0;
used += snprintf(buffer + used, size - used, "[");
for (int i = 0; i < rule_ids->num; i++)
{
used += snprintf(buffer + used, size - used, "%lu", rule_ids->elems[i]);
if (i < rule_ids->num - 1)
{
used += snprintf(buffer + used, size - used, ", ");
}
}
used += snprintf(buffer + used, size - used, "]");
return used;
}
static inline int sf_id_tostring(struct selected_chaining *chain, char *buffer, int size)
{
int used = 0;
used += snprintf(buffer + used, size - used, "[");
for (int i = 0; i < chain->chaining_used; i++)
{
used += snprintf(buffer + used, size - used, "%d", chain->chaining[i].sf_profile_id);
if (i < chain->chaining_used - 1)
{
used += snprintf(buffer + used, size - used, ", ");
}
}
used += snprintf(buffer + used, size - used, "]");
return used;
}
#define PACKET_IO_TRACE(mr_ins, mr_buff, str) \
{ \
if (marsio_dp_trace_record_can_emit(mr_buff)) \
{ \
marsio_dp_trace_record_emit_str(mr_ins, mr_buff, "(Packet I/O)", str); \
} \
}
#define PACKET_TRACE_ON_NEW(mr_ins, mr_buff) PACKET_IO_TRACE(mr_ins, mr_buff, "new packet")
#define PACKET_TRACE_ON_FREE(mr_ins, mr_buff) PACKET_IO_TRACE(mr_ins, mr_buff, "free packet")
#define PACKET_TRACE_ON_CTRL(mr_ins, mr_buff, state) \
{ \
if (marsio_dp_trace_record_can_emit(mr_buff)) \
{ \
marsio_dp_trace_record_emit_fmt(mr_ins, mr_buff, "(Session Synchronization)", "%s", control_packte_state_to_string(state)); \
} \
}
#define PACKET_TRACE_ON_POLICY(mr_ins, mr_buff, rule_ids, chain) \
{ \
if (marsio_dp_trace_record_can_emit(mr_buff)) \
{ \
char buffer1[1024] = {0}; \
char buffer2[1024] = {0}; \
rule_id_tostring(rule_ids, buffer1, sizeof(buffer1)); \
sf_id_tostring(chain, buffer2, sizeof(buffer2)); \
marsio_dp_trace_record_emit_fmt(mr_ins, mr_buff, "(Policy)", "rule_list: %s, SFP_list: %s", buffer1, buffer2); \
} \
}
#define PACKET_TRACE_ON_CHAIN(mr_ins, mr_buff, sf, meta) \
{ \
if (marsio_dp_trace_record_can_emit(mr_buff)) \
{ \
marsio_dp_trace_record_emit_fmt(mr_ins, mr_buff, "(Forwarder)", \
"SF_id: %d, fwd_type: %s, pkt_dir: %s, pkt_type: %s, state: %s %s", \
(sf)->sf_profile_id, \
forward_type_tostring((sf)->sff_forward_type), \
((meta)->direction ? "E2I" : "I2E"), \
((meta)->is_decrypted ? "decrypted" : "raw"), \
((sf)->sf_action == SESSION_ACTION_FORWARD ? "success" : "failure"), \
((sf)->sf_action == SESSION_ACTION_FORWARD ? "" : action_desc_tostring((sf)->sf_action_desc))); \
} \
}
#ifdef __cpluscplus
}
#endif
#endif