included new protocol messages

This commit is contained in:
Volker Fischer 2011-05-21 20:43:57 +00:00
parent 52210a374d
commit f41f373ead

View file

@ -1,144 +1,261 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2011 * Copyright (c) 2004-2011
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#if !defined ( TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ ) #if !defined ( TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ )
#define TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ #define TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_
#include <qobject.h> #include <qobject.h>
#include <qtimer.h> #include <qtimer.h>
#include <qdatetime.h> #include <qdatetime.h>
#include <qhostaddress.h> #include <qhostaddress.h>
#include "global.h" #include "global.h"
#include "socket.h" #include "socket.h"
#include "protocol.h" #include "protocol.h"
#include "util.h" #include "util.h"
/* Classes ********************************************************************/ /* Classes ********************************************************************/
class CTestbench : public QObject class CTestbench : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CTestbench ( QString sNewAddress, quint16 iNewPort ) : CTestbench ( QString sNewAddress, quint16 iNewPort ) :
sAddress ( sNewAddress ), iPort ( iNewPort ) sAddress ( sNewAddress ), iPort ( iNewPort )
{ {
// bind socket // bind socket (try 100 port numbers)
UdpSocket.bind ( QHostAddress ( QHostAddress::Any ), 22222 ); quint16 iPortIncrement = 0; // start value: port nubmer plus ten
bool bSuccess = false; // initialization for while loop
// connect protocol signal while ( !bSuccess && ( iPortIncrement <= 100 ) )
QObject::connect ( &Protocol, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ), {
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) ); bSuccess = UdpSocket.bind (
QHostAddress( QHostAddress::Any ),
// connect and start the timer (testbench heartbeat) 22222 + iPortIncrement );
QObject::connect ( &Timer, SIGNAL ( timeout() ),
this, SLOT ( OnTimer() ) ); iPortIncrement++;
}
Timer.start ( 1 ); // 1 ms
} // connect protocol signal
QObject::connect ( &Protocol, SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
protected: this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
int GenRandomIntInRange ( const int iStart, const int iEnd ) const
{ // connect and start the timer (testbench heartbeat)
return static_cast<int> ( iStart + QObject::connect ( &Timer, SIGNAL ( timeout() ),
( ( static_cast<double> ( iEnd - iStart + 1 ) * rand() ) / RAND_MAX ) ); this, SLOT ( OnTimer() ) );
}
Timer.start ( 1 ); // 1 ms
QString sAddress; }
quint16 iPort;
QTimer Timer; protected:
CProtocol Protocol; int GenRandomIntInRange ( const int iStart, const int iEnd ) const
QUdpSocket UdpSocket; {
return static_cast<int> ( iStart +
public slots: ( ( static_cast<double> ( iEnd - iStart + 1 ) * rand() ) / RAND_MAX ) );
void OnTimer() }
{
// generate random protocol message QString GenRandomString() const
switch ( GenRandomIntInRange ( 0, 10 ) ) {
{ const int iLen = GenRandomIntInRange ( 0, 111 );
case 0: QString strReturn = "";
Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) ); for ( int i = 0; i < iLen; i++ )
break; {
strReturn += static_cast<char> ( GenRandomIntInRange ( 0, 255 ) );
case 1: }
Protocol.CreateReqJitBufMes(); return strReturn;
break; }
case 2: QString sAddress;
Protocol.CreateChanGainMes ( GenRandomIntInRange ( 0, 20 ), quint16 iPort;
GenRandomIntInRange ( -100, 100 ) ); QTimer Timer;
break; CProtocol Protocol;
QUdpSocket UdpSocket;
case 3:
Protocol.CreateReqConnClientsList(); public slots:
break; void OnTimer()
{
case 4: CVector<CChannelShortInfo> vecChanInfo ( 1 );
Protocol.CreateChanNameMes ( QString ( "test%1" ).arg ( CNetworkTransportProps NetTrProps;
GenRandomIntInRange ( 0, 1000 ) ) ); CServerCoreInfo ServerInfo;
break; CVector<CServerInfo> vecServerInfo ( 1 );
CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort );
case 5:
Protocol.CreateChatTextMes ( QString ( "test%1" ).arg ( // generate random protocol message
GenRandomIntInRange ( 0, 1000 ) ) ); switch ( GenRandomIntInRange ( 0, 22 ) )
break; {
case 0:
case 6: Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) );
Protocol.CreatePingMes ( GenRandomIntInRange ( 0, 100000 ) ); break;
break;
case 1:
case 7: Protocol.CreateReqJitBufMes();
Protocol.CreateReqNetwTranspPropsMes(); break;
break;
case 2:
case 8: Protocol.CreateChanGainMes ( GenRandomIntInRange ( 0, 20 ),
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ), GenRandomIntInRange ( -100, 100 ) );
GenRandomIntInRange ( -100, 100 ) ); break;
break;
case 3:
case 9: vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
Protocol.CreateAndImmSendDisconnectionMes(); vecChanInfo[0].iIpAddr = GenRandomIntInRange ( 0, 100000 );
break; vecChanInfo[0].strName = GenRandomString();
case 10: Protocol.CreateConClientListMes ( vecChanInfo );
// arbitrary "audio" packet (with random sizes) break;
CVector<uint8_t> vecMessage ( GenRandomIntInRange ( 1, 1000 ) );
OnSendProtMessage ( vecMessage ); case 4:
break; Protocol.CreateReqConnClientsList();
} break;
}
case 5:
void OnSendProtMessage ( CVector<uint8_t> vecMessage ) Protocol.CreateChanNameMes ( GenRandomString() );
{ break;
UdpSocket.writeDatagram (
(const char*) &( (CVector<uint8_t>) vecMessage )[0], case 6:
vecMessage.Size(), QHostAddress ( sAddress ), iPort ); Protocol.CreateReqChanNameMes();
break;
// reset protocol so that we do not have to wait for an acknowledge to
// send the next message case 7:
Protocol.Reset(); Protocol.CreateChatTextMes ( GenRandomString() );
} break;
};
case 8:
#endif /* !defined ( TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ ) */ Protocol.CreatePingMes ( GenRandomIntInRange ( 0, 100000 ) );
break;
case 9:
NetTrProps.eAudioCodingType =
static_cast<EAudComprType> ( GenRandomIntInRange ( 0, 2 ) );
NetTrProps.iAudioCodingArg = GenRandomIntInRange ( -100, 100 );
NetTrProps.iBaseNetworkPacketSize = GenRandomIntInRange ( -2, 1000 );
NetTrProps.iBlockSizeFact = GenRandomIntInRange ( -2, 100 );
NetTrProps.iNumAudioChannels = GenRandomIntInRange ( -2, 10 );
NetTrProps.iSampleRate = GenRandomIntInRange ( -2, 10000 );
NetTrProps.iVersion = GenRandomIntInRange ( -2, 10000 );
Protocol.CreateNetwTranspPropsMes ( NetTrProps );
break;
case 10:
Protocol.CreateReqNetwTranspPropsMes();
break;
case 11:
Protocol.CreateCLPingMes ( CurHostAddress,
GenRandomIntInRange ( -2, 1000 ) );
break;
case 12:
Protocol.CreateCLPingWithNumClientsMes ( CurHostAddress,
GenRandomIntInRange ( -2, 1000 ),
GenRandomIntInRange ( -2, 1000 ) );
break;
case 13:
Protocol.CreateCLServerFullMes ( CurHostAddress );
break;
case 14:
ServerInfo.bPermanentOnline =
static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
ServerInfo.eCountry =
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
ServerInfo.iLocalPortNumber = GenRandomIntInRange ( -2, 10000 );
ServerInfo.iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
ServerInfo.strCity = GenRandomString();
ServerInfo.strName = GenRandomString();
ServerInfo.strTopic = GenRandomString();
Protocol.CreateCLRegisterServerMes ( CurHostAddress,
ServerInfo );
break;
case 15:
Protocol.CreateCLUnregisterServerMes ( CurHostAddress );
break;
case 16:
vecServerInfo[0].bPermanentOnline =
static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
vecServerInfo[0].eCountry =
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
vecServerInfo[0].HostAddr = CurHostAddress;
vecServerInfo[0].iLocalPortNumber = GenRandomIntInRange ( -2, 10000 );
vecServerInfo[0].iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
vecServerInfo[0].strCity = GenRandomString();
vecServerInfo[0].strName = GenRandomString();
vecServerInfo[0].strTopic = GenRandomString();
Protocol.CreateCLServerListMes ( CurHostAddress,
vecServerInfo );
break;
case 17:
Protocol.CreateCLReqServerListMes ( CurHostAddress );
break;
case 18:
Protocol.CreateCLSendEmptyMesMes ( CurHostAddress,
CurHostAddress );
break;
case 19:
Protocol.CreateCLEmptyMes ( CurHostAddress );
break;
case 20:
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
GenRandomIntInRange ( -100, 100 ) );
break;
case 21:
Protocol.CreateAndImmSendDisconnectionMes();
break;
case 22:
// arbitrary "audio" packet (with random sizes)
CVector<uint8_t> vecMessage ( GenRandomIntInRange ( 1, 1000 ) );
OnSendProtMessage ( vecMessage );
break;
}
}
void OnSendProtMessage ( CVector<uint8_t> vecMessage )
{
UdpSocket.writeDatagram (
(const char*) &( (CVector<uint8_t>) vecMessage )[0],
vecMessage.Size(), QHostAddress ( sAddress ), iPort );
// reset protocol so that we do not have to wait for an acknowledge to
// send the next message
Protocol.Reset();
}
};
#endif /* !defined ( TESTBENCH_HOIHJH8_3_43445KJIUHF1912__INCLUDED_ ) */