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