summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-02-14 13:55:00 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2018-02-14 17:58:51 +0100
commit91012d9af758a48c4c57fc940dfcc8a581fa46ac (patch)
tree96495c10b615ddafa94ebcfa1a0977109ec0ffe8
parente095d0ade3035c714768266755c9c61acfc2ad0f (diff)
downloadouroboros-91012d9af758a48c4c57fc940dfcc8a581fa46ac.tar.gz
ouroboros-91012d9af758a48c4c57fc940dfcc8a581fa46ac.zip
build: Allow out-of-tree build of tools
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@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
-rw-r--r--src/tools/CMakeLists.txt4
-rw-r--r--src/tools/irm/irm_ipcp_bootstrap.c1
-rw-r--r--src/tools/ocbr/CMakeLists.txt (renamed from src/tools/cbr/CMakeLists.txt)8
-rw-r--r--src/tools/ocbr/ocbr.c (renamed from src/tools/cbr/cbr.c)4
-rw-r--r--src/tools/ocbr/ocbr_client.c (renamed from src/tools/cbr/cbr_client.c)0
-rw-r--r--src/tools/ocbr/ocbr_server.c (renamed from src/tools/cbr/cbr_server.c)0
-rw-r--r--src/tools/oecho/CMakeLists.txt (renamed from src/tools/echo/CMakeLists.txt)8
-rw-r--r--src/tools/oecho/oecho.c (renamed from src/tools/echo/echo.c)0
-rw-r--r--src/tools/operf/CMakeLists.txt5
-rw-r--r--src/tools/operf/operf.c12
-rw-r--r--src/tools/operf/operf_client.c12
-rw-r--r--src/tools/operf/operf_server.c4
-rw-r--r--src/tools/oping/CMakeLists.txt5
-rw-r--r--src/tools/oping/oping.c15
-rw-r--r--src/tools/oping/oping_client.c28
-rw-r--r--src/tools/oping/oping_server.c4
-rw-r--r--src/tools/time_utils.h97
17 files changed, 150 insertions, 57 deletions
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index e8181d5f..b81e5439 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 3cad072a..986c45e1 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
index 158b5c87..5dac3e63 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
index abba8ebe..2c22cc3c 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
index bf527317..bf527317 100644
--- a/src/tools/cbr/cbr_client.c
+++ b/src/tools/ocbr/ocbr_client.c
diff --git a/src/tools/cbr/cbr_server.c b/src/tools/ocbr/ocbr_server.c
index 874155ed..874155ed 100644
--- a/src/tools/cbr/cbr_server.c
+++ b/src/tools/ocbr/ocbr_server.c
diff --git a/src/tools/echo/CMakeLists.txt b/src/tools/oecho/CMakeLists.txt
index 4766ab84..50a66138 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
index 3896a85a..3896a85a 100644
--- a/src/tools/echo/echo.c
+++ b/src/tools/oecho/oecho.c
diff --git a/src/tools/operf/CMakeLists.txt b/src/tools/operf/CMakeLists.txt
index 895d706c..b6faf04e 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 69fc5cb9..fe387724 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 c6f32440..1518bdf5 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 ac6306af..11eb92fc 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 ebf96bdb..31a4f961 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 5e01e026..3c1d4fe9 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 8952f5ed..07fbde74 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 49b14f81..e91b6f10 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 00000000..c9760a8b
--- /dev/null
+++ b/src/tools/time_utils.h
@@ -0,0 +1,97 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2018
+ *
+ * Time utilities
+ *
+ * Dimitri Staessens <dimitri.staessens@ugent.be>
+ * Sander Vrijders <sander.vrijders@ugent.be>
+ *
+ * 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 */