Update OLSR tests and reference traces for new random variable usage

This commit is contained in:
Tom Henderson
2012-08-17 06:00:53 -07:00
parent a0bda821ac
commit f645a4bc46
13 changed files with 67 additions and 3 deletions

View File

@@ -21,6 +21,7 @@
#include "ns3/olsr-routing-protocol.h"
#include "ns3/node-list.h"
#include "ns3/names.h"
#include "ns3/ptr.h"
#include "ns3/ipv4-list-routing.h"
namespace ns3 {
@@ -82,4 +83,45 @@ OlsrHelper::Set (std::string name, const AttributeValue &value)
m_agentFactory.Set (name, value);
}
int64_t
OlsrHelper::AssignStreams (NodeContainer c, int64_t stream)
{
int64_t currentStream = stream;
Ptr<Node> node;
for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
{
node = (*i);
Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
NS_ASSERT_MSG (ipv4, "Ipv4 not installed on node");
Ptr<Ipv4RoutingProtocol> proto = ipv4->GetRoutingProtocol ();
NS_ASSERT_MSG (proto, "Ipv4 routing not installed on node");
Ptr<olsr::RoutingProtocol> olsr = DynamicCast<olsr::RoutingProtocol> (proto);
if (olsr)
{
currentStream += olsr->AssignStreams (currentStream);
continue;
}
// Olsr may also be in a list
Ptr<Ipv4ListRouting> list = DynamicCast<Ipv4ListRouting> (proto);
if (list)
{
int16_t priority;
Ptr<Ipv4RoutingProtocol> listProto;
Ptr<olsr::RoutingProtocol> listOlsr;
for (uint32_t i = 0; i < list->GetNRoutingProtocols (); i++)
{
listProto = list->GetRoutingProtocol (i, priority);
listOlsr = DynamicCast<olsr::RoutingProtocol> (listProto);
if (listOlsr)
{
currentStream += olsr->AssignStreams (currentStream);
break;
}
}
}
}
return (currentStream - stream);
}
} // namespace ns3

View File

@@ -83,6 +83,19 @@ public:
*/
void Set (std::string name, const AttributeValue &value);
/**
* 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 the InternetStackHelper
* should have previously been called by the user.
*
* \param stream first stream index to use
* \param c NodeContainer of the set of nodes for which the OlsrRoutingProtocol
* should be modified to use a fixed stream
* \return the number of stream indices assigned by this helper
*/
int64_t AssignStreams (NodeContainer c, int64_t stream);
private:
/**
* \internal

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -72,7 +72,8 @@ Bug780Test::~Bug780Test()
void
Bug780Test::DoRun ()
{
SeedManager::SetSeed (123);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (12345);
CreateNodes ();
Simulator::Stop (m_time);
@@ -124,6 +125,8 @@ Bug780Test::CreateNodes (void)
InternetStackHelper internet;
internet.SetRoutingHelper (olsr);
internet.Install (adhocNodes);
int64_t streamsUsed = olsr.AssignStreams (adhocNodes, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, nWifis, "Should have assigned 3 streams");
Ipv4AddressHelper addressAdhoc;
addressAdhoc.SetBase ("10.1.1.0", "255.255.255.0");

View File

@@ -53,7 +53,8 @@ HelloRegressionTest::~HelloRegressionTest()
void
HelloRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
Simulator::Stop (m_time);
@@ -74,6 +75,8 @@ HelloRegressionTest::CreateNodes ()
InternetStackHelper internet;
internet.SetRoutingHelper (olsr);
internet.Install (c);
int64_t streamsUsed = olsr.AssignStreams (c, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, 2, "Should have assigned 2 streams");
// create p2p channel & devices
PointToPointHelper p2p;
p2p.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));

View File

@@ -58,7 +58,8 @@ TcRegressionTest::~TcRegressionTest()
void
TcRegressionTest::DoRun ()
{
SeedManager::SetSeed (12345);
RngSeedManager::SetSeed (12345);
RngSeedManager::SetRun (7);
CreateNodes ();
Simulator::Stop (m_time);
@@ -92,6 +93,8 @@ TcRegressionTest::CreateNodes ()
InternetStackHelper internet;
internet.SetRoutingHelper (olsr);
internet.Install (c);
int64_t streamsUsed = olsr.AssignStreams (c, 0);
NS_TEST_EXPECT_MSG_EQ (streamsUsed, 3, "Should have assigned 2 streams");
// create wifi channel & devices
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();