mirror of
https://github.com/rtbrick/bngblaster.git
synced 2024-05-06 15:54:57 +00:00
add --quit-loop option for shutting down timer loop after initial transmission
This commit is contained in:
@@ -63,6 +63,7 @@ static struct option long_options[] = {
|
||||
{"stream-file", required_argument, NULL, 'f'},
|
||||
{"seed", required_argument, NULL, 's'},
|
||||
{"sequence", required_argument, NULL, 'q'},
|
||||
{"quit-loop", no_argument, NULL, 'Q'},
|
||||
{"level", required_argument, NULL, 'V'},
|
||||
{"log", required_argument, NULL, 't' },
|
||||
{NULL, 0, NULL, 0}
|
||||
@@ -712,6 +713,13 @@ lspgen_add_connector(struct lsdb_ctx_ *ctx, char *conn_src)
|
||||
LOG(NORMAL, "Add connector to 0x%llx\n", node_id);
|
||||
}
|
||||
|
||||
/* Get out of event loop */
|
||||
void
|
||||
lspgen_quit_loop (void)
|
||||
{
|
||||
loop_running = false;
|
||||
}
|
||||
|
||||
void
|
||||
lspgen_sig_handler (int signum)
|
||||
{
|
||||
@@ -719,7 +727,7 @@ lspgen_sig_handler (int signum)
|
||||
|
||||
switch (signum) {
|
||||
case SIGINT:
|
||||
loop_running = false; /* Get out of event loop */
|
||||
lspgen_quit_loop();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -748,7 +756,7 @@ main(int argc, char *argv[])
|
||||
* Parse options.
|
||||
*/
|
||||
idx = 0;
|
||||
while ((opt = getopt_long(argc, argv, "vha:c:C:e:f:g:l:L:m:M:n:K:N:p:q:r:s:S:t:T:V:w:x:X:zZ",
|
||||
while ((opt = getopt_long(argc, argv, "vha:c:C:e:f:g:l:L:m:M:n:K:N:p:q:Qr:s:S:t:T:V:w:x:X:zZ",
|
||||
long_options, &idx)) != -1) {
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
@@ -866,6 +874,10 @@ main(int argc, char *argv[])
|
||||
ctx->sequence = 1;
|
||||
}
|
||||
break;
|
||||
case 'Q':
|
||||
/* Quit event loop after draining LSDB once */
|
||||
ctx->quit_loop = true;
|
||||
break;
|
||||
case 's':
|
||||
/* seed value such that random graph generation becomes deterministic */
|
||||
ctx->seed = strtol(optarg, NULL, 0);
|
||||
@@ -980,6 +992,13 @@ main(int argc, char *argv[])
|
||||
timer_add_periodic(&ctx->timer_root, &ctx->ctrl_socket_connect_timer,
|
||||
"connect", 1, 0, ctx, &lspgen_ctrl_connect_cb);
|
||||
|
||||
/*
|
||||
* Wakup at least once a second doing nothing,
|
||||
* such that we do not sleep while user tries to quit the timer loop.
|
||||
*/
|
||||
timer_add_periodic(&ctx->timer_root, &ctx->ctrl_socket_wakeup_timer,
|
||||
"wakeup", 1, 0, ctx, &lspgen_ctrl_wakeup_cb);
|
||||
|
||||
/*
|
||||
* Block SIGPIPE. This happens when a session disconnects.
|
||||
* EPIPE gets handled when writing the buffer.
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
__uint128_t lspgen_load_addr(uint8_t *, uint32_t);
|
||||
void lspgen_store_addr(__uint128_t, uint8_t *, uint32_t);
|
||||
void lspgen_store_bcd_addr(__uint128_t, uint8_t *, uint32_t);
|
||||
void lspgen_quit_loop(void);
|
||||
|
||||
/* lspgen_mrt.c */
|
||||
void lspgen_dump_mrt(lsdb_ctx_t *);
|
||||
@@ -44,6 +45,7 @@ void lspgen_dump_pcap(lsdb_ctx_t *);
|
||||
|
||||
/* lspgen_ctrl.c */
|
||||
void lspgen_ctrl_connect_cb(timer_s *);
|
||||
void lspgen_ctrl_wakeup_cb(timer_s *);
|
||||
|
||||
/* lspgen_stream.c */
|
||||
void lspgen_dump_stream(lsdb_ctx_t *);
|
||||
|
||||
@@ -207,6 +207,13 @@ lspgen_ctrl_close_cb(timer_s *timer)
|
||||
ctx->ctrl_socket_sockfd = 0;
|
||||
}
|
||||
LOG(NORMAL, "Closing connection to %s\n", ctx->ctrl_socket_path);
|
||||
|
||||
/*
|
||||
* Terminate the event loop if user wants.
|
||||
*/
|
||||
if (ctx->quit_loop) {
|
||||
lspgen_quit_loop();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -304,6 +311,14 @@ lspgen_ctrl_write_cb(timer_s *timer)
|
||||
1, 0, ctx, &lspgen_ctrl_close_cb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dummy timer for not sleeping too long in the event loop.
|
||||
*/
|
||||
void
|
||||
lspgen_ctrl_wakeup_cb(__attribute__((unused))timer_s *timer)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
lspgen_ctrl_connect_cb(timer_s *timer)
|
||||
{
|
||||
|
||||
@@ -90,11 +90,13 @@ typedef struct lsdb_ctx_
|
||||
/* BNG blaster Control socket */
|
||||
char *ctrl_socket_path;
|
||||
timer_s *ctrl_socket_connect_timer;
|
||||
timer_s *ctrl_socket_wakeup_timer; /* dummy timer */
|
||||
timer_s *ctrl_socket_write_timer;
|
||||
timer_s *ctrl_socket_close_timer;
|
||||
struct io_buffer_ ctrl_io_buf;
|
||||
int ctrl_socket_sockfd;
|
||||
bool ctrl_packet_first;
|
||||
bool quit_loop; /* Terminate loop after draining the LSDB */
|
||||
struct {
|
||||
uint32_t octets_sent;
|
||||
uint32_t packets_sent;
|
||||
|
||||
Reference in New Issue
Block a user