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 | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 31 | #include "ns3/random-variable.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 32 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 33 | #include "ndn-face.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 34 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 35 | #include "ndn-net-device-face.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 36 | #include "../helper/ndn-stack-helper.hpp" |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 37 | #include "cs/ndn-content-store.hpp" |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 39 | #include <boost/property_tree/info_parser.hpp> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 40 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 41 | #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" |
| 42 | #include "ns3/ndnSIM/NFD/daemon/mgmt/internal-face.hpp" |
| 43 | #include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp" |
| 44 | #include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp" |
| 45 | #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp" |
| 46 | #include "ns3/ndnSIM/NFD/daemon/mgmt/status-server.hpp" |
| 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", |
| 73 | MakeTraceSourceAccessor(&L3Protocol::m_outInterests)) |
| 74 | .AddTraceSource("InInterests", "InInterests", |
| 75 | MakeTraceSourceAccessor(&L3Protocol::m_inInterests)) |
| 76 | |
| 77 | //////////////////////////////////////////////////////////////////// |
| 78 | |
| 79 | .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData)) |
| 80 | .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 81 | return tid; |
| 82 | } |
| 83 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 84 | class L3Protocol::Impl { |
| 85 | private: |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 86 | Impl() |
| 87 | { |
| 88 | // Do not modify initial config file. Use helpers to set specific NFD parameters |
| 89 | std::string initialConfig = |
| 90 | "general\n" |
| 91 | "{\n" |
| 92 | "}\n" |
| 93 | "\n" |
| 94 | "tables\n" |
| 95 | "{\n" |
| 96 | " cs_max_packets 100\n" |
| 97 | "\n" |
| 98 | " strategy_choice\n" |
| 99 | " {\n" |
| 100 | " / /localhost/nfd/strategy/best-route\n" |
| 101 | " /localhost /localhost/nfd/strategy/broadcast\n" |
| 102 | " /localhost/nfd /localhost/nfd/strategy/best-route\n" |
| 103 | " /ndn/broadcast /localhost/nfd/strategy/broadcast\n" |
| 104 | " }\n" |
| 105 | "}\n" |
| 106 | "\n" |
| 107 | // "face_system\n" |
| 108 | // "{\n" |
| 109 | // "}\n" |
| 110 | "\n" |
| 111 | "authorizations\n" |
| 112 | "{\n" |
| 113 | " authorize\n" |
| 114 | " {\n" |
| 115 | " certfile any\n" |
| 116 | " privileges\n" |
| 117 | " {\n" |
| 118 | " faces\n" |
| 119 | " fib\n" |
| 120 | " strategy-choice\n" |
| 121 | " }\n" |
| 122 | " }\n" |
| 123 | "}\n" |
| 124 | "\n" |
| 125 | "rib\n" |
| 126 | "{\n" |
| 127 | " localhost_security\n" |
| 128 | " {\n" |
| 129 | " trust-anchor\n" |
| 130 | " {\n" |
| 131 | " type any\n" |
| 132 | " }\n" |
| 133 | " }\n" |
| 134 | "}\n" |
| 135 | "\n"; |
| 136 | |
| 137 | std::istringstream input(initialConfig); |
| 138 | boost::property_tree::read_info(input, m_config); |
| 139 | } |
| 140 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 141 | friend class L3Protocol; |
| 142 | |
| 143 | shared_ptr<nfd::Forwarder> m_forwarder; |
| 144 | |
| 145 | shared_ptr<nfd::InternalFace> m_internalFace; |
| 146 | shared_ptr<nfd::FibManager> m_fibManager; |
| 147 | shared_ptr<nfd::FaceManager> m_faceManager; |
| 148 | shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager; |
| 149 | shared_ptr<nfd::StatusServer> m_statusServer; |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 150 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 151 | nfd::ConfigSection m_config; |
| 152 | |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 153 | Ptr<ContentStore> m_csFromNdnSim; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 154 | }; |
| 155 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 156 | L3Protocol::L3Protocol() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 157 | : m_impl(new Impl()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 158 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 159 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 162 | L3Protocol::~L3Protocol() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 163 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 164 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 167 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 168 | L3Protocol::initialize() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 169 | { |
| 170 | m_impl->m_forwarder = make_shared<nfd::Forwarder>(); |
| 171 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 172 | initializeManagement(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 173 | |
| 174 | m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(), nfd::FACEID_NULL); |
| 175 | m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>( |
| 176 | FaceUri("contentstore://")), |
| 177 | nfd::FACEID_CONTENT_STORE); |
| 178 | } |
| 179 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 180 | class IgnoreSections |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 181 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 182 | public: |
| 183 | IgnoreSections(const std::vector<std::string>& ignored) |
| 184 | : m_ignored(ignored) |
| 185 | { |
| 186 | } |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 187 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 188 | void |
| 189 | operator()(const std::string& filename, const std::string& sectionName, |
| 190 | const nfd::ConfigSection& section, bool isDryRun) |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 191 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 192 | { |
| 193 | if (std::find(m_ignored.begin(), m_ignored.end(), sectionName) == m_ignored.end()) { |
| 194 | nfd::ConfigFile::throwErrorOnUnknownSection(filename, sectionName, section, isDryRun); |
| 195 | } |
| 196 | } |
| 197 | private: |
| 198 | std::vector<std::string> m_ignored; |
| 199 | }; |
| 200 | |
| 201 | void |
| 202 | L3Protocol::initializeManagement() |
| 203 | { |
| 204 | auto keyChain = std::ref(StackHelper::getKeyChain()); |
| 205 | auto& forwarder = m_impl->m_forwarder; |
| 206 | using namespace nfd; |
| 207 | |
| 208 | m_impl->m_internalFace = make_shared<InternalFace>(); |
| 209 | |
| 210 | m_impl->m_fibManager = make_shared<FibManager>(std::ref(forwarder->getFib()), |
| 211 | bind(&Forwarder::getFace, forwarder.get(), _1), |
| 212 | m_impl->m_internalFace, keyChain); |
| 213 | |
| 214 | m_impl->m_faceManager = make_shared<FaceManager>(std::ref(forwarder->getFaceTable()), |
| 215 | m_impl->m_internalFace, |
| 216 | keyChain); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 217 | |
| 218 | m_impl->m_strategyChoiceManager = |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 219 | make_shared<StrategyChoiceManager>(std::ref(forwarder->getStrategyChoice()), |
| 220 | m_impl->m_internalFace, |
| 221 | keyChain); |
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 | m_impl->m_statusServer = make_shared<StatusServer>(m_impl->m_internalFace, |
| 224 | ref(*forwarder), |
| 225 | keyChain); |
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 | ConfigFile config((IgnoreSections({"general", "log", "rib"}))); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 228 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 229 | TablesConfigSection tablesConfig(forwarder->getCs(), |
| 230 | forwarder->getPit(), |
| 231 | forwarder->getFib(), |
| 232 | forwarder->getStrategyChoice(), |
| 233 | forwarder->getMeasurements()); |
| 234 | tablesConfig.setConfigFile(config); |
| 235 | |
| 236 | m_impl->m_internalFace->getValidator().setConfigFile(config); |
| 237 | |
| 238 | forwarder->getFaceTable().addReserved(m_impl->m_internalFace, FACEID_INTERNAL_FACE); |
| 239 | |
| 240 | m_impl->m_faceManager->setConfigFile(config); |
| 241 | |
| 242 | // apply config |
| 243 | config.parse(m_impl->m_config, false, "ndnSIM.conf"); |
| 244 | |
| 245 | tablesConfig.ensureTablesAreConfigured(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 246 | |
| 247 | // add FIB entry for NFD Management Protocol |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 248 | shared_ptr<fib::Entry> entry = forwarder->getFib().insert("/localhost/nfd").first; |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 249 | entry->addNextHop(m_impl->m_internalFace, 0); |
| 250 | } |
| 251 | |
| 252 | shared_ptr<nfd::Forwarder> |
| 253 | L3Protocol::getForwarder() |
| 254 | { |
| 255 | return m_impl->m_forwarder; |
| 256 | } |
| 257 | |
| 258 | shared_ptr<nfd::FibManager> |
| 259 | L3Protocol::getFibManager() |
| 260 | { |
| 261 | return m_impl->m_fibManager; |
| 262 | } |
| 263 | |
| 264 | shared_ptr<nfd::StrategyChoiceManager> |
| 265 | L3Protocol::getStrategyChoiceManager() |
| 266 | { |
| 267 | return m_impl->m_strategyChoiceManager; |
| 268 | } |
| 269 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame^] | 270 | nfd::ConfigSection& |
| 271 | L3Protocol::getConfig() |
| 272 | { |
| 273 | return m_impl->m_config; |
| 274 | } |
| 275 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 276 | /* |
| 277 | * This method is called by AddAgregate and completes the aggregation |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 278 | * by setting the node in the ndn stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 279 | */ |
| 280 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 281 | L3Protocol::NotifyNewAggregate() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 282 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 283 | if (m_node == nullptr) { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 284 | m_node = GetObject<Node>(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 285 | if (m_node != nullptr) { |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 286 | NS_ASSERT(m_impl->m_forwarder != nullptr); |
| 287 | m_impl->m_csFromNdnSim = GetObject<ContentStore>(); |
| 288 | if (m_impl->m_csFromNdnSim != nullptr) { |
| 289 | m_impl->m_forwarder->setCsFromNdnSim(m_impl->m_csFromNdnSim); |
| 290 | } |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 291 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 292 | } |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 293 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 294 | Object::NotifyNewAggregate(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 297 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 298 | L3Protocol::DoDispose(void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 299 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 300 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 301 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 302 | m_node = 0; |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 303 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 304 | Object::DoDispose(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 307 | nfd::FaceId |
| 308 | L3Protocol::addFace(shared_ptr<Face> face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 309 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 310 | NS_LOG_FUNCTION(this << face.get()); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 311 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 312 | m_impl->m_forwarder->addFace(face); |
| 313 | |
| 314 | // Connect Signals to TraceSource |
| 315 | face->onReceiveInterest += |
| 316 | [this, face](const Interest& interest) { this->m_inInterests(interest, *face); }; |
| 317 | |
| 318 | face->onSendInterest += |
| 319 | [this, face](const Interest& interest) { this->m_outInterests(interest, *face); }; |
| 320 | |
| 321 | face->onReceiveData += [this, face](const Data& data) { this->m_inData(data, *face); }; |
| 322 | |
| 323 | face->onSendData += [this, face](const Data& data) { this->m_outData(data, *face); }; |
| 324 | |
| 325 | return face->getId(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 328 | // void |
| 329 | // L3Protocol::removeFace(shared_ptr<Face> face) |
| 330 | // { |
| 331 | // NS_LOG_FUNCTION(this << std::cref(*face)); |
| 332 | // } |
| 333 | |
| 334 | shared_ptr<Face> |
| 335 | L3Protocol::getFaceById(nfd::FaceId id) const |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 336 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 337 | return m_impl->m_forwarder->getFaceTable().get(id); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 340 | shared_ptr<Face> |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 341 | L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 342 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 343 | for (const auto& i : m_impl->m_forwarder->getFaceTable()) { |
| 344 | shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(i); |
| 345 | if (netDeviceFace == nullptr) |
| 346 | continue; |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 347 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 348 | if (netDeviceFace->GetNetDevice() == netDevice) |
| 349 | return i; |
| 350 | } |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 351 | return nullptr; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 354 | } // namespace ndn |
| 355 | } // namespace ns3 |