reSIProcate/stack  9694
Register.cxx
Go to the documentation of this file.
00001 #include <memory>
00002 
00003 #include "rutil/Logger.hxx"
00004 #include "rutil/Timer.hxx"
00005 
00006 #include "resip/stack/SipMessage.hxx"
00007 #include "resip/stack/Helper.hxx"
00008 #include "Resolver.hxx"
00009 
00010 #include "Register.hxx"
00011 #include "Transceiver.hxx"
00012 
00013 using namespace resip;
00014 using namespace Loadgen;
00015 using namespace std;
00016 
00017 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
00018 
00019 Register::Register(Transceiver& transceiver, const resip::Uri& registrand, 
00020                    int firstExtension, int lastExtension, 
00021                    int numRegistrations)
00022    : mTransceiver(transceiver),
00023      mRegistrand(registrand),
00024      mFirstExtension(firstExtension),
00025      mLastExtension(lastExtension),
00026      mNumRegistrations(numRegistrations)
00027 {
00028    if (mNumRegistrations == 0)
00029    {
00030       mNumRegistrations = mLastExtension - mFirstExtension;
00031    }
00032 }
00033 
00034 void
00035 Register::go()
00036 {
00037    int numRegistered = 0;
00038    
00039    Resolver target(mRegistrand);
00040    NameAddr registrand;
00041    registrand.uri() = mRegistrand;
00042    NameAddr aor(registrand);
00043    
00044    NameAddr contact;
00045    contact.uri() = mTransceiver.contactUri();
00046 
00047    UInt64 startTime = Timer::getTimeMs();
00048    while (numRegistered < mNumRegistrations)
00049    {
00050       for (int i=mFirstExtension; i < mLastExtension && numRegistered < mNumRegistrations; i++)
00051       {
00052          aor.uri().user() = Data(i);
00053          contact.uri().user() = Data(i);
00054          
00055          auto_ptr<SipMessage> registration(Helper::makeRegister(registrand, aor, contact) );
00056          //registration->header(h_Contacts).push_back(contact);
00057          
00058          mTransceiver.send(target, *registration);
00059          
00060          SipMessage* reg = mTransceiver.receive(2000);
00061          if(reg)
00062          {         
00063             auto_ptr<SipMessage> forDel(reg);
00064             //validate here
00065             numRegistered++;
00066          }
00067          else
00068          {
00069             ErrLog(<< "Registrar not responding.");
00070             assert(0);
00071          }
00072       }
00073    }
00074    UInt64 elapsed = Timer::getTimeMs() - startTime;
00075    cout << mNumRegistrations << " peformed in " << elapsed << " ms, a rate of " 
00076         << mNumRegistrations / ((float) elapsed / 1000.0) << " registrations per second." << endl;
00077 }
00078 /* ====================================================================
00079  * The Vovida Software License, Version 1.0 
00080  * 
00081  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00082  * 
00083  * Redistribution and use in source and binary forms, with or without
00084  * modification, are permitted provided that the following conditions
00085  * are met:
00086  * 
00087  * 1. Redistributions of source code must retain the above copyright
00088  *    notice, this list of conditions and the following disclaimer.
00089  * 
00090  * 2. Redistributions in binary form must reproduce the above copyright
00091  *    notice, this list of conditions and the following disclaimer in
00092  *    the documentation and/or other materials provided with the
00093  *    distribution.
00094  * 
00095  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00096  *    and "Vovida Open Communication Application Library (VOCAL)" must
00097  *    not be used to endorse or promote products derived from this
00098  *    software without prior written permission. For written
00099  *    permission, please contact vocal@vovida.org.
00100  *
00101  * 4. Products derived from this software may not be called "VOCAL", nor
00102  *    may "VOCAL" appear in their name, without prior written
00103  *    permission of Vovida Networks, Inc.
00104  * 
00105  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00106  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00107  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00108  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00109  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00110  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00111  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00112  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00113  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00114  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00115  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00116  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00117  * DAMAGE.
00118  * 
00119  * ====================================================================
00120  * 
00121  * This software consists of voluntary contributions made by Vovida
00122  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00123  * Inc.  For more information on Vovida Networks, Inc., please see
00124  * <http://www.vovida.org/>.
00125  *
00126  */