How to send files with ns-3

87 views
Skip to first unread message

Harald Ott

unread,
Apr 18, 2016, 8:52:40 AM4/18/16
to ns-3-users

At first I want to mention: I've already worked with the tutorials and spent times studying the models and other forums, but I really haven't found anything specific on my problem, so here it goes:

I'm trying to use ns-3, to set up a host and a client (which of course is pretty easy), which use TCP to interchange packages. Now the host has multiple representations of a multimedia file and the client uses some specific algorithm (details are not of interest here right now) to decide which file he's requesting from the host depending on available bandwidth.

My question is: how can I tell the host to use specific files in the directory for file transfer? The only possibility I've found (in the examples) is to just use arbitrary sample packets where I can only set the size and nothing more.

Konstantinos

unread,
Apr 18, 2016, 9:01:52 AM4/18/16
to ns-3-users
Hi Harald,

Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name. In any case, there are examples in NS-3 showing how you can add real data in a packet (the number or the filename). At your receiver side, you need to create a handler for incoming packets from which you will send the requested file.

Regards,
K. 

Harald Ott

unread,
Apr 18, 2016, 9:33:01 AM4/18/16
to ns-3-users
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:54 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

It's more a C++ question than a ns-3 one. Open the file you want with std libraries, then serialize the content on a buffer, then convert this buffer on a packet, send that packet to the TCP socket, and reconstruct at the other end. Please note that, like in real world, you probably need to define some extra field, like "how is long the file", and add them on the packet, since you will receive (in-order) chunks of data.

Nat 

Nat P

unread,
Apr 18, 2016, 9:50:54 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:54 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:55 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:55 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:55 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:58 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:50:59 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:51:00 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:51:00 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:51:01 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:51:01 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Nat P

unread,
Apr 18, 2016, 9:51:04 AM4/18/16
to ns-3-users


Il giorno lunedì 18 aprile 2016 15:33:01 UTC+2, Harald Ott ha scritto:
Just think about how a real system would work. Your client runs the specific algorithm that determines which file it needs, then he has to request that specific file from the server.
So, the solution is simple. Send a message requesting that file. The implementation could be different depending on your assumptions, for example you could simply send a packet with a number requesting the 10th file, or more elaborate requesting a file name.

This part is and was already very clear to me.
I'm very aware of how my problem has to be solved in general on an abstract level, but that's not the problem here.
Like I said, I couldn't find it anywhere in the examples / documentation, how to specifically register a file at the host side - I'm looking for the data structure / needed functions for this. I've only ran into File Descriptor NetDevice - but this obviously is only used to model a device.

Message has been deleted

Harald Ott

unread,
Apr 22, 2016, 10:47:07 AM4/22/16
to ns-3-users
This part is - again - in general clear to me. Of course, I know how to open a file in C++ and copy it to a buffer. But I need some advice on how to get my char* buffer into a packet / packets and send these specific packets to the TCP socket. Again, I would know how to do this without the ns3 framework, but in the examples I only see the possibility to send randomly generated bits
For example in tcp-bulk-send.cc, there is a BulkSendHelper, where I can add the attributes SendSize, Remote, MaxBytes, Protocol, but nothing more (see documentation) but I don't see the possibilty to add "my own" Packets anywhere...

PS @ Nat P, please remove your 15 double posts if you see this, to improve readability of this thread....

new2ns3

unread,
Sep 3, 2016, 5:59:26 PM9/3/16
to ns-3-users
Did you solve your problem ? 
I need same thing. 
Reply all
Reply to author
Forward
0 new messages