examples: Restoring old examples that can be restored and fixing existing ones
diff --git a/examples/ndn-congestion-alt-topo-plugin.cpp b/examples/ndn-congestion-alt-topo-plugin.cpp
index db0afc7..8779944 100644
--- a/examples/ndn-congestion-alt-topo-plugin.cpp
+++ b/examples/ndn-congestion-alt-topo-plugin.cpp
@@ -139,7 +139,6 @@
return 0;
}
-
} // namespace ns3
int
diff --git a/examples/ndn-congestion-topo-plugin.cpp b/examples/ndn-congestion-topo-plugin.cpp
index ba40c7a..fa72462 100644
--- a/examples/ndn-congestion-topo-plugin.cpp
+++ b/examples/ndn-congestion-topo-plugin.cpp
@@ -113,7 +113,6 @@
return 0;
}
-
} // namespace ns3
int
diff --git a/examples/ndn-simple-with-custom-app.cpp b/examples/ndn-custom-apps.cpp
similarity index 67%
rename from examples/ndn-simple-with-custom-app.cpp
rename to examples/ndn-custom-apps.cpp
index eeac173..7ea32f8 100644
--- a/examples/ndn-simple-with-custom-app.cpp
+++ b/examples/ndn-custom-apps.cpp
@@ -17,7 +17,7 @@
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
-// ndn-simple-with-custom-app.cpp
+// ndn-custom-apps.cpp
#include "ns3/core-module.h"
#include "ns3/network-module.h"
@@ -28,13 +28,12 @@
/**
* This scenario simulates a one-node two-custom-app scenario:
*
- * +------+ <-----> (CustomApp1)
+ * +------+ <-----> (CustomApp)
* | Node |
- * +------+ <-----> (CustomApp2)
+ * +------+ <-----> (Hijacker)
*
- * NS_LOG=CustomApp ./waf --run=ndn-simple-with-custom-app
+ * NS_LOG=CustomApp ./waf --run=ndn-custom-apps
*/
-
int
main(int argc, char* argv[])
{
@@ -45,23 +44,20 @@
// Creating nodes
Ptr<Node> node = CreateObject<Node>();
- // Install CCNx stack on all nodes
+ // Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
ndnHelper.InstallAll();
- // Installing applications
+ // App1
+ ndn::AppHelper app1("CustomApp");
+ app1.Install(node);
- // Consumer
- ndn::AppHelper consumerHelper("CustomApp");
- ApplicationContainer app1 = consumerHelper.Install(node);
- ApplicationContainer app2 = consumerHelper.Install(node);
+ // App2
+ ndn::AppHelper app2("Hijacker");
+ app2.Install(node); // last node
- app1.Start(Seconds(1.0)); // will send out Interest, which nobody will receive (Interests
- // generated by an app will not got back to the app)
- app2.Start(
- Seconds(2.0)); // will send out an Interests, which will be received and satisfied by app1
-
- Simulator::Stop(Seconds(3.0));
+ Simulator::Stop(Seconds(20.0));
Simulator::Run();
Simulator::Destroy();
diff --git a/examples/custom-apps/custom-app.cpp b/examples/ndn-custom-apps/custom-app.cpp
similarity index 68%
rename from examples/custom-apps/custom-app.cpp
rename to examples/ndn-custom-apps/custom-app.cpp
index cf9d886..414efa2 100644
--- a/examples/custom-apps/custom-app.cpp
+++ b/examples/ndn-custom-apps/custom-app.cpp
@@ -19,12 +19,14 @@
// custom-app.cpp
-#include "custom-app.h"
+#include "custom-app.hpp"
+
#include "ns3/ptr.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/packet.h"
+#include "ns3/ndnSIM/helper/ndn-stack-helper.hpp"
#include "ns3/ndnSIM/helper/ndn-fib-helper.hpp"
#include "ns3/random-variable.h"
@@ -50,15 +52,8 @@
// initialize ndn::App
ndn::App::StartApplication();
- Simulator::Schedule(Seconds(1.0), &CustomApp::SendInterest, this);
-
- // Create a name components object for name ``/prefix/sub``
- shared_ptr<Name> prefix = make_shared<Name>(); // now prefix contains ``/``
- prefix->append("prefix"); // now prefix contains ``/prefix``
- prefix->append("sub"); // now prefix contains ``/prefix/sub``
-
- // Add entry to FIB
- ndn::FibHelper::AddRoute(node, *prefix, m_face, 0);
+ // Add entry to FIB for `/prefix/sub`
+ ndn::FibHelper::AddRoute(GetNode(), "/prefix/sub", m_face, 0);
// Schedule send of first interest
Simulator::Schedule(Seconds(1.0), &CustomApp::SendInterest, this);
@@ -79,16 +74,13 @@
// Sending one Interest packet out //
/////////////////////////////////////
- auto prefix = make_shared<Name>("/prefix/sub"); // another way to create name
-
// Create and configure ndn::Interest
- auto interest = make_shared<Interest>();
+ auto interest = std::make_shared<ndn::Interest>("/prefix/sub");
UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
interest->setNonce(rand.GetValue());
- interest->setName(*prefix);
- interest->setInterestLifetime(time::seconds(1));
+ interest->setInterestLifetime(ndn::time::seconds(1));
- NS_LOG_DEBUG("Sending Interest packet for " << *prefix);
+ NS_LOG_DEBUG("Sending Interest packet for " << *interest);
// Call trace (for logging purposes)
m_transmittedInterests(interest, this, m_face);
@@ -98,7 +90,7 @@
// Callback that will be called when Interest arrives
void
-CustomApp::OnInterest(shared_ptr<const ndn::Interest> interest)
+CustomApp::OnInterest(std::shared_ptr<const ndn::Interest> interest)
{
ndn::App::OnInterest(interest);
@@ -106,10 +98,10 @@
// Note that Interests send out by the app will not be sent back to the app !
- auto data = make_shared<ndn::Data>(interest->getName());
- data->setFreshnessPeriod(ndn::time::milliseconds(uint64_t(1000)));
- data->setContent(make_shared<::ndn::Buffer>(1024));
- StackHelper::getKeyChain().sign(*data);
+ auto data = std::make_shared<ndn::Data>(interest->getName());
+ data->setFreshnessPeriod(ndn::time::milliseconds(1000));
+ data->setContent(std::make_shared<::ndn::Buffer>(1024));
+ ndn::StackHelper::getKeyChain().sign(*data);
NS_LOG_DEBUG("Sending Data packet for " << data->getName());
@@ -121,11 +113,11 @@
// Callback that will be called when Data arrives
void
-CustomApp::OnData(shared_ptr<const ndn::Data> contentObject)
+CustomApp::OnData(std::shared_ptr<const ndn::Data> data)
{
- NS_LOG_DEBUG("Receiving Data packet for " << contentObject->getName());
+ NS_LOG_DEBUG("Receiving Data packet for " << data->getName());
- std::cout << "DATA received for name " << contentObject->getName() << std::endl;
+ std::cout << "DATA received for name " << data->getName() << std::endl;
}
} // namespace ns3
diff --git a/examples/custom-apps/custom-app.hpp b/examples/ndn-custom-apps/custom-app.hpp
similarity index 92%
rename from examples/custom-apps/custom-app.hpp
rename to examples/ndn-custom-apps/custom-app.hpp
index a8f83e1..7ed6a78 100644
--- a/examples/custom-apps/custom-app.hpp
+++ b/examples/ndn-custom-apps/custom-app.hpp
@@ -22,8 +22,6 @@
#ifndef CUSTOM_APP_H_
#define CUSTOM_APP_H_
-#include "ns3/ndnSIM/model/ndn-common.hpp"
-
#include "ns3/ndnSIM/apps/ndn-app.hpp"
namespace ns3 {
@@ -54,11 +52,11 @@
// (overridden from ndn::App) Callback that will be called when Interest arrives
virtual void
- OnInterest(shared_ptr<const ndn::Interest> interest);
+ OnInterest(std::shared_ptr<const ndn::Interest> interest);
// (overridden from ndn::App) Callback that will be called when Data arrives
virtual void
- OnData(shared_ptr<const ndn::Data> contentObject);
+ OnData(std::shared_ptr<const ndn::Data> contentObject);
private:
void
diff --git a/examples/custom-apps/hijacker.cpp b/examples/ndn-custom-apps/hijacker.cpp
similarity index 88%
rename from examples/custom-apps/hijacker.cpp
rename to examples/ndn-custom-apps/hijacker.cpp
index 6471ff2..2a13885 100644
--- a/examples/custom-apps/hijacker.cpp
+++ b/examples/ndn-custom-apps/hijacker.cpp
@@ -21,6 +21,8 @@
#include "hijacker.hpp"
+#include "ns3/log.h"
+
#include "ns3/ndnSIM/helper/ndn-fib-helper.hpp"
NS_LOG_COMPONENT_DEFINE("Hijacker");
@@ -43,7 +45,7 @@
}
void
-Hijacker::OnInterest(shared_ptr<const ndn::Interest> interest)
+Hijacker::OnInterest(std::shared_ptr<const ndn::Interest> interest)
{
ndn::App::OnInterest(interest); // forward call to perform app-level tracing
// do nothing else (hijack interest)
@@ -56,8 +58,8 @@
{
App::StartApplication();
- // equivalent to setting interest filter for "/" prefix
- ndn::FibHelper::AddRoute(GetNode(), "/", m_face, 0);
+ // equivalent to setting interest filter for "/prefix" prefix
+ ndn::FibHelper::AddRoute(GetNode(), "/prefix/sub", m_face, 0);
}
void
diff --git a/examples/custom-apps/hijacker.hpp b/examples/ndn-custom-apps/hijacker.hpp
similarity index 89%
rename from examples/custom-apps/hijacker.hpp
rename to examples/ndn-custom-apps/hijacker.hpp
index 01d156a..c873f81 100644
--- a/examples/custom-apps/hijacker.hpp
+++ b/examples/ndn-custom-apps/hijacker.hpp
@@ -22,9 +22,7 @@
#ifndef HIJACKER_H_
#define HIJACKER_H_
-#include "ns3/core-module.h"
-#include "ns3/network-module.h"
-#include "ns3/ndnSIM-module.h"
+#include "ns3/ndnSIM/apps/ndn-app.hpp"
namespace ns3 {
@@ -37,7 +35,7 @@
// Receive all Interests but do nothing in response
void
- OnInterest(shared_ptr<const ndn::Interest> interest);
+ OnInterest(std::shared_ptr<const ndn::Interest> interest);
protected:
// inherited from Application base class.
diff --git a/examples/ndn-grid-topo-plugin-loss.cpp b/examples/ndn-grid-topo-plugin-loss.cpp
new file mode 100644
index 0000000..439a56b
--- /dev/null
+++ b/examples/ndn-grid-topo-plugin-loss.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 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/>.
+ **/
+
+// ndn-grid-topo-plugin-loss.cpp
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+namespace ns3 {
+
+/**
+ * This scenario simulates a grid topology (using topology reader module)
+ *
+ * (consumer) -- ( ) ----- ( )
+ * | | |
+ * ( ) ------ ( ) ----- ( )
+ * | | |
+ * ( ) ------ ( ) -- (producer)
+ *
+ * All links are 1Mbps with propagation 10ms delay.
+ *
+ * FIB is populated using NdnGlobalRoutingHelper.
+ *
+ * Consumer requests data from producer with frequency 10 interests per second
+ * (interests contain constantly increasing sequence number).
+ *
+ * For every received interest, producer replies with a data packet, containing
+ * 1024 bytes of virtual payload.
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
+ */
+
+int
+main(int argc, char* argv[])
+{
+ CommandLine cmd;
+ cmd.Parse(argc, argv);
+
+ AnnotatedTopologyReader topologyReader("", 25);
+ topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-grid-3x3-loss.txt");
+ topologyReader.Read();
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.InstallAll();
+
+ ndn::StrategyChoiceHelper::InstallAll("/", "ndn:/localhost/nfd/strategy/best-route");
+
+ // Installing global routing interface on all nodes
+ ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
+ ndnGlobalRoutingHelper.InstallAll();
+
+ // Getting containers for the consumer/producer
+ Ptr<Node> producer = Names::Find<Node>("Node8");
+ NodeContainer consumerNodes;
+ consumerNodes.Add(Names::Find<Node>("Node0"));
+
+ // Install NDN applications
+ std::string prefix = "/prefix";
+
+ ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetPrefix(prefix);
+ consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
+ consumerHelper.Install(consumerNodes);
+
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetPrefix(prefix);
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+ producerHelper.Install(producer);
+
+ // Add /prefix origins to ndn::GlobalRouter
+ ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
+
+ // Calculate and install FIBs
+ ndn::GlobalRoutingHelper::CalculateRoutes();
+
+ Simulator::Stop(Seconds(20.0));
+
+ Simulator::Run();
+ Simulator::Destroy();
+
+ return 0;
+}
+} // namespace ns3
+
+int
+main(int argc, char* argv[])
+{
+ return ns3::main(argc, argv);
+}
diff --git a/examples/ndn-grid-topo-plugin-red-queues.cpp b/examples/ndn-grid-topo-plugin-red-queues.cpp
new file mode 100644
index 0000000..b51c8ab
--- /dev/null
+++ b/examples/ndn-grid-topo-plugin-red-queues.cpp
@@ -0,0 +1,109 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 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/>.
+ **/
+
+// ndn-grid-topo-plugin-red-queues.cpp
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+namespace ns3 {
+
+/**
+ * This scenario simulates a grid topology (using topology reader module)
+ *
+ * (consumer) -- ( ) ----- ( )
+ * | | |
+ * ( ) ------ ( ) ----- ( )
+ * | | |
+ * ( ) ------ ( ) -- (producer)
+ *
+ * All links are 1Mbps with propagation 10ms delay.
+ *
+ * FIB is populated using ndn::GlobalRoutingHelper.
+ *
+ * Consumer requests data from producer with frequency 10 interests per second
+ * (interests contain constantly increasing sequence number).
+ *
+ * For every received interest, producer replies with a data packet, containing
+ * 1024 bytes of virtual payload.
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
+ */
+
+int
+main(int argc, char* argv[])
+{
+ CommandLine cmd;
+ cmd.Parse(argc, argv);
+
+ AnnotatedTopologyReader topologyReader("", 25);
+ topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-grid-3x3-red-queues.txt");
+ topologyReader.Read();
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.InstallAll();
+
+ ndn::StrategyChoiceHelper::InstallAll("/", "ndn:/localhost/nfd/strategy/best-route");
+
+ // Installing global routing interface on all nodes
+ ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
+ ndnGlobalRoutingHelper.InstallAll();
+
+ // Getting containers for the consumer/producer
+ Ptr<Node> producer = Names::Find<Node>("Node8");
+ NodeContainer consumerNodes;
+ consumerNodes.Add(Names::Find<Node>("Node0"));
+
+ // Install NDN applications
+ std::string prefix = "/prefix";
+
+ ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetPrefix(prefix);
+ consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
+ consumerHelper.Install(consumerNodes);
+
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetPrefix(prefix);
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+ producerHelper.Install(producer);
+
+ // Add /prefix origins to ndn::GlobalRouter
+ ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
+
+ // Calculate and install FIBs
+ ndn::GlobalRoutingHelper::CalculateRoutes();
+
+ Simulator::Stop(Seconds(20.0));
+
+ Simulator::Run();
+ Simulator::Destroy();
+
+ return 0;
+}
+} // namespace ns3
+
+int
+main(int argc, char* argv[])
+{
+ return ns3::main(argc, argv);
+}
diff --git a/examples/ndn-simple-with-content-freshness.cpp b/examples/ndn-simple-with-content-freshness.cpp
new file mode 100644
index 0000000..4557890
--- /dev/null
+++ b/examples/ndn-simple-with-content-freshness.cpp
@@ -0,0 +1,125 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 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/>.
+ **/
+
+// ndn-simple-with-content-freshness.cpp
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/ndnSIM-module.h"
+
+namespace ns3 {
+
+/**
+ * This scenario simulates a very simple network topology:
+ *
+ *
+ * +----------+ 1Mbps +--------+ 1Mbps +----------+
+ * | consumer | <------------> | router | <------------> | producer |
+ * +----------+ 10ms +--------+ 10ms +----------+
+ *
+ * This scenario demonstrates how to use content store that responds to Freshness parameter set in
+ * data packets. In other words, if the producer set FreshnessPeriod field to 2 seconds, the
+ * corresponding data packet will not be considered fresh for more than 2 seconds (can be cached
+ * for a shorter time, if entry is evicted earlier)
+ *
+ * NS_LOG=DumbRequester ./waf --run ndn-simple-with-content-freshness
+ */
+
+int
+main(int argc, char* argv[])
+{
+ // setting default parameters for PointToPoint links and channels
+ Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
+ Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
+ Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
+
+ // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
+ CommandLine cmd;
+ cmd.Parse(argc, argv);
+
+ // Creating nodes
+ NodeContainer nodes;
+ nodes.Create(3);
+
+ // Connecting nodes using two links
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+ p2p.Install(nodes.Get(1), nodes.Get(2));
+
+ // Install Ndn stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
+ ndnHelper.SetOldContentStore("ns3::ndn::cs::Freshness::Lru", "MaxSize",
+ "2"); // allow just 2 entries to be cached
+ ndnHelper.InstallAll();
+
+ // Installing applications
+
+ // Consumer
+ ndn::AppHelper consumerHelper("OneInterestRequester");
+
+ // /*
+ // 1) at time 1 second requests Data from a producer that does not specify freshness
+ // 2) at time 10 seconds requests the same Data packet as client 1
+
+ // 3) at time 2 seconds requests Data from a producer that specifies freshness set to 2 seconds
+ // 4) at time 12 seconds requests the same Data packet as client 3
+
+ // Expectation:
+ // Interests from 1, 3 and 4 will reach producers
+ // Interset from 2 will be served from cache
+ // */
+
+ consumerHelper.SetPrefix("/no-freshness");
+ consumerHelper.Install(nodes.Get(0)).Start(Seconds(1));
+ consumerHelper.Install(nodes.Get(0)).Start(Seconds(10));
+
+ consumerHelper.SetPrefix("/with-freshness");
+ consumerHelper.Install(nodes.Get(0)).Start(Seconds(2));
+ consumerHelper.Install(nodes.Get(0)).Start(Seconds(12));
+
+ // Producer
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+
+ producerHelper.SetAttribute("Freshness", TimeValue(Seconds(-1.0))); // unlimited freshness
+ producerHelper.SetPrefix("/no-freshness");
+ producerHelper.Install(nodes.Get(2)); // last node
+
+ producerHelper.SetAttribute("Freshness", TimeValue(Seconds(2.0))); // freshness 2 seconds (!!!
+ // freshness granularity is 1
+ // seconds !!!)
+ producerHelper.SetPrefix("/with-freshness");
+ producerHelper.Install(nodes.Get(2)); // last node
+
+ Simulator::Stop(Seconds(30.0));
+
+ Simulator::Run();
+ Simulator::Destroy();
+
+ return 0;
+}
+} // namespace ns3
+
+int
+main(int argc, char* argv[])
+{
+ return ns3::main(argc, argv);
+}
diff --git a/examples/custom-apps/dumb-requester.cpp b/examples/ndn-simple-with-content-freshness/one-interest-requester.cpp
similarity index 68%
rename from examples/custom-apps/dumb-requester.cpp
rename to examples/ndn-simple-with-content-freshness/one-interest-requester.cpp
index f92022b..828ae22 100644
--- a/examples/custom-apps/dumb-requester.cpp
+++ b/examples/ndn-simple-with-content-freshness/one-interest-requester.cpp
@@ -19,7 +19,8 @@
// dumb-requester.cpp
-#include "dumb-requester.hpp"
+#include "one-interest-requester.hpp"
+
#include "ns3/ptr.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
@@ -27,47 +28,45 @@
#include "ns3/random-variable.h"
#include "ns3/string.h"
-#include "ns3/ndn-app-face.hpp"
-
-NS_LOG_COMPONENT_DEFINE("DumbRequester");
+NS_LOG_COMPONENT_DEFINE("OneInterestRequester");
namespace ns3 {
-NS_OBJECT_ENSURE_REGISTERED(DumbRequester);
+NS_OBJECT_ENSURE_REGISTERED(OneInterestRequester);
// register NS-3 type
TypeId
-DumbRequester::GetTypeId()
+OneInterestRequester::GetTypeId()
{
static TypeId tid =
- TypeId("DumbRequester")
+ TypeId("OneInterestRequester")
.SetParent<ndn::App>()
- .AddConstructor<DumbRequester>()
+ .AddConstructor<OneInterestRequester>()
.AddAttribute("Prefix", "Requested name", StringValue("/dumb-interest"),
- ndn::MakeNameAccessor(&DumbRequester::m_name), ndn::MakeNameChecker());
+ ndn::MakeNameAccessor(&OneInterestRequester::m_name), ndn::MakeNameChecker());
return tid;
}
-DumbRequester::DumbRequester()
+OneInterestRequester::OneInterestRequester()
: m_isRunning(false)
{
}
// Processing upon start of the application
void
-DumbRequester::StartApplication()
+OneInterestRequester::StartApplication()
{
// initialize ndn::App
ndn::App::StartApplication();
m_isRunning = true;
- Simulator::ScheduleNow(&DumbRequester::SendInterest, this);
+ Simulator::ScheduleNow(&OneInterestRequester::SendInterest, this);
}
// Processing when application is stopped
void
-DumbRequester::StopApplication()
+OneInterestRequester::StopApplication()
{
m_isRunning = false;
// cleanup ndn::App
@@ -75,7 +74,7 @@
}
void
-DumbRequester::SendInterest()
+OneInterestRequester::SendInterest()
{
if (!m_isRunning)
return;
@@ -85,27 +84,26 @@
/////////////////////////////////////
// Create and configure ndn::Interest
- auto interest = make_shared<ndn::Interest>(*m_name);
+ auto interest = std::make_shared<ndn::Interest>(m_name);
UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
interest->setNonce(rand.GetValue());
- interest->setName(*prefix);
- interest->setInterestLifetime(time::seconds(1));
+ interest->setInterestLifetime(ndn::time::seconds(1));
- NS_LOG_DEBUG("Sending Interest packet for " << *prefix);
+ NS_LOG_DEBUG("Sending Interest packet for " << m_name);
// Call trace (for logging purposes)
m_transmittedInterests(interest, this, m_face);
+ NS_LOG_DEBUG(">> I: " << m_name);
+
// Forward packet to lower (network) layer
m_face->onReceiveInterest(*interest);
-
- Simulator::Schedule(Seconds(1.0), &DumbRequester::SendInterest, this);
}
void
-DumbRequester::OnData(shared_ptr<const ndn::Data> contentObject)
+OneInterestRequester::OnData(std::shared_ptr<const ndn::Data> data)
{
- NS_LOG_DEBUG("Receiving Data packet for " << contentObject->getName());
+ NS_LOG_DEBUG("<< D: " << data->getName());
}
} // namespace ns3
diff --git a/examples/custom-apps/dumb-requester.hpp b/examples/ndn-simple-with-content-freshness/one-interest-requester.hpp
similarity index 90%
rename from examples/custom-apps/dumb-requester.hpp
rename to examples/ndn-simple-with-content-freshness/one-interest-requester.hpp
index cbbca2c..01a5b72 100644
--- a/examples/custom-apps/dumb-requester.hpp
+++ b/examples/ndn-simple-with-content-freshness/one-interest-requester.hpp
@@ -33,13 +33,13 @@
*
* This app keeps requesting every second the same content object
*/
-class DumbRequester : public ndn::App {
+class OneInterestRequester : public ndn::App {
public:
- // register NS-3 type "DumbRequester"
+ // register NS-3 type "OneInterestRequester"
static TypeId
GetTypeId();
- DumbRequester();
+ OneInterestRequester();
// (overridden from ndn::App) Processing upon start of the application
virtual void
@@ -51,7 +51,7 @@
// (overridden from ndn::App) Callback that will be called when Data arrives
virtual void
- OnData(shared_ptr<const ndn::Data> contentObject);
+ OnData(std::shared_ptr<const ndn::Data> data);
private:
void
diff --git a/examples/ndn-simple-with-different-sizes-content-store.cpp b/examples/ndn-simple-with-different-sizes-content-store.cpp
new file mode 100644
index 0000000..7f24225
--- /dev/null
+++ b/examples/ndn-simple-with-different-sizes-content-store.cpp
@@ -0,0 +1,111 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 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/>.
+ **/
+
+// ndn-simple-with-different-sizes-content-store.cc
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/point-to-point-module.h"
+#include "ns3/ndnSIM-module.h"
+
+namespace ns3 {
+
+/**
+ * This scenario simulates a very simple network topology:
+ *
+ *
+ * +----------+ 1Mbps +--------+ 1Mbps +----------+
+ * | consumer | <------------> | router | <------------> | producer |
+ * +----------+ 10ms +--------+ 10ms +----------+
+ *
+ * This scenario demonstrates how to use content store that responds to Freshness parameter set in
+ *Datas.
+ * That is, if producer set Freshness field to 2 seconds, the corresponding content object will not
+ *be cached
+ * more than 2 seconds (can be cached for a shorter time, if entry is evicted earlier)
+ *
+ * NS_LOG=ndn.Consumer ./waf --run ndn-simple-with-different-sizes-content-store
+ */
+
+int
+main(int argc, char* argv[])
+{
+ // setting default parameters for PointToPoint links and channels
+ Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
+ Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
+ Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
+
+ // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
+ CommandLine cmd;
+ cmd.Parse(argc, argv);
+
+ // Creating nodes
+ NodeContainer nodes;
+ nodes.Create(3);
+
+ // Connecting nodes using two links
+ PointToPointHelper p2p;
+ p2p.Install(nodes.Get(0), nodes.Get(1));
+ p2p.Install(nodes.Get(1), nodes.Get(2));
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.SetDefaultRoutes(true);
+ ndnHelper.SetOldContentStore(
+ "ns3::ndn::cs::Freshness::Lru"); // don't set up max size here, will use default value = 100
+ ndnHelper.InstallAll();
+
+ // set up max sizes, after NDN stack is installed
+ Config::Set("/NodeList/0/$ns3::ndn::ContentStore/MaxSize",
+ UintegerValue(
+ 1)); // number after nodeList is global ID of the node (= node->GetId ())
+ Config::Set("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue(2));
+ Config::Set("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue(200));
+
+ // Installing applications
+
+ // Consumer
+ ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
+ // Consumer will request /prefix/0, /prefix/1, ...
+ consumerHelper.SetPrefix("/prefix");
+ consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
+ consumerHelper.Install(nodes.Get(0)); // first node
+
+ // Producer
+ ndn::AppHelper producerHelper("ns3::ndn::Producer");
+ // Producer will reply to all requests starting with /prefix
+ producerHelper.SetPrefix("/prefix");
+ producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
+ producerHelper.Install(nodes.Get(2)); // last node
+
+ Simulator::Stop(Seconds(20.0));
+
+ Simulator::Run();
+ Simulator::Destroy();
+
+ return 0;
+}
+
+} // namespace ns3
+
+int
+main(int argc, char* argv[])
+{
+ return ns3::main(argc, argv);
+}
diff --git a/examples/ndn-simple-with-link-failure.cpp b/examples/ndn-simple-with-link-failure.cpp
index f23620b..948d89e 100644
--- a/examples/ndn-simple-with-link-failure.cpp
+++ b/examples/ndn-simple-with-link-failure.cpp
@@ -46,7 +46,7 @@
*
* To run scenario and see what is happening, use the following command:
*
- * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
+ * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-with-link-failure
*/
int
diff --git a/examples/ndn-simple-with-pcap.cpp b/examples/ndn-simple-with-pcap.cpp
index e26866b..12a0cbb 100644
--- a/examples/ndn-simple-with-pcap.cpp
+++ b/examples/ndn-simple-with-pcap.cpp
@@ -24,6 +24,20 @@
#include "ns3/point-to-point-module.h"
#include "ns3/ndnSIM-module.h"
+/**
+ * This scenario demonstrates how to dump raw NDN packets into tcpdump-format
+ *
+ * Run scenario:
+ *
+ * ./waf --run ndn-simple-with-pcap
+ *
+ * After simulation finishes, it produces `ndn-simple-trace.pcap` that can be read
+ * using tcpdump or ndndump tools:
+ *
+ * ndndump -r ndn-simple-trace.pcap not ip
+ * tcpdump -r ndn-simple-trace.pcap
+ */
+
namespace ns3 {
class PcapWriter {
diff --git a/examples/ndn-triangle-calculate-routes.cpp b/examples/ndn-triangle-calculate-routes.cpp
new file mode 100644
index 0000000..b2b8138
--- /dev/null
+++ b/examples/ndn-triangle-calculate-routes.cpp
@@ -0,0 +1,120 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2011-2015 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/>.
+ **/
+
+// ndn-triangle-calculate-routes.cpp
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+#include "model/ndn-net-device-face.hpp"
+
+namespace ns3 {
+
+int
+main(int argc, char* argv[])
+{
+ // setting default parameters for PointToPoint links and channels
+ Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
+ Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
+ Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
+
+ // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
+ CommandLine cmd;
+ cmd.Parse(argc, argv);
+
+ ofstream file1("/tmp/topo1.txt");
+ file1 << "router\n\n"
+ << "#node city y x mpi-partition\n"
+ << "A1 NA 1 1 1\n"
+ << "B1 NA 80 -40 1\n"
+ << "C1 NA 80 40 1\n"
+ << "A2 NA 1 1 1\n"
+ << "B2 NA 80 -40 1\n"
+ << "C2 NA 80 40 1\n\n"
+ << "link\n\n"
+ << "# from to capacity metric delay queue\n"
+ << "A1 B1 10Mbps 100 1ms 100\n"
+ << "A1 C1 10Mbps 50 1ms 100\n"
+ << "B1 C1 10Mbps 1 1ms 100\n"
+ << "A2 B2 10Mbps 50 1ms 100\n"
+ << "A2 C2 10Mbps 100 1ms 100\n"
+ << "B2 C2 10Mbps 1 1ms 100\n";
+ file1.close();
+
+ AnnotatedTopologyReader topologyReader("");
+ topologyReader.SetFileName("/tmp/topo1.txt");
+ topologyReader.Read();
+
+ // Install NDN stack on all nodes
+ ndn::StackHelper ndnHelper;
+ ndnHelper.InstallAll();
+
+ topologyReader.ApplyOspfMetric();
+
+ ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
+ ndnGlobalRoutingHelper.InstallAll();
+
+ ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C1"));
+ ndnGlobalRoutingHelper.AddOrigins("/test/prefix", Names::Find<Node>("C2"));
+ ndn::GlobalRoutingHelper::CalculateRoutes();
+
+ auto printFib = [](Ptr<Node> node) {
+ auto ndn = node->GetObject<ndn::L3Protocol>();
+ for (const auto& entry : ndn->getForwarder()->getFib()) {
+ cout << entry.getPrefix() << " (";
+
+ bool isFirst = true;
+ for (auto& nextHop : entry.getNextHops()) {
+ cout << *nextHop.getFace();
+ auto face = dynamic_pointer_cast<ndn::NetDeviceFace>(nextHop.getFace());
+ if (face == nullptr)
+ continue;
+
+ cout << " towards ";
+
+ if (!isFirst)
+ cout << ", ";
+ cout << Names::FindName(face->GetNetDevice()->GetChannel()->GetDevice(1)->GetNode());
+ isFirst = false;
+ }
+ cout << ")" << endl;
+ }
+ };
+
+ cout << "FIB content on node A1" << endl;
+ printFib(Names::Find<Node>("A1"));
+
+ cout << "FIB content on node A2" << endl;
+ printFib(Names::Find<Node>("A2"));
+
+ Simulator::Stop(Seconds(20.0));
+ Simulator::Run();
+ Simulator::Destroy();
+
+ return 0;
+}
+
+} // namespace ns3
+
+int
+main(int argc, char* argv[])
+{
+ return ns3::main(argc, argv);
+}
diff --git a/examples/topologies/topo-grid-3x3-red-queues.txt b/examples/topologies/topo-grid-3x3-red-queues.txt
new file mode 100644
index 0000000..b87a0bf
--- /dev/null
+++ b/examples/topologies/topo-grid-3x3-red-queues.txt
@@ -0,0 +1,61 @@
+# topo-grid-3x3.txt
+
+# /--------\ /-\ /-\
+# |Consumer|<---->| |<------->| |
+# \--------/ \-/ \-/
+# ^ ^ ^
+# | | | 1Mbps/10ms delay
+# v v v
+# /-\ /-\ /-\
+# | |<-------->| |<------->| |
+# \-/ \-/ \-/
+# ^ ^ ^
+# | | |
+# v v v
+# /-\ /-\ /--------\
+# | |<-------->| |<---->|Producer|
+# \-/ \-/ \--------/
+
+# any empty lines and lines starting with '#' symbol is ignored
+#
+# The file should contain exactly two sections: router and link, each starting with the corresponding keyword
+#
+# router section defines topology nodes and their relative positions (e.g., to use in visualizer)
+router
+
+# each line in this section represents one router and should have the following data
+# node comment yPos xPos
+Node0 NA 3 1
+Node1 NA 3 2
+Node2 NA 3 3
+Node3 NA 2 1
+Node4 NA 2 2
+Node5 NA 2 3
+Node6 NA 1 1
+Node7 NA 1 2
+Node8 NA 1 3
+# Note that `node` can be any string. It is possible to access to the node by name using Names::Find, see examples.
+
+# link section defines point-to-point links between nodes and characteristics of these links
+link
+
+# Each line should be in the following format (only first two are required, the rest can be omitted)
+# srcNode dstNode bandwidth metric delay queue
+# bandwidth: link bandwidth
+# metric: routing metric
+# delay: link delay
+# queue: comma-separated list, specifying class for Queue (on both sides of the link) and necessary attributes
+# error: comma-separated list, specifying class for ErrorModel and necessary attributes
+Node0 Node1 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node0 Node3 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node1 Node2 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node1 Node4 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node2 Node5 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node3 Node4 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node3 Node6 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node4 Node5 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node4 Node7 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node5 Node8 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node6 Node7 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+Node7 Node8 1Mbps 1 10ms ns3::RedQueue,MeanPktSize=100
+
diff --git a/examples/topologies/topo-load-balancer.txt b/examples/topologies/topo-load-balancer.txt
index f05ec96..15cee4c 100644
--- a/examples/topologies/topo-load-balancer.txt
+++ b/examples/topologies/topo-load-balancer.txt
@@ -1,23 +1,23 @@
# topo-load-balancer.txt
#
-# /----\
-# |CSU |
-# <----> |HUB | <---->
-# ^ \----/ ^
+# /-----\
+# | CSU |
+# +-----> | HUB | <----+
+# | \-----/ |
# | | 1Mbps/10ms delay
# v v
-# /----\ /--------\
-# |UCLA| |Consumer|
-# | HUB| | CSU-1 |
-# <----> \----/ <----> \--------/
-# ^ ^
-# | |
-# v v
-# /--------\ /--------\
-# |Producer| |Producer|
-# | UCLA-1 | | UCLA-2 |
-# \--------/ \--------/
+# /------\ /----------\
+# | UCLA | | Consumer |
+# | HUB | | CSU-1 |
+# +-----> \------/ <-----+ \----------/
+# | |
+# | |
+# v v
+# /----------\ /----------\
+# | Producer | | Producer |
+# | UCLA-1 | | UCLA-2 |
+# \----------/ \----------/
#
# any empty lines and lines starting with '#' symbol is ignored