2011-05-21 22:43:57 +02:00
|
|
|
/******************************************************************************\
|
2020-01-01 15:41:43 +01:00
|
|
|
* Copyright (c) 2004-2020
|
2011-05-21 22:43:57 +02:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
2019-07-09 08:52:38 +02:00
|
|
|
#pragma once
|
2011-05-21 22:43:57 +02:00
|
|
|
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QDateTime>
|
2014-02-16 08:16:48 +01:00
|
|
|
#include <QUdpSocket>
|
2013-01-02 21:41:04 +01:00
|
|
|
#include <QHostAddress>
|
2011-05-21 22:43:57 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "socket.h"
|
|
|
|
#include "protocol.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Classes ********************************************************************/
|
|
|
|
class CTestbench : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
CTestbench ( QString sNewAddress, quint16 iNewPort ) :
|
2013-08-18 20:05:28 +02:00
|
|
|
sAddress ( sNewAddress ),
|
|
|
|
iPort ( iNewPort )
|
2011-05-21 22:43:57 +02:00
|
|
|
{
|
2020-04-12 14:26:21 +02:00
|
|
|
sLAddress = GenRandomIPv4Address().toString();
|
|
|
|
iLPort = static_cast<quint16> ( GenRandomIntInRange ( -2, 10000 ) );
|
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
// bind socket (try 100 port numbers)
|
|
|
|
quint16 iPortIncrement = 0; // start value: port nubmer plus ten
|
|
|
|
bool bSuccess = false; // initialization for while loop
|
2013-08-18 20:05:28 +02:00
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
while ( !bSuccess && ( iPortIncrement <= 100 ) )
|
|
|
|
{
|
2013-08-18 20:05:28 +02:00
|
|
|
bSuccess = UdpSocket.bind ( QHostAddress( QHostAddress::Any ),
|
|
|
|
22222 + iPortIncrement );
|
2011-05-21 22:43:57 +02:00
|
|
|
|
|
|
|
iPortIncrement++;
|
|
|
|
}
|
|
|
|
|
2020-05-27 16:38:36 +02:00
|
|
|
// connect protocol signals
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( &Protocol, &CProtocol::MessReadyForSending,
|
|
|
|
this, &CTestbench::OnSendProtMessage );
|
|
|
|
|
|
|
|
QObject::connect ( &Protocol, &CProtocol::CLMessReadyForSending,
|
|
|
|
this, &CTestbench::OnSendCLMessage );
|
2011-05-21 22:43:57 +02:00
|
|
|
|
|
|
|
// connect and start the timer (testbench heartbeat)
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( &Timer, &QTimer::timeout,
|
|
|
|
this, &CTestbench::OnTimer );
|
2011-05-21 22:43:57 +02:00
|
|
|
|
|
|
|
Timer.start ( 1 ); // 1 ms
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int GenRandomIntInRange ( const int iStart, const int iEnd ) const
|
|
|
|
{
|
|
|
|
return static_cast<int> ( iStart +
|
|
|
|
( ( static_cast<double> ( iEnd - iStart + 1 ) * rand() ) / RAND_MAX ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GenRandomString() const
|
|
|
|
{
|
2013-08-18 20:05:28 +02:00
|
|
|
const int iLen = GenRandomIntInRange ( 0, 111 );
|
2011-05-21 22:43:57 +02:00
|
|
|
QString strReturn = "";
|
2013-08-18 20:05:28 +02:00
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
for ( int i = 0; i < iLen; i++ )
|
|
|
|
{
|
|
|
|
strReturn += static_cast<char> ( GenRandomIntInRange ( 0, 255 ) );
|
|
|
|
}
|
2013-08-18 20:05:28 +02:00
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
return strReturn;
|
|
|
|
}
|
|
|
|
|
2020-04-09 20:06:34 +02:00
|
|
|
QHostAddress GenRandomIPv4Address() const
|
|
|
|
{
|
2020-04-10 10:12:27 +02:00
|
|
|
quint32 a = static_cast<quint32> ( 192 );
|
|
|
|
quint32 b = static_cast<quint32> ( 168 );
|
|
|
|
quint32 c = static_cast<quint32> ( GenRandomIntInRange ( 1, 253 ) );
|
|
|
|
quint32 d = static_cast<quint32> ( GenRandomIntInRange ( 1, 253 ) );
|
2020-04-09 20:06:34 +02:00
|
|
|
return QHostAddress( a << 24 | b << 16 | c << 8 | d );
|
|
|
|
}
|
|
|
|
|
2011-05-21 22:43:57 +02:00
|
|
|
QString sAddress;
|
2020-04-12 14:26:21 +02:00
|
|
|
quint16 iPort;
|
|
|
|
QString sLAddress;
|
|
|
|
quint16 iLPort;
|
2011-05-21 22:43:57 +02:00
|
|
|
QTimer Timer;
|
|
|
|
CProtocol Protocol;
|
|
|
|
QUdpSocket UdpSocket;
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void OnTimer()
|
|
|
|
{
|
2013-02-11 16:53:52 +01:00
|
|
|
CVector<CChannelInfo> vecChanInfo ( 1 );
|
|
|
|
CNetworkTransportProps NetTrProps;
|
|
|
|
CServerCoreInfo ServerInfo;
|
|
|
|
CVector<CServerInfo> vecServerInfo ( 1 );
|
2020-05-28 02:44:15 +02:00
|
|
|
CVector<uint16_t> vecLevelList ( 1 );
|
2013-02-11 16:53:52 +01:00
|
|
|
CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort );
|
2020-04-12 14:26:21 +02:00
|
|
|
CHostAddress CurLocalAddress ( QHostAddress ( sLAddress ), iLPort );
|
2013-08-18 20:05:28 +02:00
|
|
|
CChannelCoreInfo ChannelCoreInfo;
|
2015-01-23 20:43:18 +01:00
|
|
|
ELicenceType eLicenceType;
|
2020-05-28 02:44:15 +02:00
|
|
|
ESvrRegResult eSvrRegResult;
|
2011-05-21 22:43:57 +02:00
|
|
|
|
|
|
|
// generate random protocol message
|
2020-05-28 02:44:15 +02:00
|
|
|
switch ( GenRandomIntInRange ( 0, 34 ) )
|
2011-05-21 22:43:57 +02:00
|
|
|
{
|
2014-02-13 22:01:15 +01:00
|
|
|
case 0: // PROTMESSID_JITT_BUF_SIZE
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) );
|
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 1: // PROTMESSID_REQ_JITT_BUF_SIZE
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateReqJitBufMes();
|
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 2: // PROTMESSID_CHANNEL_GAIN
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateChanGainMes ( GenRandomIntInRange ( 0, 20 ),
|
2013-08-18 20:05:28 +02:00
|
|
|
GenRandomIntInRange ( -100, 100 ) );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 4: // PROTMESSID_CONN_CLIENTS_LIST
|
2013-08-18 20:05:28 +02:00
|
|
|
vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
|
2020-04-09 20:06:34 +02:00
|
|
|
vecChanInfo[0].iIpAddr = GenRandomIPv4Address().toIPv4Address();
|
2013-08-18 20:05:28 +02:00
|
|
|
vecChanInfo[0].strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateConClientListMes ( vecChanInfo );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 5: // PROTMESSID_REQ_CONN_CLIENTS_LIST
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateReqConnClientsList();
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 7: // PROTMESSID_CHANNEL_INFOS
|
2013-08-18 20:05:28 +02:00
|
|
|
ChannelCoreInfo.eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
|
|
|
|
|
|
|
ChannelCoreInfo.eSkillLevel =
|
|
|
|
static_cast<ESkillLevel> ( GenRandomIntInRange ( 0, 3 ) );
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
ChannelCoreInfo.iInstrument = GenRandomIntInRange ( 0, 100 );
|
2013-08-18 20:05:28 +02:00
|
|
|
ChannelCoreInfo.strCity = GenRandomString();
|
|
|
|
ChannelCoreInfo.strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateChanInfoMes ( ChannelCoreInfo );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 8: // PROTMESSID_REQ_CHANNEL_INFOS
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateReqChanInfoMes();
|
|
|
|
break;
|
|
|
|
|
2014-02-13 22:01:15 +01:00
|
|
|
case 9: // PROTMESSID_CHAT_TEXT
|
2013-08-18 20:05:28 +02:00
|
|
|
Protocol.CreateChatTextMes ( GenRandomString() );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 10: // PROTMESSID_LICENCE_REQUIRED
|
|
|
|
eLicenceType =
|
|
|
|
static_cast<ELicenceType> ( GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
|
|
|
|
Protocol.CreateLicenceRequiredMes ( eLicenceType );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 11: // PROTMESSID_NETW_TRANSPORT_PROPS
|
2011-05-21 22:43:57 +02:00
|
|
|
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;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 12: // PROTMESSID_REQ_NETW_TRANSPORT_PROPS
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateReqNetwTranspPropsMes();
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 14: // PROTMESSID_CLM_PING_MS
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLPingMes ( CurHostAddress,
|
|
|
|
GenRandomIntInRange ( -2, 1000 ) );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 15: // PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLPingWithNumClientsMes ( CurHostAddress,
|
|
|
|
GenRandomIntInRange ( -2, 1000 ),
|
|
|
|
GenRandomIntInRange ( -2, 1000 ) );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 16: // PROTMESSID_CLM_SERVER_FULL
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLServerFullMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 17: // PROTMESSID_CLM_REGISTER_SERVER
|
2011-05-21 22:43:57 +02:00
|
|
|
ServerInfo.bPermanentOnline =
|
|
|
|
static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
|
|
|
|
ServerInfo.eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
|
|
|
|
|
|
|
ServerInfo.iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
ServerInfo.strCity = GenRandomString();
|
|
|
|
ServerInfo.strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateCLRegisterServerMes ( CurHostAddress,
|
2020-04-09 20:06:34 +02:00
|
|
|
CurLocalAddress,
|
2011-05-21 22:43:57 +02:00
|
|
|
ServerInfo );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 18: // PROTMESSID_CLM_UNREGISTER_SERVER
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLUnregisterServerMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 19: // PROTMESSID_CLM_SERVER_LIST
|
2011-05-21 22:43:57 +02:00
|
|
|
vecServerInfo[0].bPermanentOnline =
|
|
|
|
static_cast<bool> ( GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
|
|
|
|
vecServerInfo[0].eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GenRandomIntInRange ( 0, 100 ) );
|
|
|
|
|
|
|
|
vecServerInfo[0].HostAddr = CurHostAddress;
|
2020-04-09 20:06:34 +02:00
|
|
|
vecServerInfo[0].LHostAddr = CurLocalAddress;
|
2011-05-21 22:43:57 +02:00
|
|
|
vecServerInfo[0].iMaxNumClients = GenRandomIntInRange ( -2, 10000 );
|
|
|
|
vecServerInfo[0].strCity = GenRandomString();
|
|
|
|
vecServerInfo[0].strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateCLServerListMes ( CurHostAddress,
|
|
|
|
vecServerInfo );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 20: // PROTMESSID_CLM_REQ_SERVER_LIST
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLReqServerListMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 21: // PROTMESSID_CLM_SEND_EMPTY_MESSAGE
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLSendEmptyMesMes ( CurHostAddress,
|
|
|
|
CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 22: // PROTMESSID_CLM_EMPTY_MESSAGE
|
2011-05-21 22:43:57 +02:00
|
|
|
Protocol.CreateCLEmptyMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 23: // PROTMESSID_CLM_DISCONNECTION
|
2011-05-22 11:47:09 +02:00
|
|
|
Protocol.CreateCLDisconnection ( CurHostAddress );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 24: // PROTMESSID_CLM_VERSION_AND_OS
|
2014-02-21 22:25:26 +01:00
|
|
|
Protocol.CreateCLVersionAndOSMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 25: // PROTMESSID_CLM_REQ_VERSION_AND_OS
|
2014-02-21 22:25:26 +01:00
|
|
|
Protocol.CreateCLReqVersionAndOSMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 26: // PROTMESSID_ACKN
|
2011-05-22 11:47:09 +02:00
|
|
|
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
|
2014-02-21 22:25:26 +01:00
|
|
|
GenRandomIntInRange ( -100, 100 ) );
|
2011-05-21 22:43:57 +02:00
|
|
|
break;
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
case 27:
|
2020-05-28 02:44:15 +02:00
|
|
|
{
|
2011-05-21 22:43:57 +02:00
|
|
|
// arbitrary "audio" packet (with random sizes)
|
|
|
|
CVector<uint8_t> vecMessage ( GenRandomIntInRange ( 1, 1000 ) );
|
|
|
|
OnSendProtMessage ( vecMessage );
|
|
|
|
break;
|
|
|
|
}
|
2020-05-28 02:44:15 +02:00
|
|
|
|
|
|
|
case 28: // PROTMESSID_CLM_CONN_CLIENTS_LIST
|
|
|
|
vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 );
|
|
|
|
vecChanInfo[0].iIpAddr = GenRandomIPv4Address().toIPv4Address();
|
|
|
|
vecChanInfo[0].strName = GenRandomString();
|
|
|
|
|
|
|
|
Protocol.CreateCLConnClientsListMes ( CurHostAddress, vecChanInfo );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 29: // PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST
|
|
|
|
Protocol.CreateCLReqConnClientsListMes ( CurHostAddress );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 30: // PROTMESSID_CLM_CHANNEL_LEVEL_LIST
|
|
|
|
vecLevelList[0] = GenRandomIntInRange ( 0, 0xF );
|
|
|
|
|
|
|
|
Protocol.CreateCLChannelLevelListMes ( CurHostAddress,
|
|
|
|
vecLevelList,
|
|
|
|
1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 31: // PROTMESSID_CLM_REGISTER_SERVER_RESP
|
|
|
|
eSvrRegResult =
|
|
|
|
static_cast<ESvrRegResult> ( GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
|
|
|
|
Protocol.CreateCLRegisterServerResp ( CurHostAddress,
|
|
|
|
eSvrRegResult );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 32: // PROTMESSID_CHANNEL_PAN
|
|
|
|
Protocol.CreateChanPanMes ( GenRandomIntInRange ( -2, 20 ),
|
|
|
|
GenRandomIntInRange ( 0, 32767 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 33: // PROTMESSID_MUTE_STATE_CHANGED
|
|
|
|
Protocol.CreateMuteStateHasChangedMes ( GenRandomIntInRange ( -2, 20 ),
|
|
|
|
GenRandomIntInRange ( 0, 1 ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 34: // PROTMESSID_CLIENT_ID
|
|
|
|
Protocol.CreateClientIDMes ( GenRandomIntInRange ( -2, 20 ) );
|
|
|
|
break;
|
|
|
|
}
|
2011-05-21 22:43:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2020-05-27 16:38:36 +02:00
|
|
|
|
2020-05-28 16:35:56 +02:00
|
|
|
void OnSendCLMessage ( CHostAddress, CVector<uint8_t> vecMessage )
|
2020-05-27 16:38:36 +02:00
|
|
|
{
|
|
|
|
OnSendProtMessage ( vecMessage );
|
|
|
|
}
|
2011-05-21 22:43:57 +02:00
|
|
|
};
|