|
reSIProcate/stack
9694
|
#include <iostream>#include "resip/stack/UdpTransport.hxx"#include "resip/stack/Helper.hxx"#include "resip/stack/SipMessage.hxx"#include "resip/stack/Uri.hxx"#include "rutil/Data.hxx"#include "rutil/DnsUtil.hxx"#include "rutil/Logger.hxx"#include "rutil/DataStream.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 27 of file testUdp.cxx.
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 30 of file testUdp.cxx.
References resip::UdpTransport::buildFdSet(), context, resip::Log::Cout, resip::Log::Debug, dest, resip::Data::Empty, resip::SipMessage::encode(), resip::Fifo< Msg >::getNext(), resip::Timer::getTimeMs(), resip::SipMessage::header(), resip::Uri::host(), resip::DnsUtil::inet_pton(), InfoLog, resip::Log::initialize(), resip::initNetwork(), resip::Helper::makeInvite(), resip::Transport::makeSendData(), resip::AbstractFifo< T >::messageAvailable(), resip::ParserCategory::param(), resip::Uri::port(), resip::UdpTransport::process(), received, resipCout, resip::Uri::scheme(), resip::FdSet::selectMilliSeconds(), resip::InternalTransport::send(), resip::StunDisabled, resip::UDP, resip::RequestLine::uri(), resip::NameAddr::uri(), resip::Uri::user(), and resip::V4.
{
char* logType = 0;
char* logLevel = 0;
int runs = 100;
int window = 10;
int seltime = 100;
#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-runs", 'r', POPT_ARG_INT, &runs, 0, "number of calls in test", 0},
{"window-size", 'w', POPT_ARG_INT, &window, 0, "number of registrations in test", 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
#ifdef WIN32
Log::initialize(Log::Cout, Log::Debug, argv[0]);
initNetwork();
#else
Log::initialize(logType, logLevel, argv[0]);
#endif
cout << "Performing " << runs << " runs." << endl;
Fifo<TransactionMessage> txFifo;
UdpTransport* sender = new UdpTransport(txFifo, 5070, V4, StunDisabled, Data::Empty);
Fifo<TransactionMessage> rxFifo;
UdpTransport* receiver = new UdpTransport(rxFifo, 5080, V4, StunDisabled, Data::Empty);
NameAddr target;
target.uri().scheme() = "sip";
target.uri().user() = "fluffy";
target.uri().host() = "bremen.internal.xten.net";
target.uri().port() = 5080;
target.uri().param(p_transport) = "udp";
NameAddr from = target;
from.uri().port() = 5070;
InfoLog (<< "Creating messages");
list<SipMessage*> messages;
{
UInt64 startTime = Timer::getTimeMs();
for (int i=0; i<runs; i++)
{
SipMessage* m = Helper::makeInvite( target, from, from);
//m->header(h_Vias).front().transport() = Tuple::toData(sender->transport());
//m->header(h_Vias).front().sentHost() = "localhost";
//m->header(h_Vias).front().sentPort() = sender->port();
messages.push_back(m);
}
UInt64 elapsed = Timer::getTimeMs() - startTime;
cout << runs << " calls peformed in " << elapsed << " ms, a rate of "
<< runs / ((float) elapsed / 1000.0) << " calls per second.]" << endl;
InfoLog (<< "Messages created");
}
in_addr in;
DnsUtil::inet_pton("127.0.0.1", in);
Tuple dest(in, target.uri().port(), UDP);
InfoLog (<< "Sending to " << dest);
UInt64 startTime = Timer::getTimeMs();
int tid=1;
int outstanding=0;
int count=0;
while (!messages.empty())
{
if (count > 500) exit(0);
// load up the send window
while (outstanding < window)
{
Data encoded;
{
DataStream strm(encoded);
SipMessage* next = messages.front();
messages.pop_front();
next->encode(strm);
outstanding++;
}
std::auto_ptr<SendData> toSend(sender->makeSendData(dest, encoded, Data(tid++), Data::Empty));
sender->send(toSend);
}
FdSet fdset;
receiver->buildFdSet(fdset);
//sender->buildFdSet(fdset);
fdset.selectMilliSeconds(seltime);
receiver->process(fdset);
sender->process(fdset);
Message* msg;
if (rxFifo.messageAvailable())
{
msg = rxFifo.getNext();
SipMessage* received = dynamic_cast<SipMessage*>(msg);
if (received)
{
received->encode(resipCout);
outstanding--;
assert (received->header(h_RequestLine).uri().host() == "localhost");
assert (received->header(h_To).uri().host() == "localhost");
assert (received->header(h_From).uri().host() == "localhost");
//assert (!received->header(h_Vias).begin()->sentHost().empty());
assert(received->header(h_Vias).begin()->param(p_received) == "127.0.0.1");
assert (received->header(h_Contacts).begin()->uri().host() == "localhost");
assert (!received->header(h_CallId).value().empty());
delete received;
}
}
}
UInt64 elapsed = Timer::getTimeMs() - startTime;
cout << runs << " calls peformed in " << elapsed << " ms, a rate of "
<< runs / ((float) elapsed / 1000.0) << " calls per second.]" << endl;
return 0;
}

1.7.5.1