sctp_stats.h
7a66235b
 /* 
  * $Id$
  * 
  * Copyright (C) 2009 iptelorg GmbH
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
  * copyright notice and this permission notice appear in all copies.
  *
  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 /*
  * sctp_stats.h - sctp statistics macros
  */
 /*
  * History:
  * --------
  *  2009-04-28  initial version (andrei)
 */
 
 #ifndef __sctp_stats_h
 #define __sctp_stats_h
 
 
be186dac
 /* enable sctp stats by default */
 #ifndef NO_SCTP_STATS
 #define USE_SCTP_STATS
 #endif
 
7a66235b
 #ifndef USE_SCTP_STATS
 
 #define INIT_SCTP_STATS() 0 /* success */
 #define DESTROY_SCTP_STATS()
 
 #define SCTP_STATS_ESTABLISHED()
 #define SCTP_STATS_CONNECT_FAILED()
 #define SCTP_STATS_LOCAL_REJECT()
 #define SCTP_STATS_REMOTE_SHUTDOWN()
8dfdb3c7
 #define SCTP_STATS_ASSOC_SHUTDOWN()
7a66235b
 #define SCTP_STATS_COMM_LOST()
 #define SCTP_STATS_SENDQ_FULL()
 #define SCTP_STATS_SEND_FAILED()
 #define SCTP_STATS_SEND_FORCE_RETRY()
 
 #else /* USE_SCTP_STATS */
 
be186dac
 #include "counters.h"
7a66235b
 
be186dac
 struct sctp_counters_h {
 	counter_handle_t established;
 	counter_handle_t connect_failed;
 	counter_handle_t local_reject;
 	counter_handle_t remote_shutdown;
 	counter_handle_t assoc_shutdown;
 	counter_handle_t comm_lost;
 	counter_handle_t sendq_full;
 	counter_handle_t send_failed;
 	counter_handle_t send_force_retry;
 };
 
 extern struct sctp_counters_h sctp_cnts_h;
 
 int sctp_stats_init();
 void sctp_stats_destroy();
 
 #define INIT_SCTP_STATS() sctp_stats_init() /* success */
 
 #define DESTROY_SCTP_STATS() sctp_stats_destroy()
7a66235b
 
 
 /** called each time a new sctp assoc. is established.
  * sctp notification: SCTP_COMM_UP.
  */
be186dac
 #define SCTP_STATS_ESTABLISHED() \
 	counter_inc(sctp_cnts_h.established)
7a66235b
 
 /** called each time a new outgoing connection/assoc open fails.
  *  sctp notification: SCTP_CANT_STR_ASSOC
  */
be186dac
 #define SCTP_STATS_CONNECT_FAILED() \
 	counter_inc(sctp_cnts_h.connect_failed)
7a66235b
 
 /** called each time a new incoming connection is rejected.  */
be186dac
 #define SCTP_STATS_LOCAL_REJECT() \
 	counter_inc(sctp_cnts_h.local_reject)
7a66235b
 
 
 /** called each time a connection is closed by the peer.
   * sctp notification: SCTP_SHUTDOWN_EVENT
   */
be186dac
 #define SCTP_STATS_REMOTE_SHUTDOWN() \
 	counter_inc(sctp_cnts_h.remote_shutdown)
7a66235b
 
 
8dfdb3c7
 /** called each time a connection is shutdown.
   * sctp notification: SCTP_SHUTDOWN_COMP
   */
be186dac
 #define SCTP_STATS_ASSOC_SHUTDOWN() \
 	counter_inc(sctp_cnts_h.assoc_shutdown)
8dfdb3c7
 
 
7a66235b
 /** called each time an established connection is closed due to some error.
   * sctp notification: SCTP_COMM_LOST
   */
be186dac
 #define SCTP_STATS_COMM_LOST() \
 	counter_inc(sctp_cnts_h.comm_lost)
7a66235b
 
 
 /** called each time a send fails due to the buffering capacity being exceeded.
   * (send fails due to full kernel buffers)
   */
be186dac
 #define SCTP_STATS_SENDQ_FULL() \
 	counter_inc(sctp_cnts_h.sendq_full)
7a66235b
 
 
 /** called each time a send fails.
   * (send fails for any reason except buffers full)
   * sctp notification: SCTP_SEND_FAILED
   */
be186dac
 #define SCTP_STATS_SEND_FAILED() \
 	counter_inc(sctp_cnts_h.send_failed)
7a66235b
 
 /** called each time a failed send is force-retried.
   * (possible only if sctp_send_retries is != 0)
   */
be186dac
 #define SCTP_STATS_SEND_FORCE_RETRY() \
 	counter_inc(sctp_cnts_h.send_force_retry)
7a66235b
 
 #endif /* USE_SCTP_STATS */
 
 #endif /*__sctp_stats_h*/
 
 /* vi: set ts=4 sw=4 tw=79:ai:cindent: */