Some Problems about NetAnim, Please help me...

56 views
Skip to first unread message

Sevi Zhou

unread,
Aug 2, 2019, 5:10:22 AM8/2/19
to ns-3-users
Hi, everyong! I am a newcomer to ns3.
When I run the .xml file for the examples in the src/netanim/examples, I can see the packet flow in the NetAnim. 
When I load my .xml file in NetAnim and run it, the Sim time remain 0 and there is no packet flow...But I can see the packet sending and receiving results in the terminal. 
 
This problem has been bothering me for a long time, so I hope someone can solve it. My code in the src/aqua-sim-ng/examples/broadcastMAC_example.cc is as follows:

#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"


using namespace ns3;

NS_LOG_COMPONENT_DEFINE("ASBroadcastMac");

int
main (int argc, char *argv[])
{
  double simStop = 1800; //seconds
  int nodes = 15;
  // int sinks = 1;
  uint32_t m_dataRate = 800;
  uint32_t m_packetSize = 40;


   LogComponentEnable ("ASBroadcastMac", LOG_LEVEL_INFO);
   LogComponentEnable ("AquaSimAloha", LOG_LEVEL_INFO);

  //to change on the fly
  CommandLine cmd;
  cmd.AddValue ("simStop", "Length of simulation", simStop);
  cmd.AddValue ("nodes", "Amount of regular underwater nodes", nodes);
  // cmd.AddValue ("sinks", "Amount of underwater sinks", sinks);
  cmd.Parse(argc,argv);

  std::cout << "-----------Initializing simulation-----------\n";

  NodeContainer nodesCon;
  nodesCon.Create(nodes);

  PacketSocketHelper socketHelper;
  socketHelper.Install(nodesCon);

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

  /*
   * Set up mobility model for nodes and sinks
   */
  MobilityHelper mobility;
  NetDeviceContainer devices;
  Ptr<ListPositionAllocator> position = CreateObject<ListPositionAllocator> ();

  std::cout << "Creating Nodes\n";

  //sink
  Ptr<AquaSimNetDevice> newDevice0 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(6000,10000,0));
  Ptr<AquaSimNetDevice> sink = asHelper.Create(nodesCon.Get(0), newDevice0);
  sink->SetSinkStatus();
  devices.Add(sink);

  //row 1
  Ptr<AquaSimNetDevice> newDevice1 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(4000,8000,0));
  Ptr<AquaSimNetDevice> dev1 = asHelper.Create(nodesCon.Get(1), newDevice1);
  devices.Add(dev1);

  Ptr<AquaSimNetDevice> newDevice2 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(8000,8000,0));
  Ptr<AquaSimNetDevice> dev2 = asHelper.Create(nodesCon.Get(2), newDevice2);
  devices.Add(dev2);

  //row 2
  Ptr<AquaSimNetDevice> newDevice3 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(2000,6000,0));
  Ptr<AquaSimNetDevice> dev3 = asHelper.Create(nodesCon.Get(3), newDevice3);
  devices.Add(dev3);

  Ptr<AquaSimNetDevice> newDevice4 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(6000,6000,0));
  Ptr<AquaSimNetDevice> dev4 = asHelper.Create(nodesCon.Get(4), newDevice4);
  devices.Add(dev4);

  Ptr<AquaSimNetDevice> newDevice5 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(10000,6000,0));
  Ptr<AquaSimNetDevice> dev5 = asHelper.Create(nodesCon.Get(5), newDevice5);
  devices.Add(dev5);

  //row 3
  Ptr<AquaSimNetDevice> newDevice6 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(1000,3000,0));
  Ptr<AquaSimNetDevice> dev6 = asHelper.Create(nodesCon.Get(6), newDevice6);
  devices.Add(dev6);

  Ptr<AquaSimNetDevice> newDevice7 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(6000,3000,0));
  Ptr<AquaSimNetDevice> dev7 = asHelper.Create(nodesCon.Get(7), newDevice7);
  devices.Add(dev7);

  Ptr<AquaSimNetDevice> newDevice8 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(11000,3000,0));
  Ptr<AquaSimNetDevice> dev8 = asHelper.Create(nodesCon.Get(8), newDevice8);
  devices.Add(dev8);

  //data sources:
  Ptr<AquaSimNetDevice> newDevice9 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(0,0,0));
  Ptr<AquaSimNetDevice> dev9 = asHelper.Create(nodesCon.Get(9), newDevice9);
  devices.Add(dev9);

  Ptr<AquaSimNetDevice> newDevice10 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(2000,0,0));
  Ptr<AquaSimNetDevice> dev10 = asHelper.Create(nodesCon.Get(10), newDevice10);
  devices.Add(dev10);

  Ptr<AquaSimNetDevice> newDevice11 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(5000,0,0));
  Ptr<AquaSimNetDevice> dev11 = asHelper.Create(nodesCon.Get(11), newDevice11);
  devices.Add(dev11);

  Ptr<AquaSimNetDevice> newDevice12 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(7000,0,0));
  Ptr<AquaSimNetDevice> dev12 = asHelper.Create(nodesCon.Get(12), newDevice12);
  devices.Add(dev12);

  Ptr<AquaSimNetDevice> newDevice13 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(10000,0,0));
  Ptr<AquaSimNetDevice> dev13 = asHelper.Create(nodesCon.Get(13), newDevice13);
  devices.Add(dev13);

  Ptr<AquaSimNetDevice> newDevice14 = CreateObject<AquaSimNetDevice>();
  position->Add(Vector(12000,0,0));
  Ptr<AquaSimNetDevice> dev14 = asHelper.Create(nodesCon.Get(14), newDevice14);
  devices.Add(dev14);

  mobility.SetPositionAllocator(position);
  mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
  mobility.Install(nodesCon);

  PacketSocketAddress socket;
  socket.SetAllDevices();
  socket.SetPhysicalAddress (devices.Get(0)->GetAddress()); //Set dest to first sink 
  socket.SetProtocol (0);

  OnOffHelper app ("ns3::PacketSocketFactory", Address (socket));
  app.SetAttribute("OnTime",StringValue("ns3::ConstantRandomVariable[Constant=0.4]"));
  app.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=99.6]"));
  app.SetAttribute ("DataRate", DataRateValue (m_dataRate));
  app.SetAttribute ("PacketSize", UintegerValue (m_packetSize));

  ApplicationContainer apps = app.Install (nodesCon);
  apps.Start (Seconds (0.5));
  apps.Stop (Seconds (simStop+1));

  Ptr<Node> sinkNode = nodesCon.Get(0);
  TypeId psfid = TypeId::LookupByName ("ns3::PacketSocketFactory");

  Ptr<Socket> sinkSocket = Socket::CreateSocket (sinkNode, psfid);
  sinkSocket->Bind (socket);

  std::cout << "sink node id(start from 0)=" << nodesCon.Get (0)->GetId () << std::endl;

  AnimationInterface anim("test0.xml");


  Packet::EnablePrinting (); //for debugging purposes
  std::cout << "-----------Running Simulation-----------\n";
  Simulator::Stop(Seconds(simStop));
  Simulator::Run();
  std::cout << "-----------Printing Simulation Results-----------\n";
  asHelper.GetChannel()->PrintCounters();
  
  Simulator::Destroy();

  std::cout << "fin.\n";
  return 0;
}
1564735235(1).jpg
terminal result.png

GIZAW ASSABE

unread,
Aug 4, 2019, 11:07:48 AM8/4/19
to ns-3-...@googlegroups.com
check the startup time


--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/40bea044-d6be-4fe0-b7d4-668125a5ae1a%40googlegroups.com.


--
Gizaw Assabe Agonafir
Msc Student In Computer Network and  Communication  / Kiot @2010
cell Phone No: 0922563477  /0904669890
Reply all
Reply to author
Forward
0 new messages