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 | |
| 37 | #include "../model/ccnx-forwarding-strategy.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 38 | #include "../model/ccnx-net-device-face.h" |
| 39 | #include "../model/ccnx-l3-protocol.h" |
| 40 | #include "../model/ccnx-fib.h" |
Alexander Afanasyev | 0782718 | 2011-12-13 01:07:32 -0800 | [diff] [blame] | 41 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 42 | #include "ns3/node-list.h" |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 43 | #include "ns3/loopback-net-device.h" |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 44 | #include "ns3/global-router-interface.h" |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 45 | #include "ns3/ipv4.h" |
| 46 | #include "ns3/ipv4-global-routing.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 47 | #include "../utils/ipv4-global-routing-ordered-nexthops.h" |
| 48 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 49 | #include "ns3/ipv4-routing-helper.h" |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 50 | #include "ns3/ipv4-global-routing-helper.h" |
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 | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 53 | #include "ccnx-face-container.h" |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 54 | #include "ccnx-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 | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 61 | NS_LOG_COMPONENT_DEFINE ("CcnxStackHelper"); |
| 62 | |
| 63 | namespace ns3 { |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 65 | CcnxStackHelper::CcnxStackHelper () |
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 | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 69 | m_strategyFactory.SetTypeId ("ns3::CcnxFloodingStrategy"); |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 72 | CcnxStackHelper::~CcnxStackHelper () |
| 73 | { |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 76 | void |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 77 | CcnxStackHelper::SetForwardingStrategy (std::string strategy) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 78 | { |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 79 | m_strategyFactory.SetTypeId (strategy); |
| 80 | } |
| 81 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 82 | |
| 83 | void |
| 84 | CcnxStackHelper::SetDefaultRoutes (bool needSet) |
| 85 | { |
| 86 | NS_LOG_FUNCTION (this << needSet); |
| 87 | m_needSetDefaultRoutes = needSet; |
| 88 | } |
| 89 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 90 | void |
Alexander Afanasyev | 33d6231 | 2012-01-09 13:50:20 -0800 | [diff] [blame] | 91 | CcnxStackHelper::EnableLimits (bool enable/* = true*/, |
| 92 | Time avgRtt/*=Seconds(0.1)*/, |
| 93 | uint32_t avgContentObject/*=1100*/, |
| 94 | uint32_t avgInterest/*=40*/) |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 95 | { |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 96 | NS_LOG_INFO ("EnableLimits: " << enable); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 97 | m_limitsEnabled = enable; |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 98 | m_avgRtt = avgRtt; |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 99 | m_avgContentObjectSize = avgContentObject; |
| 100 | m_avgInterestSize = avgInterest; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 103 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 104 | CcnxStackHelper::Install (NodeContainer c) const |
| 105 | { |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 106 | Ptr<CcnxFaceContainer> faces = Create<CcnxFaceContainer> (); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 107 | for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 108 | { |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 109 | faces->AddAll (Install (*i)); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 110 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 111 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 114 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 115 | CcnxStackHelper::InstallAll (void) const |
| 116 | { |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 117 | return Install (NodeContainer::GetGlobal ()); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 120 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 121 | CcnxStackHelper::Install (Ptr<Node> node) const |
| 122 | { |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 123 | // NS_ASSERT_MSG (m_forwarding, "SetForwardingHelper() should be set prior calling Install() method"); |
| 124 | Ptr<CcnxFaceContainer> faces = Create<CcnxFaceContainer> (); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 125 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 126 | if (node->GetObject<Ccnx> () != 0) |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 127 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 128 | NS_FATAL_ERROR ("CcnxStackHelper::Install (): Installing " |
| 129 | "a CcnxStack to a node with an existing Ccnx object"); |
| 130 | return 0; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 131 | } |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 132 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 133 | Ptr<CcnxFib> fib = CreateObject<CcnxFib> (); |
| 134 | node->AggregateObject (fib); |
| 135 | |
Ilya Moiseenko | fbd0a8b | 2011-10-28 13:07:16 -0700 | [diff] [blame] | 136 | Ptr<CcnxL3Protocol> ccnx = CreateObject<CcnxL3Protocol> (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 137 | node->AggregateObject (ccnx); |
| 138 | |
Alexander Afanasyev | f377b33 | 2011-12-16 15:32:12 -0800 | [diff] [blame] | 139 | ccnx->SetForwardingStrategy (m_strategyFactory.Create<CcnxForwardingStrategy> ()); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 140 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 141 | for (uint32_t index=0; index < node->GetNDevices (); index++) |
| 142 | { |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 143 | Ptr<NetDevice> device = node->GetDevice (index); |
| 144 | if (DynamicCast<LoopbackNetDevice> (device) != 0) |
| 145 | continue; // don't create face for a LoopbackNetDevice |
| 146 | |
Alexander Afanasyev | cbe92ae | 2011-12-16 13:06:18 -0800 | [diff] [blame] | 147 | Ptr<CcnxNetDeviceFace> face = CreateObject<CcnxNetDeviceFace> (node, device); |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 148 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 149 | ccnx->AddFace (face); |
| 150 | NS_LOG_LOGIC ("Node " << node->GetId () << ": added CcnxNetDeviceFace as face #" << *face); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 151 | |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 152 | if (m_needSetDefaultRoutes) |
| 153 | { |
| 154 | // default route with lowest priority possible |
| 155 | AddRoute (node, "/", face, std::numeric_limits<int32_t>::max ()); |
| 156 | } |
| 157 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 158 | if (m_limitsEnabled) |
| 159 | { |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 160 | NS_LOG_INFO ("Limits are enabled"); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 161 | Ptr<PointToPointNetDevice> p2p = DynamicCast<PointToPointNetDevice> (device); |
Alexander Afanasyev | 3f1c8b0 | 2012-01-19 19:41:34 -0800 | [diff] [blame] | 162 | if (p2p != 0) |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 163 | { |
Alexander Afanasyev | 3f1c8b0 | 2012-01-19 19:41:34 -0800 | [diff] [blame] | 164 | // Setup bucket filtering |
| 165 | // Assume that we know average data packet size, and this size is equal default size |
| 166 | // Set maximum buckets (averaging over 1 second) |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 167 | |
Alexander Afanasyev | 3f1c8b0 | 2012-01-19 19:41:34 -0800 | [diff] [blame] | 168 | DataRateValue dataRate; device->GetAttribute ("DataRate", dataRate); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 169 | |
Alexander Afanasyev | 3f1c8b0 | 2012-01-19 19:41:34 -0800 | [diff] [blame] | 170 | NS_LOG_INFO("DataRate for this link is " << dataRate.Get()); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 171 | |
Alexander Afanasyev | 3f1c8b0 | 2012-01-19 19:41:34 -0800 | [diff] [blame] | 172 | double maxInterestPackets = 1.0 * dataRate.Get ().GetBitRate () / 8.0 / (m_avgContentObjectSize + m_avgInterestSize); |
| 173 | NS_LOG_INFO ("Max packets per second: " << maxInterestPackets); |
| 174 | NS_LOG_INFO ("Max burst: " << m_avgRtt.ToDouble (Time::S) * maxInterestPackets); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 175 | |
Alexander Afanasyev | 3f1c8b0 | 2012-01-19 19:41:34 -0800 | [diff] [blame] | 176 | // Set bucket max to BDP |
| 177 | face->SetBucketMax (m_avgRtt.ToDouble (Time::S) * maxInterestPackets); // number of interests allowed |
| 178 | face->SetBucketLeak (maxInterestPackets); |
| 179 | } |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 180 | } |
Ilya Moiseenko | c926604 | 2011-11-02 17:49:21 -0700 | [diff] [blame] | 181 | |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 182 | face->SetUp (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 183 | faces->Add (face); |
| 184 | } |
Ilya Moiseenko | 25f7d4d | 2011-09-29 18:41:06 -0700 | [diff] [blame] | 185 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 186 | return faces; |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 189 | Ptr<CcnxFaceContainer> |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 190 | CcnxStackHelper::Install (std::string nodeName) const |
| 191 | { |
| 192 | Ptr<Node> node = Names::Find<Node> (nodeName); |
Alexander Afanasyev | 0ab833e | 2011-08-18 15:49:13 -0700 | [diff] [blame] | 193 | return Install (node); |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 196 | |
| 197 | void |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 198 | CcnxStackHelper::AddRoute (Ptr<Node> node, std::string prefix, Ptr<CcnxFace> face, int32_t metric) |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 199 | { |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 200 | NS_LOG_LOGIC ("[" << node->GetId () << "]$ route add " << prefix << " via " << *face << " metric " << metric); |
| 201 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 202 | Ptr<CcnxFib> fib = node->GetObject<CcnxFib> (); |
| 203 | |
| 204 | CcnxNameComponentsValue prefixValue; |
| 205 | prefixValue.DeserializeFromString (prefix, MakeCcnxNameComponentsChecker ()); |
| 206 | fib->Add (prefixValue.Get (), face, metric); |
| 207 | } |
| 208 | |
| 209 | void |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 210 | CcnxStackHelper::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] | 211 | { |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 212 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 213 | NS_ASSERT_MSG (node != 0, "Node [" << nodeName << "] does not exist"); |
Alexander Afanasyev | a4e3f85 | 2011-11-15 20:39:33 -0800 | [diff] [blame] | 214 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 215 | Ptr<Ccnx> ccnx = node->GetObject<Ccnx> (); |
| 216 | NS_ASSERT_MSG (ccnx != 0, "Ccnx stack should be installed on the node"); |
| 217 | |
| 218 | Ptr<CcnxFace> face = ccnx->GetFace (faceId); |
| 219 | NS_ASSERT_MSG (face != 0, "Face with ID [" << faceId << "] does not exist on node [" << nodeName << "]"); |
| 220 | |
| 221 | AddRoute (node, prefix, face, metric); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 222 | } |
Alexander Afanasyev | 4a5c2c1 | 2011-12-12 18:50:57 -0800 | [diff] [blame] | 223 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 224 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 225 | void |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 226 | CcnxStackHelper::InstallFakeGlobalRoutesImpl () |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 227 | { |
| 228 | for (NodeList::Iterator node = NodeList::Begin (); |
| 229 | node != NodeList::End (); |
| 230 | node ++) |
| 231 | { |
| 232 | NS_ASSERT_MSG ((*node)->GetObject<Ipv4> () != 0, |
| 233 | "InternetStack should be installed on all nodes"); |
| 234 | |
| 235 | NS_ASSERT_MSG (Ipv4RoutingHelper::GetRouting<Ipv4GlobalRoutingOrderedNexthops> |
| 236 | ( |
| 237 | (*node)->GetObject<Ipv4> ()->GetRoutingProtocol () |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 238 | ), |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 239 | "InternetStack should have Ipv4GlobalRoutingOrderedNexthops as routing protocol"); |
| 240 | // Example: |
| 241 | // |
| 242 | // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingUnorderedNexthops"); |
| 243 | // stack.SetRoutingHelper (ipv4RoutingHelper); |
| 244 | // |
| 245 | |
| 246 | Ptr<GlobalRouter> globalRouter = (*node)->GetObject<GlobalRouter> (); |
| 247 | if (globalRouter == 0) continue; |
| 248 | |
| 249 | globalRouter->InjectRoute (Ipv4Address((*node)->GetId ()), Ipv4Mask("255.255.255.255")); |
| 250 | } |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 251 | } |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 252 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 253 | void |
| 254 | CcnxStackHelper::InstallFakeGlobalRoutes () |
| 255 | { |
| 256 | InstallFakeGlobalRoutesImpl (); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 257 | Ipv4GlobalRoutingHelper::PopulateAllPossibleRoutingTables (); |
| 258 | } |
| 259 | |
| 260 | void |
| 261 | CcnxStackHelper::InstallRouteTo (Ptr<Node> destNode) |
| 262 | { |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 263 | InstallRouteTo (boost::lexical_cast<std::string> (destNode->GetId ()), destNode); |
| 264 | } |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 265 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 266 | void |
| 267 | CcnxStackHelper::InstallRouteTo (const std::string &prefix, Ptr<Node> destNode) |
| 268 | { |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 269 | Ipv4Address destIpv4 = Ipv4Address(destNode->GetId ()); |
| 270 | |
| 271 | for (NodeList::Iterator node = NodeList::Begin (); |
| 272 | node != NodeList::End (); |
| 273 | node ++) |
| 274 | { |
| 275 | if (destNode == *node) continue; |
| 276 | |
| 277 | Ptr<Ccnx> ccnx = (*node)->GetObject<Ccnx> (); |
| 278 | NS_ASSERT_MSG (ccnx != 0, "CCNx stack should be installed on all nodes"); |
| 279 | |
| 280 | Ptr<Ipv4> ipv4 = (*node)->GetObject<Ipv4> (); |
| 281 | NS_ASSERT_MSG (ipv4 != 0, |
| 282 | "InternetStack should be installed on all nodes"); |
| 283 | |
| 284 | Ptr<Ipv4GlobalRoutingOrderedNexthops> routing = |
| 285 | Ipv4RoutingHelper::GetRouting<Ipv4GlobalRoutingOrderedNexthops> (ipv4->GetRoutingProtocol ()); |
| 286 | NS_ASSERT_MSG (routing != 0, "Ipv4GlobalRoutingOrderedNexthops should be used in InternetStack"); |
| 287 | |
| 288 | Ptr<Ipv4GlobalRoutingOrderedNexthops::EntryContainer> |
| 289 | routes = routing->Lookup (destIpv4); |
| 290 | |
| 291 | NS_ASSERT_MSG (routes != 0, "Should not happen... Call the developer"); |
| 292 | |
| 293 | BOOST_FOREACH (const Ipv4RoutingTableEntry &entry, *routes) |
| 294 | { |
| 295 | Ptr<NetDevice> netDevice = ipv4->GetNetDevice (entry.GetInterface ()); |
| 296 | NS_ASSERT_MSG (netDevice != 0, "Should never happen. Call the popos"); |
| 297 | |
| 298 | Ptr<CcnxFace> face = ccnx->GetFaceByNetDevice (netDevice); |
| 299 | NS_ASSERT_MSG (face != 0, "Definitely should never happen. Call the president"); |
| 300 | |
Alexander Afanasyev | b762684 | 2012-01-12 13:43:33 -0800 | [diff] [blame] | 301 | AddRoute (*node, prefix, face, entry.GetMetric ()); |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | void |
| 307 | CcnxStackHelper::InstallRoutesToAll () |
| 308 | { |
| 309 | for (NodeList::Iterator node = NodeList::Begin (); |
| 310 | node != NodeList::End (); |
| 311 | node ++) |
| 312 | { |
| 313 | InstallRouteTo (*node); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | |
Alexander Afanasyev | 45b92d4 | 2011-08-14 23:11:38 -0700 | [diff] [blame] | 318 | } // namespace ns3 |