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