Allow a zero NetDevice in WifiChannel.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 10 Jun 2008 12:17:34 -0700
changeset 3878 3b7d0c1fce02
parent 3238 3b24ac252fba
child 3879 3a887a06b795
Allow a zero NetDevice in WifiChannel.
src/devices/wifi/wifi-channel.cc
src/devices/wifi/wifi-channel.h
src/devices/wifi/wifi-net-device.cc
--- a/src/devices/wifi/wifi-channel.cc	Fri Jun 06 11:42:19 2008 -0700
+++ b/src/devices/wifi/wifi-channel.cc	Tue Jun 10 12:17:34 2008 -0700
@@ -69,9 +69,13 @@
 }
 
 void 
-WifiChannel::Add (Ptr<NetDevice> device, Ptr<WifiPhy> phy)
+WifiChannel::Add (Ptr<NetDevice> device, Ptr<WifiPhy> phy, Ptr<Object> mobility)
 {
-  m_deviceList.push_back (std::make_pair (device, phy));
+  struct Item item;
+  item.device = device;
+  item.phy = phy;
+  item.mobility = mobility;
+  m_deviceList.push_back (item);
 }
 void 
 WifiChannel::Send (Ptr<WifiPhy> sender, Ptr<const Packet> packet, double txPowerDbm,
@@ -80,9 +84,9 @@
   Ptr<MobilityModel> senderMobility = 0;
   for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++)
     {
-      if (sender == i->second)
+      if (sender == i->phy)
         {
-          senderMobility = i->first->GetNode ()->GetObject<MobilityModel> ();
+          senderMobility = i->mobility->GetObject<MobilityModel> ();
           break;
         }
     }
@@ -90,9 +94,9 @@
   uint32_t j = 0;
   for (DeviceList::const_iterator i = m_deviceList.begin (); i != m_deviceList.end (); i++)
     {
-      if (sender != i->second)
+      if (sender != i->phy)
         {
-          Ptr<MobilityModel> receiverMobility = i->first->GetNode ()->GetObject<MobilityModel> ();
+          Ptr<MobilityModel> receiverMobility = i->mobility->GetObject<MobilityModel> ();
           Time delay = m_delay->GetDelay (senderMobility, receiverMobility);
           double rxPowerDbm = txPowerDbm + m_loss->GetLoss (senderMobility, receiverMobility);
           NS_LOG_DEBUG ("propagation: txPower="<<txPowerDbm<<"dbm, rxPower="<<rxPowerDbm<<"dbm, "<<
@@ -109,7 +113,7 @@
 WifiChannel::Receive (uint32_t i, Ptr<Packet> packet, double rxPowerDbm,
                       WifiMode txMode, WifiPreamble preamble) const
 {
-  m_deviceList[i].second->StartReceivePacket (packet, rxPowerDbm, txMode, preamble);
+  m_deviceList[i].phy->StartReceivePacket (packet, rxPowerDbm, txMode, preamble);
 }
 
 uint32_t 
@@ -120,7 +124,7 @@
 Ptr<NetDevice> 
 WifiChannel::GetDevice (uint32_t i) const
 {
-  return m_deviceList[i].first;
+  return m_deviceList[i].device;
 }
 
 } // namespace ns3
--- a/src/devices/wifi/wifi-channel.h	Fri Jun 06 11:42:19 2008 -0700
+++ b/src/devices/wifi/wifi-channel.h	Tue Jun 10 12:17:34 2008 -0700
@@ -24,6 +24,7 @@
 #include <stdint.h>
 #include "ns3/packet.h"
 #include "ns3/channel.h"
+#include "ns3/net-device.h"
 #include "wifi-mode.h"
 #include "wifi-preamble.h"
 #include "wifi-phy.h"
@@ -84,11 +85,12 @@
    *        devices.
    * \param phy the physical layer which will receive packets
    *        on behalf of the device.
+   * \param mobility the mobility model associated to the device.
    *
    * This method should not be invoked by normal users. It is 
    * currently invoked only from WifiPhy::SetChannel.
    */
-  void Add (Ptr<NetDevice> device,  Ptr<WifiPhy> phy);
+  void Add (Ptr<NetDevice> device,  Ptr<WifiPhy> phy, Ptr<Object> mobility);
   /**
    * \param sender the device from which the packet is originating.
    * \param packet the packet to send
@@ -103,7 +105,12 @@
              WifiMode wifiMode, WifiPreamble preamble) const;
 
 private:
-  typedef std::vector<std::pair<Ptr<NetDevice>, Ptr<WifiPhy> > > DeviceList;
+  struct Item {
+    Ptr<NetDevice> device;
+    Ptr<WifiPhy> phy;
+    Ptr<Object> mobility;
+  };
+  typedef std::vector<struct Item> DeviceList;
   void Receive (uint32_t i, Ptr<Packet> packet, double rxPowerDbm,
                 WifiMode txMode, WifiPreamble preamble) const;
 
--- a/src/devices/wifi/wifi-net-device.cc	Fri Jun 06 11:42:19 2008 -0700
+++ b/src/devices/wifi/wifi-net-device.cc	Tue Jun 10 12:17:34 2008 -0700
@@ -112,9 +112,9 @@
   m_phy = phy;
   if (m_phy != 0)
     {
-      if (m_channel != 0)
+      if (m_channel != 0 && m_node != 0)
         {
-          m_channel->Add (this, m_phy);
+          m_channel->Add (this, m_phy, m_node);
           m_phy->SetChannel (m_channel);
         }
       if (m_stationManager != 0)
@@ -147,9 +147,9 @@
 WifiNetDevice::SetChannel (Ptr<WifiChannel> channel)
 {
   m_channel = channel;
-  if (m_channel != 0 && m_phy != 0)
+  if (m_channel != 0 && m_phy != 0 && m_node != 0)
     {
-      m_channel->Add (this, m_phy);
+      m_channel->Add (this, m_phy, m_node);
       m_phy->SetChannel (m_channel);
     }
 }
@@ -292,6 +292,11 @@
 WifiNetDevice::SetNode (Ptr<Node> node)
 {
   m_node = node;
+  if (m_channel != 0 && m_phy != 0 && m_node != 0)
+    {
+      m_channel->Add (this, m_phy, m_node);
+      m_phy->SetChannel (m_channel);
+    }
 }
 bool 
 WifiNetDevice::NeedsArp (void) const