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 | 45b92d4 | 2011-08-14 23:11:38 -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 | 45b92d4 | 2011-08-14 23:11:38 -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 | 45b92d4 | 2011-08-14 23:11:38 -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 | 45b92d4 | 2011-08-14 23:11:38 -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 | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 20 | #include "ndn-stack-helper.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 21 | |
| 22 | #include "ns3/log.h" |
| 23 | #include "ns3/names.h" |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 24 | #include "ns3/string.h" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 25 | #include "ns3/point-to-point-net-device.h" |
Alexander Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 26 | #include "ns3/point-to-point-channel.h" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 27 | |
| 28 | #include "model/ndn-l3-protocol.hpp" |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 29 | #include "model/ndn-net-device-transport.hpp" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 30 | #include "utils/ndn-time.hpp" |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 31 | #include "utils/dummy-keychain.hpp" |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 32 | #include "model/cs/ndn-content-store.hpp" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 33 | |
| 34 | #include <limits> |
| 35 | #include <map> |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 36 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 37 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 38 | #include "ns3/ndnSIM/NFD/daemon/face/generic-link-service.hpp" |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 39 | #include "ns3/ndnSIM/NFD/daemon/table/cs-policy-priority-fifo.hpp" |
| 40 | #include "ns3/ndnSIM/NFD/daemon/table/cs-policy-lru.hpp" |
| 41 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 42 | NS_LOG_COMPONENT_DEFINE("ndn.StackHelper"); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 43 | |
| 44 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 45 | namespace ndn { |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | StackHelper::StackHelper() |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 48 | : m_isRibManagerDisabled(false) |
| 49 | // , m_isFaceManagerDisabled(false) |
| 50 | , m_isForwarderStatusManagerDisabled(false) |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 51 | , m_isStrategyChoiceManagerDisabled(false) |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 52 | , m_needSetDefaultRoutes(false) |
| 53 | , m_maxCsSize(100) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 54 | { |
Spyridon Mastorakis | 86edf6f | 2014-11-14 19:27:18 -0800 | [diff] [blame] | 55 | setCustomNdnCxxClocks(); |
| 56 | |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 57 | m_csPolicies.insert({"nfd::cs::lru", [] { return make_unique<nfd::cs::LruPolicy>(); }}); |
| 58 | m_csPolicies.insert({"nfd::cs::priority_fifo", [] () { return make_unique<nfd::cs::PriorityFifoPolicy>(); }}); |
| 59 | |
| 60 | m_csPolicyCreationFunc = m_csPolicies["nfd::cs::lru"]; |
| 61 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol"); |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 63 | m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru"); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 64 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 65 | m_netDeviceCallbacks.push_back( |
| 66 | std::make_pair(PointToPointNetDevice::GetTypeId(), |
| 67 | MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this))); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 68 | // default callback will be fired if non of others callbacks fit or did the job |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 69 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | StackHelper::~StackHelper() |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 72 | { |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 75 | KeyChain& |
| 76 | StackHelper::getKeyChain() |
| 77 | { |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 78 | static ::ndn::KeyChain keyChain("pib-dummy", "tpm-dummy"); |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 79 | return keyChain; |
| 80 | } |
| 81 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 82 | void |
Spyridon Mastorakis | 86edf6f | 2014-11-14 19:27:18 -0800 | [diff] [blame] | 83 | StackHelper::setCustomNdnCxxClocks() |
| 84 | { |
| 85 | ::ndn::time::setCustomClocks(make_shared<ns3::ndn::time::CustomSteadyClock>(), |
| 86 | make_shared<ns3::ndn::time::CustomSystemClock>()); |
| 87 | } |
| 88 | |
Spyridon Mastorakis | 588fd10 | 2014-11-20 19:50:02 -0800 | [diff] [blame] | 89 | void |
| 90 | StackHelper::SetDefaultRoutes(bool needSet) |
| 91 | { |
| 92 | NS_LOG_FUNCTION(this << needSet); |
| 93 | m_needSetDefaultRoutes = needSet; |
| 94 | } |
| 95 | |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 96 | void |
| 97 | StackHelper::SetStackAttributes(const std::string& attr1, const std::string& value1, |
| 98 | const std::string& attr2, const std::string& value2, |
| 99 | const std::string& attr3, const std::string& value3, |
| 100 | const std::string& attr4, const std::string& value4) |
| 101 | { |
| 102 | if (attr1 != "") |
| 103 | m_ndnFactory.Set(attr1, StringValue(value1)); |
| 104 | if (attr2 != "") |
| 105 | m_ndnFactory.Set(attr2, StringValue(value2)); |
| 106 | if (attr3 != "") |
| 107 | m_ndnFactory.Set(attr3, StringValue(value3)); |
| 108 | if (attr4 != "") |
| 109 | m_ndnFactory.Set(attr4, StringValue(value4)); |
| 110 | } |
| 111 | |
| 112 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 113 | StackHelper::SetOldContentStore(const std::string& contentStore, const std::string& attr1, |
| 114 | const std::string& value1, const std::string& attr2, |
| 115 | const std::string& value2, const std::string& attr3, |
| 116 | const std::string& value3, const std::string& attr4, |
| 117 | const std::string& value4) |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 118 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 119 | m_maxCsSize = 0; |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 120 | |
| 121 | m_contentStoreFactory.SetTypeId(contentStore); |
| 122 | if (attr1 != "") |
| 123 | m_contentStoreFactory.Set(attr1, StringValue(value1)); |
| 124 | if (attr2 != "") |
| 125 | m_contentStoreFactory.Set(attr2, StringValue(value2)); |
| 126 | if (attr3 != "") |
| 127 | m_contentStoreFactory.Set(attr3, StringValue(value3)); |
| 128 | if (attr4 != "") |
| 129 | m_contentStoreFactory.Set(attr4, StringValue(value4)); |
| 130 | } |
| 131 | |
| 132 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 133 | StackHelper::setCsSize(size_t maxSize) |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 134 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 135 | m_maxCsSize = maxSize; |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 136 | } |
| 137 | |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 138 | void |
| 139 | StackHelper::setPolicy(const std::string& policy) |
| 140 | { |
| 141 | auto found = m_csPolicies.find(policy); |
| 142 | if (found != m_csPolicies.end()) { |
| 143 | m_csPolicyCreationFunc = found->second; |
| 144 | } |
| 145 | else { |
| 146 | NS_FATAL_ERROR("Cache replacement policy " << policy << " not found"); |
| 147 | NS_LOG_DEBUG("Available cache replacement policies: "); |
| 148 | for (auto it = m_csPolicies.begin(); it != m_csPolicies.end(); it++) { |
| 149 | NS_LOG_DEBUG(" " << it->first); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 154 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 155 | StackHelper::Install(const NodeContainer& c) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 156 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 157 | Ptr<FaceContainer> faces = Create<FaceContainer>(); |
| 158 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 159 | faces->AddAll(Install(*i)); |
| 160 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 161 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 164 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 165 | StackHelper::InstallAll() const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 166 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 167 | return Install(NodeContainer::GetGlobal()); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 170 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 171 | StackHelper::Install(Ptr<Node> node) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 172 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 173 | Ptr<FaceContainer> faces = Create<FaceContainer>(); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 174 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 175 | if (node->GetObject<L3Protocol>() != 0) { |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 176 | NS_FATAL_ERROR("Cannot re-install NDN stack on node " |
| 177 | << node->GetId()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 178 | return 0; |
| 179 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 180 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 181 | Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>(); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 182 | |
| 183 | if (m_isRibManagerDisabled) { |
| 184 | ndn->getConfig().put("ndnSIM.disable_rib_manager", true); |
| 185 | } |
| 186 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 187 | // if (m_isFaceManagerDisabled) { |
| 188 | // ndn->getConfig().put("ndnSIM.disable_face_manager", true); |
| 189 | // } |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 190 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 191 | if (m_isForwarderStatusManagerDisabled) { |
| 192 | ndn->getConfig().put("ndnSIM.disable_forwarder_status_manager", true); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | if (m_isStrategyChoiceManagerDisabled) { |
| 196 | ndn->getConfig().put("ndnSIM.disable_strategy_choice_manager", true); |
| 197 | } |
| 198 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 199 | ndn->getConfig().put("tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize); |
| 200 | |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 201 | // Create and aggregate content store if NFD's contest store has been disabled |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 202 | if (m_maxCsSize == 0) { |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 203 | ndn->AggregateObject(m_contentStoreFactory.Create<ContentStore>()); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 204 | } |
spirosmastorakis | 34eed98 | 2016-11-02 15:20:50 -0700 | [diff] [blame] | 205 | // if NFD's CS is enabled, check if a replacement policy has been specified |
| 206 | else { |
| 207 | ndn->setCsReplacementPolicy(m_csPolicyCreationFunc); |
| 208 | } |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 209 | |
| 210 | // Aggregate L3Protocol on node (must be after setting ndnSIM CS) |
| 211 | node->AggregateObject(ndn); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 212 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 213 | for (uint32_t index = 0; index < node->GetNDevices(); index++) { |
| 214 | Ptr<NetDevice> device = node->GetDevice(index); |
| 215 | // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed, |
| 216 | // Normally, ndnSIM works without IP stack, so no reason to check |
| 217 | // if (DynamicCast<LoopbackNetDevice> (device) != 0) |
| 218 | // continue; // don't create face for a LoopbackNetDevice |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 219 | |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 220 | faces->Add(this->createAndRegisterFace(node, ndn, device)); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 221 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 222 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 223 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 226 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 227 | StackHelper::AddFaceCreateCallback(TypeId netDeviceType, |
| 228 | StackHelper::FaceCreateCallback callback) |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 229 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 230 | m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback)); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 233 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 234 | StackHelper::UpdateFaceCreateCallback(TypeId netDeviceType, |
| 235 | FaceCreateCallback callback) |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 236 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 237 | for (auto& i : m_netDeviceCallbacks) { |
| 238 | if (i.first == netDeviceType) { |
| 239 | i.second = callback; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 240 | return; |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 241 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 242 | } |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 246 | StackHelper::RemoveFaceCreateCallback(TypeId netDeviceType, |
| 247 | FaceCreateCallback callback) |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 248 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 249 | m_netDeviceCallbacks.remove_if([&] (const std::pair<TypeId, FaceCreateCallback>& i) { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 250 | return (i.first == netDeviceType); |
| 251 | }); |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 252 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 253 | |
Alexander Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 254 | std::string |
| 255 | constructFaceUri(Ptr<NetDevice> netDevice) |
| 256 | { |
| 257 | std::string uri = "netdev://"; |
| 258 | Address address = netDevice->GetAddress(); |
| 259 | if (Mac48Address::IsMatchingType(address)) { |
| 260 | uri += "[" + boost::lexical_cast<std::string>(Mac48Address::ConvertFrom(address)) + "]"; |
| 261 | } |
| 262 | |
| 263 | return uri; |
| 264 | } |
| 265 | |
| 266 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 267 | shared_ptr<Face> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 268 | StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, |
| 269 | Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 270 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 271 | NS_LOG_DEBUG("Creating default Face on node " << node->GetId()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 272 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 273 | // Create an ndnSIM-specific transport instance |
| 274 | ::nfd::face::GenericLinkService::Options opts; |
| 275 | opts.allowFragmentation = true; |
| 276 | opts.allowReassembly = true; |
| 277 | |
| 278 | auto linkService = make_unique<::nfd::face::GenericLinkService>(opts); |
| 279 | |
| 280 | auto transport = make_unique<NetDeviceTransport>(node, netDevice, |
| 281 | constructFaceUri(netDevice), |
| 282 | "netdev://[ff:ff:ff:ff:ff:ff]"); |
| 283 | |
| 284 | auto face = std::make_shared<Face>(std::move(linkService), std::move(transport)); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 285 | face->setMetric(1); |
| 286 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 287 | ndn->addFace(face); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 288 | NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 289 | << face->getLocalUri()); |
Alexander Afanasyev | c17e4bd | 2013-02-17 14:31:56 -0800 | [diff] [blame] | 290 | |
| 291 | return face; |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 292 | } |
| 293 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 294 | shared_ptr<Face> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 295 | StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, |
| 296 | Ptr<NetDevice> device) const |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 297 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 298 | NS_LOG_DEBUG("Creating point-to-point Face on node " << node->GetId()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 299 | |
Alexander Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 300 | Ptr<PointToPointNetDevice> netDevice = DynamicCast<PointToPointNetDevice>(device); |
| 301 | NS_ASSERT(netDevice != nullptr); |
| 302 | |
| 303 | // access the other end of the link |
| 304 | Ptr<PointToPointChannel> channel = DynamicCast<PointToPointChannel>(netDevice->GetChannel()); |
| 305 | NS_ASSERT(channel != nullptr); |
| 306 | |
| 307 | Ptr<NetDevice> remoteNetDevice = channel->GetDevice(0); |
| 308 | if (remoteNetDevice->GetNode() == node) |
| 309 | remoteNetDevice = channel->GetDevice(1); |
| 310 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 311 | // Create an ndnSIM-specific transport instance |
| 312 | ::nfd::face::GenericLinkService::Options opts; |
| 313 | opts.allowFragmentation = true; |
| 314 | opts.allowReassembly = true; |
Alexander Afanasyev | a9d889b | 2016-09-08 18:34:25 -0700 | [diff] [blame] | 315 | |
Spyridon Mastorakis | 5ea3322 | 2016-12-07 14:33:53 -0800 | [diff] [blame] | 316 | auto linkService = make_unique<::nfd::face::GenericLinkService>(opts); |
| 317 | |
| 318 | auto transport = make_unique<NetDeviceTransport>(node, netDevice, |
| 319 | constructFaceUri(netDevice), |
| 320 | constructFaceUri(remoteNetDevice)); |
| 321 | |
| 322 | auto face = std::make_shared<Face>(std::move(linkService), std::move(transport)); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 323 | face->setMetric(1); |
| 324 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 325 | ndn->addFace(face); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 326 | NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 327 | << face->getLocalUri()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 328 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 329 | return face; |
| 330 | } |
| 331 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 332 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 333 | StackHelper::Install(const std::string& nodeName) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 334 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 335 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 336 | return Install(node); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 339 | void |
| 340 | StackHelper::Update(Ptr<Node> node) |
| 341 | { |
| 342 | if (node->GetObject<L3Protocol>() == 0) { |
| 343 | Install(node); |
| 344 | return; |
| 345 | } |
| 346 | |
| 347 | Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>(); |
| 348 | |
| 349 | for (uint32_t index = 0; index < node->GetNDevices(); index++) { |
| 350 | |
| 351 | Ptr<NetDevice> device = node->GetDevice(index); |
| 352 | |
| 353 | if (ndn->getFaceByNetDevice(device) == nullptr) { |
| 354 | this->createAndRegisterFace(node, ndn, device); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | void |
| 360 | StackHelper::Update(const NodeContainer& c) |
| 361 | { |
| 362 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 363 | Update(*i); |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | void |
| 368 | StackHelper::Update(const std::string& nodeName) |
| 369 | { |
| 370 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 371 | Update(node); |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | StackHelper::UpdateAll() |
| 376 | { |
| 377 | Update(NodeContainer::GetGlobal()); |
| 378 | } |
| 379 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 380 | shared_ptr<Face> |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 381 | StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const |
| 382 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 383 | shared_ptr<Face> face; |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 384 | |
| 385 | for (const auto& item : m_netDeviceCallbacks) { |
| 386 | if (device->GetInstanceTypeId() == item.first || |
| 387 | device->GetInstanceTypeId().IsChildOf(item.first)) { |
| 388 | face = item.second(node, ndn, device); |
| 389 | if (face != 0) |
| 390 | break; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if (face == 0) { |
| 395 | face = DefaultNetDeviceCallback(node, ndn, device); |
| 396 | } |
| 397 | |
| 398 | if (m_needSetDefaultRoutes) { |
| 399 | // default route with lowest priority possible |
Alexander Afanasyev | ca3c67e | 2016-09-08 15:48:23 -0700 | [diff] [blame] | 400 | FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max()); |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 401 | } |
| 402 | return face; |
| 403 | } |
| 404 | |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 405 | void |
| 406 | StackHelper::disableRibManager() |
| 407 | { |
| 408 | m_isRibManagerDisabled = true; |
| 409 | } |
| 410 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 411 | // void |
| 412 | // StackHelper::disableFaceManager() |
| 413 | // { |
| 414 | // m_isFaceManagerDisabled = true; |
| 415 | // } |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 416 | |
| 417 | void |
| 418 | StackHelper::disableStrategyChoiceManager() |
| 419 | { |
| 420 | m_isStrategyChoiceManagerDisabled = true; |
| 421 | } |
| 422 | |
| 423 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 424 | StackHelper::disableForwarderStatusManager() |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 425 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame] | 426 | m_isForwarderStatusManagerDisabled = true; |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 429 | } // namespace ndn |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 430 | } // namespace ns3 |