Browse code

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)

Andrei Pelinescu-Onciul authored on 30/04/2009 16:38:54
Showing 2 changed files
... ...
@@ -23,6 +23,7 @@
23 23
  * --------
24 24
  *  2008-08-07  initial version (andrei)
25 25
  *  2009-02-27  blacklist support (andrei)
26
+ *  2009-04-28  sctp stats & events macros (andrei)
26 27
  */
27 28
 
28 29
 #ifdef USE_SCTP
... ...
@@ -57,6 +58,7 @@
57 57
 #include "clist.h"
58 58
 #include "error.h"
59 59
 #include "timer.h"
60
+#include "sctp_stats.h"
60 61
 
61 62
 
62 63
 
... ...
@@ -1496,6 +1498,10 @@ int init_sctp()
1496 1496
 	int ret;
1497 1497
 	
1498 1498
 	ret=0;
1499
+	if (INIT_SCTP_STATS()!=0){
1500
+		ERR("sctp init: failed to intialize sctp stats\n");
1501
+		goto error;
1502
+	}
1499 1503
 	/* sctp options must be initialized before  calling this function */
1500 1504
 	sctp_conn_no=shm_malloc(sizeof(*sctp_conn_tracked));
1501 1505
 	if ( sctp_conn_no==0){
... ...
@@ -1522,6 +1528,7 @@ void destroy_sctp()
1522 1522
 #ifdef SCTP_CONN_REUSE
1523 1523
 	destroy_sctp_con_tracking();
1524 1524
 #endif
1525
+	DESTROY_SCTP_STATS();
1525 1526
 }
1526 1527
 
1527 1528
 
... ...
@@ -1613,6 +1620,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
1613 1613
 	int ret;
1614 1614
 	
1615 1615
 	ret=-1;
1616
+	SCTP_STATS_SEND_FAILED();
1616 1617
 	snp=(union sctp_notification*) buf;
1617 1618
 	retries=snp->sn_send_failed.ssf_info.sinfo_context;
1618 1619
 	
