Skip to content

Commit

Permalink
Fix #249, adu size option for bpcat
Browse files Browse the repository at this point in the history
Adds a "-s" command line option to allow the ADU size to be configured
at runtime.  The existing value becomes the maximum and default.
  • Loading branch information
jphickey committed Sep 20, 2023
1 parent 3910733 commit d4b8eea
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions app/bpcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,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_MAX_BUNDLE_BUFFER_SIZE 16384
#define BPCAT_HEADER_RESERVE_SIZE 520
#define BPCAT_MAX_DATA_MESSAGE_MAX_SIZE (BPCAT_MAX_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

/*************************************************************************
* File Data
Expand All @@ -72,7 +76,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_MAX_DATA_MESSAGE_MAX_SIZE];
} bpcat_msg_content_t;

typedef struct bpcat_msg_recv
Expand All @@ -89,7 +93,8 @@ static const char ADDRESS_PREFIX[] = "ipn://";
static char local_address_string[128] = "ipn://100.1";
static char remote_address_string[128] = "ipn://101.1";

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

pthread_t cla_in_task;
pthread_t cla_out_task;
Expand Down Expand Up @@ -127,6 +132,8 @@ static void display_banner(const char *prog_name)
fprintf(stderr, " -i/--input-file=<filename> read input from given file instead of stdin\n");
fprintf(stderr, " -o/--output-file=<filename> write output to given file instead of stdout\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_MAX_DATA_MESSAGE_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 @@ -220,6 +227,7 @@ static void parse_options(int argc, char *argv[])
{"input-file", required_argument, NULL, 'i'},
{"output-file", required_argument, NULL, 'o'},
{"delay", required_argument, NULL, 'd'},
{"adu-size", required_argument, NULL, 's'},
{"help", no_argument, NULL, '?'},
{NULL, no_argument, NULL, 0}};

Expand Down Expand Up @@ -272,7 +280,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_MAX_DATA_MESSAGE_MAX_SIZE)
{
display_banner(argv[0]);
}
Expand Down Expand Up @@ -318,7 +334,7 @@ static void *cla_in_entry(void *arg)
bplib_cla_intf_id_t *cla;
ssize_t status;
size_t data_fill_sz;
uint8_t bundle_buffer[BPCAT_BUNDLE_BUFFER_SIZE];
uint8_t bundle_buffer[BPCAT_MAX_BUNDLE_BUFFER_SIZE];
struct pollfd pfd;
int error;
socklen_t errlen;
Expand Down Expand Up @@ -402,7 +418,7 @@ static void *cla_out_entry(void *arg)
size_t data_fill_sz;
size_t cla_bundle_sz;
ssize_t status;
uint8_t bundle_buffer[BPCAT_BUNDLE_BUFFER_SIZE];
uint8_t bundle_buffer[BPCAT_MAX_BUNDLE_BUFFER_SIZE];
struct timespec tm;

cla = arg;
Expand Down Expand Up @@ -581,7 +597,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 @@ -604,7 +620,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 d4b8eea

Please sign in to comment.