docs: New example on how to use custom strategy with 2-bottleneck topology
diff --git a/examples/custom-strategies/custom-strategy.cc b/examples/custom-strategies/custom-strategy.cc
new file mode 100644
index 0000000..3b1cea1
--- /dev/null
+++ b/examples/custom-strategies/custom-strategy.cc
@@ -0,0 +1,117 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+// custom-strategy.cc
+
+#include "custom-strategy.h"
+#include "ns3/ndn-fib.h"
+#include "ns3/ndn-fib-entry.h"
+#include "ns3/ndn-pit-entry.h"
+#include "ns3/ndn-interest.h"
+
+namespace ns3 {
+namespace ndn {
+namespace fw {
+
+NS_OBJECT_ENSURE_REGISTERED(CustomStrategy);
+
+LogComponent CustomStrategy::g_log = LogComponent (CustomStrategy::GetLogName ().c_str ());
+
+std::string
+CustomStrategy::GetLogName ()
+{
+ return "ndn.fw.CustomStrategy";
+}
+
+TypeId
+CustomStrategy::GetTypeId (void)
+{
+ static TypeId tid = TypeId ("ns3::ndn::fw::CustomStrategy")
+ .SetGroupName ("Ndn")
+ .SetParent <BaseStrategy> ()
+ .AddConstructor <CustomStrategy> ()
+
+ // .AddAttribute ("Attribute", "Attribute spec",
+ // StringValue ("DefaultValue"),
+ // MakeStringAccessor (&BaseStrategy::m_variable),
+ // MakeStringChecker ())
+ ;
+ return tid;
+}
+
+CustomStrategy::CustomStrategy ()
+ : m_counter (0)
+{
+}
+
+bool
+CustomStrategy::DoPropagateInterest (Ptr<Face> inFace,
+ Ptr<const InterestHeader> header,
+ Ptr<const Packet> origPacket,
+ Ptr<pit::Entry> pitEntry)
+{
+ typedef fib::FaceMetricContainer::type::index<fib::i_metric>::type FacesByMetric;
+ FacesByMetric &faces = pitEntry->GetFibEntry ()->m_faces.get<fib::i_metric> ();
+ FacesByMetric::iterator faceIterator = faces.begin ();
+
+ int propagatedCount = 0;
+
+ // forward to best-metric face
+ if (faceIterator != faces.end ())
+ {
+ if (TrySendOutInterest (inFace, faceIterator->m_face, header, origPacket, pitEntry))
+ propagatedCount ++;
+
+ faceIterator ++;
+ }
+
+ // forward to second-best-metric face
+ if (faceIterator != faces.end ())
+ {
+ if (TrySendOutInterest (inFace, faceIterator->m_face, header, origPacket, pitEntry))
+ propagatedCount ++;
+
+ faceIterator ++;
+ }
+ return propagatedCount > 0;
+}
+
+void
+CustomStrategy::DidSendOutInterest (Ptr<Face> outFace,
+ Ptr<const InterestHeader> header,
+ Ptr<const Packet> origPacket,
+ Ptr<pit::Entry> pitEntry)
+{
+ m_counter ++;
+}
+
+void
+CustomStrategy::WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry)
+{
+ for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
+ face != pitEntry->GetOutgoing ().end ();
+ face ++)
+ {
+ m_counter --;
+ }
+
+ BaseStrategy::WillEraseTimedOutPendingInterest (pitEntry);
+}
+
+
+void
+CustomStrategy::WillSatisfyPendingInterest (Ptr<Face> inFace,
+ Ptr<pit::Entry> pitEntry)
+{
+ for (pit::Entry::out_container::iterator face = pitEntry->GetOutgoing ().begin ();
+ face != pitEntry->GetOutgoing ().end ();
+ face ++)
+ {
+ m_counter --;
+ }
+
+ BaseStrategy::WillSatisfyPendingInterest (inFace, pitEntry);
+}
+
+
+} // namespace fw
+} // namespace ndn
+} // namespace ns3
diff --git a/examples/custom-strategies/custom-strategy.h b/examples/custom-strategies/custom-strategy.h
new file mode 100644
index 0000000..4a4476d
--- /dev/null
+++ b/examples/custom-strategies/custom-strategy.h
@@ -0,0 +1,67 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+
+// custom-strategy.h
+
+#ifndef CUSTOM_STRATEGY_H
+#define CUSTOM_STRATEGY_H
+
+#include "ns3/log.h"
+#include "ns3/ndn-forwarding-strategy.h"
+#include "ns3/ndn-l3-protocol.h"
+
+namespace ns3 {
+namespace ndn {
+namespace fw {
+
+typedef ForwardingStrategy BaseStrategy;
+
+class CustomStrategy:
+ public BaseStrategy
+{
+public:
+ static TypeId
+ GetTypeId ();
+
+ static std::string
+ GetLogName ();
+
+ CustomStrategy ();
+
+protected:
+ virtual bool
+ DoPropagateInterest (Ptr<Face> incomingFace,
+ Ptr<const InterestHeader> header,
+ Ptr<const Packet> origPacket,
+ Ptr<pit::Entry> pitEntry);
+
+public:
+ virtual void
+ DidSendOutInterest (Ptr<Face> outFace,
+ Ptr<const InterestHeader> header,
+ Ptr<const Packet> origPacket,
+ Ptr<pit::Entry> pitEntry);
+
+ virtual void
+ WillEraseTimedOutPendingInterest (Ptr<pit::Entry> pitEntry);
+
+ virtual void
+ WillSatisfyPendingInterest (Ptr<Face> inFace,
+ Ptr<pit::Entry> pitEntry);
+
+protected:
+ static LogComponent g_log;
+
+// private:
+// std::string m_variable;
+
+private:
+ uint32_t m_counter;
+};
+
+
+
+} // namespace fw
+} // namespace ndn
+} // namespace ns3
+
+#endif // 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'
+ ]