Redirecting data from Node to sqlite db and back, not statistics.

51 views
Skip to first unread message

Vojtech

unread,
Dec 5, 2015, 7:09:38 AM12/5/15
to ns-3-users
Hello,
I have a scenario with several nodes sending data to one node that collects data and routes them to another node. I'd like to implement simple sqlite database on that node and make some processing on that data before they are routed further. I went through the tutorial, but I am not sure how to redirect data from the sink of the collector node and how to redirect them to the output interface after the processing. As I understand the guide, only statistic output can be collected via Data Collection Framework(Probes etc.) and it should be possible to do it with tracing helpers. Could someone experienced give me some example how to do it? I know how to work with sql, but don't know how to make connector to the databse and back. Thank you very much :)

Tommaso Pecorella

unread,
Dec 5, 2015, 7:27:01 AM12/5/15
to ns-3-users
Hi,

I guess that you want to process the data that are sent in the packets, i.e., data contained in the packet payloads.
The first thing is to understand how to add real data to the payload, and this has been discussed multiple times (see also the applications, some of them do that).
Then, it's a matter of reading the payload data and use the database from the receiving function in your collector node. As n example, see UdpServer application: it prints stuff it reads from the packet in a function.
Lastly, how to connect to your database... well, that's up to you. It depends on what you're using (Sqlite, Postgres, MySql, etc.). There's no fixed rule, but remember that the simulation is "just" a program: do the same thing as you'd do for a normal program, it will work.

have fun,

T.

Vojtech

unread,
Dec 5, 2015, 2:13:15 PM12/5/15
to ns-3-users
Hi Tommaso,
thank you for reply.

Your guess is right. I need to process packet headers and payloads. For the beginning and for some simplification, I have random data generated by OnOff application. In my scenario I use PacketSink on receiver side for reception both TCP and UDP traffic, so I guess UdpServer is not exactly what I need. I did some research in reference manual and I guess some of that could be done via packet printing. (It's interesting what can you find in documentation if you spend hours on finding sth you don't exactly know what! :)). I found out that I could possibly copy data from packet and store it wherever I need. Since I'm new to NS3 and OO programming, I'm not sure how to make it work. I've found this piece of code based on CopyDatamethod in another topic:

sender side:
uint8_t buffer[1012];
for(int i=0;i<1012;i++){
     buffer[i]=85;
}
std::cout << "user data" << std::endl;
for(int i=0;i<1012;i++){
      std::cout << (uint8_t)buffer[i]; //<< std::endl;
}
std::cout << std::endl;
Ptr<Packet> p = Create<Packet> (buffer, m_size-(8+4));
 
receiver side:
uint8_t *buffer_temp=new uint8_t[1013];
packet->CopyData(buffer_temp,1012);
for(int i=0;i<1012;i++){
  std::cout << *buffer_temp;
  buffer_temp++;
}

I am missing the point of inserting value 85 and dont know what should this line do(Ptr<Packet> p = Create<Packet> (buffer, m_size-(8+4));).

I went ahead and searched packet.h and buffer.h, but I'm obviously missing something. I see I need to copy incomming packets into temporary variable and redirect it into my database. Can you please tell me if am I on a right way and help me a bit with a code?

My scenario is as follows:

http://pastebin.com/2MgwFNqn#

Thank you very much.
V

Tommaso Pecorella

unread,
Dec 5, 2015, 3:40:35 PM12/5/15
to ns-3-users
Hi,

the problem could be that you're new to OO. It's most probably the reason for not being able to go though the documentation - you expect to have procedures and you find classes (and methods inside the classes, and methods belonging to different classes with the same name, and they do slightly different things, and you don't know which one will be called).

My suggestion is to get a little grasp on OO as a start, otherwise you'll not really know what you're doing.
Still... you wasn't too far from your goal.

Reading the data: it should be done in the HandleRead method of the SinkApplication. However, in order to not change the class, you can do a subclass and override HandleRead (but make it virtual or it will not work). <- see ? You need to know a bit of OO...
Note: Packet::CopyData is the right function.

Sending the data: the code snippet you found is basically right, with one exception: you have to decide what is the packet length in your case. 
The instruction
Ptr<Packet> p = Create<Packet> (buffer, m_size-(8+4));
is creating a packet of size "m_size-(8+4)" with the content stored in the buffer. Why removing 12 bytes... not a clue, it depends on what that code was supposed to do.
If I'm right, it comes from UdpClient. In this case 8 is the UDP header length and 4 is the space for a header used by UdpClient. If you want to send an IP packet whose payload is m_size, the subtraction makes sense.

Anyway, get a OO "101" course, there are plenty online and in a couple of days you can (at least) read the code with a little less confusion. You'll learn the rest on the go.

Have fun,

T.

Vojtech

unread,
Dec 5, 2015, 5:31:02 PM12/5/15
to ns-3-users
Thank you very much for your input, I really appreciate that! Youre right, I'll go through some courses although it's a bit pain since I need this little OO code for my project :)). If I understand it well, I just need to handle data from SinkApplication with HandleRead method and use CopyData function to insert it into db. Doesn't sound that bad. Thank you. :)
Reply all
Reply to author
Forward
0 new messages