blob: 02aa54b39bc484d6234e2c008df0b94dbc34a286 [file] [log] [blame]
Ilya Moiseenko58d26672011-12-08 13:48:06 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
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 *
18 * Author: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/NDNabstraction-module.h"
26#include "ns3/point-to-point-grid.h"
27#include "ns3/ipv4-global-routing-helper.h"
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080028#include "ns3/animation-interface.h"
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080029// #include "ns3/ccnx-l3-protocol.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080030
31#include <iostream>
32#include <sstream>
Ilya Moiseenko58d26672011-12-08 13:48:06 -080033#include "ns3/annotated-topology-reader.h"
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080034#include "../utils/spring-mobility-helper.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080035
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080036#include "ns3/config-store.h"
37
Ilya Moiseenko58d26672011-12-08 13:48:06 -080038using namespace ns3;
39using namespace std;
40
41NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology");
42
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080043// int transmittedInterests = 0;
44// int receivedInterests = 0;
45// int droppedInterests = 0;
Ilya Moiseenko816de832011-12-15 16:32:24 -080046
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080047// int transmittedData = 0;
48// int receivedData = 0;
49// int droppedData = 0;
Ilya Moiseenko816de832011-12-15 16:32:24 -080050
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080051void PrintTime ()
52{
53 NS_LOG_INFO (Simulator::Now ());
54
55 Simulator::Schedule (Seconds (10.0), PrintTime);
56}
57
58void PrintFIBs ()
59{
60 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
61 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
62 for (NodeList::Iterator node = NodeList::Begin ();
63 node != NodeList::End ();
64 node++)
65 {
66 // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
67
68 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
69 NS_ASSERT_MSG (fib != 0, "Fire alarm");
70 *routingStream->GetStream () << *fib << "\n\n";
71 }
72}
73
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080074
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -080075struct AggregateAppTrace
Ilya Moiseenko816de832011-12-15 16:32:24 -080076{
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -080077 AggregateAppTrace ()
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080078 : m_transmittedInterests (0)
79 , m_transmittedData (0)
80 , m_receivedInterests (0)
81 , m_receivedNacks (0)
82 , m_receivedData (0)
83 {
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -080084 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/TransmittedInterests",
85 MakeCallback (&AggregateAppTrace::TransmittedInterests, this));
86
87 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedNacks",
88 MakeCallback (&AggregateAppTrace::ReceivedNacks, this));
89
90 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/ReceivedInterests",
91 MakeCallback (&AggregateAppTrace::ReceivedInterests, this));
92
93 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/TransmittedContentObjects",
94 MakeCallback (&AggregateAppTrace::TransmittedData, this));
95
96 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedContentObjects",
97 MakeCallback (&AggregateAppTrace::ReceivedData, this));
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080098 }
99
100 void
101 TransmittedInterests (std::string context,
102 Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>)
103 {
104 m_transmittedInterests++;
105 }
106
107 void
108 TransmittedData (std::string context,
109 Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
110 Ptr<CcnxApp>, Ptr<CcnxFace>)
111 {
112 m_transmittedData++;
113 }
114
115 void
116 ReceivedInterests (std::string context,
117 Ptr<const CcnxInterestHeader>,
118 Ptr<CcnxApp>, Ptr<CcnxFace>)
119 {
120 m_receivedInterests++;
121 }
122
123 void
124 ReceivedNacks (std::string context,
125 Ptr<const CcnxInterestHeader>,
126 Ptr<CcnxApp>, Ptr<CcnxFace>)
127 {
128 m_receivedNacks++;
129 }
130
131 void
132 ReceivedData (std::string context,
133 Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
134 Ptr<CcnxApp>, Ptr<CcnxFace>)
135 {
136 m_receivedData++;
137 }
138
139 uint64_t m_transmittedInterests;
140 uint64_t m_transmittedData;
141 uint64_t m_receivedInterests;
142 uint64_t m_receivedNacks;
143 uint64_t m_receivedData;
144};
145
146ostream&
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800147operator << (ostream &os, const AggregateAppTrace &trace)
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800148{
149 os << ">> (i): " << trace.m_transmittedInterests << "\n";
150 os << ">> (d): " << trace.m_transmittedData << "\n";
151 os << "<< (i): " << trace.m_receivedInterests << "\n";
152 os << "<< (d): " << trace.m_receivedData << "\n";
153 os << "<< (n): " << trace.m_receivedNacks << "\n";
154 return os;
Ilya Moiseenko816de832011-12-15 16:32:24 -0800155}
156
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800157struct AggregateCcnxTrace
158{
159 AggregateCcnxTrace (const std::string &node = "*")
160 : m_inInterests (0)
161 , m_outInterests (0)
162 , m_dropInterests (0)
163 , m_inNacks (0)
164 , m_outNacks (0)
165 , m_dropNacks (0)
166 , m_inData (0)
167 , m_outData (0)
168 , m_dropData (0)
169 {
170 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/ForwardingStrategy/OutInterests",
171 MakeCallback (&AggregateCcnxTrace::OutInterests, this));
172 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InInterests",
173 MakeCallback (&AggregateCcnxTrace::InInterests, this));
174 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropInterests",
175 MakeCallback (&AggregateCcnxTrace::DropInterests, this));
Ilya Moiseenko816de832011-12-15 16:32:24 -0800176
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800177 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/OutNacks",
178 MakeCallback (&AggregateCcnxTrace::OutNacks, this));
179 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InNacks",
180 MakeCallback (&AggregateCcnxTrace::InNacks, this));
181 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropNacks",
182 MakeCallback (&AggregateCcnxTrace::DropNacks, this));
Ilya Moiseenko816de832011-12-15 16:32:24 -0800183
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800184 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/OutData",
185 MakeCallback (&AggregateCcnxTrace::OutData, this));
186 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/InData",
187 MakeCallback (&AggregateCcnxTrace::InData, this));
188 Config::Connect ("/NodeList/"+node+"/$ns3::CcnxL3Protocol/DropData",
189 MakeCallback (&AggregateCcnxTrace::DropData, this));
190 }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800191
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800192 void OutInterests (std::string context,
193 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
194 { m_outInterests++; }
195 void InInterests (std::string context,
196 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
197 { m_inInterests++; }
198 void DropInterests (std::string context,
199 Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
200 { m_dropInterests++; }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800201
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800202 void OutNacks (std::string context,
203 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
204 { m_outNacks++; }
205 void InNacks (std::string context,
206 Ptr<const CcnxInterestHeader>, Ptr<const CcnxFace>)
207 { m_inNacks++; }
208 void DropNacks (std::string context,
209 Ptr<const CcnxInterestHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
210 { m_dropNacks++; }
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800211
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800212 void OutData (std::string context,
213 Ptr<const CcnxContentObjectHeader>, bool fromCache, Ptr<const CcnxFace>)
214 { m_inData++; }
215 void InData (std::string context,
216 Ptr<const CcnxContentObjectHeader>, Ptr<const CcnxFace>)
217 { m_outData++; }
218 void DropData (std::string context,
219 Ptr<const CcnxContentObjectHeader>, Ccnx::DropReason, Ptr<const CcnxFace>)
220 { m_dropData++; }
221
222 uint64_t m_inInterests;
223 uint64_t m_outInterests;
224 uint64_t m_dropInterests;
225 uint64_t m_inNacks;
226 uint64_t m_outNacks;
227 uint64_t m_dropNacks;
228 uint64_t m_inData;
229 uint64_t m_outData;
230 uint64_t m_dropData;
231};
232
233ostream&
234operator << (ostream &os, const AggregateCcnxTrace &trace)
235{
236 os << "(Interests)\n";
237 os << ">> (in): " << trace.m_inInterests << "\n";
238 os << ">> (out): " << trace.m_outInterests << "\n";
239 os << "<< (drop): " << trace.m_dropInterests << "\n";
240 os << "(Nacks)\n";
241 os << "<< (in): " << trace.m_inNacks << "\n";
242 os << "<< (out): " << trace.m_outNacks << "\n";
243 os << "<< (drop): " << trace.m_dropNacks << "\n";
244 os << "(Data)\n";
245 os << ">> (in): " << trace.m_inData << "\n";
246 os << ">> (out): " << trace.m_outData << "\n";
247 os << "<< (drop): " << trace.m_dropData << "\n";
248 return os;
249}
Ilya Moiseenko816de832011-12-15 16:32:24 -0800250
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800251int
252main (int argc, char *argv[])
253{
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800254 // Packet::EnableChecking();
255 // Packet::EnablePrinting();
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800256 string input ("./src/NDNabstraction/examples/abilene-topology.txt");
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800257
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800258 Time finishTime = Seconds (20.0);
259 string animationFile;
260 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800261 CommandLine cmd;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800262 cmd.AddValue ("finish", "Finish time", finishTime);
263 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
264 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800265 cmd.Parse (argc, argv);
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800266
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800267 ConfigStore config;
268 config.ConfigureDefaults ();
269
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800270 // ------------------------------------------------------------
271 // -- Read topology data.
272 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800273
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800274 AnnotatedTopologyReader reader ("/abilene");
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800275 reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800276 reader.SetFileName (input);
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800277
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800278 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800279
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800280 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800281 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800282 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
283 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800284 }
285
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800286 SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
287
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800288 // InternetStackHelper stack;
289 // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
290 // stack.SetRoutingHelper (ipv4RoutingHelper);
291 // stack.Install (nodes);
292
293 // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
294
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800295 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800296 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800297
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800298 // Install CCNx stack
299 NS_LOG_INFO ("Installing CCNx stack");
300 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800301 ccnxHelper.SetForwardingStrategy (strategy);
302 ccnxHelper.EnableLimits (false, Seconds(0.1));
303 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800304 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800305
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800306 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800307 CcnxConsumerHelper consumerHelper ("/5");
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800308 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800309
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800310 CcnxProducerHelper producerHelper ("/5",1024);
311 ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800312
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800313 // // Populate FIB based on IPv4 global routing controller
314 // ccnxHelper.InstallFakeGlobalRoutes ();
315 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng"));
316
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800317 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800318 // PrintFIBs ();
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800319
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800320 // Simulator::Schedule (Seconds (10.0), PrintTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800321
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800322 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800323
324 AnimationInterface *anim = 0;
325 if (animationFile != "")
326 {
327 anim = new AnimationInterface (animationFile);
328 anim->SetMobilityPollInterval (Seconds (1));
329 }
330
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800331 // NS_LOG_INFO ("Configure Tracing.");
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800332 AggregateAppTrace appTrace;
333 AggregateCcnxTrace ccnxTrace ("1");
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800334
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800335 config.ConfigureAttributes ();
336
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800337 NS_LOG_INFO ("Run Simulation.");
338 Simulator::Run ();
339 Simulator::Destroy ();
340 NS_LOG_INFO ("Done.");
Ilya Moiseenko816de832011-12-15 16:32:24 -0800341
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800342 NS_LOG_INFO ("AppTrace: \n" << appTrace);
343 NS_LOG_INFO ("CcnxTrace: \n" << ccnxTrace);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800344 return 0;
345}