... ...
@@ -1623,6 +1631,7 @@ static int sctp_handle_send_failed(struct socket_info* si,
1623 1623
 	 */
1624 1624
 	if (retries && (snp->sn_send_failed.ssf_error==0)) {
1625 1625
 		DBG("sctp: RETRY-ing (%d)\n", retries);
1626
+		SCTP_STATS_SEND_FORCE_RETRY();
1626 1627
 		retries--;
1627 1628
 		data=(char*)snp->sn_send_failed.ssf_data;
1628 1629
 		data_len=snp->sn_send_failed.ssf_length - 
... ...
@@ -1685,6 +1694,7 @@ static int sctp_handle_assoc_change(struct socket_info* si,
1685 1685
 	ret=-1;
1686 1686
 	switch(state){
1687 1687
 		case SCTP_COMM_UP:
1688
+			SCTP_STATS_ESTABLISHED();
1688 1689
 			atomic_inc(sctp_conn_no);
1689 1690
 #ifdef SCTP_CONN_REUSE
1690 1691
 			/* new connection, track it */
... ...
@@ -1707,6 +1717,7 @@ again:
1707 1707
 #endif /* SCTP_CONN_REUSE */
1708 1708
 			break;
1709 1709
 		case SCTP_COMM_LOST:
1710
+			SCTP_STATS_COMM_LOST();
1710 1711
 #ifdef USE_DST_BLACKLIST
1711 1712
 			/* blacklist only if send_retries is turned off (if on we don't
1712 1713
 			   know here if we did retry or we are at the first error) */
... ...
@@ -1732,6 +1743,7 @@ again:
1732 1732
 			/* do nothing on restart */
1733 1733
 			break;
1734 1734
 		case SCTP_CANT_STR_ASSOC:
1735
+			SCTP_STATS_CONNECT_FAILED();
1735 1736
 			/* do nothing when failing to start an assoc
1736 1737
 			  (in this case we never see SCTP_COMM_UP so we never 
1737 1738
 			  track the assoc) */
... ...
@@ -1816,6 +1828,7 @@ static int sctp_handle_notification(struct socket_info* si,
1816 1816
 					);
1817 1817
 			break;
1818 1818
 		case SCTP_SHUTDOWN_EVENT:
1819
+			SCTP_STATS_REMOTE_SHUTDOWN();
1819 1820
 			ERR_LEN_TOO_SMALL(len, sizeof(struct sctp_shutdown_event), si, su,
1820 1821
 								"SCTP_SHUTDOWN_EVENT");
1821 1822
 			SNOT("sctp notification from %s on %.*s:%d: SCTP_SHUTDOWN_EVENT:"
... ...
@@ -2162,6 +2175,7 @@ again:
2162 2162
 			"one possible reason is the server is bound to localhost and\n"
2163 2163
 			"attempts to send to the net\n");
2164 2164
 		}else if (errno==EAGAIN || errno==EWOULDBLOCK){
2165
+			SCTP_STATS_SENDQ_FULL();
2165 2166
 			LOG(L_ERR, "ERROR: sctp_msg_send: failed to send, send buffers"
2166 2167
 						" full\n");
2167 2168
 		}
2168 2169
new file mode 100644
... ...
@@ -0,0 +1,99 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2009 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * sctp_stats.h - sctp statistics macros
19
+ */
20
+/*
21
+ * History:
22
+ * --------
23
+ *  2009-04-28  initial version (andrei)
24
+*/
25
+
26
+#ifndef __sctp_stats_h
27
+#define __sctp_stats_h
28
+
29
+
30
+#ifndef USE_SCTP_STATS
31
+
32
+#define INIT_SCTP_STATS() 0 /* success */
33
+#define DESTROY_SCTP_STATS()
34
+
35
+#define SCTP_STATS_ESTABLISHED()
36
+#define SCTP_STATS_CONNECT_FAILED()
37
+#define SCTP_STATS_LOCAL_REJECT()
38
+#define SCTP_STATS_REMOTE_SHUTDOWN()
39
+#define SCTP_STATS_COMM_LOST()
40
+#define SCTP_STATS_SENDQ_FULL()
41
+#define SCTP_STATS_SEND_FAILED()
42
+#define SCTP_STATS_SEND_FORCE_RETRY()
43
+
44
+#else /* USE_SCTP_STATS */
45
+
46
+#define INIT_SCTP_STATS() 0 /* success */
47
+
48
+#define DESTROY_SCTP_STATS()
49
+
50
+
51
+/** called each time a new sctp assoc. is established.
52
+ * sctp notification: SCTP_COMM_UP.
53
+ */
54
+#define SCTP_STATS_ESTABLISHED()
55
+
56
+/** called each time a new outgoing connection/assoc open fails.
57
+ *  sctp notification: SCTP_CANT_STR_ASSOC
58
+ */
59
+#define SCTP_STATS_CONNECT_FAILED()
60
+
61
+/** called each time a new incoming connection is rejected.  */
62
+#define SCTP_STATS_LOCAL_REJECT()
63
+
64
+
65
+/** called each time a connection is closed by the peer.
66
+  * sctp notification: SCTP_SHUTDOWN_EVENT
67
+  */
68
+#define SCTP_STATS_REMOTE_SHUTDOWN()
69
+
70
+
71
+/** called each time an established connection is closed due to some error.
72
+  * sctp notification: SCTP_COMM_LOST
73
+  */
74
+#define SCTP_STATS_COMM_LOST()
75
+
76
+
77
+/** called each time a send fails due to the buffering capacity being exceeded.
78
+  * (send fails due to full kernel buffers)
79
+  */
80
+#define SCTP_STATS_SENDQ_FULL()
81
+
82
+
83
+/** called each time a send fails.
84
+  * (send fails for any reason except buffers full)
85
+  * sctp notification: SCTP_SEND_FAILED
86
+  */
87
+#define SCTP_STATS_SEND_FAILED()
88
+
89
+/** called each time a failed send is force-retried.
90
+  * (possible only if sctp_send_retries is != 0)
91
+  */
92
+#define SCTP_STATS_SEND_FORCE_RETRY()
93
+
94
+#endif /* USE_SCTP_STATS */
95
+
96
+#endif /*__sctp_stats_h*/
97
+
98
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */