【问题标题】:Calculate Packet Received time in ns3计算 ns3 中的数据包接收时间
【发布时间】: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"

    );

【问题讨论】:

    标签: c++ time packet ns-3


    【解决方案1】:

    ns3::Packet::Print 方法在这里打印数据包的内容:

    https://www.nsnam.org/doxygen/classns3_1_1_packet.html#ad25486a838ac04533c83ff600d84546f

    现在,您看到零可能是因为数据包是使用由包含零的字节组成的虚拟负载初始化的。见:

    https://www.nsnam.org/doxygen/classns3_1_1_packet.html#a897aab15901dcf1f05f075db7b8d04b1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多