?? ua_main.cpp
字號:
// System include files
#include <signal.h>
#include <memory>
#include <pthread.h>
#include <strings.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef __hpux
#include <sys/mpctl.h>
#endif //__hpux
// SIP include files
#include "sip_api.h"
#include "mgt_api.h"
#include "SIP_Scheduler.h"
#include "SIP_Probe.h"
#include "SIP_ProbeManager.h"
#include "UA_AppProbe.hpp"
#include "UA_Service.hpp"
#include "UA_Session.hpp"
#include "SIP_AppProbeManager.h"
// Application include files
#include <string>
#include <vector>
#include <iostream>
#ifdef __linux__
#include <sys/errno.h>
hrtime_t gethrtime() //return time in ns
{
hrtime_t L_time = 0;
u_int64_t L_buff=0;
struct timeval L_tv;
gettimeofday(&L_tv,0);
L_buff=L_tv.tv_usec;
L_buff= L_buff*1000;
L_time += L_buff;
L_buff=L_tv.tv_sec;
L_buff= L_buff*1000000000;
L_time += L_buff;
return L_time;
}
#endif //__linux__
// global variables
#define NUM_OF_TH 255
int G_reply;
int G_time_wait;
int G_trace;
hrtime_t G_sleep;
int G_cps;
int G_closeMode;
std::vector<UA_AppProbe*> L_probeTab;
std::vector<UA_AppProbe*>::iterator L_probeTabIterator;
hrtime_t time_v;
int L_nbProbe;
std::string L_target;
pthread_t pthread_id[NUM_OF_TH];
timeval G_jamMachineTimeout;
int L_nbSenderThread;
int G_Buggy_terminated=0;
int G_destroy_on_unsubscribe=0;
int G_snn_option=0;
int G_subscribe=0;
int G_new_call=0;
int G_expires=0;
int G_multiple_ta=0;
int G_refer=0;
std::string G_referTo;
int G_stateless_bye = 0;
int G_stateless_messages = 0;
int G_reinvite = 0;
char * G_service_username;
int G_portNumber;
int G_blockingMode = false;
int G_nfinishedCalls = 0;
int G_silent = 0;
sip_msg_uri_t * G_redir = 0;
int G_server_close = 0;
void jamMachine (bool P_blockingMode)
{
printf("New thread created\n");
do
{
if (!L_probeTab.empty())
{
time_v = gethrtime();
UA_AppProbe* L_appProbe = L_probeTab[time_v%L_nbProbe];
if (L_appProbe->getState() != SIP_PROBE_ACTIVE)
L_appProbe->getProbe().stateChange(SIP_PROBE_ACTIVE);
for (int i = G_cps/(5*L_nbSenderThread);i>=0;i--)
{
if(!G_stateless_bye) {
L_appProbe->initOrReinitSession(L_target,
&L_appProbe->getService(),
NULL);
} else {
char L_CallID[20];
sprintf(L_CallID, "%lu_%d", pthread_self(),i);
L_appProbe->statelessRequest(L_target,
&L_appProbe->getService(),
SIP_MSG_BYE,
NULL,
L_CallID);
}
if (G_trace == 1) {
printf("New call initiated by thread %d\n", pthread_self());
}
}
}
if (P_blockingMode)
{
select(0,0,0,0,&G_jamMachineTimeout);
}
}while (P_blockingMode);
}
void lp_provision(int AI_probe_index,
char * AP_className,
char * AP_appli_name,
char * AP_probe,
char * AP_username_info)
{
char VP_le[20];
char VP_lp[20];
char VA_path[1024];
mgt_status_t VI_status;
sprintf(VP_le,"%s_LE", AP_probe);
sprintf(VP_lp,"LP%d", AI_probe_index+1);
printf("Provisionning listenning Point '%s':\n", VP_lp);
sprintf(VA_path, "/%s@%s/SAPs/%s/LPs/%s/UserInfo",
AP_className,
AP_appli_name, AP_probe, VP_lp);
printf(" %s = '%s'.\n", VA_path, AP_username_info);
VI_status = mgt_provision("SIP",
VA_path,
MGT_PROV_STRING,
(void *)AP_username_info,
80,
NULL);
if (VI_status != MGT_NORMAL) {
printf("Error in provisioning Userinfo\n");
exit(1);
}
sprintf(VA_path, "/%s@%s/SAPs/%s/LPs/%s/LEname",
AP_className,
AP_appli_name, AP_probe, VP_lp);
printf(" %s = '%s'.\n", VA_path, VP_le);
VI_status = mgt_provision("SIP",
VA_path,
MGT_PROV_STRING,
(void *)VP_le,
80,
NULL);
if (VI_status != MGT_NORMAL) {
printf("Error in provisioning LE name\n");
exit(1);
}
}
void ta_provision(int AI_probe_index,
char * AP_className,
char * AP_appli_name,
char * AP_probe,
char * AP_addr,
int AI_port,
SIP_TransportType AE_protocol)
{
char VP_le[20];
char VP_ta[20];
char VA_path[1024];
char * VP_protocol;
mgt_status_t VI_status;
if (AE_protocol == SIP_TRANSPORT_TCP) {
VP_protocol = (char *)"TCP";
} else {
VP_protocol = (char *)"UDP";
}
sprintf(VP_le,"%s_LE", AP_probe);
sprintf(VP_ta,"TA_%s_%d", VP_protocol, AI_port);
// TA/LE Provisionning
printf("Provisionning Transport Address '%s':\n",VP_ta);
sprintf(VA_path, "/%s@%s/LEs/%s/TAs/%s/Address",
AP_className,
AP_appli_name, VP_le, VP_ta);
printf(" %s = '%s'.\n", VA_path, AP_addr);
VI_status = mgt_provision("SIP",
VA_path,
MGT_PROV_STRING,
(void *)AP_addr,
80,
NULL);
if (VI_status != MGT_NORMAL) {
printf("Error in provisioning Address\n");
exit(1);
}
sprintf(VA_path, "/%s@%s/LEs/%s/TAs/%s/Port",
AP_className,
AP_appli_name, VP_le, VP_ta);
printf(" %s = %d.\n", VA_path, AI_port);
VI_status = mgt_provision("SIP",
VA_path,
MGT_PROV_UINT,
(void *)(&AI_port),
sizeof(unsigned short),
NULL);
if (VI_status != MGT_NORMAL) {
printf("Error in provisioning Port\n");
exit(1);
}
sprintf(VA_path, "/%s@%s/LEs/%s/TAs/%s/Protocol",
AP_className,
AP_appli_name, VP_le, VP_ta);
printf(" %s = '%s'.\n", VA_path, VP_protocol);
VI_status = mgt_provision("SIP",
VA_path,
MGT_PROV_STRING,
VP_protocol,
80,
NULL);
if (VI_status != MGT_NORMAL) {
printf("Error in provisioning Protocol\n");
exit(1);
}
}
void misc_provision(int AI_probe_index,
char * AP_className,
char * AP_appli_name,
char * AP_probe,
int VB_stateless,
int VB_destructive_mode,
int VB_trans_deleted_event)
{
char VP_le[20];
char VA_path[1024];
mgt_status_t VI_status;
mgt_bool_t VB_true = MGT_TRUE;
int VI_true = 1;
printf("enter in misc_provision\n");
sprintf(VP_le,"%s_LE", AP_probe);
if(VB_stateless) {
printf("in VB_stateless\n");
printf("Provisionning stateless mode:\n");
sprintf(VA_path, "/%s@%s/LEs/%s/CallHandling/AllowCallStatelessMessages",
AP_className,
AP_appli_name, VP_le);
printf(" %s = 'true'.\n", VA_path);
VI_status = mgt_provision("SIP",
VA_path,
MGT_PROV_BOOL,
(void *)&VB_true,
sizeof(VB_true),
NULL);
if (VI_status != MGT_NORMAL) {
printf("Error in provisioning LE call stateless mode\n");
exit(1);
}
}
// Set the MGT param
if(VB_destructive_mode)
{
printf("in VB_destructive_mode \n");
printf("Provisionning automatic sesssion destruction mode:\n");
sprintf(VA_path,
"%s@%s/SAPs/%s/AutoSessionDestruction",
AP_className,
AP_appli_name,
AP_probe);
printf(" %s = '1'.\n", VA_path);
mgt_provision
("SIP", /* domain_name IN */
VA_path, /* Attribute name */
MGT_PROV_INT, /* MGT_PROV_ entity_type, IN */
(void*)&VI_true, /* value, IN/OUT */
sizeof(VI_true), /* size, IN */
NULL); /* trp_info IN */
}
// Set the MGT param
if(VB_trans_deleted_event)
{
printf("in VB_trans_deleted_event\n");
printf("Provisionning transaction deleted event mode:\n");
sprintf(VA_path,
"%s@%s/SAPs/%s/TransactionDeletedEvent",
AP_className,
AP_appli_name,
AP_probe);
printf(" %s = '1'.\n", VA_path);
mgt_provision
("SIP", /* domain_name IN */
VA_path, /* Attribute name */
MGT_PROV_INT, /* MGT_PROV_ entity_type, IN */
(void*)&VI_true, /* value, IN/OUT */
sizeof(VI_true), /* size, IN */
NULL); /* trp_info IN */
}
}
void usage(char * exe_name, char * ip_add)
{
fprintf
(stderr,
"\nUsage: %s [options]\n"
"\n"
" Without options, starts a default UAS on standard 5060 UDP port with\n"
" servicename 'service'. Various options allows to start UAC mode and,\n"
" or activate various protocol options.\n"
"\n"
" Options:\n"
" --------\n"
"\n"
" -h: Displays this help screen\n"
"\n"
" -l sip:username@IP:port:\n"
"\n"
" The local server to bind (default is\n"
" sip:service@%s:5060)\n"
"\n"
" -p port: Overides the default port number used locally.\n"
"\n"
" -srv username: Overides the default username used locally.\n"
"\n"
" -v: Verbose mode, activates minimal tracing\n"
"\n"
" -mgt name: Management (GMF) className\n"
"\n"
" -n nb_call: Number of calls before exiting (default is 1).\n"
"\n"
" -ubs: Triggers a unbind/bind of the service at"
" nb_call/2.\n"
"\n"
" -ubp: Unbind probe at the end of test.\n"
"\n"
" -np nb_probes: Number of listening probes.\n"
"\n"
" -silent: Silent mode. Only prints a counter every 1000\n"
" sessions.\n"
"\n"
#ifdef __hpux
" -cpu cpu_id: Set CPU affinity on SMP HPUX machines.\n"
"\n"
#endif
" -sd: Set the AutoSessionDestruction management \n"
" parameter to true. This triggers automatic session\n"
" destruction from the stack.\n"
"\n"
" -st: Set the TransactionDeletedEvent management \n"
" parameter to true. This triggers automatic \n"
" delivery of transaction deleted events.\n"
"\n"
" -ff name: Specifies the name of an alternative filter-\n"
" formater library (default is 'defaultFF', which\n"
" is embeded in the stack).\n"
"\n"
" -pm name: Sets the ProbeManager name. Use this option to\n"
" select an entry for tracing in debug.conf.\n"
"\n"
" -mp: Manual provisionning: Do not use the probe\n"
" constructor to provision mandatory MGT parameters,\n"
" use mgt_provision instead.\n"
"\n"
" -mp2ta: Same as -mp but provision 2 TAs per LP.\n"
"\n"
" -ro role: The Role may be UA, B2BController or B2BProxy \n"
" default is UA.\n"
"\n"
" -st: Allows stateless messages (Sets the \n"
" .../CallHandling/AllowCallStatelessMessages \n"
" management boolean parameter). This option is\n"
" mainly intended for the UAS. When set, the UAS\n"
" replies 200 OK to a stateless BYE request.\n"
"\n"
" -startbusy: Start state is busy.\n"
"\n"
" -noservice: Start without service bound.\n"
"\n"
" -smd: Select minimal delay in ms between 2 calls.\n"
"\n"
" -cl scenario: Close secnario (default is 0):\n"
"\n"
" 0: currentDialogMustBeClosed() message method,\n"
" 1: destroySession Probe API routine,\n"
" 2: BYE request.\n"
"\n"
" UAS options:\n"
" ------------\n"
"\n"
" -r scenario: UAS reply secnario (Default is 1):\n"
"\n"
" 1: (180 + 200),\n"
" 2: (200).\n"
" 3: (3xx),\n"
"\n"
" -redir URI: Redirect address used for contact header in 302\n"
" responses. This option automatically activates\n"
" scenario -r 3.\n"
"\n"
" -t delay: Time in seconds between Ringing and Ack rsp\n"
" (default is 0).\n"
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -