blob: dcaee0783115c0abce38b64814b616a0c1b2749a [file] [log] [blame]
Alexander Afanasyev4975f732011-12-20 17:52:19 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#include "ndn-app-helper.h"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080022#include "ns3/log.h"
23#include "ns3/string.h"
24#include "ns3/names.h"
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070025#include "ns3/ndn-app.h"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080026
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070027#ifdef NS3_MPI
28#include "ns3/mpi-interface.h"
29#endif
30
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070031NS_LOG_COMPONENT_DEFINE ("NdnAppHelper");
Alexander Afanasyev4975f732011-12-20 17:52:19 -080032
33namespace ns3
34{
35
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070036NdnAppHelper::NdnAppHelper (const std::string &app)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080037{
38 m_factory.SetTypeId (app);
39}
40
41void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070042NdnAppHelper::SetPrefix (const std::string &prefix)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080043{
44 m_factory.Set ("Prefix", StringValue(prefix));
45}
46
47void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070048NdnAppHelper::SetAttribute (std::string name, const AttributeValue &value)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080049{
50 m_factory.Set (name, value);
51}
52
53ApplicationContainer
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054NdnAppHelper::Install (Ptr<Node> node)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080055{
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070056 ApplicationContainer apps;
57 Ptr<Application> app = InstallPriv (node);
58 if (app != 0)
59 apps.Add (app);
60
61 return apps;
Alexander Afanasyev4975f732011-12-20 17:52:19 -080062}
63
64ApplicationContainer
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070065NdnAppHelper::Install (std::string nodeName)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080066{
67 Ptr<Node> node = Names::Find<Node> (nodeName);
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070068 return Install (node);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080069}
70
71ApplicationContainer
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070072NdnAppHelper::Install (NodeContainer c)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080073{
74 ApplicationContainer apps;
75 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
76 {
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070077 Ptr<Application> app = InstallPriv (*i);
78 if (app != 0)
79 apps.Add (app);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080080 }
81
82 return apps;
83}
84
85Ptr<Application>
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070086NdnAppHelper::InstallPriv (Ptr<Node> node)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080087{
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070088#ifdef NS3_MPI
89 if (MpiInterface::IsEnabled () &&
90 node->GetSystemId () != MpiInterface::GetSystemId ())
91 {
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
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070097 Ptr<NdnApp> app = m_factory.Create<NdnApp> ();
Alexander Afanasyev4975f732011-12-20 17:52:19 -080098 node->AddApplication (app);
99
100 return app;
101}
102
103}