How to use Simulink blocks to receive multiple large (fragmented) UDP packets in each time step?

14 visualizzazioni (ultimi 30 giorni)
Hi. We are trying to use Simulink library blocks to receive multiple large (16 kB) UDP packets into Simulink (in one time step) and cannot figure out how to make this happen with the Simulink UDP Receive block.
So far, we successfully receive in-tact defragmented 16 kB data payload in the UDP Receive block (as confirmed by the correct data size output from the block and by examining the packet data output from the UDP Receive block). However, we (a) cannot get downstream Simulink buffer blocks to put that full packet size into a buffer and (b) cannot figure out how to use the available network blocks to buffer up not just the first UDP packet but all of the the UDP packets (~20 x 16 kB packets) that will arrive in one Simulink step.
Our current attempt is to try putting the UDP Receive block and the s-fun in an iterator block to see ie we can get them to both run once for each packet available in the UDP Receive (until the iteration loop when output data length == 0).
Background:
For years we have used the Ethernet Receive block (with NB Chain Size, NB Manage, and NB Unlink blocks) combined with a custom S-function and an iterator loop to read dozens of standard UDP packets into our Simulink model on evey step. The Ethernet Receive block provides the IP header along with the data so we can capture the multiple UDP packets of size < 1500 bytes and then iterate through their payloads. The iterator loop outputs consecutive data payloads in consecutive vectors which are then consumed all together in one timestep (as a matrix) by the downstream Simulink model.
However, our data source is now sending large (16 kB) UDP packets (using fragmentation). The data payload is intricate (not just a bunch of consecutive data bytes), so parsing the large UDP packet in 1500-byte steps (as provided by the Ethernet Receive block) is non-trivial (although admittedly probably possible).
So now we are attempting to use the UDP Receive Simulink block because it accesses the UDP packet at a higher OSI level and therefore returns fully defragged packets. But it is not clear how to use any of the other Simulink network blocks (from any blockset) to grab all of the data payload from that packet or how to consume all of the multiple large packets that arrive in each timestep so that we can create the multi-packet matrix of data to the downstream Simulink model.
If you've worked through this situation then it would be great to hear from you!

Risposte (1)

Ayush
Ayush il 17 Nov 2023
Hi John,
I understand that you want to handle multiple large UDP packets in a single time step and get the downstream data to be used in the rest of the model through a buffer which contains all the UDP packets and not just the first one.
Here are some possible workarounds for the desired situation and outcome:
1. Change UDP Receive Block configuration: Ensure that the buffer size of the UDP Receive Block is large enough to accommodate the size of your packets. Since the data is normally received in a FIFO format and may get truncated if the buffer is full. Also you can try disabling the parameter ‘Output latest data’ to receive all the 20 16kb chunks of your data in each time step. Please refer to the below documentation to know more about the “UDP Receive Block” and its configuration parameters:
2. Use a MATLAB Function block with the udpport object: You can use the ‘udpport’ object in MATLAB to create a UDP socket which can be incorporated in a MATLAB Function block in Simulink. You can then use the ‘fread’ function to read data from the socket which will allow you to read multiple packets at each time step. Please refer to the below documentations to know more about the ‘udp’ object and ‘fread’ function in MATLAB:
3. Use a For Each Subsystem: You can use a For Each Subsystem to process each packet individually. It would allocate specific subsystem to each element or packet of the input signal received. For your particular use case, you can configure each subsystem to partition the input signal for 20 packets of 16kb each. Please refer to the below documentation to know more about the ‘For Each’ Subsystem:
4. Use a Rate Transition Block: To regulate the rate of input signals being received use the Rate Transition block to buffer the data for each time step and then pass it downstream at a separate rate for the rest of the model. Please refer to the below documentation to know more about the “Rate Transition Block”:
5. Use a Stateflow Chart: Lastly you could use Stateflow chart to manage the reception and buffering of your packets. It would allow you to design state machines and flow charts that can be integrated into your Simulink model to implement complex logic to manage your UDP packets. Please refer to the below documentation to know more about ‘Stateflow’ charts:
Hope it helps,
Regards,
Ayush Misra

Prodotti


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by