334a6a666cea58ea1596696103635193eb9e9087
[sip-router] / test / auto.c
1
2 /* test program -> switch speed */
3
4
5 /* parsing:           compact form:
6  * Via:               v:
7  * From:              f:
8  * To:                t:
9  * Cseq:              n/a
10  * Call-ID:           i:
11  * Contact:           m:
12  * Max-Forwards:      n/a
13  * Route:             n/a
14  */
15
16 enum { INITIAL=0,
17                 VIA1, VIA2,
18                 FROM1, FROM2, FROM3,
19                 TO1,
20                 C_START, CSEQ2, CSEQ3,
21                          CALLID2, CALLID3, CALLID4, CALLID5, CALLID6,
22                          CONTACT2, CONTACT3, CONTACT4, CONTACT5, CONTACT6,
23                 M_START,      MAXFORWARDS2, MAXFORWARDS3, MAXFORWARDS4, MAXFORWARDS5,
24                 MAXFORWARDS6, MAXFORWARDS7, MAXFORWARDS8, MAXFORWARDS9, MAXFORWARDS10,
25                 MAXFORWARDS11,
26                 ROUTE1, ROUTE2, ROUTE3, ROUTE4,
27                 /* final states*/
28                 F_VIA=1000, F_FROM, F_TO, F_CSEQ, F_CALLID, F_CONTACT, F_MAXFORWARDS,
29                 F_ROUTE,
30                 I_START,
31
32                 UNKNOWN_HEADER=200,
33                 BODY=220,
34                 LF=25000,
35         };
36
37 #include <stdio.h>
38
39 int main(int argc, char** argv)
40 {
41
42         char* t;
43         register int state;
44         int i;
45         int err;
46         err=0;
47
48         state=INITIAL;
49         printf(" %s (%d)\n", argv[0], argc);
50         if (argc<2){
51                         fprintf(stderr, " no parameters\n");
52                         exit(-1);
53         }
54         
55         for (i=0;i<10000000;i++){
56                 
57         for(t=argv[1];*t;t++){
58                 switch(*t){
59                         case 'V':
60                         case 'v':
61                                         switch(state){
62                                                 case INITIAL:
63                                                         state=VIA1;
64                                                         break;
65                                                 case UNKNOWN_HEADER: break;
66                                                 default:
67                                                         state=UNKNOWN_HEADER;
68                                         }
69                                         break;
70                         case 'I':
71                         case 'i':
72                                         switch(state){
73                                                 case VIA1:
74                                                         state=VIA2;
75                                                         break;
76                                                 case CALLID5:
77                                                         state=CALLID6;
78                                                         break;
79                                                 case INITIAL:
80                                                         state=I_START;
81                                                         break;
82                                                 case UNKNOWN_HEADER: break;
83                                                 default:
84                                                         state=UNKNOWN_HEADER;
85                                         }
86                                         break;
87                         case 'A':
88                         case 'a':
89                                         switch(state){
90                                                 case VIA2:
91                                                                 state=F_VIA;
92                                                                 break;
93                                                 case C_START:  /*CALLID1*/
94                                                                 state=CALLID2;
95                                                                 break;
96                                                 case CONTACT4:
97                                                                 state=CONTACT5;
98                                                                 break;
99                                                 case M_START:
100                                                                 state=MAXFORWARDS2;
101                                                                 break;
102                                                 case MAXFORWARDS8:
103                                                                 state=MAXFORWARDS9;
104                                                                 break;
105                                                 case UNKNOWN_HEADER: break;
106                                                 default:
107                                                                 state=UNKNOWN_HEADER;
108                                         }
109                                         break;
110                         case 'F':
111                         case 'f':
112                                         switch(state){
113                                                 case INITIAL:
114                                                                 state=FROM1;
115                                                                 break;
116                                                 case MAXFORWARDS4:
117                                                                 state=MAXFORWARDS5;
118                                                                 break;
119                                                 case UNKNOWN_HEADER: break;
120                                                 default:
121                                                                 state=UNKNOWN_HEADER;
122                                         }
123                                         break;
124                         case 'R':
125                         case 'r':
126                                         switch(state){
127                                                 case INITIAL:
128                                                         state=ROUTE1;
129                                                         break;
130                                                 case FROM1:
131                                                         state=FROM2;
132                                                         break;
133                                                 case MAXFORWARDS6:
134                                                         state=MAXFORWARDS7;
135                                                         break;
136                                                 case MAXFORWARDS9:
137                                                         state=MAXFORWARDS10;
138                                                         break;
139                                                 case UNKNOWN_HEADER: break;
140                                                 default:
141                                                         state=UNKNOWN_HEADER;
142                                         }
143                                         break;
144                         case 'O':
145                         case 'o':
146                                         switch(state){
147                                                 case FROM2:
148                                                         state=FROM3;
149                                                         break;
150                                                 case TO1:
151                                                         state=F_TO;
152                                                         break;
153                                                 case C_START: /*CONTACT1 */
154                                                         state=CONTACT2;
155                                                         break;
156                                                 case ROUTE1:
157                                                         state=ROUTE2;
158                                                         break;
159                                                 case MAXFORWARDS5:
160                                                         state=MAXFORWARDS6;
161                                                         break;
162                                                 case UNKNOWN_HEADER: break;
163                                                 default:
164                                                         state=UNKNOWN_HEADER;
165                                         }
166                                         break;
167                         case 'M':
168                         case 'm':
169                                                 switch(state){
170                                                         case INITIAL:
171                                                                 state=M_START;
172                                                                 break;
173                                                         case FROM3:
174                                                                 state=F_FROM;
175                                                                 break;
176                                                         case UNKNOWN_HEADER: break;
177                                                         default:
178                                                                 state=UNKNOWN_HEADER;
179                                                 }
180                                                 break;
181                         case 'T':
182                         case 't':
183                                                 switch(state){
184                                                         case INITIAL:
185                                                                 state=TO1;
186                                                                 break;
187                                                         case CONTACT3:
188                                                                 state=CONTACT4;
189                                                                 break;
190                                                         case CONTACT6:
191                                                                 state=F_CONTACT;
192                                                                 break;
193                                                         case ROUTE3:
194                                                                 state=ROUTE4;
195                                                                 break;
196                                                         case UNKNOWN_HEADER: break;
197                                                         default:
198                                                                 state=UNKNOWN_HEADER;
199                                                 }
200                                                 break;
201                         case 'C':
202                         case 'c':
203                                                 switch(state){
204                                                         case INITIAL:
205                                                                 state=C_START;
206                                                                 break;
207                                                         case CONTACT5:
208                                                                 state=CONTACT6;
209                                                                 break;
210                                                         case UNKNOWN_HEADER: break;
211                                                         default:
212                                                                 state=UNKNOWN_HEADER;
213                                                 }
214                                                 break;
215                         case 'S':
216                         case 's':
217                                                 switch(state){
218                                                         case C_START:
219                                                                 state=CSEQ2;
220                                                                 break;
221                                                         case MAXFORWARDS11:
222                                                                 state=F_MAXFORWARDS;
223                                                                 break;
224                                                         case UNKNOWN_HEADER: break;
225                                                         default:
226                                                                 state=UNKNOWN_HEADER;
227                                                 }
228                                                 break;
229                         case 'E':
230                         case 'e':
231                                                 switch(state){
232                                                         case CSEQ2:
233                                                                 state=CSEQ3;
234                                                                 break;
235                                                         case ROUTE4:
236                                                                 state=F_ROUTE;
237                                                                 break;
238                                                         case UNKNOWN_HEADER: break;
239                                                         default:
240                                                                 state=UNKNOWN_HEADER;
241                                                 }
242                                                 break;
243                         case 'Q':
244                         case 'q':
245                                                 switch(state){
246                                                         case CSEQ3:
247                                                                 state=F_CSEQ;
248                                                                 break;
249                                                         case UNKNOWN_HEADER: break;
250                                                         default:
251                                                                 state=UNKNOWN_HEADER;
252                                                 }
253                                                 break;
254                         case 'L':
255                         case 'l':
256                                                 switch(state){
257                                                         case CALLID2:
258                                                                 state=CALLID3;
259                                                                 break;
260                                                         case CALLID3:
261                                                                 state=CALLID4;
262                                                                 break;
263                                                         case UNKNOWN_HEADER: break;
264                                                         default:
265                                                                 state=UNKNOWN_HEADER;
266                                                 }
267                                                 break;
268                         case 'D':
269                         case 'd':
270                                                 switch(state){
271                                                         case CALLID6:
272                                                                 state=F_CALLID;
273                                                                 break;
274                                                         case MAXFORWARDS10:
275                                                                 state=MAXFORWARDS11;
276                                                                 break;
277                                                         case UNKNOWN_HEADER: break;
278                                                         default:
279                                                                 state=UNKNOWN_HEADER;
280                                                 }
281                                                 break;
282                         case 'N':
283                         case 'n':
284                                                 switch(state){
285                                                         case CONTACT2:
286                                                                 state=CONTACT3;
287                                                                 break;
288                                                         case UNKNOWN_HEADER: break;
289                                                         default:
290                                                                 state=UNKNOWN_HEADER;
291                                                 }
292                                                 break;
293                         case 'X':
294                         case 'x':
295                                                 switch(state){
296                                                         case MAXFORWARDS2:
297                                                                 state=MAXFORWARDS3;
298                                                                 break;
299                                                         case UNKNOWN_HEADER: break;
300                                                         default:
301                                                                 state=UNKNOWN_HEADER;
302                                                 }
303                                                 break;
304                         case '-':
305                                                 switch(state){
306                                                         case CALLID4:
307                                                                 state=CALLID5;
308                                                                 break;
309                                                         case MAXFORWARDS3:
310                                                                 state=MAXFORWARDS4;
311                                                                 break;
312                                                         case UNKNOWN_HEADER: break;
313                                                         default:
314                                                                 state=UNKNOWN_HEADER;
315                                                 }
316                                                 break;
317                         case 'W':
318                         case 'w':
319                                                 switch(state){
320                                                         case MAXFORWARDS7:
321                                                                 state=MAXFORWARDS8;
322                                                                 break;
323                                                         case UNKNOWN_HEADER: break;
324                                                         default:
325                                                                 state=UNKNOWN_HEADER;
326                                                 }
327                                                 break;
328                         case 'U':
329                         case 'u':
330                                                 switch(state){
331                                                         case ROUTE2:
332                                                                 state=ROUTE3;
333                                                                 break;
334                                                         case UNKNOWN_HEADER: break;
335                                                         default:
336                                                                 state=UNKNOWN_HEADER;
337                                                 }
338                                                 break;
339                         case ' ':
340                                                 switch(state){
341                                                         case INITIAL:
342                                                                 break; /*eat space */
343                                                         case F_VIA:
344                                                         case F_FROM:
345                                                         case F_TO:
346                                                         case F_CSEQ:
347                                                         case F_CALLID:
348                                                         case F_CONTACT:
349                                                         case F_MAXFORWARDS:
350                                                         case F_ROUTE:
351                                                                 break; /* eat trailing space*/
352                                                         case VIA1:
353                                                                 /*compact form: v: */
354                                                                 state=F_VIA;
355                                                                 break;
356                                                         case FROM1:
357                                                                 /*compact form f:*/
358                                                                 state=F_FROM;
359                                                                 break;
360                                                         case TO1:
361                                                                 /*compact form t:*/
362                                                                 state=F_TO;
363                                                                 break;
364                                                         case I_START:
365                                                                 /*compact form i: (Call-ID)*/
366                                                                 state=F_CALLID;
367                                                                 break;
368                                                         case M_START:
369                                                                 /*compact form m: (Contact)*/
370                                                                 state=F_CONTACT;
371                                                                 break;
372                                                         case UNKNOWN_HEADER: break;
373                                                         default:
374                                                                 state=UNKNOWN_HEADER;
375                                                 }
376                                                 break;
377                         case ':':
378                                                 switch(state){
379                                                         case F_VIA:
380                                                         case VIA1: /* compact form*/
381                                                         case F_FROM:
382                                                         case FROM1: /*compact form*/
383                                                         case F_TO:
384                                                         case TO1: /*compact form*/
385                                                         case F_CSEQ:
386                                                         case F_CALLID:
387                                                         case I_START: /*compact form*/
388                                                         case F_CONTACT:
389                                                         case M_START: /*compact form*/
390                                                         case F_MAXFORWARDS:
391                                                         case F_ROUTE:
392                                                         //      printf("found header, state=%d\n", state);
393                                                                 state=INITIAL; /* reset to test*/
394                                                                 break;
395                                                         case UNKNOWN_HEADER:
396                                                         default:
397                                                                 /*printf("found unkown header, state=%d\n", 
398                                                                                         state);*/
399                                                                 err=1;
400                                                                 state=INITIAL;
401                                                 }
402                                                 break;
403                         default:
404                                         /*fprintf(stderr, "Unexpected char <%c> encountered"
405                                                                                 " state=%d\n", *t, state);
406                                                 exit(-1);*/
407                                         state=UNKNOWN_HEADER;
408                 }
409         }
410
411         } //for i
412         if (err) printf("Error unknown header\n");
413         printf("final state=%d\n", state);
414
415         exit(0);
416
417 }
418