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

📄 sipp.cpp

📁 sip终端
💻 CPP
📖 第 1 页 / 共 5 页
字号:
               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){  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++)    {      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 */){  if (!signalDump) {     signalDump = true ;  }}/* 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;

⌨️ 快捷键说明

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