Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 UCLA |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 22 | #include "ns3/assert.h" |
| 23 | #include "ns3/log.h" |
| 24 | #include "ns3/object.h" |
| 25 | #include "ns3/names.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 26 | #include "ns3/packet-socket-factory.h" |
| 27 | #include "ns3/config.h" |
| 28 | #include "ns3/simulator.h" |
| 29 | #include "ns3/string.h" |
| 30 | #include "ns3/net-device.h" |
Alexander Afanasyev | a8f5d88 | 2012-11-09 14:22:48 -0800 | [diff] [blame] | 31 | #include "ns3/channel.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 32 | #include "ns3/callback.h" |
| 33 | #include "ns3/node.h" |
| 34 | #include "ns3/core-config.h" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 35 | #include "ns3/point-to-point-net-device.h" |
| 36 | #include "ns3/point-to-point-helper.h" |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 37 | #include "ns3/callback.h" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 39 | #include "../model/ndn-net-device-face.hpp" |
| 40 | #include "../model/ndn-l3-protocol.hpp" |
Alexander Afanasyev | 11f7bb4 | 2012-07-09 17:06:30 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 42 | #include "ns3/node-list.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 44 | #include "ns3/data-rate.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 45 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 46 | #include "ndn-face-container.hpp" |
| 47 | #include "ndn-stack-helper.hpp" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 48 | |
| 49 | #include <limits> |
| 50 | #include <map> |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 51 | #include <boost/foreach.hpp> |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 52 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | a5bbe0e | 2011-11-22 17:28:39 -0800 | [diff] [blame] | 53 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 54 | NS_LOG_COMPONENT_DEFINE("ndn.StackHelper"); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 55 | |
| 56 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 57 | namespace ndn { |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 58 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 59 | StackHelper::StackHelper() |
| 60 | : m_limitsEnabled(false) |
| 61 | , m_needSetDefaultRoutes(false) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 62 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 63 | m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol"); |
| 64 | m_strategyFactory.SetTypeId("ns3::ndn::fw::Flooding"); |
| 65 | m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru"); |
| 66 | m_fibFactory.SetTypeId("ns3::ndn::fib::Default"); |
| 67 | m_pitFactory.SetTypeId("ns3::ndn::pit::Persistent"); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 68 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 69 | m_netDeviceCallbacks.push_back( |
| 70 | std::make_pair(PointToPointNetDevice::GetTypeId(), |
| 71 | MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this))); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 72 | // 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] | 73 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 74 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 75 | StackHelper::~StackHelper() |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 76 | { |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 79 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | StackHelper::SetStackAttributes(const std::string& attr1, const std::string& value1, |
| 81 | const std::string& attr2, const std::string& value2, |
| 82 | const std::string& attr3, const std::string& value3, |
| 83 | const std::string& attr4, const std::string& value4) |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 84 | { |
| 85 | if (attr1 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | m_ndnFactory.Set(attr1, StringValue(value1)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 87 | if (attr2 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | m_ndnFactory.Set(attr2, StringValue(value2)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 89 | if (attr3 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 90 | m_ndnFactory.Set(attr3, StringValue(value3)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 91 | if (attr4 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | m_ndnFactory.Set(attr4, StringValue(value4)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 95 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 96 | StackHelper::SetForwardingStrategy(const std::string& strategy, const std::string& attr1, |
| 97 | const std::string& value1, const std::string& attr2, |
| 98 | const std::string& value2, const std::string& attr3, |
| 99 | const std::string& value3, const std::string& attr4, |
| 100 | const std::string& value4) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 101 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | m_strategyFactory.SetTypeId(strategy); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 103 | if (attr1 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 104 | m_strategyFactory.Set(attr1, StringValue(value1)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 105 | if (attr2 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 106 | m_strategyFactory.Set(attr2, StringValue(value2)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 107 | if (attr3 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | m_strategyFactory.Set(attr3, StringValue(value3)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 109 | if (attr4 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | m_strategyFactory.Set(attr4, StringValue(value4)); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 113 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 114 | StackHelper::SetContentStore(const std::string& contentStore, const std::string& attr1, |
| 115 | const std::string& value1, const std::string& attr2, |
| 116 | const std::string& value2, const std::string& attr3, |
| 117 | const std::string& value3, const std::string& attr4, |
| 118 | const std::string& value4) |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 119 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 120 | m_contentStoreFactory.SetTypeId(contentStore); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 121 | if (attr1 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 122 | m_contentStoreFactory.Set(attr1, StringValue(value1)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 123 | if (attr2 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 124 | m_contentStoreFactory.Set(attr2, StringValue(value2)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 125 | if (attr3 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 126 | m_contentStoreFactory.Set(attr3, StringValue(value3)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 127 | if (attr4 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | m_contentStoreFactory.Set(attr4, StringValue(value4)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 132 | StackHelper::SetPit(const std::string& pitClass, const std::string& attr1, |
| 133 | const std::string& value1, const std::string& attr2, const std::string& value2, |
| 134 | const std::string& attr3, const std::string& value3, const std::string& attr4, |
| 135 | const std::string& value4) |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 136 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 137 | m_pitFactory.SetTypeId(pitClass); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 138 | if (attr1 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 139 | m_pitFactory.Set(attr1, StringValue(value1)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 140 | if (attr2 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 141 | m_pitFactory.Set(attr2, StringValue(value2)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 142 | if (attr3 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 143 | m_pitFactory.Set(attr3, StringValue(value3)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 144 | if (attr4 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 145 | m_pitFactory.Set(attr4, StringValue(value4)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 149 | StackHelper::SetFib(const std::string& fibClass, const std::string& attr1, |
| 150 | const std::string& value1, const std::string& attr2, const std::string& value2, |
| 151 | const std::string& attr3, const std::string& value3, const std::string& attr4, |
| 152 | const std::string& value4) |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 153 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 154 | m_fibFactory.SetTypeId(fibClass); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 155 | if (attr1 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 156 | m_fibFactory.Set(attr1, StringValue(value1)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 157 | if (attr2 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 158 | m_fibFactory.Set(attr2, StringValue(value2)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 159 | if (attr3 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 160 | m_fibFactory.Set(attr3, StringValue(value3)); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 161 | if (attr4 != "") |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 162 | m_fibFactory.Set(attr4, StringValue(value4)); |
Alexander Afanasyev | d9fecdd | 2012-06-08 16:22:24 -0700 | [diff] [blame] | 163 | } |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 164 | |
| 165 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 166 | StackHelper::SetDefaultRoutes(bool needSet) |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 167 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 168 | NS_LOG_FUNCTION(this << needSet); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 169 | m_needSetDefaultRoutes = needSet; |
| 170 | } |
| 171 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 172 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 173 | StackHelper::EnableLimits(bool enable /* = true*/, Time avgRtt /*=Seconds(0.1)*/, |
| 174 | uint32_t avgData /*=1100*/, uint32_t avgInterest /*=40*/) |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 175 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 176 | NS_LOG_INFO("EnableLimits: " << enable); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 177 | m_limitsEnabled = enable; |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 178 | m_avgRtt = avgRtt; |
Alexander Afanasyev | 772f51b | 2013-08-01 18:53:25 -0700 | [diff] [blame] | 179 | m_avgDataSize = avgData; |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 180 | m_avgInterestSize = avgInterest; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 183 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 184 | StackHelper::Install(const NodeContainer& c) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 185 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 186 | Ptr<FaceContainer> faces = Create<FaceContainer>(); |
| 187 | for (NodeContainer::Iterator i = c.Begin(); i != c.End(); ++i) { |
| 188 | faces->AddAll(Install(*i)); |
| 189 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 190 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 193 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 194 | StackHelper::InstallAll() const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 195 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 196 | return Install(NodeContainer::GetGlobal()); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 199 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 200 | StackHelper::Install(Ptr<Node> node) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 201 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 202 | // NS_ASSERT_MSG (m_forwarding, "SetForwardingHelper() should be set prior calling Install() |
| 203 | // method"); |
| 204 | Ptr<FaceContainer> faces = Create<FaceContainer>(); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 205 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 206 | if (node->GetObject<L3Protocol>() != 0) { |
| 207 | NS_FATAL_ERROR("StackHelper::Install (): Installing " |
| 208 | "a NdnStack to a node with an existing Ndn object"); |
| 209 | return 0; |
| 210 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 211 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 212 | // Create L3Protocol |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 213 | Ptr<L3Protocol> ndn = m_ndnFactory.Create<L3Protocol>(); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 214 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 215 | // Create and aggregate FIB |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 216 | // Ptr<Fib> fib = m_fibFactory.Create<Fib> (); |
| 217 | // ndn->AggregateObject (fib); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 218 | |
| 219 | // Create and aggregate PIT |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 220 | // ndn->AggregateObject (m_pitFactory.Create<Pit> ()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 221 | |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 222 | // Create and aggregate forwarding strategy |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 223 | // ndn->AggregateObject (m_strategyFactory.Create<ForwardingStrategy> ()); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 224 | |
| 225 | // Create and aggregate content store |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 226 | // ndn->AggregateObject (m_contentStoreFactory.Create<ContentStore> ()); |
Alexander Afanasyev | 3a4a0b3 | 2012-06-28 14:14:22 -0700 | [diff] [blame] | 227 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 228 | // Aggregate L3Protocol on node |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 229 | node->AggregateObject(ndn); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 230 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 231 | for (uint32_t index = 0; index < node->GetNDevices(); index++) { |
| 232 | Ptr<NetDevice> device = node->GetDevice(index); |
| 233 | // This check does not make sense: LoopbackNetDevice is installed only if IP stack is installed, |
| 234 | // Normally, ndnSIM works without IP stack, so no reason to check |
| 235 | // if (DynamicCast<LoopbackNetDevice> (device) != 0) |
| 236 | // continue; // don't create face for a LoopbackNetDevice |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 237 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 238 | shared_ptr<NetDeviceFace> face; |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 239 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 240 | for (std::list<std::pair<TypeId, NetDeviceFaceCreateCallback>>::const_iterator item = |
| 241 | m_netDeviceCallbacks.begin(); |
| 242 | item != m_netDeviceCallbacks.end(); item++) { |
| 243 | if (device->GetInstanceTypeId() == item->first |
| 244 | || device->GetInstanceTypeId().IsChildOf(item->first)) { |
| 245 | face = item->second(node, ndn, device); |
| 246 | if (face != 0) |
| 247 | break; |
| 248 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 249 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 250 | if (face == 0) { |
| 251 | face = DefaultNetDeviceCallback(node, ndn, device); |
| 252 | } |
| 253 | |
| 254 | if (m_needSetDefaultRoutes) { |
| 255 | // default route with lowest priority possible |
| 256 | AddRoute(node, "/", StaticCast<Face>(face), std::numeric_limits<int32_t>::max()); |
| 257 | } |
| 258 | |
| 259 | face->SetUp(); |
| 260 | faces->Add(face); |
| 261 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 262 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 263 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 266 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 267 | StackHelper::AddNetDeviceFaceCreateCallback(TypeId netDeviceType, |
| 268 | StackHelper::NetDeviceFaceCreateCallback callback) |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 269 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 270 | m_netDeviceCallbacks.push_back(std::make_pair(netDeviceType, callback)); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 273 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 274 | StackHelper::UpdateNetDeviceFaceCreateCallback(TypeId netDeviceType, |
| 275 | NetDeviceFaceCreateCallback callback) |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 276 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 277 | for (NetDeviceCallbackList::iterator i = m_netDeviceCallbacks.begin(); |
| 278 | i != m_netDeviceCallbacks.end(); i++) { |
| 279 | if (i->first == netDeviceType) { |
| 280 | i->second = callback; |
| 281 | return; |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 282 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 283 | } |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 287 | StackHelper::RemoveNetDeviceFaceCreateCallback(TypeId netDeviceType, |
| 288 | NetDeviceFaceCreateCallback callback) |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 289 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 290 | for (NetDeviceCallbackList::iterator i = m_netDeviceCallbacks.begin(); |
| 291 | i != m_netDeviceCallbacks.end(); i++) { |
| 292 | if (i->first == netDeviceType) { |
| 293 | m_netDeviceCallbacks.erase(i); |
| 294 | return; |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 295 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 296 | } |
Alexander Afanasyev | 2a269f7 | 2013-06-06 22:59:33 -0700 | [diff] [blame] | 297 | } |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 298 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 299 | shared_ptr<NetDeviceFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 300 | StackHelper::DefaultNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, |
| 301 | Ptr<NetDevice> netDevice) const |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 302 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 303 | NS_LOG_DEBUG("Creating default NetDeviceFace on node " << node->GetId()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 304 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 305 | shared_ptr<NetDeviceFace> face = CreateObject<NetDeviceFace>(node, netDevice); |
Alexander Afanasyev | c17e4bd | 2013-02-17 14:31:56 -0800 | [diff] [blame] | 306 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 307 | ndn->AddFace(face); |
| 308 | NS_LOG_LOGIC("Node " << node->GetId() << ": added NetDeviceFace as face #" << *face); |
Alexander Afanasyev | c17e4bd | 2013-02-17 14:31:56 -0800 | [diff] [blame] | 309 | |
| 310 | return face; |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 313 | shared_ptr<NetDeviceFace> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 314 | StackHelper::PointToPointNetDeviceCallback(Ptr<Node> node, Ptr<L3Protocol> ndn, |
| 315 | Ptr<NetDevice> device) const |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 316 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 317 | NS_LOG_DEBUG("Creating point-to-point NetDeviceFace on node " << node->GetId()); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 318 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 319 | shared_ptr<NetDeviceFace> face = CreateObject<NetDeviceFace>(node, device); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 320 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 321 | ndn->AddFace(face); |
| 322 | NS_LOG_LOGIC("Node " << node->GetId() << ": added NetDeviceFace as face #" << *face); |
Alexander Afanasyev | c17e4bd | 2013-02-17 14:31:56 -0800 | [diff] [blame] | 323 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 324 | if (m_limitsEnabled) { |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 325 | // Ptr<Limits> limits = face->GetObject<Limits> (); |
| 326 | /*if (limits == 0) |
| 327 | { |
| 328 | NS_FATAL_ERROR ("Limits are enabled, but the selected forwarding strategy does not support |
| 329 | limits. Please revise your scenario"); |
| 330 | exit (1); |
| 331 | }*/ |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 332 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 333 | NS_LOG_INFO("Limits are enabled"); |
| 334 | Ptr<PointToPointNetDevice> p2p = DynamicCast<PointToPointNetDevice>(device); |
| 335 | if (p2p != 0) { |
| 336 | // Setup bucket filtering |
| 337 | // Assume that we know average data packet size, and this size is equal default size |
| 338 | // Set maximum buckets (averaging over 1 second) |
| 339 | |
| 340 | DataRateValue dataRate; |
| 341 | device->GetAttribute("DataRate", dataRate); |
| 342 | TimeValue linkDelay; |
| 343 | device->GetChannel()->GetAttribute("Delay", linkDelay); |
| 344 | |
| 345 | NS_LOG_INFO("DataRate for this link is " << dataRate.Get()); |
| 346 | |
| 347 | double maxInterestPackets = |
| 348 | 1.0 * dataRate.Get().GetBitRate() / 8.0 / (m_avgDataSize + m_avgInterestSize); |
| 349 | // NS_LOG_INFO ("Max packets per second: " << maxInterestPackets); |
| 350 | // NS_LOG_INFO ("Max burst: " << m_avgRtt.ToDouble (Time::S) * maxInterestPackets); |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 351 | // NS_LOG_INFO ("MaxLimit: " << (int)(m_avgRtt.ToDouble (Time::S) * |
| 352 | // maxInterestPackets)); |
| 353 | /* |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 354 | // Set max to BDP |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 355 | limits->SetLimits (maxInterestPackets, m_avgRtt.ToDouble (Time::S)); |
| 356 | limits->SetLinkDelay (linkDelay.Get ().ToDouble (Time::S)); */ |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 357 | } |
| 358 | } |
| 359 | |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 360 | return face; |
| 361 | } |
| 362 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 363 | Ptr<FaceContainer> |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 364 | StackHelper::Install(const std::string& nodeName) const |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 365 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 366 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 367 | return Install(node); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 370 | void |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 371 | StackHelper::AddRoute(Ptr<Node> node, const std::string& prefix, shared_ptr<Face> face, int32_t metric) |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 372 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 373 | NS_LOG_LOGIC("[" << node->GetId() << "]$ route add " << prefix << " via " << *face << " metric " |
| 374 | << metric); |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 375 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 376 | // Ptr<Fib> fib = node->GetObject<Fib> (); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 377 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 378 | // NameValue prefixValue; |
| 379 | // prefixValue.DeserializeFromString (prefix, MakeNameChecker ()); |
| 380 | ::ndn::Name name(prefix); |
| 381 | // fib->Add (name, face, metric); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 385 | StackHelper::AddRoute(Ptr<Node> node, const std::string& prefix, uint32_t faceId, int32_t metric) |
Alexander Afanasyev | 8bedcaf | 2012-07-20 15:30:44 -0700 | [diff] [blame] | 386 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 387 | Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>(); |
| 388 | NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node"); |
Alexander Afanasyev | 8bedcaf | 2012-07-20 15:30:44 -0700 | [diff] [blame] | 389 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 390 | shared_ptr<Face> face = ndn->GetFace(faceId); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 391 | NS_ASSERT_MSG(face != 0, "Face with ID [" << faceId << "] does not exist on node [" |
| 392 | << node->GetId() << "]"); |
Alexander Afanasyev | 8bedcaf | 2012-07-20 15:30:44 -0700 | [diff] [blame] | 393 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 394 | AddRoute(node, prefix, face, metric); |
Alexander Afanasyev | 8bedcaf | 2012-07-20 15:30:44 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 398 | StackHelper::AddRoute(const std::string& nodeName, const std::string& prefix, uint32_t faceId, |
| 399 | int32_t metric) |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 400 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 401 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 402 | NS_ASSERT_MSG(node != 0, "Node [" << nodeName << "] does not exist"); |
Alexander Afanasyev | 122f378 | 2013-02-02 00:04:40 -0800 | [diff] [blame] | 403 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 404 | Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>(); |
| 405 | NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node"); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 406 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 407 | shared_ptr<Face> face = ndn->GetFace(faceId); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 408 | NS_ASSERT_MSG(face != 0, "Face with ID [" << faceId << "] does not exist on node [" << nodeName |
| 409 | << "]"); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 410 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 411 | AddRoute(node, prefix, face, metric); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 412 | } |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 413 | |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 414 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 415 | StackHelper::AddRoute(Ptr<Node> node, const std::string& prefix, Ptr<Node> otherNode, |
| 416 | int32_t metric) |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 417 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 418 | for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) { |
| 419 | Ptr<PointToPointNetDevice> netDevice = |
| 420 | DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId)); |
| 421 | if (netDevice == 0) |
| 422 | continue; |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 423 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 424 | Ptr<Channel> channel = netDevice->GetChannel(); |
| 425 | if (channel == 0) |
| 426 | continue; |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 427 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 428 | if (channel->GetDevice(0)->GetNode() == otherNode |
| 429 | || channel->GetDevice(1)->GetNode() == otherNode) { |
| 430 | Ptr<L3Protocol> ndn = node->GetObject<L3Protocol>(); |
| 431 | NS_ASSERT_MSG(ndn != 0, "Ndn stack should be installed on the node"); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 432 | |
Spyridon Mastorakis | e4f0d3c | 2014-10-29 13:20:03 -0700 | [diff] [blame] | 433 | shared_ptr<Face> face = ndn->GetFaceByNetDevice(netDevice); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 434 | NS_ASSERT_MSG(face != 0, "There is no face associated with the p2p link"); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 435 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 436 | AddRoute(node, prefix, face, metric); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 437 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 438 | return; |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 439 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 440 | } |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 441 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 442 | NS_FATAL_ERROR("Cannot add route: Node# " << node->GetId() << " and Node# " << otherNode->GetId() |
| 443 | << " are not connected"); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 447 | StackHelper::AddRoute(const std::string& nodeName, const std::string& prefix, |
| 448 | const std::string& otherNodeName, int32_t metric) |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 449 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 450 | Ptr<Node> node = Names::Find<Node>(nodeName); |
| 451 | NS_ASSERT_MSG(node != 0, "Node [" << nodeName << "] does not exist"); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 452 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 453 | Ptr<Node> otherNode = Names::Find<Node>(otherNodeName); |
| 454 | NS_ASSERT_MSG(otherNode != 0, "Node [" << otherNodeName << "] does not exist"); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 455 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 456 | AddRoute(node, prefix, otherNode, metric); |
Alexander Afanasyev | fd25826 | 2012-11-23 14:59:19 -0800 | [diff] [blame] | 457 | } |
| 458 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 459 | } // namespace ndn |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 460 | } // namespace ns3 |