src/devices/wifi/mac-low.cc
changeset 5189 8fcdf87a790a
parent 5146 9e0edb76a8c7
child 5819 514ec98954ab
--- a/src/devices/wifi/mac-low.cc	Tue Sep 15 00:05:36 2009 -0700
+++ b/src/devices/wifi/mac-low.cc	Tue Sep 15 10:47:02 2009 +0200
@@ -244,6 +244,30 @@
   return os;
 }
 
+
+/***************************************************************
+ *         Listener for PHY events. Forwards to MacLow
+ ***************************************************************/
+
+
+class PhyMacLowListener : public ns3::WifiPhyListener {
+public:
+  PhyMacLowListener (ns3::MacLow *macLow)
+    : m_macLow (macLow) {}
+  virtual ~PhyMacLowListener () {}
+  virtual void NotifyRxStart (Time duration) {}
+  virtual void NotifyRxEndOk (void) {}
+  virtual void NotifyRxEndError (void) {}
+  virtual void NotifyTxStart (Time duration) {}
+  virtual void NotifyMaybeCcaBusyStart (Time duration) {}
+  virtual void NotifySwitchingStart (Time duration) { 
+    m_macLow->NotifySwitchingStartNow (duration);
+  }
+private:
+  ns3::MacLow *m_macLow;
+};
+
+
 MacLow::MacLow ()
   : m_normalAckTimeoutEvent (),
     m_fastAckTimeoutEvent (),
@@ -268,12 +292,22 @@
 }
 
 void 
+MacLow::SetupPhyMacLowListener (Ptr<WifiPhy> phy)
+{
+  m_phyMacLowListener = new PhyMacLowListener (this); 
+  phy->RegisterListener (m_phyMacLowListener);
+}
+
+
+void 
 MacLow::DoDispose (void)
 {
   NS_LOG_FUNCTION (this);
   CancelAllEvents ();
   m_phy = 0;
   m_stationManager = 0;
+  delete m_phyMacLowListener;
+  m_phyMacLowListener = 0;
 }
 
 void
@@ -339,6 +373,7 @@
   m_phy = phy;
   m_phy->SetReceiveOkCallback (MakeCallback (&MacLow::ReceiveOk, this));
   m_phy->SetReceiveErrorCallback (MakeCallback (&MacLow::ReceiveError, this));
+  SetupPhyMacLowListener(phy); 
 }
 void 
 MacLow::SetWifiRemoteStationManager (Ptr<WifiRemoteStationManager> manager)
@@ -489,6 +524,22 @@
 }
 
 void 
+MacLow::NotifySwitchingStartNow (Time duration)
+{
+  NS_LOG_DEBUG ("switching channel. Cancelling MAC pending events"); 
+  m_stationManager->Reset();
+  CancelAllEvents(); 
+  if (m_navCounterResetCtsMissed.IsRunning ())
+    {
+      m_navCounterResetCtsMissed.Cancel();
+    }
+  m_lastNavStart = Simulator::Now (); 
+  m_lastNavDuration = Seconds (0);
+  m_currentPacket = 0;
+  m_listener = 0;
+}
+
+void 
 MacLow::ReceiveOk (Ptr<Packet> packet, double rxSnr, WifiMode txMode, WifiPreamble preamble)
 {
   NS_LOG_FUNCTION (this << packet << rxSnr << txMode << preamble);