helper+docs+examples: New helper to simplify link failing
Thanks to Saran Tarnoi for providing base implementation of the code
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index be27f0b..41142c9 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -6,6 +6,9 @@
.. note::
:red:`!!! This page only shows up examples of how to config topology and perform basic operations in ndnSIM (an example equivalent to "Hello, world1") !!! These are **NOT** examples of real experimentations (just like "Hello, world!" is not a real program).`
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
.. _simple-scenario:
Simple scenario
@@ -46,6 +49,9 @@
NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
.. _9-node-grid-example:
9-node grid example
@@ -95,6 +101,9 @@
NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
.. _9-node-grid-example-using-topology-plugin:
9-node grid example using topology plugin
@@ -155,6 +164,8 @@
NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
6-node bottleneck topology
--------------------------
@@ -195,6 +206,9 @@
NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
.. _11-node 2-bottleneck topology with custom forwarding strategy:
11-node 2-bottleneck topology with custom forwarding strategy
@@ -260,6 +274,9 @@
./waf --run=ndn-congestion-alt-topo-plugin --visualize
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
3-level binary tree with packet-level trace helpers
---------------------------------------------------
@@ -309,6 +326,33 @@
tcpdump -r ndn-simple-trace.pcap
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
+.. _Simple scenario with link failures:
+
+Simple scenario with link failures
+----------------------------------
+
+The following example (``ndn-simple-with-link-failure.cc``) shows how to "fail" links in ndnSIM simulation.
+The basic idea is to set ndn::Faces that correspond to the failed link to DOWN state.
+ndnSIM now includes a simple helper that simplifies this process.
+
+.. literalinclude:: ../../examples/ndn-simple-with-link-failure.cc
+ :language: c++
+ :linenos:
+ :lines: 21-31,52-
+ :emphasize-lines: 54-56
+
+If this code is placed into ``scratch/ndn-simple-with-link-failure.cc`` and NS-3 is compiled in debug mode, you can run and see progress of the
+simulation using the following command (in optimized mode nothing will be printed out)::
+
+ NS_LOG=ndn.Consumer:ndn.Producer:ndn.LinkControlHelper ./waf --run=ndn-simple-with-link-failure
+
+.. note::
+ If you compiled ndnSIM with examples (``./waf configure --enable-examples``) you can directly run the example without putting scenario into ``scratch/`` folder.
+
+
25-node tree topology with L2Tracer
-----------------------------------
diff --git a/docs/source/faq.rst b/docs/source/faq.rst
index c660492..a7ce4bd 100644
--- a/docs/source/faq.rst
+++ b/docs/source/faq.rst
@@ -133,47 +133,7 @@
Right now, NS-3 does not provide ability to actually "break" the link between nodes in NS-3.
However, exactly the same effect can be achieved by making an interface (:ndnsim:`ndn::Face`) up or down (:ndnsim:`ndn::Face::SetUp(true)` or :ndnsim:`ndn::Face::SetUp(false)`).
-Here is an example of function to "fail" a point-to-point link between two NDN nodes:
-
-.. code-block:: c++
-
- // hijacker is more than an application. just disable all faces
- void
- FailLinks (Ptr<Node> node1, Ptr<Node> node2)
- {
- Ptr<ndn::L3Protocol> ndn1 = node1->GetObject<ndn::L3Protocol> ();
- Ptr<ndn::L3Protocol> ndn2 = node2->GetObject<ndn::L3Protocol> ();
-
- // iterate over all faces to find the right one
- for (uint32_t faceId = 0; faceId < ndn1->GetNFaces (); faceId++)
- {
- Ptr<ndn::NetDeviceFace> ndFace = ndn1->GetFace (faceId)->GetObject<ndn::NetDeviceFace> ();
- if (ndFace == 0) continue;
-
- Ptr<PointToPointNetDevice> nd1 = ndFace->GetNetDevice ()->GetObject<PointToPointNetDevice> ();
- if (nd1 == 0) continue;
-
- Ptr<Channel> channel = nd1->GetChannel ();
- if (channel == 0) continue;
-
- Ptr<PointToPointChannel> ppChannel = DynamicCast<PointToPointChannel> (channel);
-
- Ptr<NetDevice> nd2 = ppChannel->GetDevice (0);
- if (nd2->GetNode () == node1)
- nd2 = ppChannel->GetDevice (1);
-
- if (nd2->GetNode () == node2)
- {
- Ptr<ndn::Face> face1 = ndn1->GetFaceByNetDevice (nd1);
- Ptr<ndn::Face> face2 = ndn2->GetFaceByNetDevice (nd2);
-
- face1->SetUp (false);
- face2->SetUp (false);
- break;
- }
- }
- }
-
+You can use :ndnsim:`ndn::LinkControlHelper` to schedule failing links. For example, refer to :ref:`Simple scenario with link failures` example.
General questions
-----------------