Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 21 | #include "ccnx-app-helper.h" |
| 22 | #include "ns3/log.h" |
| 23 | #include "ns3/string.h" |
| 24 | #include "ns3/names.h" |
| 25 | #include "ns3/ccnx-app.h" |
| 26 | |
Alexander Afanasyev | 89e02c4 | 2012-07-27 13:42:28 -0700 | [diff] [blame] | 27 | #ifdef NS3_MPI |
| 28 | #include "ns3/mpi-interface.h" |
| 29 | #endif |
| 30 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 31 | NS_LOG_COMPONENT_DEFINE ("CcnxAppHelper"); |
| 32 | |
| 33 | namespace ns3 |
| 34 | { |
| 35 | |
| 36 | CcnxAppHelper::CcnxAppHelper (const std::string &app) |
| 37 | { |
| 38 | m_factory.SetTypeId (app); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | CcnxAppHelper::SetPrefix (const std::string &prefix) |
| 43 | { |
| 44 | m_factory.Set ("Prefix", StringValue(prefix)); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | CcnxAppHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 49 | { |
| 50 | m_factory.Set (name, value); |
| 51 | } |
| 52 | |
| 53 | ApplicationContainer |
| 54 | CcnxAppHelper::Install (Ptr<Node> node) |
| 55 | { |
Alexander Afanasyev | 89e02c4 | 2012-07-27 13:42:28 -0700 | [diff] [blame] | 56 | ApplicationContainer apps; |
| 57 | Ptr<Application> app = InstallPriv (node); |
| 58 | if (app != 0) |
| 59 | apps.Add (app); |
| 60 | |
| 61 | return apps; |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | ApplicationContainer |
| 65 | CcnxAppHelper::Install (std::string nodeName) |
| 66 | { |
| 67 | Ptr<Node> node = Names::Find<Node> (nodeName); |
Alexander Afanasyev | 89e02c4 | 2012-07-27 13:42:28 -0700 | [diff] [blame] | 68 | return Install (node); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | ApplicationContainer |
| 72 | CcnxAppHelper::Install (NodeContainer c) |
| 73 | { |
| 74 | ApplicationContainer apps; |
| 75 | for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 76 | { |
Alexander Afanasyev | 89e02c4 | 2012-07-27 13:42:28 -0700 | [diff] [blame] | 77 | Ptr<Application> app = InstallPriv (*i); |
| 78 | if (app != 0) |
| 79 | apps.Add (app); |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return apps; |
| 83 | } |
| 84 | |
| 85 | Ptr<Application> |
| 86 | CcnxAppHelper::InstallPriv (Ptr<Node> node) |
| 87 | { |
Alexander Afanasyev | 89e02c4 | 2012-07-27 13:42:28 -0700 | [diff] [blame] | 88 | #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 Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 97 | Ptr<CcnxApp> app = m_factory.Create<CcnxApp> (); |
| 98 | node->AddApplication (app); |
| 99 | |
| 100 | return app; |
| 101 | } |
| 102 | |
| 103 | } |