Skip to content

Commit

Permalink
model+apps: Replace AppFace with AppFaceModel and relevant changes in…
Browse files Browse the repository at this point in the history
… ndn::App

Change-Id: I59faedaadf9d054ae22d813a4ce41f1f30b9321c
Refs: #3560
  • Loading branch information
cawka committed Sep 11, 2016
1 parent ca3c67e commit c018a56
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 76 deletions.
20 changes: 18 additions & 2 deletions apps/ndn-app.cpp
Expand Up @@ -23,7 +23,8 @@
#include "ns3/packet.h"

#include "model/ndn-l3-protocol.hpp"
#include "model/ndn-app-face.hpp"
#include "model/ndn-app-link-service.hpp"
#include "model/null-transport.hpp"

NS_LOG_COMPONENT_DEFINE("ndn.App");

Expand Down Expand Up @@ -115,6 +116,15 @@ App::OnData(shared_ptr<const Data> data)
m_receivedDatas(data, this, m_face);
}

void
App::OnNack(shared_ptr<const lp::Nack> nack)
{
NS_LOG_FUNCTION(this << nack);

// @TODO Implement
// m_receivedDatas(data, this, m_face);
}

// Application Methods
void
App::StartApplication() // Called at time specified by Start
Expand All @@ -128,7 +138,13 @@ App::StartApplication() // Called at time specified by Start
"Ndn stack should be installed on the node " << GetNode());

// step 1. Create a face
m_face = std::make_shared<AppFace>(this);
auto appLink = make_unique<AppLinkService>(this);
auto transport = make_unique<NullTransport>("appFace://", "appFace://",
::ndn::nfd::FACE_SCOPE_LOCAL);
// @TODO Consider making AppTransport instead
m_face = std::make_shared<Face>(std::move(appLink), std::move(transport));
m_appLink = static_cast<AppLinkService*>(m_face->getLinkService());
m_face->setMetric(1);

// step 2. Add face to the Ndn stack
GetNode()->GetObject<L3Protocol>()->addFace(m_face);
Expand Down
25 changes: 16 additions & 9 deletions apps/ndn-app.hpp
Expand Up @@ -21,7 +21,8 @@
#define NDN_APP_H

#include "ns3/ndnSIM/model/ndn-common.hpp"
#include "ns3/ndnSIM/model/ndn-app-face.hpp"
#include "ns3/ndnSIM/model/ndn-app-link-service.hpp"
#include "ns3/ndnSIM/NFD/daemon/face/face.hpp"

