Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 20 | #ifndef NDN_APP_HELPER_H |
| 21 | #define NDN_APP_HELPER_H |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 22 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 23 | #include "ns3/ndnSIM/model/ndn-common.hpp" |
| 24 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 25 | #include "ns3/object-factory.h" |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 26 | #include "ns3/attribute.h" |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 27 | #include "ns3/node-container.h" |
| 28 | #include "ns3/application-container.h" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 29 | #include "ns3/ptr.h" |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 30 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 31 | namespace ns3 { |
| 32 | namespace ndn { |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 33 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 34 | /** |
Alexander Afanasyev | 7920651 | 2013-07-27 16:49:12 -0700 | [diff] [blame] | 35 | * @ingroup ndn-helpers |
Spyridon Mastorakis | 460f57c | 2014-12-17 00:44:14 -0800 | [diff] [blame] | 36 | * @brief A helper to make it easier to instantiate an ns3::ndn::App applications |
| 37 | * on a set of nodes |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 38 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | class AppHelper { |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 40 | public: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 41 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 42 | * \brief Create an NdnAppHelper to make it easier to work with Ndn apps |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 43 | * |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 44 | * \param app Class of the application |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 45 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 46 | AppHelper(const std::string& prefix); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
| 49 | * @brief Set the prefix consumer will be requesting |
| 50 | */ |
| 51 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | SetPrefix(const std::string& prefix); |
| 53 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 54 | /** |
| 55 | * \brief Helper function used to set the underlying application attributes. |
| 56 | * |
| 57 | * \param name the name of the application attribute to set |
| 58 | * \param value the value of the application attribute to set |
| 59 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | void |
| 61 | SetAttribute(std::string name, const AttributeValue& value); |
| 62 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 63 | /** |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 64 | * Install an ns3::NdnConsumer on each node of the input container |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 65 | * configured with all the attributes set with SetAttribute. |
| 66 | * |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | * \param c NodeContainer of the set of nodes on which an NdnConsumer |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 68 | * will be installed. |
| 69 | * \returns Container of Ptr to the applications installed. |
| 70 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | ApplicationContainer |
| 72 | Install(NodeContainer c); |
| 73 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 74 | /** |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 75 | * Install an ns3::NdnConsumer on the node configured with all the |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 76 | * attributes set with SetAttribute. |
| 77 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 78 | * \param node The node on which an NdnConsumer will be installed. |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 79 | * \returns Container of Ptr to the applications installed. |
| 80 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | ApplicationContainer |
| 82 | Install(Ptr<Node> node); |
| 83 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 84 | /** |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | * Install an ns3::NdnConsumer on the node configured with all the |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 86 | * attributes set with SetAttribute. |
| 87 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 88 | * \param nodeName The node on which an NdnConsumer will be installed. |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 89 | * \returns Container of Ptr to the applications installed. |
| 90 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 91 | ApplicationContainer |
| 92 | Install(std::string nodeName); |
| 93 | |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 94 | private: |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 95 | /** |
| 96 | * \internal |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 97 | * Install an ns3::NdnConsumer on the node configured with all the |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 98 | * attributes set with SetAttribute. |
| 99 | * |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 100 | * \param node The node on which an NdnConsumer will be installed. |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 101 | * \returns Ptr to the application installed. |
| 102 | */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 103 | Ptr<Application> |
| 104 | InstallPriv(Ptr<Node> node); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 105 | ObjectFactory m_factory; |
| 106 | }; |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 107 | |
Alexander Afanasyev | f19fffb | 2015-08-21 17:34:23 -0700 | [diff] [blame] | 108 | /** |
| 109 | * @brief An application that can be created using the supplied callback |
| 110 | * |
| 111 | * Example: |
| 112 | * |
| 113 | * class SomeApp |
| 114 | * { |
| 115 | * public: |
| 116 | * SomeApp(size_t initParameter); |
| 117 | * ... |
| 118 | * }; |
| 119 | * |
| 120 | * FactoryCallbackApp::Install(node, [] () -> shared_ptr<void> { |
| 121 | * return make_shared<SomeApp>(42); |
| 122 | * }) |
| 123 | * .Start(Seconds(1.01)); |
| 124 | */ |
| 125 | class FactoryCallbackApp : public Application |
| 126 | { |
| 127 | public: |
| 128 | typedef std::function<shared_ptr<void>()> FactoryCallback; |
| 129 | |
| 130 | FactoryCallbackApp(const FactoryCallback& factory); |
| 131 | |
| 132 | public: |
| 133 | static ApplicationContainer |
| 134 | Install(Ptr<Node> node, const FactoryCallback& factory); |
| 135 | |
| 136 | protected: |
| 137 | // inherited from Application base class. |
| 138 | virtual void |
| 139 | StartApplication(); |
| 140 | |
| 141 | virtual void |
| 142 | StopApplication(); |
| 143 | |
| 144 | private: |
| 145 | FactoryCallback m_factory; |
| 146 | std::shared_ptr<void> m_impl; |
| 147 | }; |
| 148 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 149 | } // namespace ndn |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 150 | } // namespace ns3 |
Ilya Moiseenko | a121411 | 2011-08-29 13:03:55 -0700 | [diff] [blame] | 151 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 152 | #endif // NDN_APP_HELPER_H |