diff --git a/src/olsr/helper/olsr-helper.cc b/src/olsr/helper/olsr-helper.cc index 447cbd06b..357a90cd3 100644 --- a/src/olsr/helper/olsr-helper.cc +++ b/src/olsr/helper/olsr-helper.cc @@ -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; + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) + { + node = (*i); + Ptr ipv4 = node->GetObject (); + NS_ASSERT_MSG (ipv4, "Ipv4 not installed on node"); + Ptr proto = ipv4->GetRoutingProtocol (); + NS_ASSERT_MSG (proto, "Ipv4 routing not installed on node"); + Ptr olsr = DynamicCast (proto); + if (olsr) + { + currentStream += olsr->AssignStreams (currentStream); + continue; + } + // Olsr may also be in a list + Ptr list = DynamicCast (proto); + if (list) + { + int16_t priority; + Ptr listProto; + Ptr listOlsr; + for (uint32_t i = 0; i < list->GetNRoutingProtocols (); i++) + { + listProto = list->GetRoutingProtocol (i, priority); + listOlsr = DynamicCast (listProto); + if (listOlsr) + { + currentStream += olsr->AssignStreams (currentStream); + break; + } + } + } + } + return (currentStream - stream); + +} + } // namespace ns3 diff --git a/src/olsr/helper/olsr-helper.h b/src/olsr/helper/olsr-helper.h index 058658fd8..763fb4afd 100644 --- a/src/olsr/helper/olsr-helper.h +++ b/src/olsr/helper/olsr-helper.h @@ -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 diff --git a/src/olsr/test/bug780-0-0.pcap b/src/olsr/test/bug780-0-0.pcap index 39c78b3ca..32b471a3f 100644 Binary files a/src/olsr/test/bug780-0-0.pcap and b/src/olsr/test/bug780-0-0.pcap differ diff --git a/src/olsr/test/bug780-1-0.pcap b/src/olsr/test/bug780-1-0.pcap index f82ff2516..2f1409d97 100644 Binary files a/src/olsr/test/bug780-1-0.pcap and b/src/olsr/test/bug780-1-0.pcap differ diff --git a/src/olsr/test/bug780-2-0.pcap b/src/olsr/test/bug780-2-0.pcap index 759395366..8778f1e13 100644 Binary files a/src/olsr/test/bug780-2-0.pcap and b/src/olsr/test/bug780-2-0.pcap differ diff --git a/src/olsr/test/bug780-test.cc b/src/olsr/test/bug780-test.cc index 1ec3b19a3..6c59853e1 100644 --- a/src/olsr/test/bug780-test.cc +++ b/src/olsr/test/bug780-test.cc @@ -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"); diff --git a/src/olsr/test/hello-regression-test.cc b/src/olsr/test/hello-regression-test.cc index 07a81c465..155055efb 100644 --- a/src/olsr/test/hello-regression-test.cc +++ b/src/olsr/test/hello-regression-test.cc @@ -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")); diff --git a/src/olsr/test/olsr-hello-regression-test-0-1.pcap b/src/olsr/test/olsr-hello-regression-test-0-1.pcap index d1218b1f8..d2e2a90ad 100644 Binary files a/src/olsr/test/olsr-hello-regression-test-0-1.pcap and b/src/olsr/test/olsr-hello-regression-test-0-1.pcap differ diff --git a/src/olsr/test/olsr-hello-regression-test-1-1.pcap b/src/olsr/test/olsr-hello-regression-test-1-1.pcap index 39ee00cc8..645195cc4 100644 Binary files a/src/olsr/test/olsr-hello-regression-test-1-1.pcap and b/src/olsr/test/olsr-hello-regression-test-1-1.pcap differ diff --git a/src/olsr/test/olsr-tc-regression-test-0-1.pcap b/src/olsr/test/olsr-tc-regression-test-0-1.pcap index 54fcb3fda..e0c810009 100644 Binary files a/src/olsr/test/olsr-tc-regression-test-0-1.pcap and b/src/olsr/test/olsr-tc-regression-test-0-1.pcap differ diff --git a/src/olsr/test/olsr-tc-regression-test-1-1.pcap b/src/olsr/test/olsr-tc-regression-test-1-1.pcap index c2a997aca..4e5edaf52 100644 Binary files a/src/olsr/test/olsr-tc-regression-test-1-1.pcap and b/src/olsr/test/olsr-tc-regression-test-1-1.pcap differ diff --git a/src/olsr/test/olsr-tc-regression-test-2-1.pcap b/src/olsr/test/olsr-tc-regression-test-2-1.pcap index b79daf3cb..844deda63 100644 Binary files a/src/olsr/test/olsr-tc-regression-test-2-1.pcap and b/src/olsr/test/olsr-tc-regression-test-2-1.pcap differ diff --git a/src/olsr/test/tc-regression-test.cc b/src/olsr/test/tc-regression-test.cc index 5b507b87e..f1e5acf23 100644 --- a/src/olsr/test/tc-regression-test.cc +++ b/src/olsr/test/tc-regression-test.cc @@ -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 ();