[aodv] Fix aodv.cc example & helpers
authorPavel Boyko <boyko@iitp.ru>
Thu, 08 Oct 2009 15:47:59 +0400
changeset 5716 b87e042f25e4
parent 5715 e84ad4735c4b
child 5717 4c67658e54af
[aodv] Fix aodv.cc example & helpers
examples/aodv.cc
examples/routing/aodv.cc
examples/routing/wscript
src/helper/aodv-helper.cc
src/helper/aodv-helper.h
src/helper/v4ping-helper.cc
src/helper/v4ping-helper.h
--- a/examples/aodv.cc	Thu Oct 08 15:30:36 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,214 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 IITP RAS
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This is an example script for AODV manet routing protocol. 
- *
- * Authors: Pavel Boyko <boyko@iitp.ru>
- */
-
-#include "ns3/aodv-module.h"
-#include "ns3/core-module.h"
-#include "ns3/common-module.h"
-#include "ns3/node-module.h"
-#include "ns3/helper-module.h"
-#include "ns3/mobility-module.h"
-#include "ns3/contrib-module.h"
-#include "ns3/wifi-module.h" 
-#include "ns3/v4ping-helper.h"
-#include <iostream>
-#include <cmath>
-
-using namespace ns3;
-
-/**
- * \brief Test script.
- * 
- * This script creates 1-dimensional grid topology and then ping last node from the first one:
- * 
- * [10.0.0.1] <-- step --> [10.0.0.2] <-- step --> [10.0.0.3] <-- step --> [10.0.04]
- * 
- * ping 10.0.0.4
- */
-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:
-  ///\name 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;
-  //\}
-  
-  ///\name 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 (10),
-  step (120),
-  totalTime (10),
-  pcap (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);
-  CommandLine cmd;
-  
-  cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
-  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));
-  Simulator::Run ();
-  Simulator::Destroy ();
-}
-
-void
-AodvExample::Report (std::ostream &)
-{ 
-}
-
-void
-AodvExample::CreateNodes ()
-{
-  std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n";
-  nodes.Create (size);
-  // 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 (0.0),
-                                "MinY", DoubleValue (0.0),
-                                "DeltaX", DoubleValue (step),
-                                "DeltaY", DoubleValue (0),
-                                "GridWidth", UintegerValue (size),
-                                "LayoutType", StringValue ("RowFirst"));
-  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
-  mobility.Install (nodes);
-}
-
-void
-AodvExample::CreateDevices ()
-{
-  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
-  wifiMac.SetType ("ns3::AdhocWifiMac");
-  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
-  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
-  wifiPhy.SetChannel (wifiChannel.Create ());
-  WifiHelper wifi = WifiHelper::Default ();
-  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("wifia-6mbs"), "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);
-  stack.Install (nodes);
-  Ipv4AddressHelper address;
-  address.SetBase ("10.0.0.0", "255.0.0.0");
-  interfaces = address.Assign (devices);
-}
-
-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));
-
-  // move node away
-  Ptr<Node> node = nodes.Get (size/2);
-  Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
-  Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector(1e5, 1e5, 1e5));
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/routing/aodv.cc	Thu Oct 08 15:47:59 2009 +0400
@@ -0,0 +1,214 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 IITP RAS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * This is an example script for AODV manet routing protocol. 
+ *
+ * Authors: Pavel Boyko <boyko@iitp.ru>
+ */
+
+#include "ns3/aodv-module.h"
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/mobility-module.h"
+#include "ns3/contrib-module.h"
+#include "ns3/wifi-module.h" 
+#include "ns3/v4ping-helper.h"
+#include <iostream>
+#include <cmath>
+
+using namespace ns3;
+
+/**
+ * \brief Test script.
+ * 
+ * This script creates 1-dimensional grid topology and then ping last node from the first one:
+ * 
+ * [10.0.0.1] <-- step --> [10.0.0.2] <-- step --> [10.0.0.3] <-- step --> [10.0.04]
+ * 
+ * ping 10.0.0.4
+ */
+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:
+  ///\name 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;
+  //\}
+  
+  ///\name 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 (10),
+  step (120),
+  totalTime (10),
+  pcap (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);
+  CommandLine cmd;
+  
+  cmd.AddValue ("pcap", "Write PCAP traces.", pcap);
+  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));
+  Simulator::Run ();
+  Simulator::Destroy ();
+}
+
+void
+AodvExample::Report (std::ostream &)
+{ 
+}
+
+void
+AodvExample::CreateNodes ()
+{
+  std::cout << "Creating " << (unsigned)size << " nodes " << step << " m apart.\n";
+  nodes.Create (size);
+  // 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 (0.0),
+                                "MinY", DoubleValue (0.0),
+                                "DeltaX", DoubleValue (step),
+                                "DeltaY", DoubleValue (0),
+                                "GridWidth", UintegerValue (size),
+                                "LayoutType", StringValue ("RowFirst"));
+  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
+  mobility.Install (nodes);
+}
+
+void
+AodvExample::CreateDevices ()
+{
+  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
+  wifiMac.SetType ("ns3::AdhocWifiMac");
+  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
+  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
+  wifiPhy.SetChannel (wifiChannel.Create ());
+  WifiHelper wifi = WifiHelper::Default ();
+  wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode", StringValue ("wifia-6mbs"), "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);
+  stack.Install (nodes);
+  Ipv4AddressHelper address;
+  address.SetBase ("10.0.0.0", "255.0.0.0");
+  interfaces = address.Assign (devices);
+}
+
+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));
+
+  // move node away
+  Ptr<Node> node = nodes.Get (size/2);
+  Ptr<MobilityModel> mob = node->GetObject<MobilityModel>();
+  Simulator::Schedule (Seconds (totalTime/3), &MobilityModel::SetPosition, mob, Vector(1e5, 1e5, 1e5));
+}
+
--- a/examples/routing/wscript	Thu Oct 08 15:30:36 2009 +0400
+++ b/examples/routing/wscript	Thu Oct 08 15:47:59 2009 +0400
@@ -44,3 +44,7 @@
     obj = bld.create_ns3_program('simple-routing-ping6',
       ['csma', 'internet-stack'])
     obj.source = 'simple-routing-ping6.cc'
