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. |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -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. |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -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. |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -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. |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -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 | **/ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 20 | #include "ndn-l3-protocol.hpp" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 21 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 22 | #include "ns3/packet.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 23 | #include "ns3/node.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 24 | #include "ns3/log.h" |
| 25 | #include "ns3/callback.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 26 | #include "ns3/uinteger.h" |
| 27 | #include "ns3/trace-source-accessor.h" |
| 28 | #include "ns3/object-vector.h" |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 29 | #include "ns3/pointer.h" |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 30 | #include "ns3/simulator.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 31 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 32 | #include "ndn-net-device-transport.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 33 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 34 | #include "../helper/ndn-stack-helper.hpp" |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 36 | #include <boost/property_tree/info_parser.hpp> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 37 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 38 | #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 39 | #include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp" |
| 40 | #include "ns3/ndnSIM/NFD/daemon/face/internal-transport.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 41 | #include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp" |
| 42 | #include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp" |
| 43 | #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp" |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 44 | #include "ns3/ndnSIM/NFD/daemon/mgmt/cs-manager.hpp" |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 45 | #include "ns3/ndnSIM/NFD/daemon/mgmt/forwarder-status-manager.hpp" |
| 46 | // #include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp" |
| 47 | #include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp" |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 48 | #include "ns3/ndnSIM/NFD/daemon/mgmt/command-authenticator.hpp" |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 11dfcb7 | 2019-07-27 17:47:32 -0400 | [diff] [blame^] | 50 | #include "ns3/ndnSIM/NFD/daemon/rib/service.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 51 | |
| 52 | #include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp" |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 53 | #include "ns3/ndnSIM/NFD/daemon/face/internal-face.hpp" |
| 54 | |
Alexander Afanasyev | 11dfcb7 | 2019-07-27 17:47:32 -0400 | [diff] [blame^] | 55 | #include "ns3/ndnSIM/NFD/daemon/common/global.hpp" |
| 56 | #include "ns3/ndnSIM/NFD/daemon/common/config-file.hpp" |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 57 | |
| 58 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 59 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 60 | NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | |
| 62 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 63 | namespace ndn { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 65 | const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 66 | const uint16_t L3Protocol::IP_STACK_PORT = 9695; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 67 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | NS_OBJECT_ENSURE_REGISTERED(L3Protocol); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 70 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | L3Protocol::GetTypeId(void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 72 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | static TypeId tid = |
| 74 | TypeId("ns3::ndn::L3Protocol") |
| 75 | .SetGroupName("ndn") |
| 76 | .SetParent<Object>() |
| 77 | .AddConstructor<L3Protocol>() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 78 | |
| 79 | .AddTraceSource("OutInterests", "OutInterests", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 80 | MakeTraceSourceAccessor(&L3Protocol::m_outInterests), |
| 81 | "ns3::ndn::L3Protocol::InterestTraceCallback") |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 82 | .AddTraceSource("InInterests", "InInterests", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 83 | MakeTraceSourceAccessor(&L3Protocol::m_inInterests), |
| 84 | "ns3::ndn::L3Protocol::InterestTraceCallback") |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 85 | |
| 86 | //////////////////////////////////////////////////////////////////// |
| 87 | |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 88 | .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData), |
| 89 | "ns3::ndn::L3Protocol::DataTraceCallback") |
| 90 | .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData), |
| 91 | "ns3::ndn::L3Protocol::DataTraceCallback") |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 92 | |
| 93 | //////////////////////////////////////////////////////////////////// |
| 94 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 95 | .AddTraceSource("OutNack", "OutNack", MakeTraceSourceAccessor(&L3Protocol::m_outNack), |
| 96 | "ns3::ndn::L3Protocol::NackTraceCallback") |
| 97 | .AddTraceSource("InNack", "InNack", MakeTraceSourceAccessor(&L3Protocol::m_inNack), |
| 98 | "ns3::ndn::L3Protocol::NackTraceCallback") |
| 99 | |
| 100 | //////////////////////////////////////////////////////////////////// |
| 101 | |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 102 | .AddTraceSource("SatisfiedInterests", "SatisfiedInterests", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 103 | MakeTraceSourceAccessor(&L3Protocol::m_satisfiedInterests), |
| 104 | "ns3::ndn::L3Protocol::SatisfiedInterestsCallback") |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 105 | .AddTraceSource("TimedOutInterests", "TimedOutInterests", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 106 | MakeTraceSourceAccessor(&L3Protocol::m_timedOutInterests), |
| 107 | "ns3::ndn::L3Protocol::TimedOutInterestsCallback") |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 108 | ; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 109 | return tid; |
| 110 | } |
| 111 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 112 | class L3Protocol::Impl { |
| 113 | private: |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 114 | Impl() |
| 115 | { |
| 116 | // Do not modify initial config file. Use helpers to set specific NFD parameters |
| 117 | std::string initialConfig = |
| 118 | "general\n" |
| 119 | "{\n" |
| 120 | "}\n" |
| 121 | "\n" |
| 122 | "tables\n" |
| 123 | "{\n" |
| 124 | " cs_max_packets 100\n" |
| 125 | "\n" |
| 126 | " strategy_choice\n" |
| 127 | " {\n" |
| 128 | " / /localhost/nfd/strategy/best-route\n" |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 129 | " /localhost /localhost/nfd/strategy/multicast\n" |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 130 | " /localhost/nfd /localhost/nfd/strategy/best-route\n" |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 131 | " /ndn/multicast /localhost/nfd/strategy/multicast\n" |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 132 | " }\n" |
| 133 | "}\n" |
| 134 | "\n" |
| 135 | // "face_system\n" |
| 136 | // "{\n" |
| 137 | // "}\n" |
| 138 | "\n" |
| 139 | "authorizations\n" |
| 140 | "{\n" |
| 141 | " authorize\n" |
| 142 | " {\n" |
| 143 | " certfile any\n" |
| 144 | " privileges\n" |
| 145 | " {\n" |
| 146 | " faces\n" |
| 147 | " fib\n" |
| 148 | " strategy-choice\n" |
| 149 | " }\n" |
| 150 | " }\n" |
| 151 | "}\n" |
| 152 | "\n" |
| 153 | "rib\n" |
| 154 | "{\n" |
| 155 | " localhost_security\n" |
| 156 | " {\n" |
| 157 | " trust-anchor\n" |
| 158 | " {\n" |
| 159 | " type any\n" |
| 160 | " }\n" |
| 161 | " }\n" |
| 162 | "}\n" |
| 163 | "\n"; |
| 164 | |
| 165 | std::istringstream input(initialConfig); |
| 166 | boost::property_tree::read_info(input, m_config); |
| 167 | } |
| 168 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 169 | friend class L3Protocol; |
| 170 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 171 | // note that shared_ptr needed for Python bindings |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 172 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 173 | std::shared_ptr<::nfd::Forwarder> m_forwarder; |
| 174 | std::unique_ptr<::nfd::face::FaceSystem> m_faceSystem; |
| 175 | |
| 176 | std::shared_ptr<::nfd::face::Face> m_internalFace; |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 177 | std::shared_ptr<::ndn::Face> m_internalClientFace; |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 178 | std::unique_ptr<::ndn::mgmt::Dispatcher> m_dispatcher; |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 179 | std::shared_ptr<::nfd::CommandAuthenticator> m_authenticator; |
| 180 | std::unique_ptr<::nfd::ForwarderStatusManager> m_forwarderStatusManager; |
| 181 | std::unique_ptr<::nfd::FaceManager> m_faceManager; |
| 182 | std::shared_ptr<::nfd::FibManager> m_fibManager; |
| 183 | std::unique_ptr<::nfd::CsManager> m_csManager; |
| 184 | std::unique_ptr<::nfd::StrategyChoiceManager> m_strategyChoiceManager; |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 185 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 186 | std::shared_ptr<::nfd::face::Face> m_internalFaceForInjects; |
| 187 | std::shared_ptr<::ndn::Face> m_internalClientFaceForInjects; |
| 188 | |
| 189 | std::shared_ptr<::nfd::Face> m_internalRibFace; |
| 190 | std::shared_ptr<::ndn::Face> m_internalRibClientFace; |
| 191 | std::unique_ptr<::nfd::rib::Service> m_ribService; |
Spyridon Mastorakis | f6d3285 | 2017-09-27 20:28:52 -0700 | [diff] [blame] | 192 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 193 | nfd::ConfigSection m_config; |
| 194 | |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 195 | PolicyCreationCallback m_policy; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 196 | }; |
| 197 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 198 | L3Protocol::L3Protocol() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 199 | : m_impl(new Impl()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 200 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 201 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 204 | L3Protocol::~L3Protocol() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 205 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 206 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 209 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 210 | L3Protocol::initialize() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 211 | { |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 212 | m_impl->m_forwarder = make_shared<::nfd::Forwarder>(); |
| 213 | |
| 214 | ::nfd::FaceTable& faceTable = m_impl->m_forwarder->getFaceTable(); |
| 215 | faceTable.addReserved(::nfd::face::makeNullFace(), ::nfd::face::FACEID_NULL); |
| 216 | // faceTable.addReserved(face::makeNullFace(FaceUri("contentstore://")), face::FACEID_CONTENT_STORE); |
| 217 | m_impl->m_faceSystem = make_unique<::nfd::face::FaceSystem>(faceTable, nullptr); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 218 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 219 | initializeManagement(); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 220 | initializeRibManager(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 221 | |
Alexander Afanasyev | dc6fae8 | 2015-01-08 21:44:15 -0800 | [diff] [blame] | 222 | m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests)); |
| 223 | m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests)); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 226 | class IgnoreSections |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 227 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 228 | public: |
| 229 | IgnoreSections(const std::vector<std::string>& ignored) |
| 230 | : m_ignored(ignored) |
| 231 | { |
| 232 | } |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 233 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 234 | void |
| 235 | operator()(const std::string& filename, const std::string& sectionName, |
| 236 | const nfd::ConfigSection& section, bool isDryRun) |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 237 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 238 | { |
| 239 | if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) { |
| 240 | nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun); |
| 241 | } |
| 242 | } |
| 243 | private: |
| 244 | std::vector<std::string> m_ignored; |
| 245 | }; |
| 246 | |
| 247 | void |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 248 | L3Protocol::injectInterest(const Interest& interest) |
| 249 | { |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 250 | m_impl->m_internalClientFaceForInjects->expressInterest(interest, nullptr, nullptr, nullptr); |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | void |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 254 | L3Protocol::setCsReplacementPolicy(const PolicyCreationCallback& policy) |
| 255 | { |
| 256 | m_impl->m_policy = policy; |
| 257 | } |
| 258 | |
| 259 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 260 | L3Protocol::initializeManagement() |
| 261 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 262 | auto& forwarder = m_impl->m_forwarder; |
| 263 | using namespace nfd; |
| 264 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 265 | std::tie(m_impl->m_internalFace, m_impl->m_internalClientFace) = face::makeInternalFace(StackHelper::getKeyChain()); |
| 266 | forwarder->getFaceTable().addReserved(m_impl->m_internalFace, face::FACEID_INTERNAL_FACE); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 267 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 268 | std::tie(m_impl->m_internalFaceForInjects, m_impl->m_internalClientFaceForInjects) = face::makeInternalFace(StackHelper::getKeyChain()); |
| 269 | forwarder->getFaceTable().addReserved(m_impl->m_internalFaceForInjects, face::FACEID_INTERNAL_FACE + 1); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 270 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 271 | m_impl->m_dispatcher = make_unique<::ndn::mgmt::Dispatcher>(*m_impl->m_internalClientFace, StackHelper::getKeyChain()); |
| 272 | m_impl->m_authenticator = ::nfd::CommandAuthenticator::create(); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 273 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 274 | if (!this->getConfig().get<bool>("ndnSIM.disable_forwarder_status_manager", false)) { |
| 275 | m_impl->m_forwarderStatusManager = make_unique<::nfd::ForwarderStatusManager>(*m_impl->m_forwarder, *m_impl->m_dispatcher); |
| 276 | } |
| 277 | m_impl->m_faceManager = make_unique<::nfd::FaceManager>(*m_impl->m_faceSystem, *m_impl->m_dispatcher, *m_impl->m_authenticator); |
| 278 | m_impl->m_fibManager = make_shared<::nfd::FibManager>(m_impl->m_forwarder->getFib(), m_impl->m_forwarder->getFaceTable(), |
| 279 | *m_impl->m_dispatcher, *m_impl->m_authenticator); |
| 280 | m_impl->m_csManager = make_unique<::nfd::CsManager>(m_impl->m_forwarder->getCs(), m_impl->m_forwarder->getCounters(), |
| 281 | *m_impl->m_dispatcher, *m_impl->m_authenticator); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 282 | if (!this->getConfig().get<bool>("ndnSIM.disable_strategy_choice_manager", false)) { |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 283 | m_impl->m_strategyChoiceManager = make_unique<::nfd::StrategyChoiceManager>(m_impl->m_forwarder->getStrategyChoice(), |
| 284 | *m_impl->m_dispatcher, *m_impl->m_authenticator); |
| 285 | |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 286 | } |
| 287 | else { |
| 288 | this->getConfig().get_child("authorizations").get_child("authorize").get_child("privileges").erase("strategy-choice"); |
| 289 | } |
| 290 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 291 | ConfigFile config(&ConfigFile::ignoreUnknownSection); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 292 | |
Alexander Afanasyev | 8fbcc64 | 2019-07-27 16:53:37 -0400 | [diff] [blame] | 293 | forwarder->getCs().setPolicy(m_impl->m_policy()); |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 294 | |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 295 | TablesConfigSection tablesConfig(*forwarder); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 296 | tablesConfig.setConfigFile(config); |
| 297 | |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 298 | m_impl->m_authenticator->setConfigFile(config); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 299 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 300 | // if (!this->getConfig().get<bool>("ndnSIM.disable_face_manager", false)) { |
Alexander Afanasyev | e93e8b0 | 2018-05-08 20:10:01 -0400 | [diff] [blame] | 301 | m_impl->m_faceSystem->setConfigFile(config); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 302 | // } |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 303 | |
| 304 | // apply config |
| 305 | config.parse(m_impl->m_config, false, "ndnSIM.conf"); |
| 306 | |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 307 | tablesConfig.ensureConfigured(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 308 | |
| 309 | // add FIB entry for NFD Management Protocol |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 310 | Name topPrefix("/localhost/nfd"); |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 311 | m_impl->m_forwarder->getFib().insert(topPrefix).first->addOrUpdateNextHop(*m_impl->m_internalFace, 0, 0); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 312 | m_impl->m_dispatcher->addTopPrefix(topPrefix, false); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame] | 315 | void |
| 316 | L3Protocol::initializeRibManager() |
| 317 | { |
| 318 | using namespace nfd; |
| 319 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 320 | std::tie(m_impl->m_internalRibFace, m_impl->m_internalRibClientFace) = face::makeInternalFace(StackHelper::getKeyChain()); |
| 321 | m_impl->m_forwarder->getFaceTable().add(m_impl->m_internalRibFace); |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 322 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 323 | m_impl->m_ribService = make_unique<rib::Service>(m_impl->m_config, |
| 324 | std::ref(*m_impl->m_internalRibClientFace), |
| 325 | std::ref(StackHelper::getKeyChain())); |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 328 | shared_ptr<nfd::Forwarder> |
| 329 | L3Protocol::getForwarder() |
| 330 | { |
| 331 | return m_impl->m_forwarder; |
| 332 | } |
| 333 | |
| 334 | shared_ptr<nfd::FibManager> |
| 335 | L3Protocol::getFibManager() |
| 336 | { |
| 337 | return m_impl->m_fibManager; |
| 338 | } |
| 339 | |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 340 | nfd::StrategyChoiceManager& |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 341 | L3Protocol::getStrategyChoiceManager() |
| 342 | { |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame] | 343 | return *m_impl->m_strategyChoiceManager; |
| 344 | } |
| 345 | |
| 346 | ::nfd::rib::Service& |
| 347 | L3Protocol::getRibService() |
| 348 | { |
| 349 | return *m_impl->m_ribService; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 352 | nfd::ConfigSection& |
| 353 | L3Protocol::getConfig() |
| 354 | { |
| 355 | return m_impl->m_config; |
| 356 | } |
| 357 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 358 | /* |
| 359 | * This method is called by AddAgregate and completes the aggregation |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 360 | * by setting the node in the ndn stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 361 | */ |
| 362 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 363 | L3Protocol::NotifyNewAggregate() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 364 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 365 | if (m_node == nullptr) { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 366 | m_node = GetObject<Node>(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 367 | if (m_node != nullptr) { |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame] | 368 | initialize(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 369 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 370 | } |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 371 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 372 | Object::NotifyNewAggregate(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 375 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 376 | L3Protocol::DoDispose(void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 377 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 378 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 379 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 380 | // MUST HAPPEN BEFORE Simulator IS DESTROYED |
| 381 | m_impl.reset(); |
| 382 | |
Alexander Afanasyev | 11dfcb7 | 2019-07-27 17:47:32 -0400 | [diff] [blame^] | 383 | nfd::resetGlobalScheduler(); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 384 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 385 | m_node = 0; |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 386 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 387 | Object::DoDispose(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 390 | nfd::FaceId |
| 391 | L3Protocol::addFace(shared_ptr<Face> face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 392 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 393 | NS_LOG_FUNCTION(this << face.get()); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 394 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 395 | m_impl->m_forwarder->addFace(face); |
| 396 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 397 | std::weak_ptr<Face> weakFace = face; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 398 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 399 | // // Connect Signals to TraceSource |
| 400 | face->afterReceiveInterest.connect([this, weakFace](const Interest& interest) { |
| 401 | shared_ptr<Face> face = weakFace.lock(); |
| 402 | if (face != nullptr) { |
| 403 | this->m_inInterests(interest, *face); |
| 404 | } |
| 405 | }); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 406 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 407 | face->afterReceiveData.connect([this, weakFace](const Data& data) { |
| 408 | shared_ptr<Face> face = weakFace.lock(); |
| 409 | if (face != nullptr) { |
| 410 | this->m_inData(data, *face); |
| 411 | } |
| 412 | }); |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 413 | |
| 414 | face->afterReceiveNack.connect([this, weakFace](const lp::Nack& nack) { |
| 415 | shared_ptr<Face> face = weakFace.lock(); |
| 416 | if (face != nullptr) { |
| 417 | this->m_inNack(nack, *face); |
| 418 | } |
| 419 | }); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 420 | |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 421 | auto tracingLink = face->getLinkService(); |
| 422 | NS_LOG_LOGIC("Adding trace sources for afterSendInterest and afterSendData"); |
| 423 | tracingLink->afterSendInterest.connect([this, weakFace](const Interest& interest) { |
| 424 | shared_ptr<Face> face = weakFace.lock(); |
| 425 | if (face != nullptr) { |
| 426 | this->m_outInterests(interest, *face); |
| 427 | } |
| 428 | }); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 429 | |
Alexander Afanasyev | ac541b1 | 2016-09-12 19:45:53 -0700 | [diff] [blame] | 430 | tracingLink->afterSendData.connect([this, weakFace](const Data& data) { |
| 431 | shared_ptr<Face> face = weakFace.lock(); |
| 432 | if (face != nullptr) { |
| 433 | this->m_outData(data, *face); |
| 434 | } |
| 435 | }); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 436 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 437 | tracingLink->afterSendNack.connect([this, weakFace](const lp::Nack& nack) { |
| 438 | shared_ptr<Face> face = weakFace.lock(); |
| 439 | if (face != nullptr) { |
| 440 | this->m_outNack(nack, *face); |
| 441 | } |
| 442 | }); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 443 | |
| 444 | return face->getId(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 447 | shared_ptr<Face> |
| 448 | L3Protocol::getFaceById(nfd::FaceId id) const |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 449 | { |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 450 | return m_impl->m_forwarder->getFaceTable().get(id)->shared_from_this(); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 453 | shared_ptr<Face> |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 454 | L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 455 | { |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 456 | for (auto& i : m_impl->m_forwarder->getFaceTable()) { |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 457 | auto transport = dynamic_cast<NetDeviceTransport*>(i.getTransport()); |
| 458 | if (transport == nullptr) |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 459 | continue; |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 460 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 461 | if (transport->GetNetDevice() == netDevice) |
Spyridon Mastorakis | b0b2241 | 2016-12-07 14:33:46 -0800 | [diff] [blame] | 462 | return i.shared_from_this(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 463 | } |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 464 | return nullptr; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Alexander Afanasyev | 6b2a3c0 | 2015-01-03 02:04:23 -0800 | [diff] [blame] | 467 | Ptr<L3Protocol> |
| 468 | L3Protocol::getL3Protocol(Ptr<Object> node) |
| 469 | { |
| 470 | Ptr<L3Protocol> retval = node->GetObject<L3Protocol>(); |
| 471 | NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object"); |
| 472 | return retval; |
| 473 | } |
| 474 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 475 | } // namespace ndn |
| 476 | } // namespace ns3 |