Browse code

sip: reorganized timer settings table

Raphael Coeffic authored on 15/09/2013 10:05:11 • Václav Kubart committed on 16/10/2013 09:19:54
Showing 5 changed files
... ...
@@ -370,10 +370,13 @@ int AmConfig::readConfiguration()
370 370
   }
371 371
   
372 372
 
373
-  for (char c = 'a'; c <= 'm'; c++) {
374
-    if(cfg.hasParameter(string("sip_timer_")+c)) {
375
-      sip_timers[c-'a']=cfg.getParameterInt(string("sip_timer_")+c, sip_timers[c-'a']);
376
-      DBG("Set SIP Timer '%c' to %u ms\n", 'A'+c-'a', sip_timers[c-'a']);
373
+  for (int t = STIMER_A; t < __STIMER_MAX; t++) {
374
+
375
+    string timer_cfg = string("sip_timer_") + timer_name(t);
376
+    if(cfg.hasParameter(timer_cfg)) {
377
+
378
+      sip_timers[t] = cfg.getParameterInt(timer_cfg, sip_timers[t]);
379
+      DBG("Set SIP Timer '%s' to %u ms\n", timer_name(t), sip_timers[t]);
377 380
     }
378 381
   }
379 382
 
... ...
@@ -26,20 +26,49 @@
26 26
  */
27 27
 #include "sip_timers.h"
28 28
 
29
-unsigned int sip_timers[n_sip_timers] = {
29
+unsigned int sip_timers[__STIMER_MAX] = {
30
+
31
+  // INVITE client transaction
30 32
   DEFAULT_A_TIMER,
31 33
   DEFAULT_B_TIMER,
32
-  DEFAULT_C_TIMER,
33 34
   DEFAULT_D_TIMER,
35
+
36
+  // non-INVITE client transaction
34 37
   DEFAULT_E_TIMER,
35 38
   DEFAULT_F_TIMER,
39
+  DEFAULT_K_TIMER,
40
+
41
+  // INVITE server transaction
36 42
   DEFAULT_G_TIMER,
37 43
   DEFAULT_H_TIMER,
38 44
   DEFAULT_I_TIMER,
45
+
46
+  // non-INVITE server transaction
39 47
   DEFAULT_J_TIMER,
40
-  DEFAULT_K_TIMER,
48
+
49
+  // Used to handle 200 ACKs automatically
50
+  // in INVITE client transactions.
41 51
   DEFAULT_L_TIMER,
42
-  DEFAULT_M_TIMER
52
+
53
+  // Transport address failover timer
54
+  DEFAULT_M_TIMER,
55
+
56
+  // INVITE client transaction
57
+  DEFAULT_C_TIMER,
58
+
59
+  // Blacklist grace timer (client transaction only)
60
+  DEFAULT_BL_TIMER
43 61
 };
44 62
 
45 63
 unsigned int sip_timer_t2 = DEFAULT_T2_TIMER;
64
+
65
+const char* _timer_name_lookup[] = {"A","B","D",
66
+				    "E","F","K",
67
+				    "G","H","I",
68
+				    "J","L","M",
69
+				    "C","BL"};
70
+
71
+const char* timer_name(unsigned int type)
72
+{
73
+  return _timer_name_lookup[(type) & 0xFFFF];
74
+}
... ...
@@ -34,8 +34,6 @@
34 34
  */
35 35
 enum sip_timer_type {
36 36
 
37
-    STIMER_INVALID=0,
38
-
39 37
     // INVITE client transaction
40 38
     STIMER_A,  // Calling: (re-)send INV
41 39
     STIMER_B,  // Calling -> Terminated
... ...
@@ -67,7 +65,12 @@ enum sip_timer_type {
67 65
     STIMER_M,
68 66
 
69 67
     // INVITE client transaction
70
-    STIMER_C   // Proceeding -> Terminated
68
+    STIMER_C,  // Proceeding -> Terminated
69
+
70
+    // Blacklist grace timer
71
+    STIMER_BL,
72
+
73
+    __STIMER_MAX
71 74
 };
72 75
 
73 76
 
... ...
@@ -126,27 +129,41 @@ enum sip_timer_type {
126 129
 //type 0x0c
127 130
 #define DEFAULT_M_TIMER  (DEFAULT_B_TIMER/4)
128 131
 
129
-#define A_TIMER sip_timers['A'-'A']
130
-#define B_TIMER sip_timers['B'-'A']
131
-#define C_TIMER sip_timers['C'-'A']
132
-#define D_TIMER sip_timers['D'-'A']
133
-#define E_TIMER sip_timers['E'-'A']
134
-#define F_TIMER sip_timers['F'-'A']
135
-#define G_TIMER sip_timers['G'-'A']
136
-#define H_TIMER sip_timers['H'-'A']
137
-#define I_TIMER sip_timers['I'-'A']
138
-#define J_TIMER sip_timers['J'-'A']
139
-#define K_TIMER sip_timers['K'-'A']
140
-#define L_TIMER sip_timers['L'-'A']
141
-#define M_TIMER sip_timers['M'-'A']
142
-
143
-#define n_sip_timers 'M'-'A'+1
144
-extern unsigned int sip_timers[n_sip_timers];
145
-#endif
132
+// Blacklist grace timer (client transaction only)
133
+// - set after locally generated 408
134
+//   to wait for downstream 408
135
+#define DEFAULT_BL_TIMER T4_TIMER
136
+
137
+#define A_TIMER sip_timers[STIMER_A]
138
+#define B_TIMER sip_timers[STIMER_B]
139
+#define D_TIMER sip_timers[STIMER_D]
140
+
141
+#define E_TIMER sip_timers[STIMER_E]
142
+#define F_TIMER sip_timers[STIMER_F]
143
+#define K_TIMER sip_timers[STIMER_K]
144
+
145
+#define G_TIMER sip_timers[STIMER_G]
146
+#define H_TIMER sip_timers[STIMER_H]
147
+#define I_TIMER sip_timers[STIMER_I]
148
+
149
+#define J_TIMER sip_timers[STIMER_J]
150
+
151
+#define L_TIMER sip_timers[STIMER_L]
152
+#define M_TIMER sip_timers[STIMER_M]
153
+#define C_TIMER sip_timers[STIMER_C]
154
+
155
+#define BL_TIMER sip_timers[STIMER_BL]
156
+
157
+//#define n_sip_timers 'M'-'A'+1
158
+extern unsigned int sip_timers[__STIMER_MAX];
146 159
 
147 160
 #define T2_TIMER sip_timer_t2
148 161
 extern unsigned int sip_timer_t2;
149 162
 
163
+const char* timer_name(unsigned int type);
164
+
165
+#endif
166
+
150 167
 /** EMACS **
151 168
  * Local variables:
152 169
  * mode: c++
... ...
@@ -28,6 +28,7 @@
28 28
  */
29 29
 
30 30
 #include "sip_trans.h"
31
+#include "sip_timers.h"
31 32
 #include "sip_parser.h"
32 33
 #include "wheeltimer.h"
33 34
 #include "trans_table.h"
... ...
@@ -40,14 +41,14 @@
40 41
 #include <assert.h>
41 42
 
42 43
 int _timer_type_lookup[] = { 
43
-    -1,    // STIMER_INVALID
44 44
     0,1,2, // STIMER_A, STIMER_B, STIMER_D
45 45
     0,1,2, // STIMER_E, STIMER_F, STIMER_K
46 46
     0,1,2, // STIMER_G, STIMER_H, STIMER_I
47 47
     0,     // STIMER_J
48 48
     2,     // STIMER_L; shares the same slot as STIMER_D
49 49
     2,     // STIMER_M; shares the same slot as STIMER_D/STIMER_K
50
-    1,     // STIMER_C; shares the same slot at STIMER_B (INV trans only)
50
+    2,     // STIMER_C; shares the same slot at STIMER_D (INV trans only)
51
+    2,     // STIMER_BL; share the same slot as STIMER_D/STIMER_K
51 52
 };
52 53
 
53 54
 inline trans_timer** fetch_timer(unsigned int timer_type, trans_timer** base)
... ...
@@ -142,9 +143,30 @@ trans_timer* sip_trans::get_timer(unsigned int timer_type)
142 143
 }
143 144
 
144 145
 
145
-char _timer_name_lookup[] = {'0','A','B','D','E','F','K','G','H','I','J','L','M','C'};
146
-#define timer_name(type) \
147
-    (_timer_name_lookup[(type) & 0xFFFF])
146
+const char* _trans_type_lookup[] = {
147
+    "0",
148
+    "UAS",
149
+    "UAC"
150
+};
151
+
152
+#define trans_type(type) \
153
+    (_trans_type_lookup[type])
154
+
155
+const char* _state_name_lookup[] = {
156
+    "0",
157
+    "TRYING",
158
+    "CALLING",
159
+    "PROCEEDING",
160
+    "PROCEEDING_REL",
161
+    "COMPLETED",
162
+    "CONFIRMED",
163
+    "TERMINATED_200",
164
+    "TERMINATED",
165
+    "REMOVED"
166
+};
167
+
168
+#define state_name(state) \
169
+    (_state_name_lookup[state])
148 170
 
149 171
 /**
150 172
  * Resets a specific timer
... ...
@@ -158,7 +180,8 @@ void sip_trans::reset_timer(trans_timer* t, unsigned int timer_type)
158 180
     
159 181
     if(*tp != NULL){
160 182
 
161
-	DBG("Clearing old timer of type %c (this=%p)\n",timer_name((*tp)->type),*tp);
183
+	DBG("Clearing old timer of type %s (this=%p)\n",
184
+	    timer_name((*tp)->type),*tp);
162 185
 	wheeltimer::instance()->remove_timer((timer*)*tp);
163 186
     }
164 187
 
... ...
@@ -174,7 +197,7 @@ void trans_timer::fire()
174 197
     if(bucket){
175 198
 	bucket->lock();
176 199
 	if(bucket->exist(t)){
177
-	    DBG("Transaction timer expired: type=%c, trans=%p, eta=%i, t=%i\n",
200
+	    DBG("Transaction timer expired: type=%s, trans=%p, eta=%i, t=%i\n",
178 201
 		timer_name(type),t,expires,wheeltimer::instance()->wall_clock);
179 202
 
180 203
 	    trans_timer* tt = t->get_timer(this->type & 0xFFFF);
... ...
@@ -215,7 +238,7 @@ void sip_trans::reset_timer(unsigned int timer_type, unsigned int expire_delay /
215 238
     unsigned int expires = expire_delay / (TIMER_RESOLUTION/1000);
216 239
     expires += wt->wall_clock;
217 240
     
218
-    DBG("New timer of type %c at time=%i (repeated=%i)\n",
241
+    DBG("New timer of type %s at time=%i (repeated=%i)\n",
219 242
 	timer_name(timer_type),expires,timer_type>>16);
220 243
 
221 244
     trans_timer* t = new trans_timer(timer_type,expires,
... ...
@@ -240,10 +263,22 @@ void sip_trans::reset_all_timers()
240 263
     }
241 264
 }
242 265
 
266
+const char* sip_trans::type_str() const
267
+{
268
+    return trans_type(type);
269
+}
270
+
271
+const char* sip_trans::state_str() const
272
+{
273
+    return state_name(state);
274
+}
275
+
243 276
 void sip_trans::dump() const
244 277
 {
245
-    DBG("type=0x%x; msg=%p; to_tag=%.*s; reply_status=%i; state=%i; retr_buf=%p\n",
246
-	type,msg,to_tag.len,to_tag.s,reply_status,state,retr_buf);
278
+    DBG("type=%s (0x%x); msg=%p; to_tag=%.*s;"
279
+	" reply_status=%i; state=%s (%i); retr_buf=%p\n",
280
+	type_str(),type,msg,to_tag.len,to_tag.s,
281
+	reply_status,state_str(),state,retr_buf);
247 282
 }
248 283
 
249 284
 /** EMACS **
... ...
@@ -194,6 +194,9 @@ class sip_trans
194 194
     sip_trans();
195 195
     ~sip_trans();
196 196
 
197
+    const char* type_str() const;
198
+    const char* state_str() const;
199
+
197 200
     void dump() const;
198 201
 };
199 202