Packet Sink and saving the received packets

237 views
Skip to first unread message

Nawras Alkassab

unread,
Jan 12, 2016, 11:49:57 PM1/12/16
to ns-3-users
Dear All,
I hope this message finds you well,

I am wondering if I can change the behavior of Packet Sink API in which it can save the files sent by UDPTrace Client instead of consuming it for later use. After a little bit of research, here is few questions I didn't know how to answer : 
1- How does Packet Sink API consume the packets ? 
2- What DoDispose function do to the packets themselves ? are these packets related to the object being disposed ? 
3- How HandleRead and HandleAccept deal with the packets ? 
4- Do I need to write my own receiving socket in order to save these files in a specific directory ? if so, can you please guide me on how to do so in a "particular directory" ( not necessarily the current directory" 

Unfortunately, my programming skills using object-oriented C++ is limited. On the other hand, I tried to simulate the scenario without using a network simulator ( i.e NS3) through configuring Cisco routers and few end points with opened customized sockets. However, the "delay" command on Cisco routers can only be used to influence the router selection and optimization by a routing protocol. Hence, it won't be scientifically sufficient to use them. 

I hope you can help me with the above-mentioned problem and questions.

Best, 
Nawras Alkassab

Tommaso Pecorella

unread,
Jan 13, 2016, 12:12:28 PM1/13/16
to ns-3-users
Hi,

answers in line


On Wednesday, January 13, 2016 at 5:49:57 AM UTC+1, Nawras Alkassab wrote:
Dear All,
I hope this message finds you well,

I am wondering if I can change the behavior of Packet Sink API in which it can save the files sent by UDPTrace Client instead of consuming it for later use. After a little bit of research, here is few questions I didn't know how to answer : 
1- How does Packet Sink API consume the packets ? 

PacketSink is an Application, not an API. Anyway, it receive the packets in the PacketSink::HandleRead function.
If you're wondering how this function is called, search for its use in the code and read the Callback chapter in the manual.
 
2- What DoDispose function do to the packets themselves ? are these packets related to the object being disposed ? 

DoDispose doesn't have anything to do with packet reception.
 
3- How HandleRead and HandleAccept deal with the packets ?

HandleRead reads the packets. HandleAccept accepts an incoming (TCP) connection.
 
4- Do I need to write my own receiving socket in order to save these files in a specific directory ? if so, can you please guide me on how to do so in a "particular directory" ( not necessarily the current directory" 

You'll have to write your own Application, not Socket.
Guidance ? Not really, it's a trivial task. Just open a file descriptor and write the packet content to it. Just google it. You can also use "plain" C file descriptors and write the packet buffer to it.
Still... since you're admitting your lack of C++ skills, let me show you how powerful it can be: http://www.cplusplus.com/doc/tutorial/files/
 std::ofstream myfile;
 myfile
.open ("example.txt");
...
 packet
->CopyData (&myfile, packet->GetSize ());

Beware of opening / closing the file and/or to use tin append mode. read the tutorial.

T.

Nawras Alkassab

unread,
Jan 15, 2016, 2:21:03 PM1/15/16
to ns-3-users
Than you for your rapid response Mr.Pecorella. Your efforts are much appreciated. 

Best, 
Nawras Alkassab
Reply all
Reply to author
Forward
0 new messages