NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 
27 #ifdef NS3_MPI
28 #include "ns3/mpi-interface.h"
29 #endif
30 
31 NS_LOG_COMPONENT_DEFINE("ndn.AppHelper");
32 
33 namespace ns3 {
34 namespace ndn {
35 
36 AppHelper::AppHelper(const std::string& app)
37 {
38  m_factory.SetTypeId(app);
39 }
40 
41 void
42 AppHelper::SetPrefix(const std::string& prefix)
43 {
44  m_factory.Set("Prefix", StringValue(prefix));
45 }
46 
47 void
48 AppHelper::SetAttribute(std::string name, const AttributeValue& value)
49 {
50  m_factory.Set(name, value);
51 }
52 
53 ApplicationContainer
54 AppHelper::Install(Ptr<Node> node)
55 {
56  ApplicationContainer apps;
57  Ptr<Application> app = InstallPriv(node);
58  if (app != 0)
59  apps.Add(app);
60 
61  return apps;
62 }
63 
64 ApplicationContainer
65 AppHelper::Install(std::string nodeName)
66 {
67  Ptr<Node> node = Names::Find<Node>(nodeName);
68  return Install(node);
69 }
70 
71 ApplicationContainer
72 AppHelper::Install(NodeContainer c)
73 {
74  ApplicationContainer apps;
75  for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) {
76  Ptr<Application> app = InstallPriv(*i);
77  if (app != 0)
78  apps.Add(app);
79  }
80 
81  return apps;
82 }
83 
84 Ptr<Application>
85 AppHelper::InstallPriv(Ptr<Node> node)
86 {
87 #ifdef NS3_MPI
88  if (MpiInterface::IsEnabled() && node->GetSystemId() != MpiInterface::GetSystemId()) {
89  // don't create an app if MPI is enabled and node is not in the correct partition
90  return 0;
91  }
92 #endif
93 
94  Ptr<Application> app = m_factory.Create<Application>();
95  node->AddApplication(app);
96 
97  return app;
98 }
99 
101 
103  : m_factory(factory)
104 {
105 }
106 
107 ApplicationContainer
108 FactoryCallbackApp::Install(Ptr<Node> node, const FactoryCallback& factory)
109 {
110  ApplicationContainer apps;
111  auto app = CreateObject<FactoryCallbackApp>(factory);
112  node->AddApplication(app);
113  apps.Add(app);
114  return apps;
115 }
116 
117 void
119 {
120  m_impl = m_factory();
121 }
122 
123 void
125 {
126  m_impl.reset();
127 }
128 
129 
130 } // namespace ndn
131 } // namespace ns3
FactoryCallbackApp(const FactoryCallback &factory)
Copyright (c) 2011-2015 Regents of the University of California.
void SetAttribute(std::string name, const AttributeValue &value)
Helper function used to set the underlying application attributes.
AppHelper(const std::string &prefix)
Create an NdnAppHelper to make it easier to work with Ndn apps.
ApplicationContainer Install(NodeContainer c)
Install an ns3::NdnConsumer on each node of the input container configured with all the attributes se...
Copyright (c) 2011-2015 Regents of the University of California.
static ApplicationContainer Install(Ptr< Node > node, const FactoryCallback &factory)
void SetPrefix(const std::string &prefix)
Set the prefix consumer will be requesting.
std::function< shared_ptr< void >)> FactoryCallback