blob: 845ea96dec9687963bef0a9ecafe0bc7ad4bfe43 [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 Afanasyev0c395372014-12-20 15:54:02 -080021#include "ndn-app-helper.hpp"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080022#include "ns3/log.h"
23#include "ns3/string.h"
24#include "ns3/names.h"
Mickey Sweatt89046c12014-11-16 20:32:27 -080025
26#include "apps/ndn-app.hpp"
Alexander Afanasyev4975f732011-12-20 17:52:19 -080027
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070028#ifdef NS3_MPI
29#include "ns3/mpi-interface.h"
30#endif
31
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080032NS_LOG_COMPONENT_DEFINE("ndn.AppHelper");
Alexander Afanasyev4975f732011-12-20 17:52:19 -080033
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070034namespace ns3 {
35namespace ndn {
Alexander Afanasyev4975f732011-12-20 17:52:19 -080036
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080037AppHelper::AppHelper(const std::string& app)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080038{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080039 m_factory.SetTypeId(app);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080040}
41
42void
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080043AppHelper::SetPrefix(const std::string& prefix)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080044{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080045 m_factory.Set("Prefix", StringValue(prefix));
Alexander Afanasyev4975f732011-12-20 17:52:19 -080046}
47
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048void
49AppHelper::SetAttribute(std::string name, const AttributeValue& value)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080050{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 m_factory.Set(name, value);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080052}
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053
Alexander Afanasyev4975f732011-12-20 17:52:19 -080054ApplicationContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055AppHelper::Install(Ptr<Node> node)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080056{
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070057 ApplicationContainer apps;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080058 Ptr<Application> app = InstallPriv(node);
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070059 if (app != 0)
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080060 apps.Add(app);
61
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070062 return apps;
Alexander Afanasyev4975f732011-12-20 17:52:19 -080063}
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064
Alexander Afanasyev4975f732011-12-20 17:52:19 -080065ApplicationContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066AppHelper::Install(std::string nodeName)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080067{
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 Ptr<Node> node = Names::Find<Node>(nodeName);
69 return Install(node);
Alexander Afanasyev4975f732011-12-20 17:52:19 -080070}
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071
Alexander Afanasyev4975f732011-12-20 17:52:19 -080072ApplicationContainer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073AppHelper::Install(NodeContainer c)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080074{
75 ApplicationContainer apps;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 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
Alexander Afanasyev4975f732011-12-20 17:52:19 -080082 return apps;
83}
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084
Alexander Afanasyev4975f732011-12-20 17:52:19 -080085Ptr<Application>
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086AppHelper::InstallPriv(Ptr<Node> node)
Alexander Afanasyev4975f732011-12-20 17:52:19 -080087{
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070088#ifdef NS3_MPI
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 if (MpiInterface::IsEnabled() && node->GetSystemId() != MpiInterface::GetSystemId()) {
90 // don't create an app if MPI is enabled and node is not in the correct partition
91 return 0;
92 }
Alexander Afanasyev89e02c42012-07-27 13:42:28 -070093#endif
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094
95 Ptr<Application> app = m_factory.Create<Application>();
96 node->AddApplication(app);
97
Alexander Afanasyev4975f732011-12-20 17:52:19 -080098 return app;
99}
100
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700101} // namespace ndn
102} // namespace ns3