#include "ns3/application.h"
#include "ns3/ptr.h"
Expand Down Expand Up @@ -63,26 +64,26 @@ class App : public Application {

/**
* @brief Method that will be called every time new Interest arrives
* @param interest Interest header
* @param packet "Payload" of the interests packet. The actual payload should be zero, but
* packet itself
* may be useful to get packet tags
*/
virtual void
OnInterest(shared_ptr<const Interest> interest);

/**
* @brief Method that will be called every time new Data arrives
* @param contentObject Data header
* @param payload payload (potentially virtual) of the Data packet (may include packet tags of
* original packet)
*/
virtual void
OnData(shared_ptr<const Data> data);

/**
* @brief Method that will be called every time new Nack arrives
*/
virtual void
OnNack(shared_ptr<const lp::Nack> nack);

public:
typedef void (*InterestTraceCallback)(shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>);
typedef void (*DataTraceCallback)(shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>);
// @TODO add NACK

protected:
virtual void
Expand All @@ -100,7 +101,9 @@ class App : public Application {

protected:
bool m_active; ///< @brief Flag to indicate that application is active (set by StartApplication and StopApplication)
shared_ptr<AppFace> m_face; ///< @brief automatically created application face through which application communicates
shared_ptr<Face> m_face;
AppLinkService* m_appLink;

uint32_t m_appId;

TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
Expand All @@ -109,11 +112,15 @@ class App : public Application {
TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
m_receivedDatas; ///< @brief App-level trace of received Data

// @TODO add NACK

TracedCallback<shared_ptr<const Interest>, Ptr<App>, shared_ptr<Face>>
m_transmittedInterests; ///< @brief App-level trace of transmitted Interests

TracedCallback<shared_ptr<const Data>, Ptr<App>, shared_ptr<Face>>
m_transmittedDatas; ///< @brief App-level trace of transmitted Data

// @TODO add NACK
};

} // namespace ndn
Expand Down
50 changes: 28 additions & 22 deletions model/ndn-app-face.cpp → model/ndn-app-link-service.cpp
Expand Up @@ -17,7 +17,7 @@
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

#include "ndn-app-face.hpp"
#include "ndn-app-link-service.hpp"

#include "ns3/log.h"
#include "ns3/packet.h"
Expand All @@ -27,64 +27,70 @@

#include "apps/ndn-app.hpp"

NS_LOG_COMPONENT_DEFINE("ndn.AppFace");
NS_LOG_COMPONENT_DEFINE("ndn.AppLinkService");

namespace ns3 {
namespace ndn {

AppFace::AppFace(Ptr<App> app)
: LocalFace(FaceUri("appFace://"), FaceUri("appFace://"))
, m_node(app->GetNode())
AppLinkService::AppLinkService(Ptr<App> app)
: m_node(app->GetNode())
, m_app(app)
{
NS_LOG_FUNCTION(this << app);

NS_ASSERT(m_app != 0);
}

AppFace::~AppFace()
AppLinkService::~AppLinkService()
{
NS_LOG_FUNCTION_NOARGS();
}

void
AppFace::close()
{
this->fail("Close connection");
}

void
AppFace::sendInterest(const Interest& interest)
AppLinkService::doSendInterest(const Interest& interest)
{
NS_LOG_FUNCTION(this << &interest);

this->emitSignal(onSendInterest, interest);

// to decouple callbacks
Simulator::ScheduleNow(&App::OnInterest, m_app, interest.shared_from_this());
}

void
AppFace::sendData(const Data& data)
AppLinkService::doSendData(const Data& data)
{
NS_LOG_FUNCTION(this << &data);

this->emitSignal(onSendData, data);

// to decouple callbacks
Simulator::ScheduleNow(&App::OnData, m_app, data.shared_from_this());
}

void
AppFace::onReceiveInterest(const Interest& interest)
AppLinkService::doSendNack(const lp::Nack& nack)
{
NS_LOG_FUNCTION(this << &nack);

// to decouple callbacks
// Simulator::ScheduleNow(&App::OnNack, m_app, nack.shared_from_this());
}

//

void
AppLinkService::onReceiveInterest(const Interest& interest)
{
this->receiveInterest(interest);
}

void
AppLinkService::onReceiveData(const Data& data)
{
this->emitSignal(onReceiveInterest, interest);
this->receiveData(data);
}

void
AppFace::onReceiveData(const Data& data)
AppLinkService::onReceiveNack(const lp::Nack& nack)
{
this->emitSignal(onReceiveData, data);
this->receiveNack(nack);
}

} // namespace ndn
Expand Down
63 changes: 29 additions & 34 deletions model/ndn-app-face.hpp → model/ndn-app-link-service.hpp
Expand Up @@ -17,12 +17,11 @@
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef NDN_APP_FACE_H
#define NDN_APP_FACE_H
#ifndef NDN_APP_LINK_SERVICE_HPP
#define NDN_APP_LINK_SERVICE_HPP

#include "ns3/ndnSIM/model/ndn-common.hpp"
#include "ns3/ndnSIM/NFD/daemon/face/local-face.hpp"
#include "ns3/ndnSIM/model/ndn-face.hpp"
#include "ns3/ndnSIM/NFD/daemon/face/link-service.hpp"

namespace ns3 {

Expand All @@ -35,50 +34,46 @@ class App;

/**
* \ingroup ndn-face
* \brief Implementation of application Ndn face
* \brief Implementation of LinkService for ndnSIM application
*
* This class defines basic functionality of Ndn face. Face is core
* component responsible for actual delivery of data packet to and
* from Ndn stack
*
* \see AppFace, NdnNetDeviceFace
* \see NetDeviceLinkService
*/
class AppFace : public nfd::LocalFace {
class AppLinkService : public nfd::face::LinkService
{
public:
/**
* \brief Default constructor
*/
AppFace(Ptr<App> app);

virtual ~AppFace();

public: // from nfd::Face
/**
* @brief Send Interest towards application
*/
virtual void
sendInterest(const Interest& interest);
AppLinkService(Ptr<App> app);

/**
* @brief Send Data towards application
*/
virtual void
sendData(const Data& data);
virtual ~AppLinkService();

/**
* @brief Send Interest towards NFD
*/
public:
void
onReceiveInterest(const Interest& interest);

/**
* @brief Send Data towards NFD
*/
void
onReceiveData(const Data& data);

void
onReceiveNack(const lp::Nack& nack);

private:
virtual void
doSendInterest(const Interest& interest) override;

virtual void
doSendData(const Data& data) override;

virtual void
doSendNack(const lp::Nack& nack) override;

virtual void
close();
doReceivePacket(nfd::face::Transport::Packet&& packet) override
{
// does nothing (all operations for now handled by LinkService)
BOOST_ASSERT(false);
}

private:
Ptr<Node> m_node;
Expand All @@ -88,4 +83,4 @@ class AppFace : public nfd::LocalFace {
} // namespace ndn
} // namespace ns3

#endif // NDN_APP_FACE_H
#endif // NDN_APP_LINK_SERVICE_HPP
1 change: 0 additions & 1 deletion utils/tracers/ndn-l3-tracer.hpp
Expand Up @@ -21,7 +21,6 @@
#define NDN_L3_TRACER_H

#include "ns3/ndnSIM/model/ndn-common.hpp"
#include "ns3/ndnSIM/model/ndn-face.hpp"

#include "ns3/ptr.h"
#include "ns3/simple-ref-count.h"
Expand Down
11 changes: 3 additions & 8 deletions wscript
Expand Up @@ -138,13 +138,8 @@ def build(bld):
module_dirs = ['apps', 'helper', 'model', 'utils']
module.source = bld.path.ant_glob(['%s/**/*.cpp' % dir for dir in module_dirs],
excl=[
'apps/*',
'model/ndn-app-face.cpp',
'model/ndn-app-link-service.cpp',
'helper/ndn-app-helper.cpp',
'helper/ndn-scenario-helper.cpp',
'utils/topology/*',
'utils/tracers/*',
'apps/ndn-consumer*.cpp',
'apps/ndn-producer*.cpp',
'model/ip-faces/*']) + ndnCxxSrc + nfdSrc

module_dirs = ['NFD/core', 'NFD/daemon', 'NFD/rib', 'apps', 'helper', 'model', 'utils']
Expand All @@ -159,7 +154,7 @@ def build(bld):
if bld.env.ENABLE_TESTS:
bld.recurse('tests')

# bld.ns3_python_bindings()
bld.ns3_python_bindings()

@TaskGen.feature('ns3fullmoduleheaders')
@TaskGen.after_method('process_rule')
Expand Down

0 comments on commit c018a56

Please sign in to comment.