NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-app-helper.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
20 #include "ndn-app-helper.hpp"
21 #include "ns3/log.h"
22 #include "ns3/string.h"
23 #include "ns3/names.h"
24 
25 #include "apps/ndn-app.hpp"
26 #include "ndn-stack-helper.hpp"
27 
28 #ifdef NS3_MPI
29 #include "ns3/mpi-interface.h"
30 #endif
31 
32 NS_LOG_COMPONENT_DEFINE("ndn.AppHelper");
33 
34 namespace ns3 {
35 namespace ndn {
36 
37 AppHelper::AppHelper(const std::string& app)
38 {
39  m_factory.SetTypeId(app);
40 }
41 
42 void
43 AppHelper::SetPrefix(const std::string& prefix)
44 {
45  m_factory.Set("Prefix", StringValue(prefix));
46 }
47 
48 void
49 AppHelper::SetAttribute(std::string name, const AttributeValue& value)
50 {
51  m_factory.Set(name, value);
52 }
53 
54 ApplicationContainer
55 AppHelper::Install(Ptr<Node> node)
56 {
57  ApplicationContainer apps;
58  Ptr<Application> app = InstallPriv(node);
59  if (app != 0)
60  apps.Add(app);
61 
62  return apps;
63 }
64 
65 ApplicationContainer
66 AppHelper::Install(std::string nodeName)
67 {
68  Ptr<Node> node = Names::Find<Node>(nodeName);
69  return Install(node);
70 }
71 
72 ApplicationContainer
73 AppHelper::Install(NodeContainer c)
74 {
75  ApplicationContainer apps;
76  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
77  Ptr<Application> app = InstallPriv(*i);
78  if (app != 0)
79  apps.Add(app);
80  }
81 
82  return apps;
83 }
84 
85 Ptr<Application>
86 AppHelper::InstallPriv(Ptr<Node> node)
87 {
88  Ptr<Application> app;
89  Simulator::ScheduleWithContext(node->GetId(), Seconds(0), MakeEvent([=, &app] {
90 #ifdef NS3_MPI
91  if (MpiInterface::IsEnabled() && node->GetSystemId() != MpiInterface::GetSystemId()) {
92  // don't create an app if MPI is enabled and node is not in the correct partition
93  return 0;
94  }
95 #endif
96 
97  app = m_factory.Create<Application>();
98  node->AddApplication(app);
99  }));
101 
102  return app;
103 }
104 
106 
108  : m_factory(factory)
109 {
110 }
111 
112 ApplicationContainer
113 FactoryCallbackApp::Install(Ptr<Node> node, const FactoryCallback& factory)
114 {
115  ApplicationContainer apps;
116  auto app = CreateObject<FactoryCallbackApp>(factory);
117  node->AddApplication(app);
118  apps.Add(app);
119  return apps;
120 }
121 
122 void
124 {
125  m_impl = m_factory();
126 }
127 
128 void
130 {
131  m_impl.reset();
132 }
133 
134 
135 } // namespace ndn
136 } // namespace ns3
ns3::ndn::FactoryCallbackApp::StartApplication
virtual void StartApplication()
Definition: ndn-app-helper.cpp:123
ndn-app.hpp
ns3::ndn::AppHelper::SetAttribute
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
Definition: ndn-app-helper.cpp:49
ns3::ndn::AppHelper::SetPrefix
void SetPrefix(const std::string &prefix)
Set the prefix consumer will be requesting.
Definition: ndn-app-helper.cpp:43
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app-link-service.cpp:32
ndn-stack-helper.hpp
ndn-app-helper.hpp
ns3::ndn::AppHelper::Install
ApplicationContainer Install(NodeContainer c)
Install an ns3::NdnConsumer on each node of the input container configured with all the attributes se...
Definition: ndn-app-helper.cpp:73
ndn::name
Definition: name-component-types.hpp:33
ns3::ndn::AppHelper::AppHelper
AppHelper(const std::string &prefix)
Create an NdnAppHelper to make it easier to work with Ndn apps.
Definition: ndn-app-helper.cpp:37
ns3::ndn::StackHelper::ProcessWarmupEvents
static void ProcessWarmupEvents()
Definition: ndn-stack-helper.cpp:410
ns3::ndn::FactoryCallbackApp::FactoryCallback
std::function< shared_ptr< void >)> FactoryCallback
Definition: ndn-app-helper.hpp:128
ns3::ndn::FactoryCallbackApp::FactoryCallbackApp
FactoryCallbackApp(const FactoryCallback &factory)
Definition: ndn-app-helper.cpp:107
ns3::ndn::FactoryCallbackApp::Install
static ApplicationContainer Install(Ptr< Node > node, const FactoryCallback &factory)
Definition: ndn-app-helper.cpp:113
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ns3::ndn::FactoryCallbackApp::StopApplication
virtual void StopApplication()
Definition: ndn-app-helper.cpp:129