Can we trace the actual contents of packet payload in ASCII traces file of NS3

145 views
Skip to first unread message

Sunny

unread,
Jan 8, 2020, 6:36:55 AM1/8/20
to ns-3-users
I am simulating a scenario of VANET for BSM_application in NS-3.27 and I am capturing the traces in ASCII format by enabling the ASCII traces (AsciiTraceHelper) and everything is going well. Now I want to capture the actual contents/data in the packet/payload sent by the nodes(The packet contains actual data, for example "Hello, I am here").NOTE: I know the said data can be captured using PCAP but I am interested to capture this packet data in my Ascii traces. I will be thankful for your help/guidance. For easy reference below is the format of ASCII traces which I have right now and I am in need to add the actual contents of payload in the end of this kind of streams.

"t 1.00909 /NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/State/Tx ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:01, BSSID=ff:ff:ff:ff:ff:ff, FragNumber=0, SeqNumber=0) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 0 protocol 17 offset (bytes) 0 flags [none] length: 228 10.1.0.1 > 255.255.255.255) ns3::UdpHeader (length: 208 9080 > 9080) Payload (size=200) ns3::WifiMacTrailer ()

r 15.5009 /NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/State/RxOk ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:05, BSSID=ff:ff:ff:ff:ff:ff, FragNumber=0, SeqNumber=11) ns3::LlcSnapHeader (type 0x800) ns3::Ipv4Header (tos 0x0 DSCP Default ECN Not-ECT ttl 64 id 11 protocol 17 offset (bytes) 0 flags [none] length: 228 10.1.0.5 > 255.255.255.255) ns3::UdpHeader (length: 208 9080 > 9080) Payload (size=200) ns3::WifiMacTrailer ()"

Adil Alsuhaim

unread,
Jan 9, 2020, 8:47:42 PM1/9/20
to ns-3-users
Yes you can. The content printed by the ASCII trace helper uses the "Print" function of Packet object. Check out the code, it goes through all PacketMetadata and print out the headers and other things as you can see in the switch statement with multiple cases. If the item is HEADER or TRAILER, it creates a temporary "chunk" of the type of that header or trailer (like WifiMacHeader, for example) and prints header relevant information by the line 

chunk->Print (os) ;

For WifiMacHeader, for example, its Print function WifiMacHeader::Print will be called. Check the code of WifiMacHeader, to see that it prints the ToDS... FromDS... etc

Notice that when the case  item is PAYLOAD, it simply prints Payload and size, which is what you're getting right here. You can modify the Packet::Print function in the packet.cc so that it prints out the payload of the packet if the item is PAYLOAD. I am not exactly sure how to do this so you may need to experiment with it.

Another way you can do this is by adding your information to the packet as Tags with AddPacketTag, and then using the PacketTagIterator when you hit the PAYLOAD section to print the info you attached to a packet. Notice that AddPacketTag doesn't change the Packet object.

Or, a more neat solution you can create a custom header to take place of the Payload. Let's say you create a class WsmpHeader and you if you properly create such class with the GetTypeId function, you can implement a WsmpPacket::Print function to print what you need.

Cheers, 

Adil 

Sunny

unread,
Jan 10, 2020, 9:12:52 AM1/10/20
to ns-3-users
Ok dear, I will try some experiment to get any solution. And thank you so much for your kind suggestion and help.

Sunny

unread,
Feb 6, 2020, 6:09:41 AM2/6/20
to ns-3-users
Hi everyone,

I have tried a piece of code to get the actual contents of packet (Payload) in the ASCII file. I have implemented this code in packet.cc file. But there is problem that it is printing some unknown characters like garbage. Please can someone help me what am I doing wrong. The code and also out put is here for clear understanding. 
-----------------------------------------------------------------------------------------------------------------------------------------------
This is the code
----------------------------------------------------------------------------------------------------------------------------------------------
           uint8_t *buf = new uint8_t[m_buffer.GetSize ()];        
            NS_ASSERT (buf != 0);
            m_buffer.CopyData(buf, m_buffer.GetSize ());
            std::string packetContents = std::string((char*)buf);
            os <<" "<<packetContents; 
-----------------------------------------------------------------------------------------------------------
Here is OUTPUT

t 6.10063 /NodeList/0/DeviceList/0/$ns3::WifiNetDevice/Phy/State/Tx ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:01, BSSID=ff:ff:ff:ff:ff:ff, FragNumber=0, SeqNumber=51) [°°]
r 6.10103 /NodeList/1/DeviceList/0/$ns3::WifiNetDevice/Phy/State/RxOk ns3::WifiMacHeader (DATA ToDS=0, FromDS=0, MoreFrag=0, Retry=0, MoreData=0 Duration/ID=0us, DA=ff:ff:ff:ff:ff:ff, SA=00:00:00:00:00:01, BSSID=ff:ff:ff:ff:ff:ff, FragNumber=0, SeqNumber=51) [°°]

The characters in the end of each line ([°°]) are unknown characters, instead of these there should be the contents of packet (i-e. "Hello I am here").
I will be thankful for your kind help.

Sunny

unread,
Feb 11, 2020, 4:11:21 AM2/11/20
to ns-3-users
Hello everyone,
Today I want to say something about this group, that I know this is a group of programming experts specially on NS3 platform (except some are learners like me), and honestly speaking learners like me join this group for the hope that they will get help and very good suggestions from the experts but unfortunately (sorry to say) no one even bothers to reply the learners (who really need expert help), except very few members and I am thankful to them for their precious suggestions. 
Previously, in the last 8 months I have posted 2-3 queries and no one answered (except @Adli Alsuhaim and thanks to him) and his suggestion helped me alot.
Hope the respected group members specially seniors will think on this and will help the learners as much as possible. (This is just a request)
Thank you so much.  
Reply all
Reply to author
Forward
0 new messages