Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:ni -*- */ |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Ilya Moiseenko | 172763c | 2011-10-28 13:21:53 -0700 | [diff] [blame] | 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | ab1d560 | 2011-08-17 19:17:18 -0700 | [diff] [blame] | 20 | */ |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 21 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 22 | #include "ndn-l3-protocol.hpp" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 24 | #include "ns3/packet.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 25 | #include "ns3/node.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 26 | #include "ns3/log.h" |
| 27 | #include "ns3/callback.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 28 | #include "ns3/uinteger.h" |
| 29 | #include "ns3/trace-source-accessor.h" |
| 30 | #include "ns3/object-vector.h" |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 31 | #include "ns3/pointer.h" |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 32 | #include "ns3/simulator.h" |
Alexander Afanasyev | ff8c5d6 | 2012-04-25 15:14:51 -0700 | [diff] [blame] | 33 | #include "ns3/random-variable.h" |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 34 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 35 | #include "ndn-face.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 36 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 37 | #include "ndn-net-device-face.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 38 | #include "../helper/ndn-stack-helper.hpp" |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | 56f79ea | 2011-08-17 23:54:27 -0700 | [diff] [blame] | 40 | #include <boost/foreach.hpp> |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 41 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 42 | #include "ns3/ndnSIM/NFD/daemon/fw/forwarder.hpp" |
| 43 | #include "ns3/ndnSIM/NFD/daemon/mgmt/internal-face.hpp" |
| 44 | #include "ns3/ndnSIM/NFD/daemon/mgmt/fib-manager.hpp" |
| 45 | #include "ns3/ndnSIM/NFD/daemon/mgmt/face-manager.hpp" |
| 46 | #include "ns3/ndnSIM/NFD/daemon/mgmt/strategy-choice-manager.hpp" |
| 47 | #include "ns3/ndnSIM/NFD/daemon/mgmt/status-server.hpp" |
| 48 | |
| 49 | #include "ns3/ndnSIM/NFD/daemon/face/null-face.hpp" |
| 50 | #include "ns3/ndnSIM/NFD/core/config-file.hpp" |
| 51 | #include "ns3/ndnSIM/NFD/daemon/mgmt/general-config-section.hpp" |
| 52 | #include "ns3/ndnSIM/NFD/daemon/mgmt/tables-config-section.hpp" |
| 53 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | NS_LOG_COMPONENT_DEFINE("ndn.L3Protocol"); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 55 | |
| 56 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 57 | namespace ndn { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 59 | const uint16_t L3Protocol::ETHERNET_FRAME_TYPE = 0x7777; |
Alexander Afanasyev | 016a5d8 | 2013-07-15 10:41:29 -0700 | [diff] [blame] | 60 | const uint16_t L3Protocol::IP_STACK_PORT = 9695; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 61 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | NS_OBJECT_ENSURE_REGISTERED(L3Protocol); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 64 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | L3Protocol::GetTypeId(void) |
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 | static TypeId tid = |
| 68 | TypeId("ns3::ndn::L3Protocol") |
| 69 | .SetGroupName("ndn") |
| 70 | .SetParent<Object>() |
| 71 | .AddConstructor<L3Protocol>() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 72 | |
| 73 | .AddTraceSource("OutInterests", "OutInterests", |
| 74 | MakeTraceSourceAccessor(&L3Protocol::m_outInterests)) |
| 75 | .AddTraceSource("InInterests", "InInterests", |
| 76 | MakeTraceSourceAccessor(&L3Protocol::m_inInterests)) |
| 77 | |
| 78 | //////////////////////////////////////////////////////////////////// |
| 79 | |
| 80 | .AddTraceSource("OutData", "OutData", MakeTraceSourceAccessor(&L3Protocol::m_outData)) |
| 81 | .AddTraceSource("InData", "InData", MakeTraceSourceAccessor(&L3Protocol::m_inData)); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 82 | return tid; |
| 83 | } |
| 84 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 85 | class L3Protocol::Impl { |
| 86 | private: |
| 87 | friend class L3Protocol; |
| 88 | |
| 89 | shared_ptr<nfd::Forwarder> m_forwarder; |
| 90 | |
| 91 | shared_ptr<nfd::InternalFace> m_internalFace; |
| 92 | shared_ptr<nfd::FibManager> m_fibManager; |
| 93 | shared_ptr<nfd::FaceManager> m_faceManager; |
| 94 | shared_ptr<nfd::StrategyChoiceManager> m_strategyChoiceManager; |
| 95 | shared_ptr<nfd::StatusServer> m_statusServer; |
| 96 | }; |
| 97 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | L3Protocol::L3Protocol() |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 99 | : m_impl(new Impl()) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 100 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | L3Protocol::~L3Protocol() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 105 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 109 | void |
| 110 | L3Protocol::initialize() |
| 111 | { |
| 112 | m_impl->m_forwarder = make_shared<nfd::Forwarder>(); |
| 113 | |
| 114 | initializeManagement(); |
| 115 | |
| 116 | m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>(), nfd::FACEID_NULL); |
| 117 | m_impl->m_forwarder->getFaceTable().addReserved(make_shared<nfd::NullFace>( |
| 118 | FaceUri("contentstore://")), |
| 119 | nfd::FACEID_CONTENT_STORE); |
| 120 | } |
| 121 | |
| 122 | void |
| 123 | L3Protocol::initializeManagement() |
| 124 | { |
| 125 | m_impl->m_internalFace = make_shared<nfd::InternalFace>(); |
| 126 | |
| 127 | m_impl->m_fibManager = |
| 128 | make_shared<nfd::FibManager>(ref(m_impl->m_forwarder->getFib()), |
| 129 | bind(&nfd::Forwarder::getFace, m_impl->m_forwarder.get(), _1), |
| 130 | m_impl->m_internalFace, std::ref(StackHelper::getKeyChain())); |
| 131 | |
| 132 | m_impl->m_faceManager = |
| 133 | make_shared<nfd::FaceManager>(ref(m_impl->m_forwarder->getFaceTable()), m_impl->m_internalFace, |
| 134 | std::ref(StackHelper::getKeyChain())); |
| 135 | |
| 136 | m_impl->m_strategyChoiceManager = |
| 137 | make_shared<nfd::StrategyChoiceManager>(ref(m_impl->m_forwarder->getStrategyChoice()), |
| 138 | m_impl->m_internalFace, |
| 139 | std::ref(StackHelper::getKeyChain())); |
| 140 | |
| 141 | m_impl->m_statusServer = |
| 142 | make_shared<nfd::StatusServer>(m_impl->m_internalFace, ref(*m_impl->m_forwarder), |
| 143 | std::ref(StackHelper::getKeyChain())); |
| 144 | |
| 145 | nfd::TablesConfigSection tablesConfig(m_impl->m_forwarder->getCs(), |
| 146 | m_impl->m_forwarder->getPit(), |
| 147 | m_impl->m_forwarder->getFib(), |
| 148 | m_impl->m_forwarder->getStrategyChoice(), |
| 149 | m_impl->m_forwarder->getMeasurements()); |
| 150 | |
| 151 | m_impl->m_forwarder->getFaceTable().addReserved(m_impl->m_internalFace, |
| 152 | nfd::FACEID_INTERNAL_FACE); |
| 153 | |
| 154 | // add FIB entry for NFD Management Protocol |
| 155 | shared_ptr<::nfd::fib::Entry> entry = |
| 156 | m_impl->m_forwarder->getFib().insert("/localhost/nfd").first; |
| 157 | entry->addNextHop(m_impl->m_internalFace, 0); |
| 158 | } |
| 159 | |
| 160 | shared_ptr<nfd::Forwarder> |
| 161 | L3Protocol::getForwarder() |
| 162 | { |
| 163 | return m_impl->m_forwarder; |
| 164 | } |
| 165 | |
| 166 | shared_ptr<nfd::FibManager> |
| 167 | L3Protocol::getFibManager() |
| 168 | { |
| 169 | return m_impl->m_fibManager; |
| 170 | } |
| 171 | |
| 172 | shared_ptr<nfd::StrategyChoiceManager> |
| 173 | L3Protocol::getStrategyChoiceManager() |
| 174 | { |
| 175 | return m_impl->m_strategyChoiceManager; |
| 176 | } |
| 177 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 178 | /* |
| 179 | * This method is called by AddAgregate and completes the aggregation |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 180 | * by setting the node in the ndn stack |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 181 | */ |
| 182 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 183 | L3Protocol::NotifyNewAggregate() |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 184 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 185 | if (m_node == nullptr) { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 186 | m_node = GetObject<Node>(); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 187 | if (m_node != nullptr) { |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 188 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 189 | } |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 190 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 191 | Object::NotifyNewAggregate(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Alexander Afanasyev | 06dba7c | 2013-02-21 11:36:26 -0800 | [diff] [blame] | 194 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 195 | L3Protocol::DoDispose(void) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 196 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 197 | NS_LOG_FUNCTION(this); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 199 | m_node = 0; |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 200 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 201 | Object::DoDispose(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 204 | nfd::FaceId |
| 205 | L3Protocol::addFace(shared_ptr<Face> face) |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 206 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 207 | NS_LOG_FUNCTION(this << face.get()); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 208 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 209 | m_impl->m_forwarder->addFace(face); |
| 210 | |
| 211 | // Connect Signals to TraceSource |
| 212 | face->onReceiveInterest += |
| 213 | [this, face](const Interest& interest) { this->m_inInterests(interest, *face); }; |
| 214 | |
| 215 | face->onSendInterest += |
| 216 | [this, face](const Interest& interest) { this->m_outInterests(interest, *face); }; |
| 217 | |
| 218 | face->onReceiveData += [this, face](const Data& data) { this->m_inData(data, *face); }; |
| 219 | |
| 220 | face->onSendData += [this, face](const Data& data) { this->m_outData(data, *face); }; |
| 221 | |
| 222 | return face->getId(); |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 223 | } |
| 224 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 225 | // void |
| 226 | // L3Protocol::removeFace(shared_ptr<Face> face) |
| 227 | // { |
| 228 | // NS_LOG_FUNCTION(this << std::cref(*face)); |
| 229 | // } |
| 230 | |
| 231 | shared_ptr<Face> |
| 232 | L3Protocol::getFaceById(nfd::FaceId id) const |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 233 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 234 | return m_impl->m_forwarder->getFaceTable().get(id); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 237 | shared_ptr<Face> |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 238 | L3Protocol::getFaceByNetDevice(Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 239 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 240 | for (const auto& i : m_impl->m_forwarder->getFaceTable()) { |
| 241 | shared_ptr<NetDeviceFace> netDeviceFace = std::dynamic_pointer_cast<NetDeviceFace>(i); |
| 242 | if (netDeviceFace == nullptr) |
| 243 | continue; |
Alexander Afanasyev | aebf5cf | 2012-08-28 17:32:17 -0700 | [diff] [blame] | 244 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 245 | if (netDeviceFace->GetNetDevice() == netDevice) |
| 246 | return i; |
| 247 | } |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 248 | return nullptr; |
Alexander Afanasyev | 08d984e | 2011-08-13 19:20:22 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 251 | } // namespace ndn |
| 252 | } // namespace ns3 |