mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:36:56 +02:00
add all initial command line options for UDTTest
This commit is contained in:
parent
532ac69091
commit
80ef80ec2e
2 changed files with 103 additions and 4 deletions
|
@ -13,7 +13,32 @@
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
|
|
||||||
|
#include <udt/Constants.h>
|
||||||
|
|
||||||
const QCommandLineOption PORT_OPTION { "p", "listening port for socket (defaults to random)", "port", 0 };
|
const QCommandLineOption PORT_OPTION { "p", "listening port for socket (defaults to random)", "port", 0 };
|
||||||
|
const QCommandLineOption TARGET_OPTION {
|
||||||
|
"target", "target for sent packets (default is listen only)",
|
||||||
|
"IP:PORT or HOSTNAME:PORT"
|
||||||
|
};
|
||||||
|
const QCommandLineOption PACKET_SIZE {
|
||||||
|
"packet-size", "size for sent packets in bytes (defaults to 1500)", "bytes",
|
||||||
|
QString(udt::MAX_PACKET_SIZE_WITH_UDP_HEADER)
|
||||||
|
};
|
||||||
|
const QCommandLineOption MIN_PACKET_SIZE {
|
||||||
|
"min-packet-size", "min size for sent packets in bytes", "min-bytes"
|
||||||
|
};
|
||||||
|
const QCommandLineOption MAX_PACKET_SIZE {
|
||||||
|
"max-packet-size", "max size for sent packets in bytes", "max-bytes"
|
||||||
|
};
|
||||||
|
const QCommandLineOption MAX_SEND_BYTES {
|
||||||
|
"max-send-bytes", "number of bytes to send before stopping (default is infinite)", "max-bytes"
|
||||||
|
};
|
||||||
|
const QCommandLineOption MAX_SEND_PACKETS {
|
||||||
|
"max-send-packets", "number of packets to send before stopping (default is infinite)", "max-packets"
|
||||||
|
};
|
||||||
|
const QCommandLineOption UNRELIABLE_PACKETS {
|
||||||
|
"unreliable", "send unreliable packets (default is reliable)"
|
||||||
|
};
|
||||||
|
|
||||||
UDTTest::UDTTest(int& argc, char** argv) :
|
UDTTest::UDTTest(int& argc, char** argv) :
|
||||||
QCoreApplication(argc, argv)
|
QCoreApplication(argc, argv)
|
||||||
|
@ -22,18 +47,82 @@ UDTTest::UDTTest(int& argc, char** argv) :
|
||||||
|
|
||||||
_socket.bind(QHostAddress::LocalHost, _argumentParser.value(PORT_OPTION).toUInt());
|
_socket.bind(QHostAddress::LocalHost, _argumentParser.value(PORT_OPTION).toUInt());
|
||||||
qDebug() << "Test socket is listening on" << _socket.localPort();
|
qDebug() << "Test socket is listening on" << _socket.localPort();
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(TARGET_OPTION)) {
|
||||||
|
// parse the IP and port combination for this target
|
||||||
|
QString hostnamePortString = _argumentParser.value(TARGET_OPTION);
|
||||||
|
|
||||||
|
QHostAddress address { hostnamePortString.left(hostnamePortString.indexOf(':')) };
|
||||||
|
quint16 port { (quint16) hostnamePortString.right(hostnamePortString.indexOf(':') + 1).toUInt() };
|
||||||
|
|
||||||
|
if (address.isNull() || port == 0) {
|
||||||
|
qCritical() << "Could not parse an IP address and port combination from" << hostnamePortString << "-" <<
|
||||||
|
"The parsed IP was" << address.toString() << "and the parsed port was" << port;
|
||||||
|
|
||||||
|
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||||
|
} else {
|
||||||
|
_target = HifiSockAddr(address, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(PACKET_SIZE)) {
|
||||||
|
// parse the desired packet size
|
||||||
|
_minPacketSize = _maxPacketSize = _argumentParser.value(PACKET_SIZE).toInt();
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(MIN_PACKET_SIZE) || _argumentParser.isSet(MAX_PACKET_SIZE)) {
|
||||||
|
qCritical() << "Cannot set a min packet size or max packet size AND a specific packet size.";
|
||||||
|
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
bool customMinSize = false;
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(MIN_PACKET_SIZE)) {
|
||||||
|
_minPacketSize = _argumentParser.value(MIN_PACKET_SIZE).toInt();
|
||||||
|
customMinSize = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(MAX_PACKET_SIZE)) {
|
||||||
|
_maxPacketSize = _argumentParser.value(MAX_PACKET_SIZE).toInt();
|
||||||
|
|
||||||
|
// if we don't have a min packet size we should make it zero, because we have a max
|
||||||
|
if (customMinSize) {
|
||||||
|
_minPacketSize = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_maxPacketSize < _minPacketSize) {
|
||||||
|
qCritical() << "Cannot set a max packet size that is smaller than the min packet size.";
|
||||||
|
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(MAX_SEND_BYTES)) {
|
||||||
|
_maxSendBytes = _argumentParser.value(MAX_SEND_BYTES).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(MAX_SEND_PACKETS)) {
|
||||||
|
_maxSendPackets = _argumentParser.value(MAX_SEND_PACKETS).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_argumentParser.isSet(UNRELIABLE_PACKETS)) {
|
||||||
|
_sendReliable = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDTTest::parseArguments() {
|
void UDTTest::parseArguments() {
|
||||||
// use a QCommandLineParser to setup command line arguments and give helpful output
|
// use a QCommandLineParser to setup command line arguments and give helpful output
|
||||||
_argumentParser.setApplicationDescription("High Fidelity Assignment Client");
|
_argumentParser.setApplicationDescription("High Fidelity UDT Protocol Test Client");
|
||||||
_argumentParser.addHelpOption();
|
_argumentParser.addHelpOption();
|
||||||
|
|
||||||
const QCommandLineOption helpOption = _argumentParser.addHelpOption();
|
const QCommandLineOption helpOption = _argumentParser.addHelpOption();
|
||||||
|
|
||||||
_argumentParser.addOption(PORT_OPTION);
|
_argumentParser.addOptions({
|
||||||
|
PORT_OPTION, TARGET_OPTION, PACKET_SIZE, MIN_PACKET_SIZE, MAX_PACKET_SIZE,
|
||||||
|
MAX_SEND_BYTES, MAX_SEND_PACKETS, UNRELIABLE_PACKETS
|
||||||
|
});
|
||||||
|
|
||||||
if (!_argumentParser.parse(QCoreApplication::arguments())) {
|
if (!_argumentParser.parse(arguments())) {
|
||||||
qCritical() << _argumentParser.errorText();
|
qCritical() << _argumentParser.errorText();
|
||||||
_argumentParser.showHelp();
|
_argumentParser.showHelp();
|
||||||
Q_UNREACHABLE();
|
Q_UNREACHABLE();
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
#include <QtCore/QCoreApplication>
|
#include <QtCore/QCoreApplication>
|
||||||
#include <QtCore/QCommandLineParser>
|
#include <QtCore/QCommandLineParser>
|
||||||
|
|
||||||
#include <udt/socket.h>
|
#include <udt/Constants.h>
|
||||||
|
#include <udt/Socket.h>
|
||||||
|
|
||||||
class UDTTest : public QCoreApplication {
|
class UDTTest : public QCoreApplication {
|
||||||
public:
|
public:
|
||||||
|
@ -27,6 +28,15 @@ private:
|
||||||
|
|
||||||
QCommandLineParser _argumentParser;
|
QCommandLineParser _argumentParser;
|
||||||
udt::Socket _socket;
|
udt::Socket _socket;
|
||||||
|
|
||||||
|
HifiSockAddr _target; // the target for sent packets
|
||||||
|
|
||||||
|
int _minPacketSize = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER;
|
||||||
|
int _maxPacketSize = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER;
|
||||||
|
int _maxSendBytes = -1; // the number of bytes to send to the target before stopping
|
||||||
|
int _maxSendPackets = -1; // the number of packets to send to the target before stopping
|
||||||
|
|
||||||
|
bool _sendReliable = true; // wether packets are sent reliably or unreliably
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_UDTTest_h
|
#endif // hifi_UDTTest_h
|
||||||
|
|
Loading…
Reference in a new issue