This removes the dependencies for the tools on some ouroboros internal
headers (endian.h and time_utils.h) so they can be built out-of-tree.
The echo-app tool has been renamed oecho and the cbr tool has been
renamed ocbr.
Signed-off-by: Dimitri Staessens <dimitri.staessens@xxxxxxxx>
---
src/tools/CMakeLists.txt | 4 +-
src/tools/irm/irm_ipcp_bootstrap.c | 1 -
src/tools/{cbr => ocbr}/CMakeLists.txt | 8 +-
src/tools/{cbr/cbr.c => ocbr/ocbr.c} | 4 +-
src/tools/{cbr/cbr_client.c => ocbr/ocbr_client.c} | 0
src/tools/{cbr/cbr_server.c => ocbr/ocbr_server.c} | 0
src/tools/{echo => oecho}/CMakeLists.txt | 8 +-
src/tools/{echo/echo.c => oecho/oecho.c} | 0
src/tools/operf/CMakeLists.txt | 5 ++
src/tools/operf/operf.c | 12 ++-
src/tools/operf/operf_client.c | 12 ---
src/tools/operf/operf_server.c | 4 -
src/tools/oping/CMakeLists.txt | 5 ++
src/tools/oping/oping.c | 15 +++-
src/tools/oping/oping_client.c | 28 ++-----
src/tools/oping/oping_server.c | 4 -
src/tools/time_utils.h | 97 ++++++++++++++++++++++
17 files changed, 150 insertions(+), 57 deletions(-)
rename src/tools/{cbr => ocbr}/CMakeLists.txt (59%)
rename src/tools/{cbr/cbr.c => ocbr/ocbr.c} (99%)
rename src/tools/{cbr/cbr_client.c => ocbr/ocbr_client.c} (100%)
rename src/tools/{cbr/cbr_server.c => ocbr/ocbr_server.c} (100%)
rename src/tools/{echo => oecho}/CMakeLists.txt (58%)
rename src/tools/{echo/echo.c => oecho/oecho.c} (100%)
create mode 100644 src/tools/time_utils.h
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index e8181d5..b81e543 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -1,5 +1,5 @@
add_subdirectory(irm)
-add_subdirectory(echo)
-add_subdirectory(cbr)
+add_subdirectory(ocbr)
+add_subdirectory(oecho)
add_subdirectory(oping)
add_subdirectory(operf)
diff --git a/src/tools/irm/irm_ipcp_bootstrap.c
b/src/tools/irm/irm_ipcp_bootstrap.c
index 3cad072..986c45e 100644
--- a/src/tools/irm/irm_ipcp_bootstrap.c
+++ b/src/tools/irm/irm_ipcp_bootstrap.c
@@ -44,7 +44,6 @@
#include <sys/socket.h>
#endif
#include <ouroboros/irm.h>
-#include <ouroboros/ipcp.h>
#include "irm_ops.h"
#include "irm_utils.h"
diff --git a/src/tools/cbr/CMakeLists.txt b/src/tools/ocbr/CMakeLists.txt
similarity index 59%
rename from src/tools/cbr/CMakeLists.txt
rename to src/tools/ocbr/CMakeLists.txt
index 158b5c8..5dac3e6 100644
--- a/src/tools/cbr/CMakeLists.txt
+++ b/src/tools/ocbr/CMakeLists.txt
@@ -6,11 +6,11 @@ include_directories(${CMAKE_BINARY_DIR}/include)
set(SOURCE_FILES
# Add source files here
- cbr.c
+ ocbr.c
)
-add_executable(cbr ${SOURCE_FILES})
+add_executable(ocbr ${SOURCE_FILES})
-target_link_libraries(cbr LINK_PUBLIC ouroboros-dev)
+target_link_libraries(ocbr LINK_PUBLIC ouroboros-dev)
-install(TARGETS cbr RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS ocbr RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/src/tools/cbr/cbr.c b/src/tools/ocbr/ocbr.c
similarity index 99%
rename from src/tools/cbr/cbr.c
rename to src/tools/ocbr/ocbr.c
index abba8eb..2c22cc3 100644
--- a/src/tools/cbr/cbr.c
+++ b/src/tools/ocbr/ocbr.c
@@ -48,14 +48,14 @@
#define BUF_SIZE 1500
-#include "cbr_client.c"
+#include "ocbr_client.c"
struct s {
long interval;
long timeout;
} server_settings;
-#include "cbr_server.c"
+#include "ocbr_server.c"
static void usage(void)
{
diff --git a/src/tools/cbr/cbr_client.c b/src/tools/ocbr/ocbr_client.c
similarity index 100%
rename from src/tools/cbr/cbr_client.c
rename to src/tools/ocbr/ocbr_client.c
diff --git a/src/tools/cbr/cbr_server.c b/src/tools/ocbr/ocbr_server.c
similarity index 100%
rename from src/tools/cbr/cbr_server.c
rename to src/tools/ocbr/ocbr_server.c
diff --git a/src/tools/echo/CMakeLists.txt b/src/tools/oecho/CMakeLists.txt
similarity index 58%
rename from src/tools/echo/CMakeLists.txt
rename to src/tools/oecho/CMakeLists.txt
index 4766ab8..50a6613 100644
--- a/src/tools/echo/CMakeLists.txt
+++ b/src/tools/oecho/CMakeLists.txt
@@ -6,11 +6,11 @@ include_directories(${CMAKE_BINARY_DIR}/include)
set(SOURCE_FILES
# Add source files here
- echo.c
+ oecho.c
)
-add_executable(echo-app ${SOURCE_FILES})
+add_executable(oecho ${SOURCE_FILES})
-target_link_libraries(echo-app LINK_PUBLIC ouroboros-dev)
+target_link_libraries(oecho LINK_PUBLIC ouroboros-dev)
-install(TARGETS echo-app RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS oecho RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/src/tools/echo/echo.c b/src/tools/oecho/oecho.c
similarity index 100%
rename from src/tools/echo/echo.c
rename to src/tools/oecho/oecho.c
diff --git a/src/tools/operf/CMakeLists.txt b/src/tools/operf/CMakeLists.txt
index 895d706..b6faf04 100644
--- a/src/tools/operf/CMakeLists.txt
+++ b/src/tools/operf/CMakeLists.txt
@@ -4,6 +4,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
+get_filename_component(CURRENT_SOURCE_PARENT_DIR
+ ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
+
+include_directories(${CURRENT_SOURCE_PARENT_DIR})
+
find_library(LIBM_LIBRARIES m)
if(NOT LIBM_LIBRARIES)
message(FATAL_ERROR "libm not found")
diff --git a/src/tools/operf/operf.c b/src/tools/operf/operf.c
index 69fc5cb..fe38772 100644
--- a/src/tools/operf/operf.c
+++ b/src/tools/operf/operf.c
@@ -39,14 +39,24 @@
#define _POSIX_C_SOURCE 199506L
#define __XSI_VISIBLE 500
-#include <ouroboros/fqueue.h>
#include <ouroboros/dev.h>
+#include <ouroboros/fccntl.h>
+#include <ouroboros/fqueue.h>
+
+#include "time_utils.h"
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <arpa/inet.h>
+#include <math.h>
+#include <errno.h>
+#include <float.h>
#define OPERF_BUF_SIZE (1024 * 1024)
diff --git a/src/tools/operf/operf_client.c b/src/tools/operf/operf_client.c
index c6f3244..1518bdf 100644
--- a/src/tools/operf/operf_client.c
+++ b/src/tools/operf/operf_client.c
@@ -36,18 +36,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <ouroboros/dev.h>
-#include <ouroboros/fccntl.h>
-#include <ouroboros/time_utils.h>
-
-#include <signal.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <arpa/inet.h>
-#include <math.h>
-#include <errno.h>
-#include <float.h>
-
static void busy_wait_until(const struct timespec * deadline)
{
struct timespec now;
diff --git a/src/tools/operf/operf_server.c b/src/tools/operf/operf_server.c
index ac6306a..11eb92f 100644
--- a/src/tools/operf/operf_server.c
+++ b/src/tools/operf/operf_server.c
@@ -36,10 +36,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <stdlib.h>
-#include <signal.h>
-#include <arpa/inet.h>
-
void shutdown_server(int signo, siginfo_t * info, void * c)
{
(void) info;
diff --git a/src/tools/oping/CMakeLists.txt b/src/tools/oping/CMakeLists.txt
index ebf96bd..31a4f96 100644
--- a/src/tools/oping/CMakeLists.txt
+++ b/src/tools/oping/CMakeLists.txt
@@ -4,6 +4,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
+get_filename_component(CURRENT_SOURCE_PARENT_DIR
+ ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY)
+
+include_directories(${CURRENT_SOURCE_PARENT_DIR})
+
find_library(LIBM_LIBRARIES m)
if(NOT LIBM_LIBRARIES)
message(FATAL_ERROR "libm not found")
diff --git a/src/tools/oping/oping.c b/src/tools/oping/oping.c
index 5e01e02..3c1d4fe 100644
--- a/src/tools/oping/oping.c
+++ b/src/tools/oping/oping.c
@@ -37,17 +37,26 @@
*/
#define _POSIX_C_SOURCE 199506L
-#define __XSI_VISIBLE 500
+#define __XSI_VISIBLE 500
-#include <ouroboros/endian.h>
-#include <ouroboros/fqueue.h>
#include <ouroboros/dev.h>
+#include <ouroboros/fccntl.h>
+#include <ouroboros/fqueue.h>
+
+#include "time_utils.h"
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <arpa/inet.h>
+#include <math.h>
+#include <errno.h>
+#include <float.h>
#define OPING_BUF_SIZE 1500
diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c
index 8952f5e..07fbde7 100644
--- a/src/tools/oping/oping_client.c
+++ b/src/tools/oping/oping_client.c
@@ -36,18 +36,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <ouroboros/dev.h>
-#include <ouroboros/fccntl.h>
-#include <ouroboros/time_utils.h>
-
-#include <signal.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <arpa/inet.h>
-#include <math.h>
-#include <errno.h>
-#include <float.h>
-
volatile bool stop;
void shutdown_client(int signo, siginfo_t * info, void * c)
@@ -88,12 +76,12 @@ void * reader(void * o)
if (msg_len < 0)
continue;
- if (ntoh32(msg->type) != ECHO_REPLY) {
+ if (ntohl(msg->type) != ECHO_REPLY) {
printf("Invalid message on fd %d.\n", fd);
continue;
}
- if (ntoh32(msg->id) >= client.count) {
+ if ((uint32_t) ntohl(msg->id) >= client.count) {
printf("Invalid id.\n");
continue;
}
@@ -102,8 +90,8 @@ void * reader(void * o)
clock_gettime(CLOCK_MONOTONIC, &now);
- sent.tv_sec = ntoh64(msg->tv_sec);
- sent.tv_nsec = ntoh64(msg->tv_nsec);
+ sent.tv_sec = msg->tv_sec;
+ sent.tv_nsec = msg->tv_nsec;
ms = ts_diff_us(&sent, &now) / 1000.0;
@@ -155,10 +143,10 @@ void * writer(void * o)
clock_gettime(CLOCK_MONOTONIC, &now);
- msg->type = hton32(ECHO_REQUEST);
- msg->id = hton32(client.sent++);
- msg->tv_sec = hton64(now.tv_sec);
- msg->tv_nsec = hton64(now.tv_nsec);
+ msg->type = htonl(ECHO_REQUEST);
+ msg->id = htonl(client.sent++);
+ msg->tv_sec = now.tv_sec;
+ msg->tv_nsec = now.tv_nsec;
if (flow_write(*fdp, buf, client.size) == -1) {
printf("Failed to send SDU.\n");
diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c
index 49b14f8..e91b6f1 100644
--- a/src/tools/oping/oping_server.c
+++ b/src/tools/oping/oping_server.c
@@ -36,10 +36,6 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <stdlib.h>
-#include <signal.h>
-#include <arpa/inet.h>
-
void shutdown_server(int signo, siginfo_t * info, void * c)
{
(void) info;
diff --git a/src/tools/time_utils.h b/src/tools/time_utils.h
new file mode 100644
index 0000000..c9760a8
--- /dev/null
+++ b/src/tools/time_utils.h
@@ -0,0 +1,97 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2018
+ *
+ * Time utilities
+ *
+ * Dimitri Staessens <dimitri.staessens@xxxxxxxx>
+ * Sander Vrijders <sander.vrijders@xxxxxxxx>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OUROBOROS_TOOLS_TIME_UTILS_H
+#define OUROBOROS_TOOLS_TIME_UTILS_H
+
+#ifdef MILLION
+#undef MILLION
+#endif
+
+#ifdef BILLION
+#undef BILLION
+#endif
+
+#define MILLION 1000000L
+#define BILLION 1000000000L
+
+#include <time.h>
+#include <sys/time.h>
+#include <limits.h> /* LONG_MAX */
+
+/* functions for timespecs */
+#define ts_diff_ns(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * BILLION \
+ + ((tx)->tv_nsec - (t0)->tv_nsec))
+#define ts_diff_us(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \
+ + ((tx)->tv_nsec - (t0)->tv_nsec) / 1000L)
+#define ts_diff_ms(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \
+ + ((tx)->tv_nsec - (t0)->tv_nsec) / MILLION)
+
+/* functions for timevals are the same */
+#define tv_diff_us(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \
+ + ((tx)->tv_usec - (t0)->tv_usec) / 1000L)
+#define tv_diff_ms(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \
+ + ((tx)->tv_usec - (t0)->tv_usec) / MILLION)
+
+/* functions for timespecs */
+int ts_add(const struct timespec * t,
+ const struct timespec * intv,
+ struct timespec * res);
+
+int ts_diff(const struct timespec * t,
+ const struct timespec * intv,
+ struct timespec * res);
+
+/* functions for timevals */
+int tv_add(const struct timeval * t,
+ const struct timeval * intv,
+ struct timeval * res);
+
+int tv_diff(const struct timeval * t,
+ const struct timeval * intv,
+ struct timeval * res);
+
+/* copying a timeval into a timespec */
+int tv_to_ts(const struct timeval * src,
+ struct timespec * dst);
+
+/* copying a timespec into a timeval (loss of resolution) */
+int ts_to_tv(const struct timespec * src,
+ struct timeval * dst);
+
+#endif /* OUROBOROS_TOOLS_TIME_UTILS_H */
--
2.16.1