Update mesh model, tests and reference traces for new random variable usage

This commit is contained in:
Tom Henderson
2012-08-17 13:31:40 -07:00
parent 8567f250e2
commit 243f52e1ce
42 changed files with 241 additions and 41 deletions

View File

@@ -207,5 +207,34 @@ MeshHelper::ResetStats (const ns3::Ptr<ns3::NetDevice>& device)
NS_ASSERT (mp != 0);
m_stack->ResetStats (mp);
}
int64_t
MeshHelper::AssignStreams (NetDeviceContainer c, int64_t stream)
{
int64_t currentStream = stream;
Ptr<NetDevice> netDevice;
for (NetDeviceContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
netDevice = (*i);
Ptr<MeshPointDevice> mpd = DynamicCast<MeshPointDevice> (netDevice);
Ptr<WifiNetDevice> wifi;
Ptr<MeshWifiInterfaceMac> mac;
if (mpd)
{
// To access, we need the underlying WifiNetDevices
std::vector<Ptr<NetDevice> > ifaces = mpd->GetInterfaces ();
for (std::vector<Ptr<NetDevice> >::iterator i = ifaces.begin (); i != ifaces.end (); i++)
{
wifi = DynamicCast<WifiNetDevice> (*i);
mac = DynamicCast<MeshWifiInterfaceMac> (wifi->GetMac ());
if (mac)
{
currentStream += mac->AssignStreams (currentStream);
}
}
}
}
return (currentStream - stream);
}
} // namespace ns3

View File

@@ -190,6 +190,19 @@ public:
* \brief Reset statistics.
*/
void ResetStats (const ns3::Ptr<ns3::NetDevice>&);
/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned. The Install() method of this helper
* should have previously been called by the user.
*
* \param stream first stream index to use
* \param c NetDeviceContainer of the set of devices for which the mesh devices
* should be modified to use a fixed stream
* \return the number of stream indices assigned by this helper
*/
int64_t AssignStreams (NetDeviceContainer c, int64_t stream);
private:
/**
* \internal

View File

@@ -476,5 +476,12 @@ HwmpProtocolMac::ResetStats ()
m_stats = Statistics ();
}
int64_t
HwmpProtocolMac::AssignStreams (int64_t stream)
{
return m_protocol->AssignStreams (stream);
}
} // namespace dot11s
} // namespace ns3

View File

@@ -53,6 +53,7 @@ public:
bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
/// Update beacon is empty, because HWMP does not know anything about beacons
void UpdateBeacon (MeshWifiBeacon & beacon) const {};
int64_t AssignStreams (int64_t stream);
//\}
private:

View File

@@ -29,7 +29,7 @@
#include "ns3/wifi-net-device.h"
#include "ns3/mesh-point-device.h"
#include "ns3/mesh-wifi-interface-mac.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "airtime-metric.h"
#include "ie-dot11s-preq.h"
#include "ie-dot11s-prep.h"
@@ -192,11 +192,7 @@ HwmpProtocol::HwmpProtocol () :
m_rfFlag (false)
{
NS_LOG_FUNCTION_NOARGS ();
if (m_isRoot)
{
SetRoot ();
}
m_coefficient = CreateObject<UniformRandomVariable> ();
}
HwmpProtocol::~HwmpProtocol ()
@@ -204,6 +200,16 @@ HwmpProtocol::~HwmpProtocol ()
NS_LOG_FUNCTION_NOARGS ();
}
void
HwmpProtocol::DoStart ()
{
m_coefficient->SetAttribute ("Max", DoubleValue (m_randomStart.GetSeconds ()));
if (m_isRoot)
{
SetRoot ();
}
}
void
HwmpProtocol::DoDispose ()
{
@@ -1017,8 +1023,7 @@ HwmpProtocol::RetryPathDiscovery (Mac48Address dst, uint8_t numOfRetry)
void
HwmpProtocol::SetRoot ()
{
UniformVariable coefficient (0.0, m_randomStart.GetSeconds ());
Time randomStart = Seconds (coefficient.GetValue ());
Time randomStart = Seconds (m_coefficient->GetValue ());
m_proactivePreqTimer = Simulator::Schedule (randomStart, &HwmpProtocol::SendProactivePreq, this);
NS_LOG_DEBUG ("ROOT IS: " << m_address);
m_isRoot = true;
@@ -1163,6 +1168,15 @@ HwmpProtocol::ResetStats ()
plugin->second->ResetStats ();
}
}
int64_t
HwmpProtocol::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
m_coefficient->SetStream (stream);
return 1;
}
HwmpProtocol::QueuedPacket::QueuedPacket () :
pkt (0),
protocol (0),

View File

@@ -32,6 +32,7 @@ namespace ns3 {
class MeshPointDevice;
class Packet;
class Mac48Address;
class UniformRandomVariable;
namespace dot11s {
class HwmpProtocolMac;
class HwmpRtable;
@@ -85,9 +86,21 @@ public:
///\brief Statistics:
void Report (std::ostream &) const;
void ResetStats ();
/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned.
*
* \param stream first stream index to use
* \return the number of stream indices assigned by this model
*/
int64_t AssignStreams (int64_t stream);
private:
friend class HwmpProtocolMac;
virtual void DoStart ();
HwmpProtocol& operator= (const HwmpProtocol &);
HwmpProtocol (const HwmpProtocol &);
@@ -267,6 +280,8 @@ private:
bool m_doFlag;
bool m_rfFlag;
///\}
/// Random variable for random start time
Ptr<UniformRandomVariable> m_coefficient;
Callback <std::vector<Mac48Address>, uint32_t> m_neighboursCallback;
};
} // namespace dot11s

