NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndn-app.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "ndn-app.hpp"
21 #include "ns3/log.h"
22 #include "ns3/assert.h"
23 #include "ns3/packet.h"
24 
26 #include "model/ndn-app-face.hpp"
27 
28 NS_LOG_COMPONENT_DEFINE("ndn.App");
29 
30 namespace ns3 {
31 namespace ndn {
32 
34 
35 TypeId
37 {
38  static TypeId tid = TypeId("ns3::ndn::App")
39  .SetGroupName("Ndn")
40  .SetParent<Application>()
41  .AddConstructor<App>()
42 
43  .AddTraceSource("ReceivedInterests", "ReceivedInterests",
44  MakeTraceSourceAccessor(&App::m_receivedInterests))
45 
46  .AddTraceSource("ReceivedDatas", "ReceivedDatas",
47  MakeTraceSourceAccessor(&App::m_receivedDatas))
48 
49  .AddTraceSource("TransmittedInterests", "TransmittedInterests",
50  MakeTraceSourceAccessor(&App::m_transmittedInterests))
51 
52  .AddTraceSource("TransmittedDatas", "TransmittedDatas",
53  MakeTraceSourceAccessor(&App::m_transmittedDatas));
54  return tid;
55 }
56 
58  : m_active(false)
59  , m_face(0)
60 {
61 }
62 
64 {
65 }
66 
67 void
69 {
70  NS_LOG_FUNCTION_NOARGS();
71 
72  // Unfortunately, this causes SEGFAULT
73  // The best reason I see is that apps are freed after ndn stack is removed
74  // StopApplication ();
75  Application::DoDispose();
76 }
77 
78 uint32_t
79 App::GetId() const
80 {
81  if (m_face == 0)
82  return (uint32_t)-1;
83  else
84  return m_face->getId();
85 }
86 
87 void
88 App::OnInterest(shared_ptr<const Interest> interest)
89 {
90  NS_LOG_FUNCTION(this << interest);
91  m_receivedInterests(interest, this, m_face);
92 }
93 
94 void
95 App::OnData(shared_ptr<const Data> data)
96 {
97  NS_LOG_FUNCTION(this << data);
98  m_receivedDatas(data, this, m_face);
99 }
100 
101 // Application Methods
102 void
103 App::StartApplication() // Called at time specified by Start
104 {
105  NS_LOG_FUNCTION_NOARGS();
106 
107  NS_ASSERT(m_active != true);
108  m_active = true;
109 
110  NS_ASSERT_MSG(GetNode()->GetObject<L3Protocol>() != 0,
111  "Ndn stack should be installed on the node " << GetNode());
112 
113  // step 1. Create a face
114  m_face = std::make_shared<AppFace>(this);
115 
116  // step 2. Add face to the Ndn stack
117  GetNode()->GetObject<L3Protocol>()->addFace(m_face);
118 }
119 
120 void
121 App::StopApplication() // Called at time specified by Stop
122 {
123  NS_LOG_FUNCTION_NOARGS();
124 
125  if (!m_active)
126  return; // don't assert here, just return
127 
128  m_active = false;
129 
130  m_face->close();
131 }
132 
133 } // namespace ndn
134 } // namespace ns3
virtual void StopApplication()
Called at time specified by Stop.
Definition: ndn-app.cpp:121
virtual ~App()
Definition: ndn-app.cpp:63
ndn App
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app.cpp:28
NS_OBJECT_ENSURE_REGISTERED(ContentStore)
virtual void StartApplication()
Called at time specified by Start.
Definition: ndn-app.cpp:103
TracedCallback< shared_ptr< const Interest >, Ptr< App >, shared_ptr< Face > > m_receivedInterests
communicates
Definition: ndn-app.hpp:105
static TypeId GetTypeId()
Definition: ndn-app.cpp:36
virtual void OnInterest(shared_ptr< const Interest > interest)
Method that will be called every time new Interest arrives.
Definition: ndn-app.cpp:88
virtual void DoDispose()
Do cleanup when application is destroyed.
Definition: ndn-app.cpp:68
TracedCallback< shared_ptr< const Interest >, Ptr< App >, shared_ptr< Face > > m_transmittedInterests
App-level trace of transmitted Interests.
Definition: ndn-app.hpp:111
shared_ptr< Face > m_face
and StopApplication)
Definition: ndn-app.hpp:101
TracedCallback< shared_ptr< const Data >, Ptr< App >, shared_ptr< Face > > m_transmittedDatas
App-level trace of transmitted Data.
Definition: ndn-app.hpp:114
Implementation network-layer of NDN stack.
App()
Default constructor.
Definition: ndn-app.cpp:57
TracedCallback< shared_ptr< const Data >, Ptr< App >, shared_ptr< Face > > m_receivedDatas
App-level trace of received Data.
Definition: ndn-app.hpp:108
bool m_active
Flag to indicate that application is active (set by StartApplication.
Definition: ndn-app.hpp:98
virtual void OnData(shared_ptr< const Data > data)
Method that will be called every time new Data arrives.
Definition: ndn-app.cpp:95
uint32_t GetId() const
Get application ID (ID of applications face)
Definition: ndn-app.cpp:79