⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipp.cpp

📁 sipbomber - tool for testing SIP-protocol implementation (RFC3261). Current version can check only
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    TRACE_MSG((s,"Adding socket : L_i %d and socket = %d\n", L_i , pollfiles[L_i].fd));  }    TRACE_MSG((s,"Adding socket :\n"));  */    return pollnfds - 1;}void pollset_attached(call * p_call, int P_pollset_idx){  pollcalls[P_pollset_idx]         = p_call;}void pollset_remove(int idx){    // TRACE_MSG((s,"remove socket : idx %d\n", idx));  if(idx >= pollnfds) {    ERROR("Pollset error");  }  /*  int L_i ;  TRACE_MSG((s,"remove socket : idx %d\n", idx));  for (L_i = 0; L_i <  pollnfds ; L_i++) {    TRACE_MSG((s,"remove socket : L_i %d and socket = %d\n", L_i , pollfiles[L_i].fd));  }  TRACE_MSG((s,"remove socket :\n"));  */  /* 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);  }#ifdef PCAPPLAY  /* if has media abilities */  if (hasMedia != 0) {    sprintf(temp_str, "%d Total RTP pckts sent ",            rtp_pckts_pcap);    if (clock_tick-last_report_time) {       fprintf(f,"  %-38s %d.%03d last period RTP rate (kB/s)" SIPP_ENDL,              temp_str,              (rtp_bytes_pcap)/(clock_tick-last_report_time),              (rtp_bytes_pcap)%(clock_tick-last_report_time));    }    rtp_bytes_pcap = 0;    rtp2_bytes_pcap = 0;  }#endif  /* 5th line, RTP echo statistics */  if (rtp_echo_enabled && (media_socket > 0)) {    sprintf(temp_str, "%d Total echo RTP pckts 1st stream",            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));    }    /* second stream statitics: */    sprintf(temp_str, "%d Total echo RTP pckts 2nd stream",            rtp2_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,	      (rtp2_bytes)/(clock_tick-last_report_time),	      (rtp2_bytes)%(clock_tick-last_report_time));    }    rtp_bytes = 0;    rtp2_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( strncmp(src, "SIP/2.0", 7) == 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) {      if(scenario[index] -> pause < 0) {        if(toolMode == MODE_SERVER) {          fprintf(f,"  [%7dms] Var Pause          ", duration);      } else {          fprintf(f,"   Var Pause [%7dms]         ", duration);      }      } else {      if(toolMode == MODE_SERVER) {          fprintf(f,"  [%7dms] Pause              ", scenario[index]->pause);      } else {           fprintf(f,"       Pause [%7dms]         ", scenario[index]->pause);        }      }      fprintf(f,"%-9d", scenario[index]->sessions);      fprintf(f,"                     %-9d" , scenario[index]->nb_unexp);    } else if (scenario[index] -> pause_max) {      if(toolMode == MODE_SERVER) {        fprintf(f,"  [%6dms/%6dms] Pause      ", scenario[index]->pause_min, scenario[index]->pause_max);      } else {         fprintf(f,"       Pause [%6dms/%6dms] ", scenario[index]->pause_min, scenario[index]->pause_max);      }      fprintf(f,"%-9d", scenario[index]->sessions);      fprintf(f,"                     %-9d" , scenario[index]->nb_unexp);    } 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);    }    else if(scenario[index] -> M_type == MSG_TYPE_NOP) {      fprintf(f,"              [ NOP ]              ");    }#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("Scenario command not implemented in display\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){  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] = ", j);                  action->afficheInfo();                  printf(SIPP_ENDL);                  found = true;                }            }        }    }  if(!found) printf("=> No action found on any messages"SIPP_ENDL);    printf(SIPP_ENDL);  printf("Setted Variable List:" SIPP_ENDL);  found = false;  for(i=0; i<SCEN_VARIABLE_SIZE; i++) {    for (int j=0;j<SCEN_MAX_MESSAGES;j++)    {      variable = scenVariableTable[i][j];      if(variable != NULL)        {          printf("=> Variable[%d] : setted regExp[%s]" SIPP_ENDL,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -