📄 sipp.cpp
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Author : Richard GAYRAUD - 04 Nov 2003 * Marc LAMBERTON * From Hewlett Packard Company. */#define GLOBALS_FULL_DEFINITION#include "sipp.hpp"/***************** System Portability Features *****************/unsigned int getmilliseconds(){ struct timeval LS_system_time; unsigned long long int VI_milli; gettimeofday(&LS_system_time, NULL); VI_milli = ((unsigned long long) LS_system_time.tv_sec) * 1000LL + (LS_system_time.tv_usec / 1000LL); VI_milli = VI_milli - 788400000000ULL; return (unsigned int) VI_milli;}int send_nowait(int s, const void *msg, int len, int flags){#ifdef MSG_DONTWAIT return send(s, msg, len, flags | MSG_DONTWAIT);#else int fd_flags = fcntl(s, F_GETFL , NULL); int initial_fd_flags; int rc; initial_fd_flags = fd_flags; // fd_flags &= ~O_ACCMODE; // Remove the access mode from the value fd_flags |= O_NONBLOCK; fcntl(s, F_SETFL , fd_flags); rc = send(s, msg, len, flags); fcntl(s, F_SETFL , initial_fd_flags); return rc;#endif }/******************** Recv Poll Processing *********************/int pollnfds;struct pollfd pollfiles[SIPP_MAXFDS];call * pollcalls[SIPP_MAXFDS];/***************** Check of the message received ***************/bool sipMsgCheck (char *P_msg, int P_msgSize#ifdef __3PCC__ ,int P_pollSetIdx#endif ) { const char C_sipHeader[] = "SIP/2.0" ;#ifdef __3PCC__ if (pollfiles[P_pollSetIdx].fd == twinSippSocket) { return true ; } else {#endif // __3PCC__ if (strstr(P_msg, C_sipHeader) != NULL) { return true ; } return false ;#ifdef __3PCC__ }#endif // __3PCC__}void pollset_reset(){ pollnfds = 0; pollfiles[pollnfds].fd = main_socket; pollfiles[pollnfds].events = POLLIN | POLLERR; pollfiles[pollnfds].revents = 0; pollcalls[pollnfds] = NULL; pollnfds++; if(tcp_multiplex) { /* Adds the TCP multiplex in the file descriptor array */ pollfiles[pollnfds].fd = tcp_multiplex; pollfiles[pollnfds].events = POLLIN | POLLERR; pollfiles[pollnfds].revents = 0; pollcalls[pollnfds] = NULL; pollnfds++; } #ifdef __3PCC__ if(twinSippSocket) { /* Adds the twinSippSocket */ pollfiles[pollnfds].fd = twinSippSocket; pollfiles[pollnfds].events = POLLIN | POLLERR; pollfiles[pollnfds].revents = 0; pollcalls[pollnfds] = NULL; pollnfds++; } if(localTwinSippSocket) { /* Adds the twinSippSocket */ pollfiles[pollnfds].fd = localTwinSippSocket; pollfiles[pollnfds].events = POLLIN | POLLERR; pollfiles[pollnfds].revents = 0; pollcalls[pollnfds] = NULL; pollnfds++; } #endif}int pollset_add(call * p_call, int sock){ // WARNING_P2("Adding socket %d at idx = %d", sock, pollnfds); pollfiles[pollnfds].fd = sock; pollfiles[pollnfds].events = POLLIN | POLLERR; pollfiles[pollnfds].revents = 0; pollcalls[pollnfds] = p_call; pollnfds++; return pollnfds - 1;}void pollset_remove(int idx){ if(idx >= pollnfds) { ERROR("Pollset error"); } /* Adds call sockets in the array */ if(pollnfds) { // WARNING_P2("Removing socket %d at idx = %d", pollfiles[idx].fd, idx); pollnfds--; pollfiles[idx] = pollfiles[pollnfds]; pollcalls[idx] = pollcalls[pollnfds]; if((pollcalls[idx]) && (pollcalls[idx] -> pollset_index)) { pollcalls[idx] -> pollset_index = idx; } } else { ERROR("Pollset underflow"); }}/************** Statistics display & User control *************/void print_stats_in_file(FILE * f, int last){ int index; static char temp_str[256]; int divisor;#define SIPP_ENDL "\r\n" /* Optional timestamp line for files only */ if(f != stdout) { time_t tim; time(&tim); fprintf(f, " Timestamp: %s" SIPP_ENDL, ctime(&tim)); } /* Header line with global parameters */ sprintf(temp_str, "%3.1f(%d ms)/%5.3fs", rate, duration, rate_period_s); if( toolMode == MODE_SERVER) { fprintf (f, " Port Total-time Total-calls Transport" SIPP_ENDL " %-5d %6d.%02d s %8d %s" SIPP_ENDL SIPP_ENDL, local_port, clock_tick / 1000, (clock_tick % 1000) / 10, total_calls, TRANSPORT_TO_STRING(transport)); } else { fprintf (f, " Call-rate(length) Port Total-time Total-calls Remote-host" SIPP_ENDL "%19s %-5d %6d.%02d s %8d %s:%d(%s)" SIPP_ENDL SIPP_ENDL, temp_str, local_port, clock_tick / 1000, (clock_tick % 1000) / 10, total_calls, remote_ip, remote_port, TRANSPORT_TO_STRING(transport)); } /* 1st line */ if(total_calls < stop_after) { sprintf(temp_str, "%d new calls during %d.%03d s period ", total_calls - last_report_calls, (clock_tick-last_report_time) / 1000, ((clock_tick-last_report_time) % 1000)); } else { sprintf(temp_str, "Call limit reached (-m %d), %d.%03d s period ", stop_after, (clock_tick-last_report_time) / 1000, ((clock_tick-last_report_time) % 1000)); } divisor = scheduling_loops; if(!divisor) { divisor = 1; } fprintf(f," %-38s %d ms scheduler resolution" SIPP_ENDL, temp_str, (clock_tick-last_report_time) / divisor); /* 2nd line */ if( toolMode == MODE_SERVER) { sprintf(temp_str, "%d concurrent calls", open_calls); } else { sprintf(temp_str, "%d concurrent calls (limit %d)", open_calls, open_calls_allowed); } fprintf(f," %-38s Peak was %d calls, after %d s" SIPP_ENDL, temp_str, open_calls_peak, open_calls_peak_time); /* 3rd line (optional) */ if( toolMode != MODE_SERVER) { sprintf(temp_str,"%d out-of-call msg (discarded)", nb_out_of_the_blue); fprintf(f," %-37s", temp_str); } if(compression) { fprintf(f," Comp resync: %d sent, %d recv" , resynch_send, resynch_recv); } if(compression || (toolMode != MODE_SERVER)) { fprintf(f,SIPP_ENDL); } /* 4th line , sockets and optional errors */ sprintf(temp_str,"%d open sockets", pollnfds); fprintf(f," %-38s", temp_str); if(nb_net_recv_errors || nb_net_send_errors || nb_net_cong) { fprintf(f," %d/%d/%d %s errors (send/recv/cong)" SIPP_ENDL, nb_net_send_errors, nb_net_recv_errors, nb_net_cong, TRANSPORT_TO_STRING(transport)); } else { fprintf(f,SIPP_ENDL); } /* 5th line, RTP echo statistics */ if (media_socket > 0) { sprintf(temp_str, "%d Total echo RTP pckts", rtp_pckts); // AComment: Fix for random coredump when using RTP echo if (clock_tick-last_report_time) { fprintf(f," %-38s %d.%03d last period RTP rate (kB/s)" SIPP_ENDL, temp_str, (rtp_bytes)/(clock_tick-last_report_time), (rtp_bytes)%(clock_tick-last_report_time)); } rtp_bytes = 0; } /* Scenario counters */ fprintf(f,SIPP_ENDL); if(!lose_packets) { fprintf(f," " "Messages Retrans Timeout Unexpected-Msg" SIPP_ENDL); } else { fprintf(f," " "Messages Retrans Timeout Unexp. Lost" SIPP_ENDL); } for(index = 0; index < scenario_len; index ++) { if(scenario[index] -> send_scheme) { char *dest, *src; int len; dest = temp_str; src = scenario[index] -> send_scheme; if((*src == 'S') && (strstr(src, "SIP/2.0"))) { src += 8; } while((*src) && (*src != ' ') && (*src != '\t') && (*src != '\n')) { *dest++ = *src ++; } *dest = 0; if(toolMode == MODE_SERVER) { fprintf(f," <---------- %-10s %-8s", temp_str, scenario[index] -> start_rtd ? "B-RTD" : scenario[index] -> stop_rtd ? "E-RTD" : ""); } else { fprintf(f," %10s ----------> %-8s", temp_str, scenario[index] -> start_rtd ? "B-RTD" : scenario[index] -> stop_rtd ? "E-RTD" : ""); } if(scenario[index] -> retrans_delay) { fprintf(f,"%-9d %-9d %-9d" , scenario[index] -> nb_sent, scenario[index] -> nb_sent_retrans, scenario[index] -> nb_timeout); } else { fprintf(f,"%-9d %-9d " , scenario[index] -> nb_sent, scenario[index] -> nb_sent_retrans); } } else if(scenario[index] -> recv_response) { if(toolMode == MODE_SERVER) { fprintf(f," ----------> %-10d %-8s", scenario[index] -> recv_response, scenario[index] -> start_rtd ? "B-RTD" : scenario[index] -> stop_rtd ? "E-RTD" : ""); } else { fprintf(f," %10d <---------- %-8s", scenario[index] -> recv_response, scenario[index] -> start_rtd ? "B-RTD" : scenario[index] -> stop_rtd ? "E-RTD" : ""); } if(toolMode == MODE_SERVER) { fprintf(f,"%-9d %-9d %-9d" , scenario[index] -> nb_recv, scenario[index] -> nb_recv_retrans, scenario[index] -> nb_unexp); } else { fprintf(f,"%-9d %-9d %-9d" , scenario[index] -> nb_recv, scenario[index] -> nb_recv_retrans, scenario[index] -> nb_unexp); } } else if (scenario[index] -> pause) { int pause; if(scenario[index] -> pause < 0) { pause = duration; } else { pause = scenario[index] -> pause; } if(toolMode == MODE_SERVER) { fprintf(f," [%6d ms]", pause); } else { fprintf(f," [%6d ms]", pause); } } else if(scenario[index] -> recv_request) { if(toolMode == MODE_SERVER) { fprintf(f," ----------> %-10s %-8s", scenario[index] -> recv_request, scenario[index] -> start_rtd ? "B-RTD" : scenario[index] -> stop_rtd ? "E-RTD" : ""); } else { fprintf(f," %10s <---------- %-8s", scenario[index] -> recv_request, scenario[index] -> start_rtd ? "B-RTD" : scenario[index] -> stop_rtd ? "E-RTD" : ""); } fprintf(f,"%-9d %-9d %-9d" , scenario[index] -> nb_recv, scenario[index] -> nb_recv_retrans, scenario[index] -> nb_unexp); }#ifdef __3PCC__ else if(scenario[index] -> M_type == MSG_TYPE_RECVCMD) { fprintf(f," [ Received Command ] "); fprintf(f,"%-9d %-9s %-9s" , scenario[index] -> M_nbCmdRecv, "", ""); } else if(scenario[index] -> M_type == MSG_TYPE_SENDCMD) { fprintf(f," [ Sent Command ] "); fprintf(f,"%-9d %-9s %-9s" , scenario[index] -> M_nbCmdSent, "", ""); }#endif else { ERROR("Not Implemented\n"); } if(lose_packets && (scenario[index] -> nb_lost)) { fprintf(f," %-9d" SIPP_ENDL, scenario[index] -> nb_lost); } else { fprintf(f,SIPP_ENDL); } if(scenario[index] -> crlf) { fprintf(f,SIPP_ENDL); } }}void print_header_line(FILE *f, int last){ switch(currentScreenToDisplay) { case DISPLAY_STAT_SCREEN : fprintf(f,"----------------------------- Statistics Screen ------- [1-4]: Change Screen --" SIPP_ENDL); break; case DISPLAY_REPARTITION_SCREEN : fprintf(f,"---------------------------- Repartition Screen ------- [1-4]: Change Screen --" SIPP_ENDL); break; case DISPLAY_VARIABLE_SCREEN : fprintf(f,"----------------------------- Variables Screen -------- [1-4]: Change Screen --" SIPP_ENDL); break; case DISPLAY_SCENARIO_SCREEN : default: fprintf(f,"------------------------------ Scenario Screen -------- [1-4]: Change Screen --" SIPP_ENDL); break; }}void print_bottom_line(FILE *f, int last){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -