如何检查数据包是否已发送,AquaSimTrafficGen-(NS-3)

时间:2018-10-04 16:20:42

标签: networking ns-3

我想使用NS-3的“ AquaSimNG”模块将数据包从一个节点发送到另一个节点,该模块用于水下网络仿真。 我已经使用“ AquaSimTrafficGenHelper”来生成流量,但是我无法找到一种方法来确保数据包是否已成功发送。日志记录无济于事。 这是我的代码:

#include <iostream>
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/mobility-module.h"
#include "ns3/aqua-sim-ng-module.h"
#include "ns3/applications-module.h"
#include "ns3/log.h"
#include "ns3/callback.h"
#include "ns3/netanim-module.h"
#include "ns3/point-to-point-module.h"

using namespace ns3;
using namespace std;

NS_LOG_COMPONENT_DEFINE ("2nodes");

int
main (int argc, char *argv[])
{
  double simStop = 100; //seconds
  int nodes = 1;
  int sinks = 1;
  string animFile = "Script.xml";


  cout << "....Simulation Starts....\n";

Time::SetResolution (Time::NS);
  LogComponentEnable ("AquaSimTrafficGen", LOG_INFO);

//Nodes creation
  NodeContainer nodesCon;
  nodesCon.Create(nodes);

//sink creation
  NodeContainer sinksCon;
  sinksCon.Create(sinks);


//InstallSockets            
    PacketSocketHelper socketHelper;
        socketHelper.Install(nodesCon);
        socketHelper.Install(sinksCon);




//establish layers using helper's pre-build settings
                  AquaSimChannelHelper channel = AquaSimChannelHelper::Default();
                  AquaSimHelper asHelper = AquaSimHelper::Default();
                  asHelper.SetChannel(channel.Create());


  //Set up mobility model for nodes and sinks

                  MobilityHelper mobility;
                  MobilityHelper nodeMobility;
                  NetDeviceContainer devices;
                  Ptr<ListPositionAllocator> position = CreateObject<ListPositionAllocator> ();
                  Vector boundry = Vector(0,0,0);


  cout << "...Creating Nodes....\n";
              for (NodeContainer::Iterator i = nodesCon.Begin(); i != nodesCon.End(); i++)
                {
                  Ptr<AquaSimNetDevice> newDevice = CreateObject<AquaSimNetDevice>();
                  position->Add(boundry);
//                devices.Add(asHelper.Create(&(nodesCon(0)), newDevice1));

                  devices.Add(asHelper.Create(*i, newDevice));
                  cout<<"Node:" << newDevice->GetAddress() << " position(x):" << boundry.x<<"\n";

                  boundry.x += 10;
                }
                boundry.x += 10;
                boundry.y += 10;


//SINK  creation
              cout<<"Sink's creation Iterator\n";
              for (NodeContainer::Iterator i = sinksCon.Begin(); i != sinksCon.End(); i++)
                {
                  Ptr<AquaSimNetDevice> newDevice = CreateObject<AquaSimNetDevice>();
                  position->Add(boundry);
                  devices.Add(asHelper.Create(*i, newDevice));
                  cout<<"Sink:" << newDevice->GetAddress() << " position(x):" << boundry.x << "\n";
                 // boundry.x += 100;
                }


// Nodes Position
//sink mobility
              mobility.SetPositionAllocator(position);
              mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
              mobility.Install(sinksCon);



//node mobility
              nodeMobility.SetPositionAllocator("ns3::UniformDiscPositionAllocator", "X", DoubleValue(1000.0),
                                  "Y", DoubleValue(1000.0), "rho", DoubleValue(1000));
              nodeMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
              nodeMobility.Install(nodesCon);

// Generate Traffic
          PacketSocketAddress socket;
          socket.SetAllDevices();
          cout<<"\n befor physiacal affress:  ... \n";
          socket.SetPhysicalAddress (devices.Get(1)->GetAddress()); //Set dest to first sink (nodes+1 device)
          socket.SetProtocol (0);


//Application Helper
          AquaSimTrafficGenHelper traffic ("ns3::PacketSocketFactory", Address (socket));
          traffic.SetAttribute ("Delay", DoubleValue(2));
          traffic.SetAttribute ("PacketSize", UintegerValue(40));

//Application contaniner
          ApplicationContainer apps = traffic.Install (nodesCon);
          apps.Start (Seconds (0.5));
          apps.Stop (Seconds (100));

          Ptr<Node> sinkNode = sinksCon.Get(0);
          TypeId psfid = TypeId::LookupByName ("ns3::PacketSocketFactory");
          Ptr<Socket> sinkSocket = Socket::CreateSocket (sinkNode, psfid);
          sinkSocket->Bind (socket);


    AnimationInterface anim (animFile);

          Simulator::Stop(Seconds(simStop));
          Simulator::Run();
          Simulator::Destroy();
  cout << "...Simulation ends...\n";

  return 0;
    }

代码正在运行,没有任何错误。 但是日志记录不会显示数据包是否已发送。 请让我知道,如果代码有任何问题,以及如何检查数据包是否已发送。 谢谢。

0 个答案:

没有答案