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" |
| 26 | |
| 27 | #include "model/ndn-l3-protocol.hpp" |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 28 | #include "model/ndn-net-device-link-service.hpp" |
| 29 | #include "model/null-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 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 38 | NS_LOG_COMPONENT_DEFINE("ndn.StackHelper"); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 39 | |
| 40 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | namespace ndn { |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 42 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 43 | StackHelper::StackHelper() |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 44 | : m_isRibManagerDisabled(false) |
| 45 | // , m_isFaceManagerDisabled(false) |
| 46 | , m_isForwarderStatusManagerDisabled(false) |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 47 | , m_isStrategyChoiceManagerDisabled(false) |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 48 | , m_needSetDefaultRoutes(false) |
| 49 | , m_maxCsSize(100) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 50 | { |
Spyridon Mastorakis | 86edf6f | 2014-11-14 19:27:18 -0800 | [diff] [blame] | 51 | setCustomNdnCxxClocks(); |
| 52 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 53 | m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol"); |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 54 | m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru"); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 55 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | m_netDeviceCallbacks.push_back( |
| 57 | std::make_pair(PointToPointNetDevice::GetTypeId(), |
| 58 | MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this))); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 59 | // 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] | 60 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | StackHelper::~StackHelper() |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 63 | { |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 66 | KeyChain& |
| 67 | StackHelper::getKeyChain() |
| 68 | { |
Alexander Afanasyev | df26b5a | 2015-01-15 23:30:56 -0800 | [diff] [blame] | 69 | static ::ndn::KeyChain keyChain("pib-dummy", "tpm-dummy"); |
Alexander Afanasyev | 34e13f3 | 2014-12-14 15:13:28 -0800 | [diff] [blame] | 70 | return keyChain; |
| 71 | } |
| 72 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 73 | void |
Spyridon Mastorakis | 86edf6f | 2014-11-14 19:27:18 -0800 | [diff] [blame] | 74 | StackHelper::setCustomNdnCxxClocks() |
| 75 | { |
| 76 | ::ndn::time::setCustomClocks(make_shared<ns3::ndn::time::CustomSteadyClock>(), |
| 77 | make_shared<ns3::ndn::time::CustomSystemClock>()); |
| 78 | } |
| 79 | |
Spyridon Mastorakis | 588fd10 | 2014-11-20 19:50:02 -0800 | [diff] [blame] | 80 | void |
| 81 | StackHelper::SetDefaultRoutes(bool needSet) |
| 82 | { |
| 83 | NS_LOG_FUNCTION(this << needSet); |
| 84 | m_needSetDefaultRoutes = needSet; |
| 85 | } |
| 86 | |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 87 | void |
| 88 | StackHelper::SetStackAttributes(const std::string& attr1, const std::string& value1, |
| 89 | const std::string& attr2, const std::string& value2, |
| 90 | const std::string& attr3, const std::string& value3, |
| 91 | const std::string& attr4, const std::string& value4) |
| 92 | { |
| 93 | if (attr1 != "") |
| 94 | m_ndnFactory.Set(attr1, StringValue(value1)); |
| 95 | if (attr2 != "") |
| 96 | m_ndnFactory.Set(attr2, StringValue(value2)); |
| 97 | if (attr3 != "") |
| 98 | m_ndnFactory.Set(attr3, StringValue(value3)); |
| 99 | if (attr4 != "") |
| 100 | m_ndnFactory.Set(attr4, StringValue(value4)); |
| 101 | } |
| 102 | |
| 103 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 104 | StackHelper::SetOldContentStore(const std::string& contentStore, const std::string& attr1, |
| 105 | const std::string& value1, const std::string& attr2, |
| 106 | const std::string& value2, const std::string& attr3, |
| 107 | const std::string& value3, const std::string& attr4, |
| 108 | const std::string& value4) |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 109 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 110 | m_maxCsSize = 0; |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 111 | |
| 112 | m_contentStoreFactory.SetTypeId(contentStore); |
| 113 | if (attr1 != "") |
| 114 | m_contentStoreFactory.Set(attr1, StringValue(value1)); |
| 115 | if (attr2 != "") |
| 116 | m_contentStoreFactory.Set(attr2, StringValue(value2)); |
| 117 | if (attr3 != "") |
| 118 | m_contentStoreFactory.Set(attr3, StringValue(value3)); |
| 119 | if (attr4 != "") |
| 120 | m_contentStoreFactory.Set(attr4, StringValue(value4)); |
| 121 | } |
| 122 | |
| 123 | void |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 124 | StackHelper::setCsSize(size_t maxSize) |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 125 | { |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 126 | m_maxCsSize = maxSize; |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 127 | } |
| 128 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 129 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 130 | StackHelper::Install(const NodeContainer& c) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 131 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 132 | Ptr<FaceContainer> faces = Create<FaceContainer>(); |
| 133 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 134 | faces->AddAll(Install(*i)); |
| 135 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 136 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 139 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 140 | StackHelper::InstallAll() const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 141 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 142 | return Install(NodeContainer::GetGlobal()); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 145 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 146 | StackHelper::Install(Ptr<Node> node) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 147 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 148 | Ptr<FaceContainer> faces = Create<FaceContainer>(); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 149 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 150 | if (node->GetObject<L3Protocol>() != 0) { |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 151 | NS_FATAL_ERROR("Cannot re-install NDN stack on node " |
| 152 | << node->GetId()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 153 | return 0; |
| 154 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 155 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 156 | Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>(); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 157 | |
| 158 | if (m_isRibManagerDisabled) { |
| 159 | ndn->getConfig().put("ndnSIM.disable_rib_manager", true); |
| 160 | } |
| 161 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 162 | // if (m_isFaceManagerDisabled) { |
| 163 | // ndn->getConfig().put("ndnSIM.disable_face_manager", true); |
| 164 | // } |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 165 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 166 | if (m_isForwarderStatusManagerDisabled) { |
| 167 | ndn->getConfig().put("ndnSIM.disable_forwarder_status_manager", true); |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | if (m_isStrategyChoiceManagerDisabled) { |
| 171 | ndn->getConfig().put("ndnSIM.disable_strategy_choice_manager", true); |
| 172 | } |
| 173 | |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 174 | ndn->getConfig().put("tables.cs_max_packets", (m_maxCsSize == 0) ? 1 : m_maxCsSize); |
| 175 | |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 176 | // 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] | 177 | if (m_maxCsSize == 0) { |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 178 | ndn->AggregateObject(m_contentStoreFactory.Create<ContentStore>()); |
Alexander Afanasyev | dde1e81 | 2015-01-06 14:26:09 -0800 | [diff] [blame] | 179 | } |
Spyridon Mastorakis | de1f773 | 2014-12-05 22:43:34 -0800 | [diff] [blame] | 180 | |
| 181 | // Aggregate L3Protocol on node (must be after setting ndnSIM CS) |
| 182 | node->AggregateObject(ndn); |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 183 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 184 | for (uint32_t index = 0; index < node->GetNDevices(); index++) { |
| 185 | Ptr<NetDevice> device = node->GetDevice(index); |
| 186 | // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed, |
| 187 | // Normally, ndnSIM works without IP stack, so no reason to check |
| 188 | // if (DynamicCast<LoopbackNetDevice> (device) != 0) |
| 189 | // continue; // don't create face for a LoopbackNetDevice |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 190 | |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 191 | faces->Add(this->createAndRegisterFace(node, ndn, device)); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 192 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 193 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 194 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 197 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 198 | StackHelper::AddFaceCreateCallback(TypeId netDeviceType, |
| 199 | StackHelper::FaceCreateCallback callback) |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 200 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 201 | m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback)); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 204 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 205 | StackHelper::UpdateFaceCreateCallback(TypeId netDeviceType, |
| 206 | FaceCreateCallback callback) |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 207 | { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 208 | for (auto& i : m_netDeviceCallbacks) { |
| 209 | if (i.first == netDeviceType) { |
| 210 | i.second = callback; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 211 | return; |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 212 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 213 | } |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 217 | StackHelper::RemoveFaceCreateCallback(TypeId netDeviceType, |
| 218 | FaceCreateCallback callback) |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 219 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 220 | m_netDeviceCallbacks.remove_if([&] (const std::pair<TypeId, FaceCreateCallback>& i) { |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 221 | return (i.first == netDeviceType); |
| 222 | }); |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 223 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 224 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 225 | shared_ptr<Face> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 226 | StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, |
| 227 | Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 228 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 229 | NS_LOG_DEBUG("Creating default Face on node " << node->GetId()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 230 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 231 | auto netDeviceLink = make_unique<NetDeviceLinkService>(node, netDevice); |
| 232 | auto transport = make_unique<NullTransport>("netDevice://", "netDevice://"); |
| 233 | auto face = std::make_shared<Face>(std::move(netDeviceLink), std::move(transport)); |
| 234 | face->setMetric(1); |
| 235 | |
| 236 | // @TODO add netDevice ID |
Alexander Afanasyev | c17e4bd | 2013-02-17 14:31:56 -0800 | [diff] [blame] | 237 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 238 | ndn->addFace(face); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 239 | NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 240 | << face->getLocalUri()); |
Alexander Afanasyev | c17e4bd | 2013-02-17 14:31:56 -0800 | [diff] [blame] | 241 | |
| 242 | return face; |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 245 | shared_ptr<Face> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 246 | StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, |
| 247 | Ptr<NetDevice> device) const |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 248 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 249 | NS_LOG_DEBUG("Creating point-to-point Face on node " << node->GetId()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 250 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 251 | auto netDeviceLink = make_unique<NetDeviceLinkService>(node, device); |
| 252 | auto transport = make_unique<NullTransport>("netDevice://", "netDevice://"); |
| 253 | auto face = std::make_shared<Face>(std::move(netDeviceLink), std::move(transport)); |
| 254 | face->setMetric(1); |
| 255 | |
| 256 | // @TODO add netDevice ID |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 257 | |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 258 | ndn->addFace(face); |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 259 | NS_LOG_LOGIC("Node " << node->GetId() << ": added Face as face #" |
Spyridon Mastorakis | 9760bd0 | 2014-11-12 13:32:55 -0800 | [diff] [blame] | 260 | << face->getLocalUri()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 261 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 262 | return face; |
| 263 | } |
| 264 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 265 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 266 | StackHelper::Install(const std::string& nodeName) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 267 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 268 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 269 | return Install(node); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 272 | void |
| 273 | StackHelper::Update(Ptr<Node> node) |
| 274 | { |
| 275 | if (node->GetObject<L3Protocol>() == 0) { |
| 276 | Install(node); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>(); |
| 281 | |
| 282 | for (uint32_t index = 0; index < node->GetNDevices(); index++) { |
| 283 | |
| 284 | Ptr<NetDevice> device = node->GetDevice(index); |
| 285 | |
| 286 | if (ndn->getFaceByNetDevice(device) == nullptr) { |
| 287 | this->createAndRegisterFace(node, ndn, device); |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | void |
| 293 | StackHelper::Update(const NodeContainer& c) |
| 294 | { |
| 295 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 296 | Update(*i); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void |
| 301 | StackHelper::Update(const std::string& nodeName) |
| 302 | { |
| 303 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 304 | Update(node); |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | StackHelper::UpdateAll() |
| 309 | { |
| 310 | Update(NodeContainer::GetGlobal()); |
| 311 | } |
| 312 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 313 | shared_ptr<Face> |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 314 | StackHelper::createAndRegisterFace(Ptr<Node> node, Ptr<L3Protocol> ndn, Ptr<NetDevice> device) const |
| 315 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 316 | shared_ptr<Face> face; |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 317 | |
| 318 | for (const auto& item : m_netDeviceCallbacks) { |
| 319 | if (device->GetInstanceTypeId() == item.first || |
| 320 | device->GetInstanceTypeId().IsChildOf(item.first)) { |
| 321 | face = item.second(node, ndn, device); |
| 322 | if (face != 0) |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | if (face == 0) { |
| 328 | face = DefaultNetDeviceCallback(node, ndn, device); |
| 329 | } |
| 330 | |
| 331 | if (m_needSetDefaultRoutes) { |
| 332 | // default route with lowest priority possible |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 333 | |
| 334 | // TODO: Restore when FibHelper is available |
| 335 | // FibHelper::AddRoute(node, "/", face, std::numeric_limits<int32_t>::max()); |
Spyridon Mastorakis | 21226ae | 2015-03-31 18:03:11 -0700 | [diff] [blame] | 336 | } |
| 337 | return face; |
| 338 | } |
| 339 | |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 340 | void |
| 341 | StackHelper::disableRibManager() |
| 342 | { |
| 343 | m_isRibManagerDisabled = true; |
| 344 | } |
| 345 | |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 346 | // void |
| 347 | // StackHelper::disableFaceManager() |
| 348 | // { |
| 349 | // m_isFaceManagerDisabled = true; |
| 350 | // } |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 351 | |
| 352 | void |
| 353 | StackHelper::disableStrategyChoiceManager() |
| 354 | { |
| 355 | m_isStrategyChoiceManagerDisabled = true; |
| 356 | } |
| 357 | |
| 358 | void |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 359 | StackHelper::disableForwarderStatusManager() |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 360 | { |
Alexander Afanasyev | a91aab4 | 2016-09-08 15:47:38 -0700 | [diff] [blame^] | 361 | m_isForwarderStatusManagerDisabled = true; |
spirosmastorakis | 0df15ba | 2015-11-14 08:46:24 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 364 | } // namespace ndn |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 365 | } // namespace ns3 |