ns3 print 丢包内容的两种方法

1.方法一enable ascii print

  AsciiTraceHelper ascii;
  pointToPoint.EnableAsciiAll (ascii.CreateFileStream ("myfirst.tr"));
ns-3 tutorial: 5.3 Using the Tracing System

2.方法二 打印packet的metadata

首先enable printing

Packet::EnablePrinting ();

然后开始输出

    PacketMetadata::ItemIterator metadataIterator = q->BeginItem();

    PacketMetadata::Item item;
    while (metadataIterator.HasNext())
    {
      item = metadataIterator.Next();
        if(item.tid.GetName()=="ns3::TcpHeader"){
          Callback<ObjectBase *> constr = item.tid.GetConstructor();
                NS_ASSERT(!constr.IsNull());
           
                // Ptr<> and DynamicCast<> won't work here as all headers are from ObjectBase, not Object
                ObjectBase *instance = constr();
                NS_ASSERT(instance != 0);
           
                TcpHeader* tcpHeader = dynamic_cast<TcpHeader*> (instance);
                NS_ASSERT(tcpHeader != 0);
           
                tcpHeader->Deserialize(item.current);
           
                // The tcp sequence can now obtain the source of the packet

     break;

            }

     }

arp - What protocol is inside my packet? (Ns3) - Stack Overflow

how to find TCP ack number - Google 网上论坛

posted @ 2017-01-02 20:11  juejiang  阅读(905)  评论(0编辑  收藏  举报