📄 sipp.cpp
字号:
if(last) { fprintf(f,"------------------------------ Test Terminated --------------------------------" SIPP_ENDL); } else if(quitting) { fprintf(f,"------- Waiting for active calls to end. Press [Ctrl-c] to force exit. --------" SIPP_ENDL ); } else if(paused) { fprintf(f,"----------------- Traffic Paused - Press [p] again to resume ------------------" SIPP_ENDL ); } else if(cpu_max) { fprintf(f,"-------------------------------- CPU CONGESTED ---------------------------------" SIPP_ENDL); } else { switch(toolMode) { case MODE_SERVER : fprintf(f,"------------------------------ Sipp Server Mode -------------------------------" SIPP_ENDL); break;#ifdef __3PCC__ case MODE_3PCC_CONTROLLER_B : fprintf(f,"----------------------- 3PCC Mode - Controller B side -------------------------" SIPP_ENDL); break; case MODE_3PCC_A_PASSIVE : fprintf(f,"------------------ 3PCC Mode - Controller A side (passive) --------------------" SIPP_ENDL); break; case MODE_3PCC_CONTROLLER_A : fprintf(f,"----------------------- 3PCC Mode - Controller A side -------------------------" SIPP_ENDL); break;#endif case MODE_CLIENT : default: fprintf(f,"------ [+|-|*|/]: Adjust rate ---- [q]: Soft exit ---- [p]: Pause traffic -----" SIPP_ENDL); break; } } fprintf(f,SIPP_ENDL); fflush(stdout);}void print_variable_list(){ CActions * actions; CAction * action; CVariable * variable; int i; bool found; printf("Action defined Per Message :" SIPP_ENDL); found = false; for(i=0; i<scenario_len; i++) { actions = scenario[i]->M_actions; if(actions != NULL) { switch(scenario[i]->M_type) { case MSG_TYPE_RECV: printf("=> Message[%d] (Receive Message) - " "[%d] action(s) defined :" SIPP_ENDL, i, actions->getUsedAction()); break;#ifdef __3PCC__ case MSG_TYPE_RECVCMD: printf("=> Message[%d] (Receive Command Message) - " "[%d] action(s) defined :" SIPP_ENDL, i, actions->getUsedAction()); break;#endif default: printf("=> Message[%d] - [%d] action(s) defined :" SIPP_ENDL, i, actions->getUsedAction()); break; } for(int j=0; j<actions->getUsedAction(); j++) { action = actions->getAction(j); if(action != NULL) { printf(" --> action[%d] = "); action->afficheInfo(); printf(SIPP_ENDL); found = true; } } } } if(!found) printf("=> No action found on any messages"SIPP_ENDL); printf(SIPP_ENDL); printf("Setted Variable Liste :" SIPP_ENDL); found = false; for(i=0; i<SCEN_VARIABLE_SIZE; i++) { variable = scenVariableTable[i]; if(variable != NULL) { printf("=> Variable[%d] : setted regExp[%s]" SIPP_ENDL, i, variable->getRegularExpression()); found = true; } } if(!found) printf("=> No variable found for this scenario"SIPP_ENDL); }/* Function to dump all available screens in a file */void print_screens(void){ int oldScreen = currentScreenToDisplay; currentScreenToDisplay = DISPLAY_SCENARIO_SCREEN; print_header_line( screenf, 0); print_stats_in_file( screenf, 0); print_bottom_line( screenf, 0); currentScreenToDisplay = DISPLAY_STAT_SCREEN; print_header_line( screenf, 0); CStat::instance()->displayStat(screenf); print_bottom_line( screenf, 0); currentScreenToDisplay = DISPLAY_REPARTITION_SCREEN; print_header_line( screenf, 0); CStat::instance()->displayRepartition(screenf); print_bottom_line( screenf, 0); currentScreenToDisplay = oldScreen;}void print_statistics(int last){ static int first = 1; if(backgroundMode == false) { if(!last) { screen_clear(); } if(first) { first = 0; printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); } print_header_line(stdout,last); switch(currentScreenToDisplay) { case DISPLAY_STAT_SCREEN : CStat::instance()->displayStat(stdout); break; case DISPLAY_REPARTITION_SCREEN : CStat::instance()->displayRepartition(stdout); break; case DISPLAY_VARIABLE_SCREEN : print_variable_list(); break; case DISPLAY_SCENARIO_SCREEN : default: print_stats_in_file(stdout, last); break; } print_bottom_line(stdout,last); if(last) { fprintf(stdout,"\n"); } }}void set_rate(double new_rate){ double L_temp ; if(toolMode == MODE_SERVER) { rate = 0; open_calls_allowed = 0; } rate = new_rate; if(rate < 0) { rate = 0; } last_rate_change_time = clock_tick; calls_since_last_rate_change = 0; if(!open_calls_user_setting) { int call_duration_min = scenario_duration; if(duration > call_duration_min) call_duration_min = duration; if(call_duration_min < 1000) call_duration_min = 1000; L_temp = (3 * rate * call_duration_min) / rate_period_s / 1000 ; open_calls_allowed = (unsigned int) L_temp ; }}void sipp_sigusr1(int /* not used */){ /* Smooth exit: do not place any new calls and exit */ quitting = 1;}void sipp_sigusr2(int /* not used */){ /* Screen dumping in a file */ if(screenf) { print_screens(); } else { /* If the -trace_screen option has not been set, */ /* create the file at this occasion */ char *L_file_name ; /* 11 for '_screen.log' and 6 for pid */ L_file_name = new char [ strlen(scenario_file)+11+6 ] ; sprintf (L_file_name, "%s_%d_screen.log", scenario_file, getpid()); screenf = fopen(L_file_name, "a"); if(!screenf) { WARNING_P1("Unable to create '%s'", L_file_name); } delete [] L_file_name ; L_file_name = NULL ; print_screens(); fclose(screenf); screenf = 0; }}/* User interface thread */void keyb_thread (void * param){ int c; while(!feof(stdin)){ c = screen_readkey(); switch (c) { case '1': currentScreenToDisplay = DISPLAY_SCENARIO_SCREEN; print_statistics(0); break; case '2': currentScreenToDisplay = DISPLAY_STAT_SCREEN; print_statistics(0); break; case '3': currentScreenToDisplay = DISPLAY_REPARTITION_SCREEN; print_statistics(0); break; case '4': currentScreenToDisplay = DISPLAY_VARIABLE_SCREEN; print_statistics(0); break; case '+': set_rate(rate + 1); print_statistics(0); break; case '-': set_rate(rate - 1); print_statistics(0); break; case '*': set_rate(rate + 10); print_statistics(0); break; case '/': set_rate(rate - 10); print_statistics(0); break; case 'p': if(paused) { paused = 0; set_rate(rate); } else { paused = 1; } print_statistics(0); break; case 'q': quitting = 1; print_statistics(0); return; } }}/*************************** Mini SIP parser ***************************/char * get_peer_tag(char *msg){ char * to_hdr; char * ptr; char * end_ptr; static char tag[MAX_HEADER_LEN]; int tag_i = 0; to_hdr = strstr(msg, "To:"); if(!to_hdr) to_hdr = strstr(msg, "to:"); if(!to_hdr) to_hdr = strstr(msg, "TO:"); if(!to_hdr) { ERROR("No valid To: header in reply"); } end_ptr = strchr(to_hdr,'\n'); ptr = strchr(to_hdr, '>'); if (!ptr) { return NULL; } ptr = strchr(to_hdr, ';'); if(!ptr) { return NULL; } to_hdr = ptr; ptr = strstr(to_hdr, "tag"); if(!ptr) { ptr = strstr(to_hdr, "TAG"); } if(!ptr) { ptr = strstr(to_hdr, "Tag"); } if(!ptr) { return NULL; } if (ptr>end_ptr) { return NULL ; } ptr = strchr(ptr, '='); if(!ptr) { ERROR("Invalid tag param in To: header"); } ptr ++; while((*ptr) && (*ptr != ' ') && (*ptr != ';') && (*ptr != '\t') && (*ptr != '\t') && (*ptr != '\r') && (*ptr != '\n') && (*ptr)) { tag[tag_i++] = *(ptr++); } tag[tag_i] = 0; return tag;}char * get_call_id(char *msg){ static char call_id[MAX_HEADER_LEN]; char * ptr1, * ptr2, backup; ptr1 = strstr(msg, "Call-ID:"); if(!ptr1) { ptr1 = strstr(msg, "Call-Id:"); } if(!ptr1) { ptr1 = strstr(msg, "Call-id:"); } if(!ptr1) { ptr1 = strstr(msg, "call-Id:"); } if(!ptr1) { ptr1 = strstr(msg, "call-id:"); } if(!ptr1) { ptr1 = strstr(msg, "CALL-ID:"); } if(!ptr1) { ERROR_P1("(1) No valid Call-ID: header in reply '%s'", msg); } ptr1 += 8; while((*ptr1 == ' ') || (*ptr1 == '\t')) { ptr1++; } if(!(*ptr1)) { ERROR("(2) No valid Call-ID: header in reply"); } ptr2 = ptr1; while((*ptr2) && (*ptr2 != ' ') && (*ptr2 != '\t') && (*ptr2 != '\r') && (*ptr2 != '\n')) { ptr2 ++; } if(!*ptr2) { ERROR("(3) No valid Call-ID: header in reply"); } backup = *ptr2; *ptr2 = 0; strcpy(call_id, ptr1); *ptr2 = backup; return (char *) call_id;}unsigned long get_reply_code(char *msg){ while((*msg != ' ') && (*msg != '\t')) msg ++; while((*msg == ' ') || (*msg == '\t')) msg ++; return atol(msg);}/*************************** I/O functions ***************************/int recv_all_tcp(int sock, char *buffer, int size, int trace_id){ int recv_size = 0; char * start_buffer = buffer; int to_be_recvd = size; int part_size ; do { part_size = recv(sock, start_buffer, to_be_recvd, 0); if(part_size > 0) { to_be_recvd -= part_size; start_buffer += part_size; recv_size += part_size; } else { recv_size = part_size; } } while((part_size > 0) && to_be_recvd); if(recv_size <= 0) { if(recv_size != 0) { nb_net_recv_errors++; WARNING_P3("TCP %d Recv error : size = %d, sock = %d", trace_id, recv_size, sock); WARNING_NO("TCP Recv error"); // ERROR_NO("TCP recv error"); } else {#ifdef __3PCC__ if (toolMode == MODE_3PCC_CONTROLLER_B) { /* In 3PCC controller B mode, twin socket is closed at peer closing. * This is a normal case: 3PCC controller B should end now */ ERROR("3PCC controller A has ended -> exiting"); } else#endif /* This is normal for a server to have its client close * the connection */ if(toolMode != MODE_SERVER) { WARNING_P3("TCP %d Recv error : size = %d, sock = %d, " "remote host closed connection", trace_id, recv_size, sock);#ifdef __3PCC__ if(sock == twinSippSocket || sock == localTwinSippSocket) { int L_poll_idx = 0 ; quitting = 1; for((L_poll_idx) = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -