docs: New example on how to use custom strategy with 2-bottleneck topology
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index c1161d3..ddb4b26 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -105,6 +105,7 @@
.. literalinclude:: ../../examples/topologies/topo-grid-3x3.txt
:language: bash
:linenos:
+ :lines: 1-2,19-
:emphasize-lines: 8,24
@@ -175,6 +176,7 @@
.. literalinclude:: ../../examples/topologies/topo-6-node.txt
:language: bash
:linenos:
+ :lines: 1-2,15-
:emphasize-lines: 3,13
.. literalinclude:: ../../examples/ndn-congestion-topo-plugin.cc
@@ -184,3 +186,72 @@
:emphasize-lines: 15,21-22,29-34,41-47,52-62
.. :lines: 20-25,53-
+
+To run this scenario and see what is happening, use the following command::
+
+ NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
+
+.. _11-node 2-bottleneck topology with custom forwarding strategy:
+
+11-node 2-bottleneck topology with custom forwarding strategy
+-------------------------------------------------------------
+
+To effectively use the example :ref:`custom strategy <Writing your own custom strategy>`, we need to make sure that FIB entries contain at least two entries.
+In the current version of ndnSIM, this can be accomplished using manual route configuration.
+
+The following example illustrates how the strategy can be used in simulation scenario.
+
+Let us first define a meaningful topology:
+
+.. aafig::
+ :aspect: 60
+ :scale: 120
+
+ /------\ 0 0 /------\
+ | c1 |<-----+ +----->| p1 |
+ \------/ \ / \------/
+ \ /-----\ /
+ /------\ 0 \ +==>| r12 |<==+ / 0 /------\
+ | c2 |<--+ \ / \-----/ \ / +-->| p2 |
+ \------/ \ \ | | / / \------/
+ \ | | 1Mbps links | | /
+ \ 1 v0 v5 1v 2v 3 /
+ +->/------\ /------\<-+
+ 2| r1 |<===============>| r2 |4
+ +->\------/4 0\------/<-+
+ / 3^ ^5 \
+ / | | \
+ /------\ 0 / / \ \ 0 /------\
+ | c3 |<--+ / \ +-->| p3 |
+ \------/ / \ \------/
+ / "All consumer-router and" \
+ /------\ 0 / "router-producer links are" \ 0 /------\
+ | c4 |<-----+ "10Mbps" +---->| p4 |
+ \------/ \------/
+
+ "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link"
+ "definitions in the topology file"
+
+The corresponding topology file (``topo-11-node-two-bottlenecks.txt``):
+
+.. literalinclude:: ../../examples/topologies/topo-11-node-two-bottlenecks.txt
+ :language: bash
+ :linenos:
+ :lines: 1-2,28-
+
+Example simulation (``ndn-congestion-alt-topo-plugin.cc``) scenario that utilizes CustomStrategy forwarding strategy:
+
+.. literalinclude:: ../../examples/ndn-congestion-alt-topo-plugin.cc
+ :language: c++
+ :linenos:
+ :lines: 21-28,61-
+ :emphasize-lines: 16,21,49-50,65-79
+
+
+To run this scenario and see what is happening, use the following command::
+
+ NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin
+
+You can also run using visualizer module to verify that both bottleneck links are utilized::
+
+ ./waf --run=ndn-congestion-alt-topo-plugin --visualize
diff --git a/docs/source/fw.rst b/docs/source/fw.rst
index 21e3531..dd4176b 100644
--- a/docs/source/fw.rst
+++ b/docs/source/fw.rst
@@ -6,6 +6,8 @@
A new forwarding strategy can be implement completely different processing or override just specific actions/events of the :ndnsim:`forwarding strategy interface <ndn::ForwardingStrategy>`.
Please refer to :ndnsim:`API documentation <ndn::ForwardingStrategy>` of the forwarding strategy interface, which lists all default actions/events.
+.. _Writing your own custom strategy:
+
Writing your own custom strategy
++++++++++++++++++++++++++++++++
@@ -14,15 +16,16 @@
The follwoing are template strategy h/cc files:
-.. literalinclude:: _static/code-samples/custom-strategy.h
+.. literalinclude:: ../../examples/custom-strategies/custom-strategy.h
:language: c++
:linenos:
:lines: 1-36,51-55,59-
-.. literalinclude:: _static/code-samples/custom-strategy.cc
+.. literalinclude:: ../../examples/custom-strategies/custom-strategy.cc
:language: c++
:linenos:
:lines: 1-40,42-50,75-76,115-
+ :emphasize-lines: 21,27
After having the template, we can fill the necesasry functionality.
@@ -30,7 +33,7 @@
That is, if node has two or more alternative paths to forward the Interests, this Interest will be forwarded to the best two neighbors.
The following implementation of CustomStrategy::DoPropagateInterest accomplishes the task:
-.. literalinclude:: _static/code-samples/custom-strategy.cc
+.. literalinclude:: ../../examples/custom-strategies/custom-strategy.cc
:language: c++
:linenos:
:lines: 45-75
@@ -54,12 +57,19 @@
The highlighted ares of the following code demonstrates how it can be impelmented:
-.. literalinclude:: _static/code-samples/custom-strategy.h
+.. literalinclude:: ../../examples/custom-strategies/custom-strategy.h
:language: c++
:linenos:
:emphasize-lines: 37-50,56-58
-.. literalinclude:: _static/code-samples/custom-strategy.cc
+.. literalinclude:: ../../examples/custom-strategies/custom-strategy.cc
:language: c++
:linenos:
- :emphasize-lines: 41,51-74,77-114
+ :emphasize-lines: 41,77-114
+
+
+Example of using custom strategy
+++++++++++++++++++++++++++++++++
+
+Please refer to :ref:`this example <11-node 2-bottleneck topology with custom forwarding strategy>`.
+
diff --git a/docs/source/_static/code-samples/custom-strategy.cc b/examples/custom-strategies/custom-strategy.cc
similarity index 100%
rename from docs/source/_static/code-samples/custom-strategy.cc
rename to examples/custom-strategies/custom-strategy.cc
diff --git a/docs/source/_static/code-samples/custom-strategy.h b/examples/custom-strategies/custom-strategy.h
similarity index 100%
rename from docs/source/_static/code-samples/custom-strategy.h
rename to examples/custom-strategies/custom-strategy.h
diff --git a/examples/ndn-congestion-alt-topo-plugin.cc b/examples/ndn-congestion-alt-topo-plugin.cc
new file mode 100644
index 0000000..bb98008
--- /dev/null
+++ b/examples/ndn-congestion-alt-topo-plugin.cc
@@ -0,0 +1,139 @@
+/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2011-2012 University of California, Los Angeles
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+// ndn-congestion-alt-topo-plugin.cc
+
+#include "ns3/core-module.h"
+#include "ns3/network-module.h"
+#include "ns3/ndnSIM-module.h"
+
+using namespace ns3;
+
+/**
+ *
+ * /------\ 0 0 /------\
+ * | c1 |<-----+ +----->| p1 |
+ * \------/ \ / \------/
+ * \ /-----\ /
+ * /------\ 0 \ +==>| r12 |<==+ / 0 /------\
+ * | c2 |<--+ \ / \-----/ \ / +-->| p2 |
+ * \------/ \ \ | | / / \------/
+ * \ | | 1Mbps links | | /
+ * \ 1 v0 v5 1v 2v 3 /
+ * +->/------\ /------\<-+
+ * 2| r1 |<===============>| r2 |4
+ * +->\------/4 0\------/<-+
+ * / 3^ ^5 \
+ * / | | \
+ * /------\ 0 / / \ \ 0 /------\
+ * | c3 |<--+ / \ +-->| p3 |
+ * \------/ / \ \------/
+ * / "All consumer-router and" \
+ * /------\ 0 / "router-producer links are" \ 0 /------\
+ * | c4 |<-----+ "10Mbps" +---->| p4 |
+ * \------/ \------/
+ *
+ * "Numbers near nodes denote face IDs. Face ID is assigned based on the order of link"
+ * "definitions in the topology file"
+ *
+ * To run scenario and see what is happening, use the following command:
+ *
+ * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-alt-topo-plugin
+ */
+
+int
+main (int argc, char *argv[])
+{
+ CommandLine cmd;
+ cmd.Parse (argc, argv);
+
+ AnnotatedTopologyReader topologyReader ("", 1);
+ topologyReader.SetFileName ("src/ndnSIM/examples/topologies/topo-11-node-two-bottlenecks.txt");
+ topologyReader.Read ();
+
+ // Install CCNx stack on all nodes
+ ndn::StackHelper ccnxHelper;
+ ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::CustomStrategy");
+ ccnxHelper.SetContentStore ("ns3::ndn::cs::Lru",
+ "MaxSize", "1"); // ! Attention ! If set to 0, then MaxSize is infinite
+ ccnxHelper.InstallAll ();
+
+ // Getting containers for the consumer/producer
+ Ptr<Node> consumers[4] = { Names::Find<Node> ("c1"), Names::Find<Node> ("c2"), Names::Find<Node> ("c3"), Names::Find<Node> ("c4") };
+ Ptr<Node> producers[4] = { Names::Find<Node> ("p1"), Names::Find<Node> ("p2"), Names::Find<Node> ("p3"), Names::Find<Node> ("p4") };
+
+ if (consumers[0] == 0 || consumers[1] == 0 || consumers[2] == 0 || consumers[3] == 0 ||
+ producers[0] == 0 || producers[1] == 0 || producers[2] == 0 || producers[3] == 0)
+ {
+ NS_FATAL_ERROR ("Error in topology: one nodes c1, c2, c3, c4, p1, p2, p3, or p4 is missing");
+ }
+
+ for (int i = 0; i < 4; i++)
+ {
+ std::string prefix = "/data/"+Names::FindName (producers[i]);
+
+ /////////////////////////////////////////////////////////////////////////////////
+ // install consumer app on consumer node c_i to request data from producer p_i //
+ /////////////////////////////////////////////////////////////////////////////////
+
+ ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
+ consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 100 interests a second
+
+ consumerHelper.SetPrefix (prefix);
+ ApplicationContainer consumer = consumerHelper.Install (consumers[i]);
+ consumer.Start (Seconds (i)); // start consumers at 0s, 1s, 2s, 3s
+ consumer.Stop (Seconds (19-i)); // stop consumers at 19s, 18s, 17s, 16s
+
+ ///////////////////////////////////////////////
+ // install producer app on producer node p_i //
+ ///////////////////////////////////////////////
+
+ ndn::AppHelper producerHelper ("ns3::ndn::Producer");
+ producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
+
+ // install producer that will satisfy Interests in /dst1 namespace
+ producerHelper.SetPrefix (prefix);
+ ApplicationContainer producer = producerHelper.Install (producers[i]);
+ // when Start/Stop time is not specified, the application is running throughout the simulation
+ }
+
+ // Manually configure FIB routes
+ ndn::StackHelper::AddRoute ("c1", "/data", 0, 1); // link to n1
+ ndn::StackHelper::AddRoute ("c2", "/data", 0, 1); // link to n1
+ ndn::StackHelper::AddRoute ("c3", "/data", 0, 1); // link to n1
+ ndn::StackHelper::AddRoute ("c4", "/data", 0, 1); // link to n1
+
+ ndn::StackHelper::AddRoute ("n1", "/data", 4, 1); // link to n2
+ ndn::StackHelper::AddRoute ("n1", "/data", 5, 2); // link to n12
+
+ ndn::StackHelper::AddRoute ("n12", "/data", 1, 2); // link to n2
+
+ ndn::StackHelper::AddRoute ("n2", "/data/p1", 2, 2); // link to p1
+ ndn::StackHelper::AddRoute ("n2", "/data/p2", 3, 2); // link to p2
+ ndn::StackHelper::AddRoute ("n2", "/data/p3", 4, 2); // link to p3
+ ndn::StackHelper::AddRoute ("n2", "/data/p4", 5, 2); // link to p4
+
+ // Schedule simulation time and run the simulation
+ Simulator::Stop (Seconds (20.0));
+ Simulator::Run ();
+ Simulator::Destroy ();
+
+ return 0;
+}
diff --git a/examples/ccnx-simple-with-pcap.cc b/examples/ndn-simple-with-pcap.cc
similarity index 100%
rename from examples/ccnx-simple-with-pcap.cc
rename to examples/ndn-simple-with-pcap.cc
diff --git a/examples/wscript b/examples/wscript
index 31127c9..5c478a7 100644
--- a/examples/wscript
+++ b/examples/wscript
@@ -6,9 +6,6 @@
obj = bld.create_ns3_program('ndn-grid', ['ndnSIM', 'point-to-point-layout'])
obj.source = 'ndn-grid.cc'
-
- obj = bld.create_ns3_program('trie', ['ndnSIM'])
- obj.source = 'trie.cc'
if 'topology' in bld.env['NDN_plugins']:
obj = bld.create_ns3_program('ndn-grid-topo-plugin', ['ndnSIM'])
@@ -16,3 +13,9 @@
obj = bld.create_ns3_program('ndn-congestion-topo-plugin', ['ndnSIM'])
obj.source = 'ndn-congestion-topo-plugin.cc'
+
+ obj = bld.create_ns3_program('ndn-congestion-alt-topo-plugin', ['ndnSIM'])
+ obj.source = [
+ 'custom-strategies/custom-strategy.cc',
+ 'ndn-congestion-alt-topo-plugin.cc'
+ ]