utils+helper+tests: Fix an issue with RandomPolicy
This commit also extends ndn::ScenarioHelper to expose the underlying
StackHelper for customization, as well as adds a basic test case for the
RandomPolicy.
Change-Id: Ieb948996497fd282f1afe4e7c102ec224299ac7f
diff --git a/helper/ndn-scenario-helper.cpp b/helper/ndn-scenario-helper.cpp
index 0c661da..1be86e6 100644
--- a/helper/ndn-scenario-helper.cpp
+++ b/helper/ndn-scenario-helper.cpp
@@ -144,5 +144,11 @@
throw std::invalid_argument("Link between " + node1 + " and " + node2 + " does not exist");
}
+StackHelper&
+ScenarioHelper::getStackHelper()
+{
+ return ndnHelper;
+}
+
} // namespace ndn
} // namespace ns3
diff --git a/helper/ndn-scenario-helper.hpp b/helper/ndn-scenario-helper.hpp
index 5131daa..52d19b7 100644
--- a/helper/ndn-scenario-helper.hpp
+++ b/helper/ndn-scenario-helper.hpp
@@ -181,6 +181,12 @@
void
disableStatusServer();
+ /**
+ * \brief Get NDN stack helper, e.g., to adjust its parameters
+ */
+ StackHelper&
+ getStackHelper();
+
private:
Ptr<Node>
getOrCreateNode(const std::string& nodeName);
diff --git a/tests/unit-tests/model/ndn-old-content-store.t.cpp b/tests/unit-tests/model/ndn-old-content-store.t.cpp
new file mode 100644
index 0000000..362988c
--- /dev/null
+++ b/tests/unit-tests/model/ndn-old-content-store.t.cpp
@@ -0,0 +1,73 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2016 Regents of the University of California.
+ *
+ * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
+ * contributors.
+ *
+ * ndnSIM is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+
+#include "../tests-common.hpp"
+
+namespace ns3 {
+namespace ndn {
+
+BOOST_FIXTURE_TEST_SUITE(ModelNdnOldContentStore, ScenarioHelperWithCleanupFixture)
+
+BOOST_AUTO_TEST_CASE(RandomPolicy)
+{
+ Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"));
+ Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
+ Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
+
+ getStackHelper().SetOldContentStore("ns3::ndn::cs::Random", "MaxSize", "10");
+
+ createTopology({
+ {"1", "2"},
+ });
+
+ addRoutes({
+ {"1", "2", "/prefix", 1},
+ });
+
+ addApps({
+ {"1", "ns3::ndn::ConsumerCbr",
+ {{"Prefix", "/prefix"}, {"Frequency", "10"}},
+ "0s", "9.99s"},
+ {"2", "ns3::ndn::Producer",
+ {{"Prefix", "/prefix"}, {"PayloadSize", "1024"}},
+ "0s", "100s"}
+ });
+
+ Simulator::Stop(Seconds(20.001));
+ Simulator::Run();
+
+ std::map<std::string, std::vector<Name>> entries;
+ for (const std::string& node : {"1", "2"}) {
+ auto cs = getNode(node)->GetObject<ContentStore>();
+ auto& nodeCs = entries[node];
+ for (auto it = cs->Begin(); it != cs->End(); it = cs->Next(it)) {
+ nodeCs.push_back(it->GetName());
+ }
+ }
+
+ BOOST_CHECK_EQUAL(entries["1"].size(), 10);
+ BOOST_CHECK_EQUAL(entries["2"].size(), 10);
+ BOOST_CHECK(entries["1"] != entries["2"]); // this test has a small chance of failing
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
+} // namespace ns3
diff --git a/utils/trie/random-policy.hpp b/utils/trie/random-policy.hpp
index 1e2aa4a..a6e3517 100644
--- a/utils/trie/random-policy.hpp
+++ b/utils/trie/random-policy.hpp
@@ -23,6 +23,7 @@
/// @cond include_hidden
#include "ns3/random-variable-stream.h"
+#include "ns3/double.h"
#include <boost/intrusive/options.hpp>
#include <boost/intrusive/set.hpp>
@@ -92,8 +93,8 @@
, u_rand(CreateObject<UniformRandomVariable>())
, max_size_(100)
{
- u_rand->SetAttribute("Min", UintegerValue(0));
- u_rand->SetAttribute("Max", UintegerValue(std::numeric_limits<uint32_t>::max()));
+ u_rand->SetAttribute("Min", DoubleValue(0));
+ u_rand->SetAttribute("Max", DoubleValue(std::numeric_limits<uint32_t>::max()));
}
inline void