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

📄 scenario.cpp

📁 sipp is sip protocal testing tool.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            (char *) malloc(strlen(ptr) + 3);                  if(!msg) { ERROR("Memory Overflow"); }          strcpy(msg, ptr);                    //          // If this is a request we are sending, then copy over the method so that we can associate          // responses to the request          //          if (0 != strncmp (ptr, "SIP/2.0", 7) )          {            char *methodEnd = ptr;            int   bytesToCopy = 0;            while (*methodEnd != ' ') {              methodEnd++;              bytesToCopy++;            }            if (method_list_length + bytesToCopy + 1 > METHOD_LIST_LENGTH) {              ERROR_P2("METHOD_LIST_LENGTH in scenario.hpp is too small (currently %d, need at least %d). Please modify and recompile.",                        METHOD_LIST_LENGTH,                       method_list_length + bytesToCopy + 1);            }            strncat (method_list, ptr, bytesToCopy);            method_list_length += bytesToCopy;            method_list[method_list_length+1] = '\0';          }          L_content_length = xp_get_content_length(msg);           switch (L_content_length) {            case  -1 :                   // the msg does not contain content-length field                  break ;            case  0 :                  scenario[scenario_len] -> content_length_flag =                            message::ContentLengthValueZero;   // Initialize to No present                  break ;            default :                  scenario[scenario_len] -> content_length_flag =                            message::ContentLengthValueNoZero;   // Initialize to No present                  break ;                      }                     ptr = msg + strlen(msg);          ptr --;          while((ptr >= msg) &&                 ((*ptr == ' ')  ||                  (*ptr == '\t') ||                  (*ptr == '\n'))) {            if(*ptr == '\n') {              removed_clrf++;            }            *ptr-- = 0;          }                  if(ptr == msg) {            ERROR("Empty cdata in xml scenario file");              }          if(!strstr(msg, "\n\n")) {            strcat(msg, "\n\n");          }                  while(ptr = strstr(msg, "\n ")) {            memmove(((char *)(ptr + 1)),                     ((char *)(ptr + 2)),                     strlen(ptr) - 1);          }                  while(ptr = strstr(msg, " \n")) {            memmove(((char *)(ptr)),                     ((char *)(ptr + 1)),                     strlen(ptr));          }          if((msg[strlen(msg) - 1] != '\n') && (removed_clrf)) {            strcat(msg, "\n");          }        } else {          ERROR("No CDATA in 'send' section of xml scenario file");        }              if(ptr = xp_get_value((char *)"retrans")) {          scenario[scenario_len] -> retrans_delay = get_long(ptr, "retransmission timer");        }              if(ptr = xp_get_value((char *)"rtd")) {          scenario[scenario_len] -> stop_rtd = get_rtd(ptr);	}        if(ptr = xp_get_value((char *)"start_rtd")) {          scenario[scenario_len] -> start_rtd = get_rtd(ptr);	}        if(ptr = xp_get_value((char *)"counter")) {          scenario[scenario_len] -> counter = get_counter(ptr, "counter");	}#ifdef PCAPPLAY        getActionForThisMessage();#endif      } else if(!strcmp(elem, (char *)"recv")) {        recv_count++;        scenario[scenario_len]->M_type = MSG_TYPE_RECV;        /* Received messages descriptions */        if(ptr = xp_get_value((char *)"response")) {          scenario[scenario_len] -> recv_response = get_long(ptr, "response code");          strcpy (scenario[scenario_len]->recv_response_for_cseq_method_list, method_list);        }        if(ptr = xp_get_value((char *)"request")) {          scenario[scenario_len] -> recv_request = strdup(ptr);        }        if(ptr = xp_get_value((char *)"rtd")) {          scenario[scenario_len] -> stop_rtd = get_rtd(ptr);	}        if(ptr = xp_get_value((char *)"start_rtd")) {          scenario[scenario_len] -> start_rtd = get_rtd(ptr);	}	if(ptr = xp_get_value((char *)"counter")) {	  scenario[scenario_len] -> counter = get_counter(ptr, "counter");	}        if (0 != (ptr = xp_get_value((char *)"optional"))) {          if(!strcmp(ptr, "true")) {            scenario[scenario_len] -> optional = OPTIONAL_TRUE;            ++recv_opt_count;          } else if(!strcmp(ptr, "global")) {            scenario[scenario_len] -> optional = OPTIONAL_GLOBAL;            ++recv_opt_count;          } else if(!strcmp(ptr, "false")) {            scenario[scenario_len] -> optional = OPTIONAL_FALSE;          } else {	    ERROR_P1("Could not understand optional value: %s", ptr);	  }        }        if (0 != (ptr = xp_get_value((char *)"timeout"))) {          scenario[scenario_len]->retrans_delay = get_long(ptr, "message timeout");        }        /* record the route set  */        /* TODO disallow optional and rrs to coexist? */        if(ptr = xp_get_value((char *)"rrs")) {	  scenario[scenario_len] -> bShouldRecordRoutes = get_bool(ptr, "record route set");        }      #ifdef _USE_OPENSSL        /* record the authentication credentials  */        if(ptr = xp_get_value((char *)"auth")) {	  scenario[scenario_len] -> bShouldAuthenticate = get_bool(ptr, "message authentication");        }#endif        getActionForThisMessage();      } else if(!strcmp(elem, "pause")) {        if (recv_count) {          if (recv_count != recv_opt_count) {            recv_count = 0;            recv_opt_count = 0;          } else {            ERROR_P1("<recv> before <send> sequence without a mandatory message. Please remove one 'optional=true'.", scenario_file_cursor);          }        }        scenario[scenario_len]->M_type = MSG_TYPE_PAUSE;	if(ptr = xp_get_value("milliseconds")) {	  scenario[scenario_len] -> pause_function = pause_default;	  scenario[scenario_len] -> pause_param = get_long(ptr, "Pause milliseconds");	  scenario[scenario_len] -> pause_desc =	    strdup(time_string(scenario[scenario_len] -> pause_param));	  scenario_duration += scenario[scenario_len] -> pause_param;	} else if(xp_get_value("min") || xp_get_value("max")) {	  int isMin = !!xp_get_value("min");	  int isMax = !!xp_get_value("max");	  int min, max;	  char tmp[42];	  if (isMin && !isMax) {	    ERROR("Max without min for a variable pause");	  }	  if (isMax && !isMin) {	    ERROR("Min without max for a variable pause");	  }	  min = get_long(xp_get_value("min"), "Pause minimum");	  max = get_long(xp_get_value("max"), "Pause maximum");	  scenario[scenario_len] -> pause_function = pause_uniform;	  strncpy(tmp, time_string(min), sizeof(tmp));	  strncat(tmp, "/", sizeof(tmp) - strlen(tmp));	  strncat(tmp, time_string(max), sizeof(tmp) - strlen(tmp));	  scenario[scenario_len] -> pause_desc = strdup(tmp);	  scenario[scenario_len] -> pause_param = min;	  scenario[scenario_len] -> pause_param2 = max;	  if (min >= max) {	    ERROR("Min is greater than or equal to max in variable pause!");	  }          /* Update scenario duration with max duration */	  scenario_duration += scenario[scenario_len] -> pause_param;#ifdef HAVE_GSL	} else if (xp_get_value("normal")) {	  long mean = 0;	  long stdev = 1;	  char tmp[45];	  init_rng();          if (ptr = xp_get_value("mean")) {		mean = get_long(ptr, "Mean pause");	  }          if (ptr = xp_get_value("stdev")) {		stdev = get_long(ptr, "Pause standard deviation");	  }	  if (stdev < 0) {	    ERROR_P1("Standard deviations must be positive: %d\n", stdev);	  }	  if (mean < 0) {	    ERROR_P1("Pause means should not be negative: %d\n", mean);	  }          scenario[scenario_len] -> pause_param  = mean;          scenario[scenario_len] -> pause_param2 = stdev;	  scenario[scenario_len] -> pause_function = pause_normal;	  strcpy(tmp, "N(");	  strncat(tmp, time_string(mean), sizeof(tmp) - strlen(tmp));	  strncat(tmp, ",", sizeof(tmp) - strlen(tmp));	  strncat(tmp, time_string(stdev), sizeof(tmp) - strlen(tmp));	  strncat(tmp, ")", sizeof(tmp) - strlen(tmp));	  scenario[scenario_len] -> pause_desc = strdup(tmp);	  /* We have no true maximum duration for a distributed pause, but this	   * captures 99% of all calls. */	  scenario_duration += (int)gsl_cdf_gaussian_Pinv(0.99, stdev) + mean;	} else if (xp_get_value("lognormal")) {	  double mean = 0;	  double stdev = 1;	  char tmp[46];	  init_rng();          if (ptr = xp_get_value("mean")) {		mean = get_double(ptr, "Exp(Mean) pause");	  }          if (ptr = xp_get_value("stdev")) {		stdev = get_double(ptr, "Pause standard deviation");	  }	  if (stdev < 0) {	    ERROR_P1("Standard deviations must be positive: %d\n", stdev);	  }	  if (mean < 0) {	    ERROR_P1("Pause means should not be negative: %d\n", mean);	  }          scenario[scenario_len] -> pause_dparam  = mean;          scenario[scenario_len] -> pause_dparam2 = stdev;	  scenario[scenario_len] -> pause_function = pause_lognormal;	  strcpy(tmp, "LN(");	  strncat(tmp, double_time_string(mean), sizeof(tmp) - strlen(tmp));	  strncat(tmp, ",", sizeof(tmp) - strlen(tmp));	  strncat(tmp, double_time_string(stdev), sizeof(tmp) - strlen(tmp));	  strncat(tmp, ")", sizeof(tmp) - strlen(tmp));	  scenario[scenario_len] -> pause_desc = strdup(tmp);	  /* It is easy to shoot yourself in the foot with this distribution,	   * so the 99-th percentile serves as a sanity check for duration. */	  if (gsl_cdf_lognormal_Pinv(0.99, mean, stdev) > INT_MAX) {	    ERROR_P2("You should use different Lognormal(%d, %d) parameters.\n"		"The scenario is likely to take much too long.\n", mean, stdev);	  }	  scenario_duration += (int)gsl_cdf_lognormal_Pinv(0.99, mean, stdev);	} else if (xp_get_value("exponential")) {	  long mean = 0;	  char tmp[26];	  init_rng();          if (ptr = xp_get_value("mean")) {		mean = get_long(ptr, "Mean pause");	  }	  if (mean < 0) {	    ERROR_P1("Pause means should not be negative: %d\n", mean);	  }          scenario[scenario_len] -> pause_param = mean;          scenario[scenario_len] -> pause_function = pause_exponential;	  strcpy(tmp, "Exp(");	  strncat(tmp, time_string(mean), sizeof(tmp) - strlen(tmp));	  strncat(tmp, ")", sizeof(tmp) - strlen(tmp));	  scenario[scenario_len] -> pause_desc = strdup(tmp);	  scenario_duration += (int)gsl_cdf_exponential_Pinv(0.99, mean);#else	} else if (xp_get_value("normal") ||		   xp_get_value("lognormal") ||		   xp_get_value("exponential")	          ) {	  ERROR("To use a statistically distributed pause, you must have the GNU Scientific Library.\n");#endif        } else {	  scenario[scenario_len] -> pause_function = pause_default;          scenario[scenario_len] -> pause_param = -1;	  scenario[scenario_len] -> pause_desc = strdup(time_string(duration));        }        getActionForThisMessage();      }      else if(!strcmp(elem, "nop")) {	/* Does nothing at SIP level.  This message type can be used to handle	 * actions, increment counters, or for RTDs. */	scenario[scenario_len]->M_type = MSG_TYPE_NOP;        if(ptr = xp_get_value((char *)"rtd")) {          scenario[scenario_len] -> stop_rtd = get_rtd(ptr);	}        if(ptr = xp_get_value((char *)"start_rtd")) {          scenario[scenario_len] -> start_rtd = get_rtd(ptr);	}        if(ptr = xp_get_value((char *)"counter")) {          scenario[scenario_len] -> counter = get_counter(ptr, "counter");	}        getActionForThisMessage();      }#ifdef __3PCC__      else if(!strcmp(elem, "recvCmd")) {        if (recv_count) {          if (recv_count != recv_opt_count) {            recv_count = 0;            recv_opt_count = 0;          } else {            ERROR_P1("<recv> before <send> sequence without a mandatory message. Please remove one 'optional=true'.", scenario_file_cursor);          }        }        scenario[scenario_len]->M_type = MSG_TYPE_RECVCMD;        getActionForThisMessage();      } else if(!strcmp(elem, "sendCmd")) {        if (recv_count) {          if (recv_count != recv_opt_count) {            recv_count = 0;            recv_opt_count = 0;          } else {            ERROR_P1("<recv> before <send> sequence without a mandatory message. Please remove one 'optional=true'.", scenario_file_cursor);          }        }        scenario[scenario_len]->M_type = MSG_TYPE_SENDCMD;        /* Sent messages descriptions */        if(ptr = xp_get_cdata()) {                  char * msg;                  while((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n')) ptr++;                  msg =             scenario[scenario_len] -> M_sendCmdData =             (char *) malloc(strlen(ptr) + 3);                  if(!msg) { ERROR("Memory Overflow"); }

⌨️ 快捷键说明

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