176404edcSAsim Jamshed #ifndef __DEBUG_H_ 276404edcSAsim Jamshed #define __DEBUG_H_ 376404edcSAsim Jamshed 4*cafe7743SAsim Jamshed #ifdef DBGMSG 5*cafe7743SAsim Jamshed #define _GNU_SOURCE 6*cafe7743SAsim Jamshed #include <sched.h> 7*cafe7743SAsim Jamshed #endif 876404edcSAsim Jamshed #include <errno.h> 976404edcSAsim Jamshed #include <stdio.h> 1076404edcSAsim Jamshed #include <assert.h> 1176404edcSAsim Jamshed #include "mtcp.h" 1276404edcSAsim Jamshed #include "tcp_in.h" 1376404edcSAsim Jamshed 1476404edcSAsim Jamshed #ifdef DBGTEMP 1576404edcSAsim Jamshed 1676404edcSAsim Jamshed #define TRACE_TEMP(f, m...) { \ 1776404edcSAsim Jamshed fprintf(stderr, "[CPU %d][%10s:%4d] " f, mtcp->ctx->cpu, \ 1876404edcSAsim Jamshed __FUNCTION__, __LINE__, ##m); \ 1976404edcSAsim Jamshed } 2076404edcSAsim Jamshed 2176404edcSAsim Jamshed #else 2276404edcSAsim Jamshed 2376404edcSAsim Jamshed #define TRACE_TEMP(f, m...) (void)0 2476404edcSAsim Jamshed 2576404edcSAsim Jamshed #endif /* DBGTEMP*/ 2676404edcSAsim Jamshed 2776404edcSAsim Jamshed #ifdef DBGERR 2876404edcSAsim Jamshed 2976404edcSAsim Jamshed #define TRACE_ERROR(f, m...) { \ 3076404edcSAsim Jamshed fprintf(stderr, "[%10s:%4d] " f, __FUNCTION__, __LINE__, ##m); \ 3176404edcSAsim Jamshed } 3276404edcSAsim Jamshed 3376404edcSAsim Jamshed #else 3476404edcSAsim Jamshed 3576404edcSAsim Jamshed #define TRACE_ERROR(f, m...) (void)0 3676404edcSAsim Jamshed 3776404edcSAsim Jamshed #endif /* DBGERR */ 3876404edcSAsim Jamshed 3976404edcSAsim Jamshed #ifdef DBGCERR 4076404edcSAsim Jamshed 4176404edcSAsim Jamshed #define CTRACE_ERROR(f, m...) { \ 4276404edcSAsim Jamshed fprintf(stderr, "[CPU %d][%10s:%4d] " f, mtcp->ctx->cpu, __FUNCTION__, __LINE__, ##m); \ 4376404edcSAsim Jamshed } 4476404edcSAsim Jamshed 4576404edcSAsim Jamshed #else 4676404edcSAsim Jamshed 4776404edcSAsim Jamshed #define CTRACE_ERROR(f, m...) (void)0 4876404edcSAsim Jamshed 4976404edcSAsim Jamshed #endif /* DBGERR */ 5076404edcSAsim Jamshed 5176404edcSAsim Jamshed #ifdef DBGMSG 52*cafe7743SAsim Jamshed #define __PREPARE_DGBLOGGING() \ 53*cafe7743SAsim Jamshed struct mtcp_context mctx = { \ 54*cafe7743SAsim Jamshed .cpu = sched_getcpu(), \ 55*cafe7743SAsim Jamshed }; \ 56*cafe7743SAsim Jamshed \ 57*cafe7743SAsim Jamshed mtcp_manager_t mtcp = GetMTCPManager(&mctx); 5876404edcSAsim Jamshed 5976404edcSAsim Jamshed #define TRACE_DBG(f, m...) {\ 6076404edcSAsim Jamshed thread_printf(mtcp, mtcp->log_fp, "[%10s:%4d] " \ 6176404edcSAsim Jamshed f, __FUNCTION__, __LINE__, ##m); \ 6276404edcSAsim Jamshed } 6376404edcSAsim Jamshed 6476404edcSAsim Jamshed #else 6576404edcSAsim Jamshed 6676404edcSAsim Jamshed #define TRACE_DBG(f, m...) (void)0 6776404edcSAsim Jamshed 6876404edcSAsim Jamshed #endif /* DBGMSG */ 6976404edcSAsim Jamshed 7076404edcSAsim Jamshed #ifdef INFO 7176404edcSAsim Jamshed 7276404edcSAsim Jamshed #define TRACE_INFO(f, m...) { \ 7376404edcSAsim Jamshed fprintf(stderr, "[%10s:%4d] " f,__FUNCTION__, __LINE__, ##m); \ 7476404edcSAsim Jamshed } 7576404edcSAsim Jamshed 7676404edcSAsim Jamshed #else 7776404edcSAsim Jamshed 7876404edcSAsim Jamshed #define TRACE_INFO(f, m...) (void)0 7976404edcSAsim Jamshed 8076404edcSAsim Jamshed #endif /* INFO */ 8176404edcSAsim Jamshed 8276404edcSAsim Jamshed #define TRACE_CONFIG(f, m...) fprintf(stderr, f, ##m) 8376404edcSAsim Jamshed 8476404edcSAsim Jamshed #ifdef DBGLOG 8576404edcSAsim Jamshed #define TRACE_LOG(f, m...) TRACE_INFO(f, ##m) 8676404edcSAsim Jamshed #else 8776404edcSAsim Jamshed #define TRACE_LOG(f, m...) (void)0 8876404edcSAsim Jamshed #endif 8976404edcSAsim Jamshed 9076404edcSAsim Jamshed #ifdef MONITOR 9176404edcSAsim Jamshed #define TRACE_MONITOR(f, m...) TRACE_FUNC("MONITOR", f, ##m) 9276404edcSAsim Jamshed #else 9376404edcSAsim Jamshed #define TRACE_MONITOR(f, m...) (void)0 9476404edcSAsim Jamshed #endif 9576404edcSAsim Jamshed 9676404edcSAsim Jamshed #ifdef STREAM 9776404edcSAsim Jamshed #define TRACE_STREAM(f, m...) TRACE_FUNC("STREAM", f, ##m) 9876404edcSAsim Jamshed #else 9976404edcSAsim Jamshed #define TRACE_STREAM(f, m...) (void)0 10076404edcSAsim Jamshed #endif 10176404edcSAsim Jamshed 10276404edcSAsim Jamshed #ifdef STATE 10376404edcSAsim Jamshed #define TRACE_STATE(f, m...) TRACE_FUNC("STATE", f, ##m) 10476404edcSAsim Jamshed #else 10576404edcSAsim Jamshed #define TRACE_STATE(f, m...) (void)0 10676404edcSAsim Jamshed #endif 10776404edcSAsim Jamshed 10876404edcSAsim Jamshed #ifdef SNDBUF 10976404edcSAsim Jamshed #define TRACE_SNDBUF(f, m...) TRACE_FUNC("SNDBUF", f, ##m) 11076404edcSAsim Jamshed #else 11176404edcSAsim Jamshed #define TRACE_SNDBUF(f, m...) (void)0 11276404edcSAsim Jamshed #endif 11376404edcSAsim Jamshed 11476404edcSAsim Jamshed #ifdef RCVBUF 11576404edcSAsim Jamshed #define TRACE_RCVBUF(f, m...) TRACE_FUNC("RCVBUF", f, ##m) 11676404edcSAsim Jamshed #else 11776404edcSAsim Jamshed #define TRACE_RCVBUF(f, m...) (void)0 11876404edcSAsim Jamshed #endif 11976404edcSAsim Jamshed 12076404edcSAsim Jamshed #ifdef CLWND 12176404edcSAsim Jamshed #define TRACE_CLWND(f, m...) TRACE_FUNC("CLWND", f, ##m) 12276404edcSAsim Jamshed #else 12376404edcSAsim Jamshed #define TRACE_CLWND(f, m...) (void)0 12476404edcSAsim Jamshed #endif 12576404edcSAsim Jamshed 12676404edcSAsim Jamshed #ifdef LOSS 12776404edcSAsim Jamshed #define TRACE_LOSS(f, m...) TRACE_FUNC("LOSS", f, ##m) 12876404edcSAsim Jamshed #else 12976404edcSAsim Jamshed #define TRACE_LOSS(f, m...) (void)0 13076404edcSAsim Jamshed #endif 13176404edcSAsim Jamshed 13276404edcSAsim Jamshed #ifdef SACK 13376404edcSAsim Jamshed #define TRACE_SACK(f, m...) TRACE_FUNC("SACK", f, ##m) 13476404edcSAsim Jamshed #else 13576404edcSAsim Jamshed #define TRACE_SACK(f, m...) (void)0 13676404edcSAsim Jamshed #endif 13776404edcSAsim Jamshed 13876404edcSAsim Jamshed #ifdef TSTAMP 13976404edcSAsim Jamshed #define TRACE_TSTAMP(f, m...) TRACE_FUNC("TSTAMP", f, ##m) 14076404edcSAsim Jamshed #else 14176404edcSAsim Jamshed #define TRACE_TSTAMP(f, m...) (void)0 14276404edcSAsim Jamshed #endif 14376404edcSAsim Jamshed 14476404edcSAsim Jamshed #ifdef RTT 14576404edcSAsim Jamshed #define TRACE_RTT(f, m...) TRACE_FUNC("RTT", f, ##m) 14676404edcSAsim Jamshed #else 14776404edcSAsim Jamshed #define TRACE_RTT(f, m...) (void)0 14876404edcSAsim Jamshed #endif 14976404edcSAsim Jamshed 15076404edcSAsim Jamshed #ifdef RTO 15176404edcSAsim Jamshed #define TRACE_RTO(f, m...) TRACE_FUNC("RTO", f, ##m) 15276404edcSAsim Jamshed #else 15376404edcSAsim Jamshed #define TRACE_RTO(f, m...) (void)0 15476404edcSAsim Jamshed #endif 15576404edcSAsim Jamshed 15676404edcSAsim Jamshed #ifdef CONG 15776404edcSAsim Jamshed #define TRACE_CONG(f, m...) TRACE_FUNC("CONG", f, ##m) 15876404edcSAsim Jamshed #else 15976404edcSAsim Jamshed #define TRACE_CONG(f, m...) (void)0 16076404edcSAsim Jamshed #endif 16176404edcSAsim Jamshed 16276404edcSAsim Jamshed #ifdef EPOLL 16376404edcSAsim Jamshed #define TRACE_EPOLL(f, m...) TRACE_FUNC("EPOLL", f, ##m) 16476404edcSAsim Jamshed #else 16576404edcSAsim Jamshed #define TRACE_EPOLL(f, m...) (void)0 16676404edcSAsim Jamshed #endif 16776404edcSAsim Jamshed 16876404edcSAsim Jamshed #ifdef FSTAT 16976404edcSAsim Jamshed #define TRACE_FSTAT(f, m...) TRACE_FUNC("FSTAT", f, ##m) 17076404edcSAsim Jamshed #else 17176404edcSAsim Jamshed #define TRACE_FSTAT(f, m...) (void)0 17276404edcSAsim Jamshed #endif 17376404edcSAsim Jamshed 17476404edcSAsim Jamshed #ifdef APP 17576404edcSAsim Jamshed #define TRACE_APP(f, m...) TRACE_FUNC("APP", f, ##m) 17676404edcSAsim Jamshed #else 17776404edcSAsim Jamshed #define TRACE_APP(f, m...) (void)0 17876404edcSAsim Jamshed #endif 17976404edcSAsim Jamshed 18076404edcSAsim Jamshed #ifdef DBGFIN 18176404edcSAsim Jamshed #define TRACE_FIN(f, m...) TRACE_FUNC("FIN", f, ##m) 18276404edcSAsim Jamshed #else 18376404edcSAsim Jamshed #define TRACE_FIN(f, m...) (void)0 18476404edcSAsim Jamshed #endif 18576404edcSAsim Jamshed 18676404edcSAsim Jamshed #ifdef TSTAT 18776404edcSAsim Jamshed #define TRACE_TSTAT(f, m...) TRACE_FUNC("TSTAT", f, ##m) 18876404edcSAsim Jamshed #else 18976404edcSAsim Jamshed #define TRACE_TSTAT(f, m...) (void)0 19076404edcSAsim Jamshed #endif 19176404edcSAsim Jamshed 19276404edcSAsim Jamshed #ifdef LOOP 19376404edcSAsim Jamshed #define TRACE_LOOP(f, m...) TRACE_FUNC("LOOP", "ts: %u, "f, cur_ts, ##m) 19476404edcSAsim Jamshed #else 19576404edcSAsim Jamshed #define TRACE_LOOP(f, m...) (void)0 19676404edcSAsim Jamshed #endif 19776404edcSAsim Jamshed 19876404edcSAsim Jamshed #ifdef ROUND 19976404edcSAsim Jamshed #define TRACE_ROUND(f, m...) TRACE_FUNC("ROUND", f, ##m) 20076404edcSAsim Jamshed #else 20176404edcSAsim Jamshed #define TRACE_ROUND(f, m...) (void)0 20276404edcSAsim Jamshed #endif 20376404edcSAsim Jamshed 20476404edcSAsim Jamshed #ifdef SELECT 20576404edcSAsim Jamshed #define TRACE_SELECT(f, m...) TRACE_FUNC("SELECT", f, ##m) 20676404edcSAsim Jamshed #else 20776404edcSAsim Jamshed #define TRACE_SELECT(f, m...) (void)0 20876404edcSAsim Jamshed #endif 20976404edcSAsim Jamshed 21076404edcSAsim Jamshed #ifdef API 21176404edcSAsim Jamshed #define TRACE_API(f, m...) TRACE_FUNC("API", f, ##m) 21276404edcSAsim Jamshed #else 21376404edcSAsim Jamshed #define TRACE_API(f, m...) (void)0 21476404edcSAsim Jamshed #endif 21576404edcSAsim Jamshed 21676404edcSAsim Jamshed #ifdef DBGFUNC 21776404edcSAsim Jamshed 21876404edcSAsim Jamshed #define TRACE_FUNC(n, f, m...) { \ 21976404edcSAsim Jamshed thread_printf(mtcp, mtcp->log_fp, "[%6s: %10s:%4d] " \ 22076404edcSAsim Jamshed f, n, __FUNCTION__, __LINE__, ##m); \ 22176404edcSAsim Jamshed } 22276404edcSAsim Jamshed 22376404edcSAsim Jamshed #else 22476404edcSAsim Jamshed 22576404edcSAsim Jamshed #define TRACE_FUNC(f, m...) (void)0 22676404edcSAsim Jamshed 22776404edcSAsim Jamshed #endif /* DBGFUNC */ 22876404edcSAsim Jamshed 22976404edcSAsim Jamshed void 23076404edcSAsim Jamshed DumpPacket(mtcp_manager_t mtcp, char *buf, int len, char *step, int ifindex); 23176404edcSAsim Jamshed 23276404edcSAsim Jamshed void 23376404edcSAsim Jamshed DumpIPPacket(mtcp_manager_t mtcp, const struct iphdr *iph, int len); 23476404edcSAsim Jamshed 23576404edcSAsim Jamshed void 23676404edcSAsim Jamshed DumpIPPacketToFile(FILE *fout, const struct iphdr *iph, int len); 23776404edcSAsim Jamshed 23876404edcSAsim Jamshed void 23976404edcSAsim Jamshed flush_log_data(mtcp_manager_t mtcp); 24076404edcSAsim Jamshed 24176404edcSAsim Jamshed void 24276404edcSAsim Jamshed thread_printf(mtcp_manager_t mtcp, FILE* f_idx, const char* _Format, ...); 24376404edcSAsim Jamshed 24476404edcSAsim Jamshed #endif /* __DEBUG_H_ */ 245