|
reSIProcate/stack
9694
|
#include <sys/types.h>#include <unistd.h>#include <iostream>#include <memory>#include "rutil/DnsUtil.hxx"#include "rutil/Inserter.hxx"#include "rutil/Logger.hxx"#include "resip/stack/Helper.hxx"#include "resip/stack/SipMessage.hxx"#include "resip/stack/SipStack.hxx"#include "resip/stack/Uri.hxx"
Go to the source code of this file.
Defines | |
| #define | RESIPROCATE_SUBSYSTEM Subsystem::SIP |
Functions | |
| int | main (int argc, char *argv[]) |
| #define RESIPROCATE_SUBSYSTEM Subsystem::SIP |
Definition at line 33 of file testTls.cxx.
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 36 of file testTls.cxx.
References resip::SipStack::addTransport(), resip::SipStack::buildFdSet(), context, DebugLog, resip::DTLS, resip::RequestLine::getMethod(), resip::Timer::getTimeMs(), resip::SipMessage::header(), resip::Uri::host(), InfoLog, resip::Log::initialize(), resip::SipMessage::isRequest(), resip::SipMessage::isResponse(), resip::Helper::makeRegister(), resip::Helper::makeResponse(), resip::RequestLine::method(), resip::ParserCategory::param(), resip::Uri::port(), resip::SipStack::process(), resip::SipStack::receive(), resip::Uri::scheme(), resip::FdSet::selectMilliSeconds(), resip::SipStack::send(), resip::StunDisabled, resip::TLS, resip::NameAddr::uri(), resip::Uri::user(), and resip::V4.
{
#ifdef USE_SSL
char logType[] = "cout";
char logLevel[] = "DEBUG";
int window = 5*20;
int seltime = 100;
const int MaxStacks=100;
int numStacks=20;
//logLevel = "ALERT";
//logLevel = "INFO";
#if defined(HAVE_POPT_H)
struct poptOption table[] = {
{"log-type", 'l', POPT_ARG_STRING, &logType, 0, "where to send logging messages", "syslog|cerr|cout"},
{"log-level", 'v', POPT_ARG_STRING, &logLevel, 0, "specify the default log level", "DEBUG|INFO|WARNING|ALERT"},
{"num-stacks", 'r', POPT_ARG_INT, &numStacks, 0, "number of calls in test", 0},
{"window-size", 'w', POPT_ARG_INT, &window, 0, "number of concurrent transactions", 0},
{"select-time", 's', POPT_ARG_INT, &seltime, 0, "number of runs in test", 0},
POPT_AUTOHELP
{ NULL, 0, 0, NULL, 0 }
};
poptContext context = poptGetContext(NULL, argc, const_cast<const char**>(argv), table, 0);
poptGetNextOpt(context);
#endif
int runs = 3*numStacks*numStacks;
runs = 1;
Log::initialize(logType, logLevel, argv[0]);
cout << "Performing " << runs << " runs." << endl;
IpVersion version = V4;
Data bindInterface;
//bindInterface = Data( "127.0.0.1" );
SipStack* stack[MaxStacks];
for ( int s=0; s<numStacks; s++)
{
stack[s] = new SipStack;
Data domain = Data("example") + Data(s) +".com";
#ifdef USE_DTLS
stack[s]->addTransport(DTLS, 25000+s,version, StunDisabled, bindInterface, domain);
#else
stack[s]->addTransport(TLS, 25000+s,version, StunDisabled, bindInterface, domain);
#endif
}
NameAddr target;
target.uri().scheme() = "sip";
target.uri().user() = "fluffy";
target.uri().host() = Data("127.0.0.1");
target.uri().port() = 25000;
#ifdef USE_DTLS
target.uri().param(p_transport) = "dtls";
#else
target.uri().param(p_transport) = "tls";
#endif
NameAddr contact;
contact.uri().scheme() = "sip";
contact.uri().user() = "fluffy";
contact.uri().host() = Data("127.0.0.1");
contact.uri().port() = 25000;
NameAddr from = target;
from.uri().port() = 25000;
UInt64 startTime = Timer::getTimeMs();
int outstanding=0;
int count = 0;
int sent = 0;
int msgMod=0;
while (count < runs)
{
//InfoLog (<< "count=" << count << " messages=" << messages.size());
// load up the send window
while (sent < runs && outstanding < window)
{
DebugLog (<< "Sending " << count << " / " << runs << " (" << outstanding << ")");
// send from stack s to to stack r
int s = msgMod%numStacks;
int r = (msgMod/numStacks)%numStacks;
msgMod++;
if ( s == r )
{
continue;
}
target.uri().port() = 25000+r;
from.uri().port() = 25000+s;
contact.uri().port() = 25000+s;
SipMessage* msg = Helper::makeRegister( target, from, contact);
msg->header(h_Vias).front().sentPort() = 25000+s;
stack[s]->send(*msg);
outstanding++;
sent++;
delete msg;
}
FdSet fdset;
for ( int s=0; s<numStacks; s++)
{
stack[s]->buildFdSet(fdset);
}
fdset.selectMilliSeconds(seltime);
for ( int s=0; s<numStacks; s++)
{
stack[s]->process(fdset);
}
for ( int s=0; s<numStacks; s++)
{
SipMessage* msg = stack[s]->receive();
if ( msg )
{
if ( msg->isRequest() )
{
assert(msg->isRequest());
assert(msg->header(h_RequestLine).getMethod() == REGISTER);
SipMessage* response = Helper::makeResponse(*msg, 200);
stack[s]->send(*response);
delete response;
delete msg;
}
else
{
assert(msg->isResponse());
assert(msg->header(h_CSeq).method() == REGISTER);
assert(msg->header(h_StatusLine).statusCode() == 200);
outstanding--;
count++;
delete msg;
}
}
}
}
InfoLog (<< "Finished " << count << " runs");
UInt64 elapsed = Timer::getTimeMs() - startTime;
cout << runs << " registrations peformed in " << elapsed << " ms, a rate of "
<< runs / ((float) elapsed / 1000.0) << " transactions per second.]" << endl;
#if defined(HAVE_POPT_H)
poptFreeContext(context);
#endif
while (true)
{
sleep(10);
}
#endif
return 0;
}

1.7.5.1