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(); |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame^] | 189 | Simulator::ScheduleWithContext(m_node->GetId(), Seconds(0), &L3Protocol::initializeRibManager, this); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 190 | |
| 191 | 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] | 192 | |
| 193 | m_impl->m_forwarder->beforeSatisfyInterest.connect(std::ref(m_satisfiedInterests)); |
| 194 | m_impl->m_forwarder->beforeExpirePendingInterest.connect(std::ref(m_timedOutInterests)); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 195 | } |
| 196 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 197 | class IgnoreSections |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 198 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 199 | public: |
| 200 | IgnoreSections(const std::vector<std::string>& ignored) |
| 201 | : m_ignored(ignored) |
| 202 | { |
| 203 | } |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 204 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 205 | void |
| 206 | operator()(const std::string& filename, const std::string& sectionName, |
| 207 | const nfd::ConfigSection& section, bool isDryRun) |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 208 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 209 | { |
| 210 | if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) { |
| 211 | nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun); |
| 212 | } |
| 213 | } |
| 214 | private: |
| 215 | std::vector<std::string> m_ignored; |
| 216 | }; |
| 217 | |
| 218 | void |
| 219 | L3Protocol::initializeManagement() |
| 220 | { |
Alexander Afanasyev | 5b4c467 | 2015-08-21 12:23:55 -0700 | [diff] [blame] | 221 | auto& keyChain = StackHelper::getKeyChain(); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 222 | auto& forwarder = m_impl->m_forwarder; |
| 223 | using namespace nfd; |
| 224 | |
| 225 | m_impl->m_internalFace = make_shared<InternalFace>(); |
| 226 | |
| 227 | m_impl->m_fibManager = make_shared<FibManager>(std::ref(forwarder->getFib()), |
| 228 | bind(&Forwarder::getFace, forwarder.get(), _1), |
| 229 | m_impl->m_internalFace, keyChain); |
| 230 | |
| 231 | m_impl->m_faceManager = make_shared<FaceManager>(std::ref(forwarder->getFaceTable()), |
| 232 | m_impl->m_internalFace, |
| 233 | keyChain); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 234 | |
| 235 | m_impl->m_strategyChoiceManager = |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 236 | make_shared<StrategyChoiceManager>(std::ref(forwarder->getStrategyChoice()), |
| 237 | m_impl->m_internalFace, |
| 238 | keyChain); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 239 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 240 | m_impl->m_statusServer = make_shared<StatusServer>(m_impl->m_internalFace, |
| 241 | ref(*forwarder), |
| 242 | keyChain); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 243 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 244 | ConfigFile config((IgnoreSections({"general", "log", "rib"}))); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 245 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 246 | TablesConfigSection tablesConfig(forwarder->getCs(), |
| 247 | forwarder->getPit(), |
| 248 | forwarder->getFib(), |
| 249 | forwarder->getStrategyChoice(), |
| 250 | forwarder->getMeasurements()); |
| 251 | tablesConfig.setConfigFile(config); |
| 252 | |
| 253 | m_impl->m_internalFace->getValidator().setConfigFile(config); |
| 254 | |
| 255 | forwarder->getFaceTable().addReserved(m_impl->m_internalFace, FACEID_INTERNAL_FACE); |
| 256 | |
| 257 | m_impl->m_faceManager->setConfigFile(config); |
| 258 | |
| 259 | // apply config |
| 260 | config.parse(m_impl->m_config, false, "ndnSIM.conf"); |
| 261 | |
| 262 | tablesConfig.ensureTablesAreConfigured(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 263 | |
| 264 | // add FIB entry for NFD Management Protocol |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 265 | shared_ptr<fib::Entry> entry = forwarder->getFib().insert("/localhost/nfd").first; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 266 | entry->addNextHop(m_impl->m_internalFace, 0); |
| 267 | } |
| 268 | |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame^] | 269 | void |
| 270 | L3Protocol::initializeRibManager() |
| 271 | { |
| 272 | using namespace nfd; |
| 273 | |
| 274 | m_impl->m_face = make_shared< ::ndn::Face>(); |
| 275 | m_impl->m_ribManager = make_shared<rib::RibManager>(*(m_impl->m_face), |
| 276 | StackHelper::getKeyChain()); |
| 277 | |
| 278 | ConfigFile config([] (const std::string& filename, const std::string& sectionName, |
| 279 | const ConfigSection& section, bool isDryRun) { |
| 280 | // Ignore "log" and sections belonging to NFD, |
| 281 | // but raise an error if we're missing a handler for a "rib" section. |
| 282 | if (sectionName != "rib" || sectionName == "log") { |
| 283 | // do nothing |
| 284 | } |
| 285 | else { |
| 286 | // missing NRD section |
| 287 | ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun); |
| 288 | } |
| 289 | }); |
| 290 | |
| 291 | m_impl->m_ribManager->setConfigFile(config); |
| 292 | |
| 293 | // apply config |
| 294 | config.parse(m_impl->m_config, false, "ndnSIM.conf"); |
| 295 | |
| 296 | m_impl->m_ribManager->registerWithNfd(); |
| 297 | |
| 298 | m_impl->m_ribManager->enableLocalControlHeader(); |
| 299 | } |
| 300 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 301 | shared_ptr<nfd::Forwarder> |
| 302 | L3Protocol::getForwarder() |
| 303 | { |
| 304 | return m_impl->m_forwarder; |
| 305 | } |
| 306 | |
| 307 | shared_ptr<nfd::FibManager> |
| 308 | L3Protocol::getFibManager() |
| 309 | { |
| 310 | return m_impl->m_fibManager; |
| 311 | } |
| 312 | |
| 313 | shared_ptr<nfd::StrategyChoiceManager> |
| 314 | L3Protocol::getStrategyChoiceManager() |
| 315 | { |
| 316 | return m_impl->m_strategyChoiceManager; |
| 317 | } |
| 318 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 319 | nfd::ConfigSection& |
| 320 | L3Protocol::getConfig() |
| 321 | { |
| 322 | return m_impl->m_config; |
| 323 | } |
| 324 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 325 | /* |
| 326 | * This method is called by AddAgregate and completes the aggregation |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 327 | * by setting the node in the ndn stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 328 | */ |
| 329 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 330 | L3Protocol::NotifyNewAggregate() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 331 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 332 | if (m_node == nullptr) { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 333 | m_node = GetObject<Node>(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 334 | if (m_node != nullptr) { |
Spyridon Mastorakis | 8fde22b | 2015-08-19 23:12:44 -0700 | [diff] [blame^] | 335 | initialize(); |
| 336 | |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 337 | NS_ASSERT(m_impl->m_forwarder != nullptr); |
| 338 | m_impl->m_csFromNdnSim = GetObject<ContentStore>(); |
| 339 | if (m_impl->m_csFromNdnSim != nullptr) { |
| 340 | m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim); |
| 341 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 342 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 343 | } |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 344 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 345 | Object::NotifyNewAggregate(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 348 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 349 | L3Protocol::DoDispose(void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 350 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 351 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 352 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 353 | m_node = 0; |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 354 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 355 | Object::DoDispose(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 358 | nfd::FaceId |
| 359 | L3Protocol::addFace(shared_ptr<Face> face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 360 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 361 | NS_LOG_FUNCTION(this << face.get()); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 362 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 363 | m_impl->m_forwarder->addFace(face); |
| 364 | |
| 365 | // Connect Signals to TraceSource |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 366 | face->onReceiveInterest.connect |
| 367 | ([this, face](const Interest& interest) { this->m_inInterests(interest, *face); }); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 368 | |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 369 | face->onSendInterest.connect |
| 370 | ([this, face](const Interest& interest) { this->m_outInterests(interest, *face); }); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 371 | |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 372 | 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] | 373 | |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 374 | 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] | 375 | |
| 376 | return face->getId(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 379 | // void |
| 380 | // L3Protocol::removeFace(shared_ptr<Face> face) |
| 381 | // { |
| 382 | // NS_LOG_FUNCTION(this << std::cref(*face)); |
| 383 | // } |
| 384 | |
| 385 | shared_ptr<Face> |
| 386 | L3Protocol::getFaceById(nfd::FaceId id) const |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 387 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 388 | return m_impl->m_forwarder->getFaceTable().get(id); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 391 | shared_ptr<Face> |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 392 | L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 393 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 394 | for (const auto& i : m_impl->m_forwarder->getFaceTable()) { |
| 395 | shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(i); |
| 396 | if (netDeviceFace == nullptr) |
| 397 | continue; |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 398 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 399 | if (netDeviceFace->GetNetDevice() == netDevice) |
| 400 | return i; |
| 401 | } |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 402 | return nullptr; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Alexander Afanasyev | 6b2a3c0 | 2015-01-03 02:04:23 -0800 | [diff] [blame] | 405 | Ptr<L3Protocol> |
| 406 | L3Protocol::getL3Protocol(Ptr<Object> node) |
| 407 | { |
| 408 | Ptr<L3Protocol> retval = node->GetObject<L3Protocol>(); |
| 409 | NS_ASSERT_MSG(retval != nullptr, "L3Protocol is not aggregated on this object"); |
| 410 | return retval; |
| 411 | } |
| 412 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 413 | } // namespace ndn |
| 414 | } // namespace ns3 |