Code review fixes
authorKirill Andreev <andreev@iitp.ru>
Tue, 25 Aug 2009 17:21:34 +0400
changeset 5163 f1119f03b7a9
parent 5162 35963e5411c0
child 5164 b81ab8394a61
Code review fixes
examples/mesh.cc
src/devices/mesh/mesh-point-device.cc
src/devices/mesh/mesh-point-device.h
src/helper/mesh-helper.cc
src/helper/mesh-helper.h
--- a/examples/mesh.cc	Tue Aug 25 15:27:49 2009 +0400
+++ b/examples/mesh.cc	Tue Aug 25 17:21:34 2009 +0400
@@ -123,11 +123,18 @@
   wifiPhy.SetChannel (wifiChannel.Create ());
   // Install mesh point devices & protocols
   mesh.SetStackInstaller (m_stack, "Root", Mac48AddressValue (Mac48Address (m_root.c_str ())));
-  mesh.SetSpreadInterfaceChannels (m_chan);
+  if (m_chan)
+    {
+      mesh.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);
+    }
+  else
+    {
+      mesh.SetSpreadInterfaceChannels (MeshHelper::ZERO_CHANNEL);
+    }
   MeshInterfaceHelper interface = MeshInterfaceHelper::Default ();
   interface.SetType ("RandomStart", TimeValue (Seconds(m_randomStart)));
-
-  meshDevices = mesh.Install (wifiPhy, interface, nodes, m_nIfaces);
+  mesh.SetNumberOfInterfaces (m_nIfaces);
+  meshDevices = mesh.Install (wifiPhy, interface, nodes);
   // Setup mobility
   MobilityHelper mobility;
   mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
--- a/src/devices/mesh/mesh-point-device.cc	Tue Aug 25 15:27:49 2009 +0400
+++ b/src/devices/mesh/mesh-point-device.cc	Tue Aug 25 17:21:34 2009 +0400
@@ -96,7 +96,7 @@
   if (dst48.IsGroup ())
     {
       Ptr<Packet> packet_copy = packet->Copy ();
-      if (m_removeRoutingStuff (incomingPort->GetIfIndex (), src48, dst48, packet_copy, realProtocol))
+      if (m_routingProtocol->RemoveRoutingStuff (incomingPort->GetIfIndex (), src48, dst48, packet_copy, realProtocol))
         {
           m_rxCallback (this, packet_copy, realProtocol, src);
           Forward (incomingPort, packet, protocol, src48, dst48);
@@ -109,10 +109,9 @@
   if (dst48 == m_address)
     {
       Ptr<Packet> packet_copy = packet->Copy ();
-      if (m_removeRoutingStuff (incomingPort->GetIfIndex (), src48, dst48, packet_copy, realProtocol))
+      if (m_routingProtocol->RemoveRoutingStuff (incomingPort->GetIfIndex (), src48, dst48, packet_copy, realProtocol))
         {
           m_rxCallback (this, packet_copy, realProtocol, src);
-
           m_rxStats.unicastData++;
           m_rxStats.unicastDataBytes += packet->GetSize ();
         }
@@ -127,7 +126,8 @@
     const Mac48Address src, const Mac48Address dst)
 {
   // pass through routing protocol
-  m_requestRoute (inport->GetIfIndex (), src, dst, packet, protocol, m_myResponse);
+  m_routingProtocol->RequestRoute (inport->GetIfIndex (), src, dst, packet, protocol, MakeCallback (
+      &MeshPointDevice::DoSend, this));
 }
 
 void
@@ -240,7 +240,8 @@
 MeshPointDevice::Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber)
 {
   const Mac48Address dst48 = Mac48Address::ConvertFrom (dest);
-  return m_requestRoute (m_ifIndex, m_address, dst48, packet, protocolNumber, m_myResponse);
+  return m_routingProtocol->RequestRoute (m_ifIndex, m_address, dst48, packet, protocolNumber, MakeCallback (
+      &MeshPointDevice::DoSend, this));
 }
 
 bool
@@ -249,7 +250,8 @@
 {
   const Mac48Address src48 = Mac48Address::ConvertFrom (src);
   const Mac48Address dst48 = Mac48Address::ConvertFrom (dest);
-  return m_requestRoute (m_ifIndex, src48, dst48, packet, protocolNumber, m_myResponse);
+  return m_routingProtocol->RequestRoute (m_ifIndex, src48, dst48, packet, protocolNumber, MakeCallback (
+      &MeshPointDevice::DoSend, this));
 }
 
 Ptr<Node>
@@ -377,14 +379,9 @@
 MeshPointDevice::SetRoutingProtocol (Ptr<MeshL2RoutingProtocol> protocol)
 {
   NS_LOG_FUNCTION_NOARGS ();
-
   NS_ASSERT_MSG (PeekPointer (protocol->GetMeshPoint ()) == this,
       "Routing protocol must be installed on mesh point to be useful.");
-
   m_routingProtocol = protocol;
-  m_requestRoute = MakeCallback (&MeshL2RoutingProtocol::RequestRoute, protocol);
-  m_removeRoutingStuff = MakeCallback (&MeshL2RoutingProtocol::RemoveRoutingStuff, protocol);
-  m_myResponse = MakeCallback (&MeshPointDevice::DoSend, this);
 }
 
 Ptr<MeshL2RoutingProtocol>
--- a/src/devices/mesh/mesh-point-device.h	Tue Aug 25 15:27:49 2009 +0400
+++ b/src/devices/mesh/mesh-point-device.h	Tue Aug 25 17:21:34 2009 +0400
@@ -163,18 +163,6 @@
   uint16_t m_mtu;
   /// Virtual channel for upper layers
   Ptr<BridgeChannel> m_channel;
-
-  /// Routing request callback
-  Callback<bool,
-           uint32_t,
-           Mac48Address,
-           Mac48Address,
-           Ptr<const Packet>,
-           uint16_t,
-           MeshL2RoutingProtocol::RouteReplyCallback>  m_requestRoute;
-  Callback<bool, uint32_t, Mac48Address, Mac48Address, Ptr<Packet>, uint16_t&> m_removeRoutingStuff;
-  /// Routing response callback, this is supplied to mesh routing protocol
-  MeshL2RoutingProtocol::RouteReplyCallback  m_myResponse;
   /// Current routing protocol, used mainly by GetRoutingProtocol
   Ptr<MeshL2RoutingProtocol> m_routingProtocol;
 
--- a/src/helper/mesh-helper.cc	Tue Aug 25 15:27:49 2009 +0400
+++ b/src/helper/mesh-helper.cc	Tue Aug 25 17:21:34 2009 +0400
@@ -27,13 +27,14 @@
 namespace ns3
 {
 MeshHelper::MeshHelper () :
-  m_spreadInterfaceChannels (false), m_stack (0)
+  m_nInterfaces (1),
+  m_spreadChannelPolicy (ZERO_CHANNEL), m_stack (0)
 {
 }
 void
-MeshHelper::SetSpreadInterfaceChannels (bool s)
+MeshHelper::SetSpreadInterfaceChannels (enum ChannelPolicy policy)
 {
-  m_spreadInterfaceChannels = s;
+  m_spreadChannelPolicy = policy;
 }
 void
 MeshHelper::SetStackInstaller (std::string type,
@@ -64,9 +65,14 @@
     }
 }
 
+void
+MeshHelper::SetNumberOfInterfaces (uint32_t nInterfaces)
+{
+  m_nInterfaces = nInterfaces;
+}
 NetDeviceContainer
 MeshHelper::Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper,
-    NodeContainer c, uint32_t nInterfaces) const
+    NodeContainer c) const
 {
   NetDeviceContainer devices;
   NS_ASSERT (m_stack != 0);
@@ -80,11 +86,10 @@
       node->AddDevice (mp);
 
       // Create wifi interfaces (single interface by default)
-      for (uint32_t i = 0; i < nInterfaces; ++i)
+      for (uint32_t i = 0; i < m_nInterfaces; ++i)
         {
           uint32_t channel = i * 5;
-          Ptr<WifiNetDevice> iface = interfaceHelper.CreateInterface (phyHelper, node,
-              (m_spreadInterfaceChannels ? channel : 0));
+          Ptr<WifiNetDevice> iface = interfaceHelper.CreateInterface (phyHelper, node, channel);
           mp->AddInterface (iface);
         }
       if (!m_stack->InstallStack (mp))
@@ -96,13 +101,6 @@
     }
   return devices;
 }
