From ce4dfa68147745b116ee316b012653b11a328cd9 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 3 Apr 2020 00:23:11 +0200 Subject: [PATCH] Update UTCP to support fragmenting packets on UDP style channels. This allows the application to send packets of arbitrary size (up to 64 kiB) without worrying about the path MTU to the destination node, which might vary, especially at the start of a connection. If the application doesn't want packets to fragment, it should use meshlink_channel_get_mss() to query the maximum size for unfragmented packets. --- src/utcp | 2 +- test/channels-udp.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/utcp b/src/utcp index 134cccee..a7d31e61 160000 --- a/src/utcp +++ b/src/utcp @@ -1 +1 @@ -Subproject commit 134cccee1441033ad5bcb736a689a3a7481886d8 +Subproject commit a7d31e61566f0d2e6cb0821fcdaf74ccfc1f8f64 diff --git a/test/channels-udp.c b/test/channels-udp.c index 27265aac..0c24a937 100644 --- a/test/channels-udp.c +++ b/test/channels-udp.c @@ -20,6 +20,7 @@ struct client { meshlink_handle_t *mesh; meshlink_channel_t *channel; size_t received; + bool got_large_packet; }; static void server_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, const void *data, size_t len) { @@ -52,10 +53,14 @@ static void client_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *chann (void)data; // We expect always the same amount of data from the server. - assert(len == 1000); assert(mesh->priv); struct client *client = mesh->priv; + assert(len == 512 || len == 2000); client->received += len; + + if(len == 2000) { + client->got_large_packet = true; + } } static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) { @@ -135,9 +140,21 @@ int main() { assert(clients[i].channel); } + // Send a packet larger than the MTU + + char large_data[2000] = ""; + + for(int i = 0; i < 3; i++) { + assert(meshlink_channel_send(server, channels[i], large_data, sizeof(large_data)) == sizeof(large_data)); + } + + // Assert that packets larger than 64 kiB are not allowed + + assert(meshlink_channel_send(server, channels[0], large_data, 65537) == -1); + // Stream packets from server to clients for 5 seconds at 40 Mbps (1 kB * 500 Hz) - char data[1000]; + char data[512]; memset(data, 'U', sizeof(data)); for(int j = 0; j < 2500; j++) { @@ -165,8 +182,9 @@ int main() { } for(int i = 0; i < 3; i++) { - assert(clients[i].received >= 2400000); - assert(clients[i].received <= 2500000); + assert(clients[i].received >= 1000000); + assert(clients[i].received <= 1282000); + assert(clients[i].got_large_packet); } // Clean up. -- 2.39.2