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