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