[SR-Dev] git:ser_core_cvs: sctp: internal macro-hooks for stats

Andrei Pelinescu-Onciul andrei at iptel.org
Thu May 7 14:39:31 CEST 2009


Module: sip-router
Branch: ser_core_cvs
Commit: 7a66235b9f972d735575ebb839f87f2eaa1b0c61
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7a66235b9f972d735575ebb839f87f2eaa1b0c61

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Apr 30 16:38:54 2009 +0000

sctp: internal macro-hooks for stats

Added macros for sctp statistics.  (for now empty, keeping
more statistics will only involve redefining them):

SCTP_STATS_ESTABLISHED() - new association is opened successfully
SCTP_STATS_CONNECT_FAILED() - attempt to open new assoc. failed
SCTP_STATS_LOCAL_REJECT() - local reject of a "connect" attempt
                            (unused for now)
SCTP_STATS_REMOTE_SHUTDOWN()
SCTP_STATS_COMM_LOST() - error on open association
SCTP_STATS_SENDQ_FULL() - send failed due to full buffers (kernel)
SCTP_STATS_SEND_FAILED() - send failed for some other reason
SCTP_STATS_SEND_FORCE_RETRY() - send failed and retried
                                (sctp_send_retries!=0)

---

 sctp_server.c |   14 ++++++++
 sctp_stats.h  |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+), 0 deletions(-)

diff --git a/sctp_server.c b/sctp_server.c
index ff2e778..b4aed18 100644
--- a/sctp_server.c
+++ b/sctp_server.c
@@ -23,6 +23,7 @@
  * --------
  *  2008-08-07  initial version (andrei)
  *  2009-02-27  blacklist support (andrei)
+ *  2009-04-28  sctp stats & events macros (andrei)
  */
 
 #ifdef USE_SCTP
@@ -57,6 +58,7 @@
 #include "clist.h"
 #include "error.h"
 #include "timer.h"
+#include "sctp_stats.h"
 
 
 
@@ -1496,6 +1498,10 @@ int init_sctp()
 	int ret;
 	
 	ret=0;
+	if (INIT_SCTP_STATS()!=0){
+		ERR("sctp init: failed to intialize sctp stats\n");
+		goto error;
+	}
 	/* sctp options must be initialized before  calling this function */
 	sctp_conn_no=shm_malloc(sizeof(*sctp_conn_tracked));
 	if ( sctp_conn_no==0){
@@ -1522,6 +1528,7 @@ void destroy_sctp()
 #ifdef SCTP_CONN_REUSE
 	destroy_sctp_con_tracking();
 #endif
+	DESTROY_SCTP_STATS();
 }
 
 
@@ -1613,6 +1620,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
 	int ret;
 	
 	ret=-1;
+	SCTP_STATS_SEND_FAILED();
 	snp=(union sctp_notification*) buf;
 	retries=snp->sn_send_failed.ssf_info.sinfo_context;
 	
@@ -1623,6 +1631,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
 	 */
 	if (retries && (snp->sn_send_failed.ssf_error==0)) {
 		DBG("sctp: RETRY-ing (%d)\n", retries);
+		SCTP_STATS_SEND_FORCE_RETRY();
 		retries--;
 		data=(char*)snp->sn_send_failed.ssf_data;
 		data_len=snp->sn_send_failed.ssf_length - 
@@ -1685,6 +1694,7 @@ static int sctp_handle_assoc_change(struct socket_info* si,
 	ret=-1;
 	switch(state){
 		case SCTP_COMM_UP:
+			SCTP_STATS_ESTABLISHED();
 			atomic_inc(sctp_conn_no);
 #ifdef SCTP_CONN_REUSE
 			/* new connection, track it */
@@ -1707,6 +1717,7 @@ again:
 #endif /* SCTP_CONN_REUSE */
 			break;
 		case SCTP_COMM_LOST:
+			SCTP_STATS_COMM_LOST();
 #ifdef USE_DST_BLACKLIST
 			/* blacklist only if send_retries is turned off (if on we don't
 			   know here if we did retry or we are at the first error) */
@@ -1732,6 +1743,7 @@ again:
 			/* do nothing on restart */
 			break;
 		case SCTP_CANT_STR_ASSOC:
+			SCTP_STATS_CONNECT_FAILED();
 			/* do nothing when failing to start an assoc
 			  (in this case we never see SCTP_COMM_UP so we never 
 			  track the assoc) */
@@ -1816,6 +1828,7 @@ static int sctp_handle_notification(struct socket_info* si,
 					);
 			break;
 		case SCTP_SHUTDOWN_EVENT:
+			SCTP_STATS_REMOTE_SHUTDOWN();
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_shutdown_event), si, su,
 								"SCTP_SHUTDOWN_EVENT");
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SHUTDOWN_EVENT:"
@@ -2162,6 +2175,7 @@ again:
 			"one possible reason is the server is bound to localhost and\n"
 			"attempts to send to the net\n");
 		}else if (errno==EAGAIN || errno==EWOULDBLOCK){
+			SCTP_STATS_SENDQ_FULL();
 			LOG(L_ERR, "ERROR: sctp_msg_send: failed to send, send buffers"
 						" full\n");
 		}
diff --git a/sctp_stats.h b/sctp_stats.h
new file mode 100644
index 0000000..e895ce8
--- /dev/null
+++ b/sctp_stats.h
@@ -0,0 +1,99 @@
+/* 
+ * $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
+
+
+#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()
+#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 */
+
+#define INIT_SCTP_STATS() 0 /* success */
+
+#define DESTROY_SCTP_STATS()
+
+
+/** called each time a new sctp assoc. is established.
+ * sctp notification: SCTP_COMM_UP.
+ */
+#define SCTP_STATS_ESTABLISHED()
+
+/** called each time a new outgoing connection/assoc open fails.
+ *  sctp notification: SCTP_CANT_STR_ASSOC
+ */
+#define SCTP_STATS_CONNECT_FAILED()
+
+/** called each time a new incoming connection is rejected.  */
+#define SCTP_STATS_LOCAL_REJECT()
+
+
+/** called each time a connection is closed by the peer.
+  * sctp notification: SCTP_SHUTDOWN_EVENT
+  */
+#define SCTP_STATS_REMOTE_SHUTDOWN()
+
+
+/** called each time an established connection is closed due to some error.
+  * sctp notification: SCTP_COMM_LOST
+  */
+#define SCTP_STATS_COMM_LOST()
+
+
+/** called each time a send fails due to the buffering capacity being exceeded.
+  * (send fails due to full kernel buffers)
+  */
+#define SCTP_STATS_SENDQ_FULL()
+
+
+/** called each time a send fails.
+  * (send fails for any reason except buffers full)
+  * sctp notification: SCTP_SEND_FAILED
+  */
+#define SCTP_STATS_SEND_FAILED()
+
+/** called each time a failed send is force-retried.
+  * (possible only if sctp_send_retries is != 0)
+  */
+#define SCTP_STATS_SEND_FORCE_RETRY()
+
+#endif /* USE_SCTP_STATS */
+
+#endif /*__sctp_stats_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */




More information about the sr-dev mailing list