implement AP beaconing
This commit is contained in:
@@ -41,12 +41,12 @@
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
static void
|
||||
void
|
||||
WifiNetDeviceTrace (const TraceContext &context, Packet p, Mac48Address address)
|
||||
{
|
||||
std::cout << context << " ad=" << address << " p: " << p << std::endl;
|
||||
}
|
||||
static void
|
||||
void
|
||||
WifiPhyStateTrace (const TraceContext &context, Time start, Time duration, enum WifiPhy::State state)
|
||||
{
|
||||
std::cout << context << " state=";
|
||||
@@ -71,11 +71,13 @@ static Ptr<Node>
|
||||
CreateApNode (Ptr<WifiChannel> channel,
|
||||
Position position,
|
||||
const char *ipAddress,
|
||||
Ssid ssid)
|
||||
Ssid ssid,
|
||||
Time at)
|
||||
{
|
||||
Ptr<Node> node = Create<InternetNode> ();
|
||||
Ptr<NqapWifiNetDevice> device = Create<NqapWifiNetDevice> (node);
|
||||
device->SetSsid (ssid);
|
||||
Simulator::Schedule (at, &NqapWifiNetDevice::StartBeaconing, device);
|
||||
device->ConnectTo (channel);
|
||||
Ptr<MobilityModel> mobility = Create<StaticMobilityModel> ();
|
||||
mobility->Set (position);
|
||||
@@ -164,7 +166,8 @@ int main (int argc, char *argv[])
|
||||
Ptr<Node> a = CreateApNode (channel,
|
||||
Position (5.0,0.0,0.0),
|
||||
"192.168.0.1",
|
||||
ssid);
|
||||
ssid,
|
||||
Seconds (0.1));
|
||||
Simulator::Schedule (Seconds (1.0), &AdvancePosition, a);
|
||||
|
||||
Ptr<Node> b = CreateStaNode (channel,
|
||||
@@ -186,8 +189,8 @@ int main (int argc, char *argv[])
|
||||
|
||||
GlobalRouteManager::PopulateRoutingTables ();
|
||||
|
||||
NodeList::Connect ("/nodes/*/devices/*/*", MakeCallback (&WifiNetDeviceTrace));
|
||||
NodeList::Connect ("/nodes/*/devices/*/phy/state", MakeCallback (&WifiPhyStateTrace));
|
||||
//NodeList::Connect ("/nodes/*/devices/*/*", MakeCallback (&WifiNetDeviceTrace));
|
||||
//NodeList::Connect ("/nodes/*/devices/*/phy/state", MakeCallback (&WifiPhyStateTrace));
|
||||
|
||||
Simulator::Run ();
|
||||
|
||||
|
||||
@@ -52,6 +52,13 @@ MacHighNqap::SetDcaTxop (DcaTxop *dca)
|
||||
m_dca->SetTxFailedCallback (MakeCallback (&MacHighNqap::TxFailed, this));
|
||||
}
|
||||
void
|
||||
MacHighNqap::SetBeaconDcaTxop (DcaTxop *dca)
|
||||
{
|
||||
// we do not need to be notified when a beacon has been transmitted
|
||||
// successfully or not.
|
||||
m_beaconDca = dca;
|
||||
}
|
||||
void
|
||||
MacHighNqap::SetDevice (WifiNetDevice *device)
|
||||
{
|
||||
m_device = device;
|
||||
@@ -76,6 +83,11 @@ MacHighNqap::SetBeaconInterval (Time interval)
|
||||
{
|
||||
m_beaconInterval = interval;
|
||||
}
|
||||
void
|
||||
MacHighNqap::StartBeaconing (void)
|
||||
{
|
||||
SendOneBeacon ();
|
||||
}
|
||||
void
|
||||
MacHighNqap::ForwardDown (Packet packet, Mac48Address from, Mac48Address to)
|
||||
{
|
||||
@@ -160,6 +172,27 @@ MacHighNqap::SendAssocResp (Mac48Address to, bool success)
|
||||
|
||||
m_dca->Queue (packet, hdr);
|
||||
}
|
||||
void
|
||||
MacHighNqap::SendOneBeacon (void)
|
||||
{
|
||||
TRACE ("send probe response to="<<Mac48Address::GetBroadcast ());
|
||||
WifiMacHeader hdr;
|
||||
hdr.SetBeacon ();
|
||||
hdr.SetAddr1 (Mac48Address::GetBroadcast ());
|
||||
hdr.SetAddr2 (m_device->GetSelfAddress ());
|
||||
hdr.SetAddr3 (m_device->GetSelfAddress ());
|
||||
hdr.SetDsNotFrom ();
|
||||
hdr.SetDsNotTo ();
|
||||
Packet packet;
|
||||
MgtBeaconHeader beacon;
|
||||
beacon.SetSsid (m_device->GetSsid ());
|
||||
beacon.SetSupportedRates (GetSupportedRates ());
|
||||
beacon.SetBeaconIntervalUs (m_beaconInterval.GetMicroSeconds ());
|
||||
packet.AddHeader (beacon);
|
||||
|
||||
m_beaconDca->Queue (packet, hdr);
|
||||
Simulator::Schedule (m_beaconInterval, &MacHighNqap::SendOneBeacon, this);
|
||||
}
|
||||
void
|
||||
MacHighNqap::TxOk (WifiMacHeader const &hdr)
|
||||
{
|
||||
|
||||
@@ -43,6 +43,7 @@ public:
|
||||
~MacHighNqap ();
|
||||
|
||||
void SetDcaTxop (DcaTxop *dca);
|
||||
void SetBeaconDcaTxop (DcaTxop *dca);
|
||||
void SetDevice (WifiNetDevice *device);
|
||||
void SetStations (MacStations *stations);
|
||||
void SetPhy (Ptr<WifiPhy> phy);
|
||||
@@ -51,6 +52,8 @@ public:
|
||||
|
||||
void Queue (Packet packet, Mac48Address to);
|
||||
|
||||
void StartBeaconing (void);
|
||||
|
||||
void Receive (Packet packet, WifiMacHeader const *hdr);
|
||||
private:
|
||||
void ForwardDown (Packet packet, Mac48Address from, Mac48Address to);
|
||||
@@ -58,9 +61,11 @@ private:
|
||||
void TxFailed (WifiMacHeader const &hdr);
|
||||
void SendProbeResp (Mac48Address to);
|
||||
void SendAssocResp (Mac48Address to, bool success);
|
||||
void SendOneBeacon (void);
|
||||
SupportedRates GetSupportedRates (void) const;
|
||||
|
||||
DcaTxop *m_dca;
|
||||
DcaTxop *m_beaconDca;
|
||||
WifiNetDevice *m_device;
|
||||
MacStations *m_stations;
|
||||
Ptr<WifiPhy> m_phy;
|
||||
|
||||
@@ -448,6 +448,16 @@ NqapWifiNetDevice::NqapWifiNetDevice (Ptr<Node> node)
|
||||
m_ssid = WifiDefaultParameters::GetSsid ();
|
||||
|
||||
m_dca = CreateDca (15, 1023);
|
||||
m_beaconDca = CreateDca (15, 1023);
|
||||
/**
|
||||
* We use a DIFS value for the beacons smaller than the 802.11 default
|
||||
* value to ensure that the beacon queue will get access to the medium
|
||||
* even when a lot of data has been queued. This is an 'extension' of
|
||||
* 802.11 which is a first step towards 802.11e but it is a nice way
|
||||
* to get timely beacons without a lot of other hacks.
|
||||
*/
|
||||
Time beaconDifs = m_parameters->GetSifs () + m_parameters->GetSlotTime ();
|
||||
m_beaconDca->SetDifs (beaconDifs);
|
||||
|
||||
// By default, we configure the Basic Rate Set to be the set
|
||||
// of rates we support which are mandatory.
|
||||
@@ -464,6 +474,7 @@ NqapWifiNetDevice::NqapWifiNetDevice (Ptr<Node> node)
|
||||
MacHighNqap *high = new MacHighNqap ();
|
||||
high->SetDevice (this);
|
||||
high->SetDcaTxop (m_dca);
|
||||
high->SetBeaconDcaTxop (m_beaconDca);
|
||||
high->SetStations (m_stations);
|
||||
high->SetPhy (m_phy);
|
||||
high->SetForwardCallback (MakeCallback (&NqapWifiNetDevice::DoForwardUp,
|
||||
@@ -488,6 +499,11 @@ NqapWifiNetDevice::SetSsid (Ssid ssid)
|
||||
{
|
||||
m_ssid = ssid;
|
||||
}
|
||||
void
|
||||
NqapWifiNetDevice::StartBeaconing (void)
|
||||
{
|
||||
m_high->StartBeaconing ();
|
||||
}
|
||||
bool
|
||||
NqapWifiNetDevice::DoSendTo (const Packet &packet, Mac48Address const & to)
|
||||
{
|
||||
@@ -506,9 +522,11 @@ NqapWifiNetDevice::DoDispose (void)
|
||||
WifiNetDevice::DoDispose ();
|
||||
// local cleanup
|
||||
delete m_dca;
|
||||
delete m_beaconDca;
|
||||
delete m_high;
|
||||
m_dca = 0;
|
||||
m_high = 0;
|
||||
m_beaconDca = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -217,6 +217,7 @@ public:
|
||||
virtual Mac48Address GetBssid (void) const;
|
||||
virtual Ssid GetSsid (void) const;
|
||||
void SetSsid (Ssid ssid);
|
||||
void StartBeaconing (void);
|
||||
protected:
|
||||
virtual void DoDispose (void);
|
||||
private:
|
||||
@@ -225,6 +226,7 @@ private:
|
||||
friend class WifiNetDeviceFactory;
|
||||
Ssid m_ssid;
|
||||
DcaTxop *m_dca;
|
||||
DcaTxop *m_beaconDca;
|
||||
MacHighNqap *m_high;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user