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