【发布时间】:2019-04-08 08:05:11
【问题描述】:
我在 ns3 中使用以下 c++ 代码在收到数据包时使用
打印其内容和到达时间 Simulator::Now ().GetSeconds()
但它每次都变成零。谁能告诉我为什么?我怎样才能得到实时?
Ptr<const Packet> p = packet;
LrWpanMacHeader h;
p->PeekHeader(h); //remove the header in order to print packet
content, so that's why the size differ between packet and p
BasicPacketData bpd (p);
std::cout<<"Packet Size:"<<p->GetSize()<<std::endl;
uint8_t *buffer = new uint8_t[p->GetSize()];
p->CopyData (buffer, p->GetSize());
std::string receivedData(buffer, buffer+p->GetSize ());
std::cout<<"Received:"<<receivedData.c_str()<<std::endl;
if(!h.IsAcknowledgment()) //Returns true if the header is an ack
{
NS_LOG_UNCOND ("----------Packet received----------\n"
<< "Packet of size " << bpd.size << " bytes received\n"
<< "on device with address "<< dev3->GetMac()->GetShortAddress()<<"\n"
<< "was sent from address " << dev->GetMac()->GetShortAddress() << "\n"
// << "on device with address "<< bpd.dst<<"\n"
//<< "was sent from address " << bpd.src << "\n"
<< "sequence number is " << (int) bpd.seq_nr << "\n"
<< "PAN ID is " << bpd.pan_id << "\n"
<<"with time "<< " on time: " << Simulator::Now ().GetSeconds() << "s"
<< "----------Packet received------------\n\n"
);
【问题讨论】: