How do I send personalized packets between a client and a server?

374 views
Skip to first unread message

name surname

unread,
Jun 19, 2022, 4:10:16 PM6/19/22
to ns-3-users
Hello, I'm new to the group and to ns3. I'm trying to develop a network in which there is a client and a server connected using udp. The aim of the network is to send personalized packets (so packets with a payload that I decide) between the client and the server. I've read the "udp-client-server" example given by ns3, but I didn't see any personalized packet, moreover I've created some personalized packets but I don't know how to send them. Do you know if it is possible (and if yes, how) to send personalized packets between client and server?
Thanks.

Tom Henderson

unread,
Jun 20, 2022, 12:40:42 AM6/20/22
to ns-3-...@googlegroups.com
Yes, it is possible.  However, I am not sure whether there are any
examples in the repository for sending custom UDP packets.

Most ns-3 applications are traffic generation applications, or a packet
sink application that just consumes received packets, so they do not
populate the packets with real data, nor do they attempt to read the
payload data.  In fact, the packet's size value is inflated but the
(dummy) bytes are not written to the buffer.

However, it is possible to write custom data into a packet payload
before adding headers and trailers, and to read it after headers and
trailers are removed.  In general:

- when you create a packet, pass it a character buffer, and size, as
arguments:

https://www.nsnam.org/doxygen/classns3_1_1_packet.html#a7f6a0314efee85ac6cf4a64e05450538

- on the receive side, you can use the CopyData method to copy data
bytes into a character buffer:

https://www.nsnam.org/doxygen/classns3_1_1_packet.html#a5bafd70ccf970b10524e2d61afd39dc1

Then, you will need to create sockets (see, for example, the tutorial
program fifth.cc for how this is done on the sending side, for TCP), for
both sender and receiver, and write packets into the sending socket and
read packets from the receiving socket (and CopyData() from them).

As an alternative, you can also define a custom Header type for your
data (if it is structured data of some sort) and AddHeader/RemoveHeader,
instead of copying to and from a byte buffer.

- Tom


Li, Ye

unread,
Jun 20, 2022, 3:09:27 AM6/20/22
to ns-3-...@googlegroups.com
FYI, the following codes contain examples of what Tom have mentioned, i.e., creating Packet with payload from unsigned chars in memory:


and reading out them at the client using CopyData: 


Hope it helps.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/3add8977-4422-aa5d-7127-f112ff41a1d1%40tomh.org.


--
LI, Ye
School of Information Science and Technology
Nantong University
Nantong 226019, Jiangsu Province, China

name surname

unread,
Jun 23, 2022, 3:23:46 PM6/23/22
to ns-3-users
Thank you very much, you have been very helpful!

name surname

unread,
Jun 28, 2022, 6:56:46 AM6/28/22
to ns-3-users
Hello, I've tried to follow your suggestions (they helped me a lot!), but I have the following problem: after having sent the packet (in the attached code it's a buffer) from the server to the client, it seems that the packet isn't really received because the variable recPacket of the attached code is a null pointer. I don't know why this could happen because client and server seem to be correctly connected and because the buffer that the server sends to the client isn't empty.
code.PNG

Tom Henderson

unread,
Jun 28, 2022, 4:13:18 PM6/28/22
to ns-3-...@googlegroups.com
On 6/28/22 03:56, name surname wrote:
Hello, I've tried to follow your suggestions (they helped me a lot!), but I have the following problem: after having sent the packet (in the attached code it's a buffer) from the server to the client, it seems that the packet isn't really received because the variable recPacket of the attached code is a null pointer. I don't know why this could happen because client and server seem to be correctly connected and because the buffer that the server sends to the client isn't empty.

When you send a packet, you have to wait some amount of simulation time for it to be received on the destination.  It looks like you are just trying to receive it immediately after calling SendTo().

name surname

unread,
Jun 29, 2022, 3:26:38 AM6/29/22
to ns-3-users
Thanks for the help! I've tried to wait the arrival of the packet in the way specified in the attached code, but it still doesn't work because it remains stuck in the while loop.
code2.PNG
Reply all
Reply to author
Forward
0 new messages