--- original/sta-wifi-mac.cc 2017-04-01 02:35:08.000000000 +0530 +++ edited/sta-wifi-mac.cc 2017-04-01 02:35:18.000000000 +0530 @@ -73,6 +73,7 @@ .SetParent () .SetGroupName ("Wifi") .AddConstructor () + /* Edited by manish ProbeRequestTimeout is no more in use , can be remove */ .AddAttribute ("ProbeRequestTimeout", "The interval between two consecutive probe request attempts.", TimeValue (Seconds (0.05)), MakeTimeAccessor (&StaWifiMac::m_probeRequestTimeout), @@ -81,7 +82,7 @@ TimeValue (Seconds (0.5)), MakeTimeAccessor (&StaWifiMac::m_assocRequestTimeout), MakeTimeChecker ()) - .AddAttribute ("ScanningTimeout", "The interval to dwell on a channel while scanning", + .AddAttribute ("ScanningTimeout", "The interval to dwell on a channel while scanning during passive probring", TimeValue (MilliSeconds (120)), MakeTimeAccessor (&StaWifiMac::m_scanningTimeout), MakeTimeChecker ()) @@ -100,6 +101,18 @@ BooleanValue (false), MakeBooleanAccessor (&StaWifiMac::SetActiveProbing, &StaWifiMac::GetActiveProbing), MakeBooleanChecker ()) + /* Edited by manish MinChannelTimeout */ + .AddAttribute ("MinChannelTimeout", "The time duration upto which the station have to wait" + "for probe response (in active probing )if no activity found on channel till the end of this time duration.", + TimeValue (Seconds (0.010)), + MakeTimeAccessor (&StaWifiMac::m_minChannelTimeout), + MakeTimeChecker ()) + /* Edited by manish MaxChannelTimeout */ + .AddAttribute ("MaxChannelTimeout", "The time duration upto which the station have to wait" + "for probe response (in active probing )if some activity found on channel till the end of this time duration.", + TimeValue (Seconds (0.040)), + MakeTimeAccessor (&StaWifiMac::m_maxChannelTimeout), + MakeTimeChecker ()) .AddTraceSource ("Assoc", "Associated with an access point.", MakeTraceSourceAccessor (&StaWifiMac::m_assocLogger), "ns3::Mac48Address::TracedCallback") @@ -136,7 +149,7 @@ void StaWifiMac::DoInitialize (void) { - StartScanning (); + StartScanning (); } void @@ -223,8 +236,13 @@ { m_probeRequestEvent.Cancel (); } - m_probeRequestEvent = Simulator::Schedule (m_probeRequestTimeout, - &StaWifiMac::ProbeRequestTimeout, this); + //edited by manish start + // if (m_candidateChannels.size () == 0) + // { + // //m_probeRequestEvent = Simulator::Schedule (m_probeRequestTimeout, + // &StaWifiMac::ProbeRequestTimeout, this); + //} + //edited by manish end } void @@ -293,7 +311,7 @@ if (m_activeProbing) { SetState (WAIT_PROBE_RESP); - m_bestBeaconObserved.Clear (); + //m_bestBeaconObserved.Clear ();removed by manish as resulting in clearing of best becon data of channel SendProbeRequest (); } else @@ -302,9 +320,10 @@ { m_waitBeaconEvent.Cancel (); } - m_bestBeaconObserved.Clear (); - m_waitBeaconEvent = Simulator::Schedule (m_scanningTimeout, - &StaWifiMac::WaitBeaconTimeout, this); + //m_bestBeaconObserved.Clear ();removed by manish as resulting in clearing of best becon data of channel + //m_waitBeaconEvent = Simulator::Schedule (m_scanningTimeout, + // &StaWifiMac::WaitBeaconTimeout, this); + //no need to call WaitBeaconTimeout as it is not end of scanning SetState (WAIT_BEACON); } break; @@ -409,7 +428,9 @@ SetBssid (m_bestBeaconObserved.m_bssid); Time delay = MicroSeconds (m_bestBeaconObserved.m_probeResp.GetBeaconIntervalUs () * m_maxMissedBeacons); RestartBeaconWatchdog (delay); - if (m_probeRequestEvent.IsRunning ()) + NS_LOG_DEBUG ("Stopping scanning; best beacon found on channel " << m_bestBeaconObserved.m_channelNumber);//manish + m_phy->SetChannelNumber (m_bestBeaconObserved.m_channelNumber);//manish + if (m_probeRequestEvent.IsRunning ()) { m_probeRequestEvent.Cancel (); } @@ -419,7 +440,7 @@ else { NS_LOG_DEBUG ("no probe responses received; resend request"); - SendProbeRequest (); + StartScanning ();//manish restart scanning process } } @@ -432,13 +453,15 @@ NS_LOG_DEBUG ("Beacon found, selecting " << m_bestBeaconObserved.m_bssid); SetBssid (m_bestBeaconObserved.m_bssid); SetState (WAIT_ASSOC_RESP); + m_phy->SetChannelNumber (m_bestBeaconObserved.m_channelNumber);//manish SendAssociationRequest (); } - else - { - NS_LOG_DEBUG ("no beacons received; restart scanning"); - StartScanning (); - } + // edited by manish check allready present in channelScanning Timeout + //else + // { + // NS_LOG_DEBUG ("no beacons received; restart scanning"); + //StartScanning (); + //} } void @@ -557,47 +580,99 @@ StaWifiMac::StartScanning (void) { NS_LOG_FUNCTION (this); + m_bestBeaconObserved.Clear ();//rev manish moved from TryToEnsureAssociated SetState (SCANNING); - m_candidateChannels = m_phy->GetOperationalChannelList (); + m_candidateChannels = m_phy->GetOperationalChannelList (); if (m_candidateChannels.size () == 1) { NS_LOG_DEBUG ("No need to scan; only one channel possible"); + //rev1.0 manish setting channel number and communicating to phy layer + uint32_t nextChannel = m_candidateChannels.back (); + m_phy->SetChannelNumber (nextChannel); m_candidateChannels.clear (); - SetState (UNASSOCIATED); + SetState (UNASSOCIATED); TryToEnsureAssociated (); return; } // Keep track of whether we find any good beacons, so that if we do // not, we restart scanning - m_bestBeaconObserved.Clear (); + //m_bestBeaconObserved.Clear ();rev1.0 manish moved above uint32_t nextChannel = m_candidateChannels.back (); m_candidateChannels.pop_back (); - NS_LOG_DEBUG ("Scanning channel " << nextChannel); - Simulator::Schedule (m_scanningTimeout, &StaWifiMac::ScanningTimeout, this); + NS_LOG_DEBUG ("Scanning channel " << nextChannel); + m_phy->SetChannelNumber (nextChannel);//rev1.0 manish setting channel number + SetState (UNASSOCIATED);//rev1.0 manish setting state + + // edited by manish checking whether active probing or passive probing + if (m_activeProbing) + { + Simulator::Schedule (m_minChannelTimeout, &StaWifiMac::MinScanningTimeout, this); + } + else + { + Simulator::Schedule (m_scanningTimeout, &StaWifiMac::ChannelScanningTimeout, this); + } + TryToEnsureAssociated ();//rev1.0 manish +} +//edited by manish adding new function +void +StaWifiMac::MinScanningTimeout (void) +{ + if (! activityDetected) + { Simulator::ScheduleNow ( &StaWifiMac::ChannelScanningTimeout, this); + } + else{Simulator::Schedule (m_maxChannelTimeout - m_minChannelTimeout ), + &StaWifiMac::ChannelScanningTimeout, this); + activityDetected = false ; + } } void -StaWifiMac::ScanningTimeout (void) +StaWifiMac::ChannelScanningTimeout (void) { NS_LOG_FUNCTION (this); if (m_candidateChannels.size () == 0) { - if (m_bestBeaconObserved.m_channelNumber == 0) - { - NS_LOG_DEBUG ("No beacons found when scanning; restart scanning"); - StartScanning (); - return; - } + if (m_bestBeaconObserved.m_channelNumber == 0) + { + NS_LOG_DEBUG ("No beacons/ probe reponse found when scanning; restart scanning"); + StartScanning (); + return; + } NS_LOG_DEBUG ("Stopping scanning; best beacon found on channel " << m_bestBeaconObserved.m_channelNumber); - m_phy->SetChannelNumber (m_bestBeaconObserved.m_channelNumber); - SetState (UNASSOCIATED); - TryToEnsureAssociated (); + //edited by manish no need of following lines at this place + // m_phy->SetChannelNumber (m_bestBeaconObserved.m_channelNumber); + //SetState (UNASSOCIATED); + //TryToEnsureAssociated (); + + // manish checking active /passive probing + if (m_activeProbing) + { + m_probeRequestEvent = Simulator::ScheduleNow (&StaWifiMac::ProbeRequestTimeout, this);//manish + } + else + { + m_waitBeaconEvent = Simulator::Schedule (m_scanningTimeout,&StaWifiMac::WaitBeaconTimeout, this); + } //manish + + return; } uint32_t nextChannel = m_candidateChannels.back (); m_candidateChannels.pop_back (); NS_LOG_DEBUG ("Scanning channel " << nextChannel); - Simulator::Schedule (m_scanningTimeout, &StaWifiMac::ScanningTimeout, this); + m_phy->SetChannelNumber (nextChannel);//rev1.0 manish setting channel number + SetState (UNASSOCIATED);//rev1.0 manish setting channel number + // manish checking active /passive probing + if (m_activeProbing) + { + Simulator::Schedule (m_minChannelTimeout, &StaWifiMac::MinScanningTimeout, this); + } + else + ( + Simulator::Schedule (m_scanningTimeout, &StaWifiMac::ChannelScanningTimeout, this); + )//manish + TryToEnsureAssociated ();//rev1.0 manish setting channel number } void @@ -605,6 +680,7 @@ { NS_LOG_FUNCTION (this << packet << hdr); NS_ASSERT (!hdr->IsCtl ()); + activityDetected = true ;//new variable to sense channel if (hdr->GetAddr3 () == GetAddress ()) { NS_LOG_LOGIC ("packet sent by us."); @@ -725,12 +801,12 @@ m_stationManager->SetShortPreambleEnabled (isShortPreambleEnabled); m_stationManager->SetShortSlotTimeEnabled (capabilities.IsShortSlotTime ()); } - if (goodBeacon && m_state == UNASSOCIATED) - { - SetState (WAIT_ASSOC_RESP); - SendAssociationRequest (); - } - if (goodBeacon && (m_state == SCANNING || m_state == WAIT_BEACON)) + // if (goodBeacon && m_state == UNASSOCIATED) + // { + // SetState (WAIT_ASSOC_RESP); + //SendAssociationRequest (); + //} edited by manish no need to send association request + if (goodBeacon && (m_state == SCANNING || m_state == WAIT_BEACON) && !m_activeProbing) { NS_LOG_DEBUG ("Beacon received while scanning"); if (m_bestBeaconObserved.m_snr < tag.Get ()) --- original/sta-wifi-mac.h 2017-04-01 02:35:08.000000000 +0530 +++ edited/sta-wifi-mac.h 2017-04-01 02:35:16.000000000 +0530 @@ -213,10 +213,15 @@ * Start the scanning process to find the strongest beacon */ void StartScanning (void); + /** + * (edited by manish)To check the waiting time (MaxTime Or MinTime) on the channel during Active Probing + */ + void MinScanningTimeout (void); /** + * Edited by Manish old ScanningTimeout is now channel scanning timeout * Continue scanning process or terminate if no further channels to scan */ - void ScanningTimeout (void); + void ChannelScanningTimeout (void); virtual void DoInitialize (void); @@ -224,6 +229,8 @@ Time m_probeRequestTimeout; Time m_assocRequestTimeout; Time m_scanningTimeout; + Time m_minChannelTimeout;// edited by manish used when scanning + Time m_maxChannelTimeout;// edited by manish used when scanning EventId m_probeRequestEvent; EventId m_assocRequestEvent; EventId m_beaconWatchdog; @@ -231,6 +238,7 @@ Time m_beaconWatchdogEnd; uint32_t m_maxMissedBeacons; bool m_activeProbing; + bool activityDetected ;// edited by manish used when scanning std::vector m_candidateChannels; /// used when scanning BeaconInfo m_bestBeaconObserved; /// used when scanning --- original/yans-wifi-phy.cc 2017-04-01 02:35:08.000000000 +0530 +++ edited/yans-wifi-phy.cc 2017-04-01 02:35:18.000000000 +0530 @@ -515,8 +515,10 @@ { if (m_operationalChannelList[i] != m_channelNumber) { - channelList.push_back (m_channelNumber); - } + //edited by Manish Puraswani ver 1.0 as the original one was not updating channel list + //channelList.push_back (m_channelNumber); (original code) + channelList.push_back (m_operationalChannelList[i]); + } } return channelList; }