fireperf_SOURCES = \
src/client.c \
src/client.h \
+ src/ctx.c \
+ src/ctx.h \
src/logging.c \
src/logging.h \
src/main.c \
#include <unistd.h>
#include "client.h"
+#include "ctx.h"
#include "logging.h"
#include "main.h"
#include "random.h"
#ifndef FIREPERF_CLIENT_H
#define FIREPERF_CLIENT_H
+#include "ctx.h"
#include "main.h"
int fireperf_client(struct fireperf_ctx* ctx, struct fireperf_stats* stats,
--- /dev/null
+/*#############################################################################
+# #
+# fireperf - A network benchmarking tool #
+# Copyright (C) 2024 IPFire Development Team #
+# #
+# 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 3 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, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include "ctx.h"
--- /dev/null
+/*#############################################################################
+# #
+# fireperf - A network benchmarking tool #
+# Copyright (C) 2024 IPFire Development Team #
+# #
+# 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 3 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, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef FIREPERF_CTX_H
+#define FIREPERF_CTX_H
+
+#include <netinet/in.h>
+
+#define MAX_WORKERS 128
+
+// Forward declarations
+struct fireperf_random_pool;
+struct fireperf_worker;
+
+struct fireperf_ctx {
+ int terminated;
+ int loglevel;
+ enum {
+ FIREPERF_MODE_NONE = 0,
+ FIREPERF_MODE_CLIENT,
+ FIREPERF_MODE_SERVER,
+ } mode;
+ struct in6_addr address;
+ int duplex;
+ int keepalive_only;
+ int keepalive_count;
+ int keepalive_interval;
+ struct fireperf_random_pool* pool;
+ int port;
+ unsigned int listening_sockets;
+ unsigned long parallel;
+ unsigned int timeout;
+ int close;
+ int zero;
+
+ // Workers
+ struct fireperf_workers* workers[MAX_WORKERS];
+ unsigned int num_workers;
+ unsigned int max_workers;
+};
+
+#endif /* FIREPERF_CTX_H */
#include <syslog.h>
-#include "main.h"
+#include "ctx.h"
static inline void __attribute__((always_inline, format(printf, 2, 3)))
fireperf_log_null(struct fireperf_ctx* ctx, const char* format, ...) {}
// Initialise random number generator
srandom(time(NULL));
+ // Fetch how many workers we would launch
+ ctx.max_workers = sysconf(_SC_NPROCESSORS_ONLN);
+
// Set limits
r = set_limits(&ctx);
if (r)
#ifndef FIREPERF_MAIN_H
#define FIREPERF_MAIN_H
-#include <netinet/in.h>
#include <time.h>
#define DEFAULT_KEEPALIVE_COUNT 3
#define EPOLL_MAX_EVENTS 128
-// Forward declaration
-struct fireperf_random_pool;
-
-struct fireperf_ctx {
- int terminated;
- int loglevel;
- enum {
- FIREPERF_MODE_NONE = 0,
- FIREPERF_MODE_CLIENT,
- FIREPERF_MODE_SERVER,
- } mode;
- struct in6_addr address;
- int duplex;
- int keepalive_only;
- int keepalive_count;
- int keepalive_interval;
- struct fireperf_random_pool* pool;
- int port;
- unsigned int listening_sockets;
- unsigned long parallel;
- unsigned int timeout;
- int close;
- int zero;
-};
+#include "ctx.h"
// Struct to collect statistics
struct fireperf_stats {
#include <stdlib.h>
#include <sys/random.h>
+#include "ctx.h"
#include "logging.h"
-#include "main.h"
#include "random.h"
struct fireperf_random_pool* fireperf_random_pool_create(struct fireperf_ctx* ctx, size_t size) {
#ifndef FIREPERF_RANDOM_H
#define FIREPERF_RANDOM_H
-#include "main.h"
-
struct fireperf_random_pool {
char* data;
size_t size;
};
+#include "ctx.h"
+
struct fireperf_random_pool* fireperf_random_pool_create(
struct fireperf_ctx* ctx, size_t size);
void fireperf_random_pool_free(struct fireperf_random_pool* pool);
#ifndef FIREPERF_SERVER_H
#define FIREPERF_SERVER_H
-#include "main.h"
+#include "ctx.h"
int fireperf_server(struct fireperf_ctx* ctx, int epollfd, int timerfd);
struct fireperf_worker;
-#include "main.h"
+#include "ctx.h"
int fireperf_worker_create(struct fireperf_worker** worker, struct fireperf_ctx* ctx);
void fireperf_worker_free(struct fireperf_worker* worker);