class AodvExampleÂ
{
public:
 AodvExample ();
 /// Configure script parameters, \return true on successful configuration
 bool Configure (int argc, char **argv);
 /// Run simulation
 void Run ();
 /// Report results
 void Report (std::ostream & os);
private:
 // parameters
 /// Number of nodes
 uint32_t size;
 /// Distance between nodes, meters
 double step;
 /// Simulation time, seconds
 double totalTime;
 /// Write per-device PCAP traces if true
 bool pcap;
 /// Print routes if true
 bool printRoutes;
 // network
 NodeContainer nodes;
 NetDeviceContainer devices;
 Ipv4InterfaceContainer interfaces;
private:
 void CreateNodes ();
 void CreateDevices ();
 void InstallInternetStack ();
 void InstallApplications ();
};
int main (int argc, char **argv)
{
 AodvExample test;
 if (!test.Configure (argc, argv))
  NS_FATAL_ERROR ("Configuration failed. Aborted.");
 test.Run ();
 test.Report (std::cout);
 return 0;
}
//-----------------------------------------------------------------------------
AodvExample::AodvExample () :
 size (18),
 step (6),
 totalTime (40),
 pcap (true),
 printRoutes (true)
{
}
bool
AodvExample::Configure (int argc, char **argv)
{
 // Enable AODV logs by default. Comment this if too noisy
 // LogComponentEnable("AodvRoutingProtocol", LOG_LEVEL_ALL);
 SeedManager::SetSeed (12345);
 Â
//Config::SetDefault("ns3::RangePropagationLossModel::MaxRange",UintegerValue(30));
 CommandLine cmd;
 cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
 cmd.AddValue ("printRoutes", "Print routing table dumps.", printRoutes);
 cmd.AddValue ("size", "Number of nodes.", size);
 cmd.AddValue ("time", "Simulation time, s.", totalTime);
 cmd.AddValue ("step", "Grid step, m", step);
 cmd.Parse (argc, argv);
 return true;
}
void
AodvExample::Run ()
{
//Â Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold", UintegerValue (1)); // enable rts cts all the time.
 CreateNodes ();
 CreateDevices ();
 InstallInternetStack ();
 InstallApplications ();
 std::cout << "Starting simulation for " << totalTime << " s ...\n";
 Â
 Simulator::Stop (Seconds (totalTime));
 AnimationInterface anim ("aodvnew.xml");
 Simulator::Run ();
 Simulator::Destroy ();
}
void
AodvExample::Report (std::ostream &)
{Â
}
void
AodvExample::CreateNodes ()
{
 std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n";
 nodes.Create (18);
 // Name nodes
 for (uint32_t i = 0; i < size; ++i)
  {
   std::ostringstream os;
   os << "node-" << i;
   Names::Add (os.str (), nodes.Get (i));
  }
 // Create static grid
 MobilityHelper mobility;
 mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
                 "MinX", DoubleValue (10.0),
                 "MinY", DoubleValue (10.0),
                 "DeltaX", DoubleValue (step),
                 "DeltaY", DoubleValue (10.0),
                 "GridWidth", UintegerValue (6),
                 "LayoutType", StringValue ("RowFirst"));
 Â
 mobility.SetMobilityModel ("ns3::RandomWalk2dMobilityModel",
               "Bounds", RectangleValue (Rectangle (-50, 50, -50, 50)));
//mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
 mobility.Install (nodes);
}
void
AodvExample::CreateDevices ()
{
 WifiMacHelper wifiMac;
 wifiMac.SetType ("ns3::AdhocWifiMac");
 YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
 YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
 //YansWifiChannelHelper wifiChannel;
 //wifiChannel.AddPropagationLoss("ns3::RangePropagationLossModel","MaxRange",StringValue("15"));
 //wifiChannel.AddPropagationLoss(&RangePropagationLossModel::m_range(15));
 wifiPhy.SetChannel (wifiChannel.Create ());
 WifiHelper wifi;
 wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("OfdmRate6Mbps"), "RtsCtsThreshold", UintegerValue (0));
 devices = wifi.Install (wifiPhy, wifiMac, nodes);Â
 if (pcap)
  {
   wifiPhy.EnablePcapAll (std::string ("aodv"));
  }
}
void
AodvExample::InstallInternetStack ()
{
 AodvHelper aodv;
 // you can configure AODV attributes here using aodv.Set(name, value)
 InternetStackHelper stack;
 stack.SetRoutingHelper (aodv); // has effect on the next Install ()
 stack.Install (nodes);
 Ipv4AddressHelper address;
 address.SetBase ("10.0.0.0", "255.0.0.0");
 interfaces = address.Assign (devices);
 if (printRoutes)
  {
   Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("aodv.routes", std::ios::out);
   aodv.PrintRoutingTableAllAt (Seconds (30), routingStream);
  }
}
void
AodvExample::InstallApplications ()
{
 V4PingHelper ping (interfaces.GetAddress (size - 1));
 ping.SetAttribute ("Verbose", BooleanValue (true));
 ApplicationContainer p = ping.Install (nodes.Get (0));
 p.Start (Seconds (0));
 p.Stop (Seconds (totalTime) - Seconds (0.001));