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