View File

@@ -316,6 +316,12 @@ PeerManagementProtocolMac::GetLinkMetric (Mac48Address peerAddress)
{
return m_parent->GetLinkMetric (peerAddress);
}
int64_t
PeerManagementProtocolMac::AssignStreams (int64_t stream)
{
return m_protocol->AssignStreams (stream);
}
} // namespace dot11s
} // namespace ns3

View File

@@ -50,6 +50,7 @@ public:
bool Receive (Ptr<Packet> packet, const WifiMacHeader & header);
bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
void UpdateBeacon (MeshWifiBeacon & beacon) const;
int64_t AssignStreams (int64_t stream);
// \}
///\name Statistics
// \{
@@ -57,6 +58,7 @@ public:
void ResetStats ();
uint32_t GetLinkMetric (Mac48Address peerAddress);
// \}
private:
PeerManagementProtocolMac& operator= (const PeerManagementProtocolMac &);
PeerManagementProtocolMac (const PeerManagementProtocolMac &);
@@ -118,6 +120,7 @@ private:
Statistics ();
void Print (std::ostream & os) const;
};
private:
struct Statistics m_stats;
///\}

View File

@@ -27,7 +27,7 @@
#include "ns3/simulator.h"
#include "ns3/assert.h"
#include "ns3/log.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/mesh-wifi-interface-mac.h"
#include "ns3/mesh-wifi-interface-mac-plugin.h"
#include "ns3/wifi-net-device.h"
@@ -85,6 +85,7 @@ PeerManagementProtocol::GetTypeId (void)
PeerManagementProtocol::PeerManagementProtocol () :
m_lastAssocId (0), m_lastLocalLinkId (1), m_enableBca (true), m_maxBeaconShift (15)
{
m_beaconShift = CreateObject<UniformRandomVariable> ();
}
PeerManagementProtocol::~PeerManagementProtocol ()
{
@@ -436,14 +437,10 @@ PeerManagementProtocol::CheckBeaconCollisions (uint32_t interface)
void
PeerManagementProtocol::ShiftOwnBeacon (uint32_t interface)
{
// If beacon interval is equal to the neighbor's one and one o more beacons received
// by my neighbor coincide with my beacon - apply random uniformly distributed shift from
// [-m_maxBeaconShift, m_maxBeaconShift] except 0.
UniformVariable beaconShift (-m_maxBeaconShift, m_maxBeaconShift);
int shift = 0;
do
{
shift = (int) beaconShift.GetValue ();
shift = (int) m_beaconShift->GetValue ();
}
while (shift == 0);
// Apply beacon shift parameters:
@@ -581,6 +578,24 @@ PeerManagementProtocol::ResetStats ()
}
}
int64_t
PeerManagementProtocol::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
m_beaconShift->SetStream (stream);
return 1;
}
void
PeerManagementProtocol::DoStart ()
{
// If beacon interval is equal to the neighbor's one and one o more beacons received
// by my neighbor coincide with my beacon - apply random uniformly distributed shift from
// [-m_maxBeaconShift, m_maxBeaconShift] except 0.
m_beaconShift->SetAttribute ("Min", DoubleValue (-m_maxBeaconShift));
m_beaconShift->SetAttribute ("Max", DoubleValue (m_maxBeaconShift));
}
void
PeerManagementProtocol::SetBeaconCollisionAvoidance (bool enable)
{

View File

@@ -34,6 +34,7 @@
#include <map>
namespace ns3 {
class MeshPointDevice;
class UniformRandomVariable;
namespace dot11s {
class PeerManagementProtocolMac;
class PeerLink;
@@ -149,7 +150,18 @@ public:
///\brief: Report statistics
void Report (std::ostream &) const;
void ResetStats ();
/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned.
*
* \param stream first stream index to use
* \return the number of stream indices assigned by this model
*/
int64_t AssignStreams (int64_t stream);
private:
virtual void DoStart ();
/**
* \name Private structures
* \{
@@ -261,6 +273,8 @@ private:
};
struct Statistics m_stats;
// \}
/// Add randomness to beacon shift
Ptr<UniformRandomVariable> m_beaconShift;
};
} // namespace dot11s

View File

@@ -43,6 +43,8 @@ public:
bool UpdateOutcomingFrame (Ptr<Packet> packet, WifiMacHeader & header, Mac48Address from, Mac48Address to);
/// Update beacon is empty, because HWMP does not know anything about beacons
void UpdateBeacon (MeshWifiBeacon & beacon) const {};
/// AssignStreams is empty, because this model doesn't use random variables
int64_t AssignStreams (int64_t stream) { return 0; }
//\}
uint16_t GetChannelId () const;
/// Report statistics

View File

@@ -65,6 +65,16 @@ public:
* TODO define when MAC call this
*/
virtual void UpdateBeacon (MeshWifiBeacon & beacon) const = 0;
/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned.
*
* \param stream first stream index to use
* \return the number of stream indices assigned by this model
*/
virtual int64_t AssignStreams (int64_t stream) = 0;
};
} // namespace ns3

View File

@@ -28,10 +28,11 @@
#include "ns3/mac-rx-middle.h"
#include "ns3/mac-low.h"
#include "ns3/dca-txop.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/simulator.h"
#include "ns3/yans-wifi-phy.h"
#include "ns3/pointer.h"
#include "ns3/double.h"
#include "ns3/trace-source-accessor.h"
#include "ns3/qos-tag.h"
@@ -79,6 +80,7 @@ MeshWifiInterfaceMac::MeshWifiInterfaceMac () :
// Let the lower layers know that we are acting as a mesh node
SetTypeOfStation (MESH);
m_coefficient = CreateObject<UniformRandomVariable> ();
}
MeshWifiInterfaceMac::~MeshWifiInterfaceMac ()
{
@@ -124,6 +126,38 @@ MeshWifiInterfaceMac::DoDispose ()
RegularWifiMac::DoDispose ();
}
void
MeshWifiInterfaceMac::DoStart ()
{
m_coefficient->SetAttribute ("Max", DoubleValue (m_randomStart.GetSeconds ()));
if (m_beaconEnable)
{
Time randomStart = Seconds (m_coefficient->GetValue ());
// Now start sending beacons after some random delay (to avoid collisions)
NS_ASSERT (!m_beaconSendEvent.IsRunning ());
m_beaconSendEvent = Simulator::Schedule (randomStart, &MeshWifiInterfaceMac::SendBeacon, this);
m_tbtt = Simulator::Now () + randomStart;
}
else
{
// stop sending beacons
m_beaconSendEvent.Cancel ();
}
}
int64_t
MeshWifiInterfaceMac::AssignStreams (int64_t stream)
{
NS_LOG_FUNCTION (this << stream);
int64_t currentStream = stream;
m_coefficient->SetStream (currentStream++);
for (PluginList::const_iterator i = m_plugins.begin (); i < m_plugins.end (); i++)
{
currentStream += (*i)->AssignStreams (currentStream);
}
return (currentStream - stream);
}
//-----------------------------------------------------------------------------
// Plugins
//-----------------------------------------------------------------------------
@@ -329,20 +363,7 @@ void
MeshWifiInterfaceMac::SetBeaconGeneration (bool enable)
{
NS_LOG_FUNCTION (this << enable);
UniformVariable coefficient (0.0, m_randomStart.GetSeconds ());
if (enable)
{
Time randomStart = Seconds (coefficient.GetValue ());
// Now start sending beacons after some random delay (to avoid collisions)
NS_ASSERT (!m_beaconSendEvent.IsRunning ());
m_beaconSendEvent = Simulator::Schedule (randomStart, &MeshWifiInterfaceMac::SendBeacon, this);
m_tbtt = Simulator::Now () + randomStart;
}
else
{
// stop sending beacons
m_beaconSendEvent.Cancel ();
}
m_beaconEnable = enable;
}
bool
MeshWifiInterfaceMac::GetBeaconGeneration () const