-
-NetDeviceContainer
-MeshHelper::Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node,
-    uint32_t nInterfaces) const
-{
-  return Install (phy, interfaceHelper, NodeContainer (node), nInterfaces);
-}
 void
 MeshHelper::Report (const ns3::Ptr<ns3::NetDevice>& device, std::ostream& os)
 {
--- a/src/helper/mesh-helper.h	Tue Aug 25 15:27:49 2009 +0400
+++ b/src/helper/mesh-helper.h	Tue Aug 25 17:21:34 2009 +0400
@@ -46,8 +46,17 @@
    * 
    *  If set to true different non-overlaping 20MHz frequency 
    *  channels will be assigned to different mesh point interfaces.
-   */ 
-  void SetSpreadInterfaceChannels (bool); 
+   */
+  enum ChannelPolicy {
+  SPREAD_CHANNELS,
+  ZERO_CHANNEL
+  };
+  void SetSpreadInterfaceChannels (ChannelPolicy);
+  /**
+   * \brief Set a number of interfaces in a mesh network
+   * \param nInterfaces is the number of interfaces
+   */
+  void SetNumberOfInterfaces (uint32_t nInterfaces);
   
   /** 
    * \brief Install 802.11s mesh device & protocols on given node list
@@ -59,18 +68,8 @@
    * 
    * \return list of created mesh point devices, see MeshPointDevice
    */
-  NetDeviceContainer Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c, uint32_t nInterfaces = 1) const;
-  /** 
-   * \brief Install 802.11s mesh device & protocols on given node
-   * 
-   * \param phy                 Wifi PHY helper
-   * \param node                Node to install
-   * \param roots               List of root mesh points
-   * \param nInterfaces         Number of mesh point radio interfaces (= WiFi NICs)
-   * 
-   * \return list of created mesh point devices, see MeshPointDevice
-   */ 
-  NetDeviceContainer Install (const WifiPhyHelper &phy, const MeshInterfaceHelper &interfaceHelper, Ptr<Node> node, uint32_t nInterfaces = 1) const;
+  NetDeviceContainer
+  Install (const WifiPhyHelper &phyHelper, const MeshInterfaceHelper &interfaceHelper, NodeContainer c) const;
   /**
    * \param type the type of ns3::MeshStack.
    *
@@ -89,7 +88,8 @@
   void Report (const ns3::Ptr<ns3::NetDevice>&, std::ostream&);
   void ResetStats (const ns3::Ptr<ns3::NetDevice>&);
 private:
-  bool m_spreadInterfaceChannels;
+  uint32_t m_nInterfaces;
+  ChannelPolicy m_spreadChannelPolicy;
   Ptr<MeshStack> m_stack;
   ObjectFactory m_stackFactory;
 };