examples: Modifying examples to work with the new codebase
diff --git a/examples/custom-apps/custom-app.cpp b/examples/custom-apps/custom-app.cpp
index 62cacc4..b081c27 100644
--- a/examples/custom-apps/custom-app.cpp
+++ b/examples/custom-apps/custom-app.cpp
@@ -26,9 +26,8 @@
#include "ns3/simulator.h"
#include "ns3/packet.h"
-#include "ns3/ndn-app-face.hpp"
+#include "ns3/ndnSIM/helper/ndn-fib-helper.hpp"
-#include "ns3/ndn-fib.hpp"
#include "ns3/random-variable.h"
NS_LOG_COMPONENT_DEFINE("CustomApp");
@@ -52,22 +51,17 @@
// initialize ndn::App
ndn::App::StartApplication();
+ Simulator::Schedule(Seconds(1.0), &CustomApp::SendInterest, this);
+
// Create a name components object for name ``/prefix/sub``
- Ptr<ndn::Name> prefix = Create<ndn::Name>(); // now prefix contains ``/``
- prefix->append("prefix"); // now prefix contains ``/prefix``
- prefix->append("sub"); // now prefix contains ``/prefix/sub``
-
- /////////////////////////////////////////////////////////////////////////////
- // Creating FIB entry that ensures that we will receive incoming Interests //
- /////////////////////////////////////////////////////////////////////////////
-
- // Get FIB object
- Ptr<ndn::Fib> fib = GetNode()->GetObject<ndn::Fib>();
+ 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
- // Note that ``m_face`` is cretaed by ndn::App
- Ptr<ndn::fib::Entry> fibEntry = fib->Add(*prefix, m_face, 0);
+ ndn::FibHelper::AddRoute(node, *prefix, m_face, 0);
+ // Schedule send of first interest
Simulator::Schedule(Seconds(1.0), &CustomApp::SendInterest, this);
}
@@ -86,55 +80,53 @@
// Sending one Interest packet out //
/////////////////////////////////////
- Ptr<ndn::Name> prefix = Create<ndn::Name>("/prefix/sub"); // another way to create name
+ auto prefix = make_shared<Name>("/prefix/sub"); // another way to create name
// Create and configure ndn::Interest
- Ptr<ndn::Interest> interest = Create<ndn::Interest>();
+ auto interest = make_shared<Interest>();
UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
- interest->SetNonce(rand.GetValue());
- interest->SetName(prefix);
- interest->SetInterestLifetime(Seconds(1.0));
+ interest->setNonce(rand.GetValue());
+ interest->setName(*prefix);
+ interest->setInterestLifetime(time::seconds(1));
NS_LOG_DEBUG("Sending Interest packet for " << *prefix);
// Call trace (for logging purposes)
m_transmittedInterests(interest, this, m_face);
- m_face->ReceiveInterest(interest);
+ m_face->onReceiveInterest(*interest);
}
// Callback that will be called when Interest arrives
void
-CustomApp::OnInterest(Ptr<const ndn::Interest> interest)
+CustomApp::OnInterest(shared_ptr<const ndn::Interest> interest)
{
ndn::App::OnInterest(interest);
- NS_LOG_DEBUG("Received Interest packet for " << interest->GetName());
-
- // Create and configure ndn::Data and ndn::DataTail
- // (header is added in front of the packet, tail is added at the end of the packet)
+ NS_LOG_DEBUG("Received Interest packet for " << interest->getName());
// Note that Interests send out by the app will not be sent back to the app !
- Ptr<ndn::Data> data = Create<ndn::Data>(Create<Packet>(1024));
- data->SetName(
- Create<ndn::Name>(interest->GetName())); // data will have the same name as Interests
+ 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);
- NS_LOG_DEBUG("Sending Data packet for " << data->GetName());
+ NS_LOG_DEBUG("Sending Data packet for " << data->getName());
// Call trace (for logging purposes)
m_transmittedDatas(data, this, m_face);
- m_face->ReceiveData(data);
+ m_face->onReceiveData(*data);
}
// Callback that will be called when Data arrives
void
-CustomApp::OnData(Ptr<const ndn::Data> contentObject)
+CustomApp::OnData(shared_ptr<const ndn::Data> contentObject)
{
- NS_LOG_DEBUG("Receiving Data packet for " << contentObject->GetName());
+ NS_LOG_DEBUG("Receiving Data packet for " << contentObject->getName());
- std::cout << "DATA received for name " << contentObject->GetName() << std::endl;
+ std::cout << "DATA received for name " << contentObject->getName() << std::endl;
}
} // namespace ns3
diff --git a/examples/custom-apps/custom-app.hpp b/examples/custom-apps/custom-app.hpp
index 7dca200..8d90f40 100644
--- a/examples/custom-apps/custom-app.hpp
+++ b/examples/custom-apps/custom-app.hpp
@@ -25,7 +25,7 @@
#include "ns3/ndnSIM/model/ndn-common.hpp"
-#include "ns3/ndn-app.hpp"
+#include "ns3/ndnSIM/apps/ndn-app.hpp"
namespace ns3 {
@@ -55,11 +55,11 @@
// (overridden from ndn::App) Callback that will be called when Interest arrives
virtual void
- OnInterest(Ptr<const ndn::Interest> interest);
+ OnInterest(shared_ptr<const ndn::Interest> interest);
// (overridden from ndn::App) Callback that will be called when Data arrives
virtual void
- OnData(Ptr<const ndn::Data> contentObject);
+ OnData(shared_ptr<const ndn::Data> contentObject);
private:
void
diff --git a/examples/custom-apps/dumb-requester.cpp b/examples/custom-apps/dumb-requester.cpp
index 8850e18..44ec204 100644
--- a/examples/custom-apps/dumb-requester.cpp
+++ b/examples/custom-apps/dumb-requester.cpp
@@ -85,14 +85,12 @@
// Sending one Interest packet out //
/////////////////////////////////////
- Ptr<ndn::Name> prefix = Create<ndn::Name>(m_name); // another way to create name
-
// Create and configure ndn::Interest
- Ptr<ndn::Interest> interest = Create<ndn::Interest>();
+ auto interest = make_shared<ndn::Interest>(*m_name);
UniformVariable rand(0, std::numeric_limits<uint32_t>::max());
- interest->SetNonce(rand.GetValue());
- interest->SetName(prefix);
- interest->SetInterestLifetime(Seconds(1.0));
+ interest->setNonce(rand.GetValue());
+ interest->setName(*prefix);
+ interest->setInterestLifetime(time::seconds(1));
NS_LOG_DEBUG("Sending Interest packet for " << *prefix);
@@ -100,15 +98,15 @@
m_transmittedInterests(interest, this, m_face);
// Forward packet to lower (network) layer
- m_face->ReceiveInterest(interest);
+ m_face->onReceiveInterest(*interest);
Simulator::Schedule(Seconds(1.0), &DumbRequester::SendInterest, this);
}
void
-DumbRequester::OnData(Ptr<const ndn::Data> contentObject)
+DumbRequester::OnData(shared_ptr<const ndn::Data> contentObject)
{
- NS_LOG_DEBUG("Receiving Data packet for " << contentObject->GetName());
+ NS_LOG_DEBUG("Receiving Data packet for " << contentObject->getName());
}
} // namespace ns3
diff --git a/examples/custom-apps/dumb-requester.hpp b/examples/custom-apps/dumb-requester.hpp
index 0091c25..a1f9427 100644
--- a/examples/custom-apps/dumb-requester.hpp
+++ b/examples/custom-apps/dumb-requester.hpp
@@ -25,7 +25,7 @@
#include "ns3/ndnSIM/model/ndn-common.hpp"
-#include "ns3/ndn-app.hpp"
+#include "ns3/ndnSIM/apps/ndn-app.hpp"
namespace ns3 {
@@ -52,7 +52,7 @@
// (overridden from ndn::App) Callback that will be called when Data arrives
virtual void
- OnData(Ptr<const ndn::Data> contentObject);
+ OnData(shared_ptr<const ndn::Data> contentObject);
private:
void
diff --git a/examples/custom-apps/hijacker.cpp b/examples/custom-apps/hijacker.cpp
index 70e2d9e..eedd08f 100644
--- a/examples/custom-apps/hijacker.cpp
+++ b/examples/custom-apps/hijacker.cpp
@@ -17,11 +17,12 @@
*
* Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
*/
-
// hijacker.cc
#include "hijacker.hpp"
+#include "ns3/ndnSIM/helper/ndn-fib-helper.hpp"
+
NS_LOG_COMPONENT_DEFINE("Hijacker");
namespace ns3 {
@@ -42,12 +43,12 @@
}
void
-Hijacker::OnInterest(Ptr<const ndn::Interest> interest)
+Hijacker::OnInterest(shared_ptr<const ndn::Interest> interest)
{
ndn::App::OnInterest(interest); // forward call to perform app-level tracing
// do nothing else (hijack interest)
- NS_LOG_DEBUG("Do nothing for incoming interest for" << interest->GetName());
+ NS_LOG_DEBUG("Do nothing for incoming interest for" << interest->getName());
}
void
@@ -56,9 +57,7 @@
App::StartApplication();
// equivalent to setting interest filter for "/" prefix
- Ptr<ndn::Fib> fib = GetNode()->GetObject<ndn::Fib>();
- Ptr<ndn::fib::Entry> fibEntry = fib->Add(ndn::Name("/"), m_face, 0);
- fibEntry->UpdateStatus(m_face, ndn::fib::FaceMetric::NDN_FIB_GREEN);
+ ndn::FibHelper::AddRoute(GetNode(), "/", m_face, 0);
}
void
diff --git a/examples/custom-apps/hijacker.hpp b/examples/custom-apps/hijacker.hpp
index a794f12..73efad0 100644
--- a/examples/custom-apps/hijacker.hpp
+++ b/examples/custom-apps/hijacker.hpp
@@ -38,7 +38,7 @@
// Receive all Interests but do nothing in response
void
- OnInterest(Ptr<const ndn::Interest> interest);
+ OnInterest(shared_ptr<const ndn::Interest> interest);
protected:
// inherited from Application base class.