View File

@@ -39,6 +39,7 @@ namespace ns3 {
class WifiMacHeader;
class DcaTxop;
class UniformRandomVariable;
/**
* \ingroup mesh
*
@@ -134,6 +135,15 @@ public:
void SetBeaconGeneration (bool enable);
WifiPhyStandard GetPhyStandard () const;
virtual void FinishConfigureStandard (enum WifiPhyStandard standard);
/**
* Assign a fixed random variable stream number to the random variables
* used by this model. Return the number of streams (possibly zero) that
* have been assigned.
*
* \param stream first stream index to use
* \return the number of stream indices assigned by this model
*/
int64_t AssignStreams (int64_t stream);
private:
/// Frame receive handler
void Receive (Ptr<Packet> packet, WifiMacHeader const *hdr);
@@ -151,8 +161,12 @@ private:
private:
typedef std::vector<Ptr<MeshWifiInterfaceMacPlugin> > PluginList;
virtual void DoStart ();
///\name Mesh timing intervals
// \{
/// whether beaconing is enabled
bool m_beaconEnable;
/// Beaconing interval.
Time m_beaconInterval;
/// Maximum delay before first beacon
@@ -186,6 +200,9 @@ private:
// \}
/// Current PHY standard: needed to configure metric
WifiPhyStandard m_standard;
/// Add randomness to beacon generation
Ptr<UniformRandomVariable> m_coefficient;
};
} // namespace ns3