+    
+    obj = bld.create_ns3_program('aodv',
+                                 ['wifi', 'internet-stack', 'aodv'])
+    obj.source = 'aodv.cc'
--- a/src/helper/aodv-helper.cc	Thu Oct 08 15:30:36 2009 +0400
+++ b/src/helper/aodv-helper.cc	Thu Oct 08 15:47:59 2009 +0400
@@ -31,6 +31,12 @@
   m_agentFactory.SetTypeId ("ns3::aodv::RoutingProtocol");
 }
 
+AodvHelper* 
+AodvHelper::Copy (void) const 
+{
+  return new AodvHelper (*this); 
+}
+
 Ptr<Ipv4RoutingProtocol> 
 AodvHelper::Create (Ptr<Node> node) const
 {
--- a/src/helper/aodv-helper.h	Thu Oct 08 15:30:36 2009 +0400
+++ b/src/helper/aodv-helper.h	Thu Oct 08 15:47:59 2009 +0400
@@ -35,17 +35,25 @@
 {
 public:
   AodvHelper();
-  
+
+  /**
+   * \internal
+   * \returns pointer to clone of this OlsrHelper 
+   * 
+   * This method is mainly for internal use by the other helpers;
+   * clients are expected to free the dynamic memory allocated by this method
+   */
+  AodvHelper* Copy (void) const;
+
   /**
    * \param node the node on which the routing protocol will run
-   * \return a newly-created routing protocol
+   * \returns a newly-created routing protocol
    *
    * This method will be called by ns3::InternetStackHelper::Install
    * 
    * TODO: support installing AODV on the subset of all available IP interfaces
    */
   virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;
-
   /**
    * \param name the name of the attribute to set
    * \param value the value of the attribute to set.
--- a/src/helper/v4ping-helper.cc	Thu Oct 08 15:30:36 2009 +0400
+++ b/src/helper/v4ping-helper.cc	Thu Oct 08 15:47:59 2009 +0400
@@ -30,6 +30,12 @@
   m_factory.Set ("Remote", Ipv4AddressValue (remote));
 }
 
+void 
+V4PingHelper::SetAttribute (std::string name, const AttributeValue &value)
+{
+  m_factory.Set (name, value);
+}
+
 ApplicationContainer
 V4PingHelper::Install (Ptr<Node> node) const
 {
--- a/src/helper/v4ping-helper.h	Thu Oct 08 15:30:36 2009 +0400
+++ b/src/helper/v4ping-helper.h	Thu Oct 08 15:47:59 2009 +0400
@@ -55,6 +55,12 @@
    */
   ApplicationContainer Install (std::string nodeName) const;
 
+  /**
+   * \brief Configure ping applications attribute 
+   * \param name   attribute's name
+   * \param value  attribute's value
+   */
+  void SetAttribute (std::string name, const AttributeValue &value);
 private:
   /**
    * \internal