From 68074cb22a3a0492cb31e3329a88e490944808fa Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 12:59:10 -0700 Subject: [PATCH 01/10] added a simple udp send/receive jitter test tool --- tests/jitter/CMakeLists.txt | 33 +++++++++ tests/jitter/src/main.cpp | 139 ++++++++++++++++++++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 tests/jitter/CMakeLists.txt create mode 100644 tests/jitter/src/main.cpp diff --git a/tests/jitter/CMakeLists.txt b/tests/jitter/CMakeLists.txt new file mode 100644 index 0000000000..8000e4af50 --- /dev/null +++ b/tests/jitter/CMakeLists.txt @@ -0,0 +1,33 @@ +set(TARGET_NAME jitter-tests) + +set(ROOT_DIR ../..) +set(MACRO_DIR ${ROOT_DIR}/cmake/macros) + +# setup for find modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules/") + +#find_package(Qt5Network REQUIRED) +#find_package(Qt5Script REQUIRED) +#find_package(Qt5Widgets REQUIRED) + +include(${MACRO_DIR}/SetupHifiProject.cmake) +setup_hifi_project(${TARGET_NAME} TRUE) + +#include(${MACRO_DIR}/AutoMTC.cmake) +#auto_mtc(${TARGET_NAME} ${ROOT_DIR}) + +#qt5_use_modules(${TARGET_NAME} Network Script Widgets) + +#include glm - because it's a dependency of shared utils... +include(${MACRO_DIR}/IncludeGLM.cmake) +include_glm(${TARGET_NAME} ${ROOT_DIR}) + +# link in the shared libraries +include(${MACRO_DIR}/LinkHifiLibrary.cmake) +link_hifi_library(shared ${TARGET_NAME} ${ROOT_DIR}) +link_hifi_library(networking ${TARGET_NAME} ${ROOT_DIR}) + +IF (WIN32) + target_link_libraries(${TARGET_NAME} Winmm Ws2_32) +ENDIF(WIN32) + diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp new file mode 100644 index 0000000000..05a05e53d2 --- /dev/null +++ b/tests/jitter/src/main.cpp @@ -0,0 +1,139 @@ +// +// main.cpp +// JitterTester +// +// Created by Philip on 8/1/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#include +#include +#include +#include +#include +#include + +#include // for usecTimeStampNow() +#include // for MovingMinMaxAvg + +void runSend(const char* addressOption, int port, int gap, int size); +void runReceive(const char* addressOption, int port, int gap, int size); + + +int main(int argc, const char * argv[]) { + if (argc != 6) { + printf("usage: jitter-tests <--send|--receive>
\n"); + exit(1); + } + const char* typeOption = argv[1]; + const char* addressOption = argv[2]; + const char* portOption = argv[3]; + const char* gapOption = argv[4]; + const char* sizeOption = argv[5]; + int port = atoi(portOption); + int gap = atoi(gapOption); + int size = atoi(sizeOption); + + std::cout << "type:" << typeOption << "\n"; + std::cout << "address:" << addressOption << "\n"; + std::cout << "port:" << port << "\n"; + std::cout << "gap:" << gap << "\n"; + std::cout << "size:" << size << "\n"; + + if (strcmp(typeOption, "--send") == 0) { + runSend(addressOption, port, gap, size); + } else if (strcmp(typeOption, "--receive") == 0) { + runReceive(addressOption, port, gap, size); + } + exit(1); +} + +void runSend(const char* addressOption, int port, int gap, int size) { + std::cout << "runSend...\n"; + + int sockfd; + struct sockaddr_in servaddr; + + char* outputBuffer = new char[size]; + memset(outputBuffer, 0, size); + + sockfd=socket(AF_INET,SOCK_DGRAM,0); + + bzero(&servaddr,sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr=inet_addr(addressOption); + servaddr.sin_port=htons(port); + + const int SAMPLES_FOR_30_SECONDS = 30 * 1000 / gap; + MovingMinMaxAvg timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats + + quint64 last = usecTimestampNow(); + + while (true) { + + quint64 now = usecTimestampNow(); + quint64 actualGap = now - last; + + + if (actualGap >= gap) { + sendto(sockfd, outputBuffer, size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); + + timeGaps.update(actualGap); + std::cout << "packet sent gap:" << actualGap << " " + << "min:" << timeGaps.getMin() << " " + << "max:" << timeGaps.getMax() << " " + << "avg:" << timeGaps.getAverage() << " " + << "min last 30:" << timeGaps.getWindowMin() << " " + << "max last 30:" << timeGaps.getWindowMax() << " " + << "avg last 30:" << timeGaps.getWindowAverage() << " " + << "\n"; + last = now; + } + } +} + +void runReceive(const char* addressOption, int port, int gap, int size) { + std::cout << "runReceive...\n"; + + + int sockfd,n; + struct sockaddr_in myaddr; + + char* inputBuffer = new char[size]; + memset(inputBuffer, 0, size); + + sockfd=socket(AF_INET, SOCK_DGRAM, 0); + + bzero(&myaddr,sizeof(myaddr)); + myaddr.sin_family = AF_INET; + myaddr.sin_addr.s_addr=htonl(INADDR_ANY); + myaddr.sin_port=htons(port); + + const int SAMPLES_FOR_30_SECONDS = 30 * 1000 / gap; + MovingMinMaxAvg timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats + + if (bind(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) { + std::cout << "bind failed\n"; + return; + } + + quint64 last = usecTimestampNow(); + + while (true) { + n = recvfrom(sockfd, inputBuffer, size, 0, NULL, NULL); // we don't care about where it came from + + quint64 now = usecTimestampNow(); + int actualGap = now - last; + timeGaps.update(actualGap); + std::cout << "packet received gap:" << actualGap << " " + << "min:" << timeGaps.getMin() << " " + << "max:" << timeGaps.getMax() << " " + << "avg:" << timeGaps.getAverage() << " " + << "min last 30:" << timeGaps.getWindowMin() << " " + << "max last 30:" << timeGaps.getWindowMax() << " " + << "avg last 30:" << timeGaps.getWindowAverage() << " " + << "\n"; + last = now; + } +} + From 8359ebb82f028d4eb9a2643630f5f8166d001622 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:12:37 -0700 Subject: [PATCH 02/10] use c std version of usecTimestampNow() --- tests/jitter/src/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index 05a05e53d2..f3d2960d2d 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -12,13 +12,19 @@ #include #include #include +#include -#include // for usecTimeStampNow() +//#include // for usecTimestampNow() #include // for MovingMinMaxAvg void runSend(const char* addressOption, int port, int gap, int size); void runReceive(const char* addressOption, int port, int gap, int size); +quint64 usecTimestampNow() { + struct timeval tv; + gettimeofday(&tv,NULL); + return tv.tv_sec*(uint64_t)1000000+tv.tv_usec; +} int main(int argc, const char * argv[]) { if (argc != 6) { From 8c14f948f2ea3f917293699cf3d17afcd2f10465 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:15:57 -0700 Subject: [PATCH 03/10] handle first packet stats better --- tests/jitter/src/main.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index f3d2960d2d..a44bb3bef1 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -123,23 +123,28 @@ void runReceive(const char* addressOption, int port, int gap, int size) { return; } - quint64 last = usecTimestampNow(); + quint64 last = 0; // first case while (true) { n = recvfrom(sockfd, inputBuffer, size, 0, NULL, NULL); // we don't care about where it came from - - quint64 now = usecTimestampNow(); - int actualGap = now - last; - timeGaps.update(actualGap); - std::cout << "packet received gap:" << actualGap << " " - << "min:" << timeGaps.getMin() << " " - << "max:" << timeGaps.getMax() << " " - << "avg:" << timeGaps.getAverage() << " " - << "min last 30:" << timeGaps.getWindowMin() << " " - << "max last 30:" << timeGaps.getWindowMax() << " " - << "avg last 30:" << timeGaps.getWindowAverage() << " " - << "\n"; - last = now; + + if (last == 0) { + last = usecTimestampNow(); + std::cout << "first packet received\n"; + } else { + quint64 now = usecTimestampNow(); + int actualGap = now - last; + timeGaps.update(actualGap); + std::cout << "packet received gap:" << actualGap << " " + << "min:" << timeGaps.getMin() << " " + << "max:" << timeGaps.getMax() << " " + << "avg:" << timeGaps.getAverage() << " " + << "min last 30:" << timeGaps.getWindowMin() << " " + << "max last 30:" << timeGaps.getWindowMax() << " " + << "avg last 30:" << timeGaps.getWindowAverage() << " " + << "\n"; + last = now; + } } } From ddfdfc92424d9e3b052f85f004d0816225bc0591 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:21:46 -0700 Subject: [PATCH 04/10] windows build --- tests/jitter/src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index a44bb3bef1..e29a26a51b 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -7,7 +7,11 @@ // #include +#ifdef _WINDOWS +#include +#else #include +#endif #include #include #include From ad4dd9404d88a6a257f929dcc3d9125cf2337232 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:26:56 -0700 Subject: [PATCH 05/10] windows build --- tests/jitter/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index e29a26a51b..cb7455cebe 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -12,7 +12,7 @@ #else #include #endif -#include +//#include #include #include #include From e0946838f394a656457b54943e8cfd2e2cfbdad2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:34:01 -0700 Subject: [PATCH 06/10] windows build --- tests/jitter/src/main.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index cb7455cebe..1f42b9e517 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -12,13 +12,10 @@ #else #include #endif -//#include #include -#include #include #include -//#include // for usecTimestampNow() #include // for MovingMinMaxAvg void runSend(const char* addressOption, int port, int gap, int size); From 48b73e3f0e771b8638daff8e2741b3a1e3ac6a2a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:42:37 -0700 Subject: [PATCH 07/10] windows build --- tests/jitter/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index 1f42b9e517..8c42e8e157 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -11,9 +11,9 @@ #include #else #include +#include #endif #include -#include #include #include // for MovingMinMaxAvg From 8db66e4322bf8c08d3be7d95ffa36114b90dcf27 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 13:58:38 -0700 Subject: [PATCH 08/10] use our ported version of usecTimestampNow cause windows sucks --- tests/jitter/src/main.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index 8c42e8e157..224f3c90cb 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -14,19 +14,13 @@ #include #endif #include -#include #include // for MovingMinMaxAvg +#include // for usecTimestampNow void runSend(const char* addressOption, int port, int gap, int size); void runReceive(const char* addressOption, int port, int gap, int size); -quint64 usecTimestampNow() { - struct timeval tv; - gettimeofday(&tv,NULL); - return tv.tv_sec*(uint64_t)1000000+tv.tv_usec; -} - int main(int argc, const char * argv[]) { if (argc != 6) { printf("usage: jitter-tests <--send|--receive>
\n"); From 36f635ed8d91456fceecbcc2bef40bf15571acc6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 14:07:14 -0700 Subject: [PATCH 09/10] change stats to display difference between gap and expected gap --- tests/jitter/src/main.cpp | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index 224f3c90cb..eebf88c5d0 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -66,27 +66,29 @@ void runSend(const char* addressOption, int port, int gap, int size) { servaddr.sin_port=htons(port); const int SAMPLES_FOR_30_SECONDS = 30 * 1000 / gap; - MovingMinMaxAvg timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats + MovingMinMaxAvg timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats quint64 last = usecTimestampNow(); while (true) { quint64 now = usecTimestampNow(); - quint64 actualGap = now - last; + int actualGap = now - last; if (actualGap >= gap) { sendto(sockfd, outputBuffer, size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr)); - timeGaps.update(actualGap); - std::cout << "packet sent gap:" << actualGap << " " - << "min:" << timeGaps.getMin() << " " - << "max:" << timeGaps.getMax() << " " - << "avg:" << timeGaps.getAverage() << " " - << "min last 30:" << timeGaps.getWindowMin() << " " - << "max last 30:" << timeGaps.getWindowMax() << " " - << "avg last 30:" << timeGaps.getWindowAverage() << " " + int gapDifferece = actualGap - gap; + timeGaps.update(gapDifferece); + std::cout << "packet sent gap: " << actualGap << " " + << "gapDifference: " << gapDifferece << " " + << "min: " << timeGaps.getMin() << " " + << "max: " << timeGaps.getMax() << " " + << "avg: " << timeGaps.getAverage() << " " + << "min last 30: " << timeGaps.getWindowMin() << " " + << "max last 30: " << timeGaps.getWindowMax() << " " + << "avg last 30: " << timeGaps.getWindowAverage() << " " << "\n"; last = now; } @@ -111,7 +113,7 @@ void runReceive(const char* addressOption, int port, int gap, int size) { myaddr.sin_port=htons(port); const int SAMPLES_FOR_30_SECONDS = 30 * 1000 / gap; - MovingMinMaxAvg timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats + MovingMinMaxAvg timeGaps(1, SAMPLES_FOR_30_SECONDS); // stats if (bind(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) { std::cout << "bind failed\n"; @@ -129,14 +131,16 @@ void runReceive(const char* addressOption, int port, int gap, int size) { } else { quint64 now = usecTimestampNow(); int actualGap = now - last; - timeGaps.update(actualGap); + int gapDifferece = actualGap - gap; + timeGaps.update(gapDifferece); std::cout << "packet received gap:" << actualGap << " " - << "min:" << timeGaps.getMin() << " " - << "max:" << timeGaps.getMax() << " " - << "avg:" << timeGaps.getAverage() << " " - << "min last 30:" << timeGaps.getWindowMin() << " " - << "max last 30:" << timeGaps.getWindowMax() << " " - << "avg last 30:" << timeGaps.getWindowAverage() << " " + << "gapDifference: " << gapDifferece << " " + << "min: " << timeGaps.getMin() << " " + << "max: " << timeGaps.getMax() << " " + << "avg: " << timeGaps.getAverage() << " " + << "min last 30: " << timeGaps.getWindowMin() << " " + << "max last 30: " << timeGaps.getWindowMax() << " " + << "avg last 30: " << timeGaps.getWindowAverage() << " " << "\n"; last = now; } From ca4bca704210c4649f3310a647d3d4575687e5be Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 1 Aug 2014 14:11:24 -0700 Subject: [PATCH 10/10] more windows headaches memset instead of bzero --- tests/jitter/src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/jitter/src/main.cpp b/tests/jitter/src/main.cpp index eebf88c5d0..23199f03b3 100644 --- a/tests/jitter/src/main.cpp +++ b/tests/jitter/src/main.cpp @@ -60,7 +60,7 @@ void runSend(const char* addressOption, int port, int gap, int size) { sockfd=socket(AF_INET,SOCK_DGRAM,0); - bzero(&servaddr,sizeof(servaddr)); + memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr=inet_addr(addressOption); servaddr.sin_port=htons(port); @@ -107,7 +107,7 @@ void runReceive(const char* addressOption, int port, int gap, int size) { sockfd=socket(AF_INET, SOCK_DGRAM, 0); - bzero(&myaddr,sizeof(myaddr)); + memset(&myaddr, 0, sizeof(myaddr)); myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr=htonl(INADDR_ANY); myaddr.sin_port=htons(port);