View File

@@ -20,7 +20,8 @@
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -55,7 +56,8 @@ HwmpProactiveRegressionTest::~HwmpProactiveRegressionTest ()
void
HwmpProactiveRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
CreateDevices ();
InstallApplications ();
@@ -114,6 +116,10 @@ HwmpProactiveRegressionTest::CreateDevices ()
mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
mesh.SetNumberOfInterfaces (1);
NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
// Five nodes, one device per node, 3 streams per mac
int64_t streamsUsed = mesh.AssignStreams (meshDevices, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, (3*5), "Stream assignment unexpected value");
// 3. setup TCP/IP
InternetStackHelper internetStack;
internetStack.Install (*m_nodes);

View File

@@ -20,7 +20,8 @@
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -51,7 +52,8 @@ HwmpReactiveRegressionTest::~HwmpReactiveRegressionTest ()
void
HwmpReactiveRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
CreateDevices ();
InstallApplications ();
@@ -111,6 +113,10 @@ HwmpReactiveRegressionTest::CreateDevices ()
mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
mesh.SetNumberOfInterfaces (1);
NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
// Six nodes, one device per node, 3 streams per mac
int64_t streamsUsed = mesh.AssignStreams (meshDevices, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, (6*3), "Stream assignment unexpected value");
// 3. setup TCP/IP
InternetStackHelper internetStack;
internetStack.Install (*m_nodes);

