Skip to content

Commit

Permalink
Merge pull request #256 from jphickey/fix-249-bundle-size
Browse files Browse the repository at this point in the history
Fix #249, adu size option for bpcat
  • Loading branch information
jphickey committed Sep 27, 2023
2 parents 7f85ff5 + fc7634b commit 13f5269
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions app/bpcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@
//#define BPCAT_MAX_WAIT_MSEC 1800000
#define BPCAT_MAX_WAIT_MSEC 250

#define BPCAT_BUNDLE_BUFFER_SIZE 16384
#define BPCAT_DATA_MESSAGE_MAX_SIZE (BPCAT_BUNDLE_BUFFER_SIZE - 520)
#define BPCAT_RECV_WINDOW_SZ 32
#define BPCAT_BUNDLE_BUFFER_SIZE 16384
#define BPCAT_HEADER_RESERVE_SIZE 520
#define BPCAT_ADU_MAX_SIZE (BPCAT_BUNDLE_BUFFER_SIZE - BPCAT_HEADER_RESERVE_SIZE)
#define BPCAT_RECV_WINDOW_SZ 32

#define BPCAT_DEFAULT_INTER_BUNDLE_DELAY 20
#define BPCAT_MAX_INTER_BUNDLE_DELAY 1000

#define BPCAT_DEFAULT_LOCAL_NODENUM 100
#define BPCAT_DEFAULT_REMOTE_NODENUM 101
Expand All @@ -81,7 +85,7 @@ typedef struct bpcat_msg_content
{
uint32_t stream_pos;
uint32_t segment_len;
uint8_t content[BPCAT_DATA_MESSAGE_MAX_SIZE];
uint8_t content[BPCAT_ADU_MAX_SIZE];
} bpcat_msg_content_t;

typedef struct bpcat_msg_recv
Expand All @@ -104,7 +108,8 @@ static char remote_dtnaddr_string[ADDR_MAX_SIZE];
static char local_ipaddr_string[ADDR_MAX_SIZE];
static char remote_ipaddr_string[ADDR_MAX_SIZE];

static long inter_bundle_delay = 20;
static long inter_bundle_delay = BPCAT_DEFAULT_INTER_BUNDLE_DELAY;
static uint32_t bundle_adu_size = BPCAT_ADU_MAX_SIZE;

pthread_t cla_in_task;
pthread_t cla_out_task;
Expand Down Expand Up @@ -144,6 +149,8 @@ static void display_banner(const char *prog_name)
fprintf(stderr, " --local-cla-uri=udp://<ip>:<port> Bind local CLA to given IP:port \n");
fprintf(stderr, " --remote-cla-uri=udp://<ip>:<port> Send bundles to remote CLA at given IP:port\n");
fprintf(stderr, " -d/--delay=<msec> forced inter bundle send delay (20ms default)\n");
fprintf(stderr, " -s/--adu-size=stream chunk (ADU) size to pass to bplib (default and max=%u bytes)\n",
BPCAT_ADU_MAX_SIZE);
fprintf(stderr, "\n");
fprintf(stderr, " Creates a local BP agent with local IPN address as specified. All data\n");
fprintf(stderr, " received from standard input is forwarded over BP bundles, and all data\n");
Expand Down Expand Up @@ -309,7 +316,7 @@ static void parse_options(int argc, char *argv[])
/*
* getopts parameter passing options string
*/
static const char *opt_string = "l:r:i:o:12d:?";
static const char *opt_string = "l:r:i:o:12d:s:?";

/*
* getopts_long long form argument table
Expand All @@ -321,6 +328,7 @@ static void parse_options(int argc, char *argv[])
{"local-cla-uri", required_argument, NULL, 1000},
{"remote-cla-uri", required_argument, NULL, 1001},
{"delay", required_argument, NULL, 'd'},
{"adu-size", required_argument, NULL, 's'},
{"help", no_argument, NULL, '?'},
{NULL, no_argument, NULL, 0}};

Expand Down Expand Up @@ -373,7 +381,15 @@ static void parse_options(int argc, char *argv[])

case 'd':
inter_bundle_delay = strtoul(optarg, NULL, 0);
if (inter_bundle_delay >= 1000)
if (inter_bundle_delay >= BPCAT_MAX_INTER_BUNDLE_DELAY)
{
display_banner(argv[0]);
}
break;

case 's':
bundle_adu_size = strtoul(optarg, NULL, 0);
if (bundle_adu_size > BPCAT_ADU_MAX_SIZE)
{
display_banner(argv[0]);
}
Expand Down Expand Up @@ -681,7 +697,7 @@ static void *app_in_entry(void *arg)
current_time = 0;
}

if (send_deadline > current_time && data_fill_sz < sizeof(msg_buffer.content))
if (send_deadline > current_time && data_fill_sz < bundle_adu_size)
{
pfd.fd = app_fd;
pfd.events = POLLIN;
Expand All @@ -704,7 +720,7 @@ static void *app_in_entry(void *arg)
}
if ((pfd.revents & POLLIN) != 0)
{
status = read(app_fd, &msg_buffer.content[data_fill_sz], sizeof(msg_buffer.content) - data_fill_sz);
status = read(app_fd, &msg_buffer.content[data_fill_sz], bundle_adu_size - data_fill_sz);
fprintf(stderr, "read()... size=%ld\n", (long)status);
if (status < 0)
{
Expand Down

0 comments on commit 13f5269

Please sign in to comment.