Capture only packet header in pcap

97 views
Skip to first unread message

Pascal

unread,
Jul 15, 2023, 4:56:12 AM7/15/23
to ns-3-users
Hi all

I was wondering if there is some elegant way to configure NS3 to only write the header of packets into the pcap it produces when EnablePCAP() is used on some NetDevice. In other words, I would like to exclude the data from being written into the pcap files for the benefit of reduced file size.

From what I've seen, pcap-file.cc has some points where I could try and start with, basically preventing the write calls with the data being performed in the different PcapFile::Write() implementations:
void
PcapFile::Write(uint32_t tsSec, uint32_t tsUsec, const uint8_t* const data, uint32_t totalLen)
{
NS_LOG_FUNCTION(this << tsSec << tsUsec << &data << totalLen);
uint32_t inclLen = WritePacketHeader(tsSec, tsUsec, totalLen);
m_file.write((const char*)data, inclLen);
NS_BUILD_DEBUG(m_file.flush());
}

void
PcapFile::Write(uint32_t tsSec, uint32_t tsUsec, Ptr<const Packet> p)
{
NS_LOG_FUNCTION(this << tsSec << tsUsec << p);
uint32_t inclLen = WritePacketHeader(tsSec, tsUsec, p->GetSize());
p->CopyData(&m_file, inclLen);
NS_BUILD_DEBUG(m_file.flush());
}

void
PcapFile::Write(uint32_t tsSec, uint32_t tsUsec, const Header& header, Ptr<const Packet> p)
{
NS_LOG_FUNCTION(this << tsSec << tsUsec << &header << p);
uint32_t headerSize = header.GetSerializedSize();
uint32_t totalSize = headerSize + p->GetSize();
uint32_t inclLen = WritePacketHeader(tsSec, tsUsec, totalSize);

Buffer headerBuffer;
headerBuffer.AddAtStart(headerSize);
header.Serialize(headerBuffer.Begin());
uint32_t toCopy = std::min(headerSize, inclLen);
headerBuffer.CopyData(&m_file, toCopy);
inclLen -= toCopy;
p->CopyData(&m_file, inclLen);
}

However, this then requires changes to existing files of the ns-3 code-base which I would rather avoid if possible. 
Is there some way to simply configure the simulator to only trace packet headers that does not require altering the source code of the installation?

Best regards,
Pascal

Reply all
Reply to author
Forward
0 new messages