View File

@@ -20,7 +20,8 @@
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -54,7 +55,8 @@ HwmpSimplestRegressionTest::~HwmpSimplestRegressionTest ()
void
HwmpSimplestRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
CreateDevices ();
InstallApplications ();
@@ -123,6 +125,10 @@ HwmpSimplestRegressionTest::CreateDevices ()
mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
mesh.SetNumberOfInterfaces (1);
NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
// Two nodes, one device per node, three streams per device
int64_t streamsUsed = mesh.AssignStreams (meshDevices, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, (2*3), "Stream assignment unexpected value");
// 3. setup TCP/IP
InternetStackHelper internetStack;
internetStack.Install (*m_nodes);

View File

@@ -20,7 +20,8 @@
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -54,7 +55,8 @@ HwmpDoRfRegressionTest::~HwmpDoRfRegressionTest ()
void
HwmpDoRfRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
CreateDevices ();
InstallApplications ();
@@ -130,6 +132,9 @@ HwmpDoRfRegressionTest::CreateDevices ()
mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
mesh.SetNumberOfInterfaces (1);
NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
// Four nodes, one device per node, three streams per mac
int64_t streamsUsed = mesh.AssignStreams (meshDevices, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, (4*3), "Stream assignment unexpected value");
// 3. setup TCP/IP
InternetStackHelper internetStack;
internetStack.Install (*m_nodes);

View File

@@ -19,7 +19,8 @@
*/
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -52,7 +53,8 @@ PeerManagementProtocolRegressionTest::~PeerManagementProtocolRegressionTest ()
void
PeerManagementProtocolRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
CreateDevices ();
@@ -95,6 +97,9 @@ PeerManagementProtocolRegressionTest::CreateDevices ()
mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
mesh.SetNumberOfInterfaces (1);
NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
// Three nodes, one device per node, two streams (one for mac, one for plugin)
int64_t streamsUsed = mesh.AssignStreams (meshDevices, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, (3*2), "Stream assignment unexpected value");
// 3. write PCAP if needed
wifiPhy.EnablePcapAll (CreateTempDirFilename (PREFIX));
}

View File

@@ -19,7 +19,8 @@
*/
#include "ns3/mesh-helper.h"
#include "ns3/simulator.h"
#include "ns3/random-variable.h"
#include "ns3/random-variable-stream.h"
#include "ns3/rng-seed-manager.h"
#include "ns3/mobility-helper.h"
#include "ns3/double.h"
#include "ns3/uinteger.h"
@@ -55,7 +56,8 @@ FlameRegressionTest::~FlameRegressionTest ()
void
FlameRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
CreateDevices ();
InstallApplications ();
@@ -101,6 +103,9 @@ FlameRegressionTest::CreateDevices ()
mesh.SetMacType ("RandomStart", TimeValue (Seconds (0.1)));
mesh.SetNumberOfInterfaces (1);
NetDeviceContainer meshDevices = mesh.Install (wifiPhy, *m_nodes);
// Three nodes, one device per node
int64_t streamsUsed = mesh.AssignStreams (meshDevices, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, 3, "Stream assignment unexpected value");
// 3. setup TCP/IP
InternetStackHelper internetStack;
internetStack.Install (*m_nodes);