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