blob: 8c83930f30cb746eaf5e1485a79027ccf23c2663 [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
75struct AggregateTrace
Ilya Moiseenko816de832011-12-15 16:32:24 -080076{
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080077 AggregateTrace ()
78 : m_transmittedInterests (0)
79 , m_transmittedData (0)
80 , m_receivedInterests (0)
81 , m_receivedNacks (0)
82 , m_receivedData (0)
83 {
84 }
85
86 void
87 TransmittedInterests (std::string context,
88 Ptr<const CcnxInterestHeader>, Ptr<CcnxApp>, Ptr<CcnxFace>)
89 {
90 m_transmittedInterests++;
91 }
92
93 void
94 TransmittedData (std::string context,
95 Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
96 Ptr<CcnxApp>, Ptr<CcnxFace>)
97 {
98 m_transmittedData++;
99 }
100
101 void
102 ReceivedInterests (std::string context,
103 Ptr<const CcnxInterestHeader>,
104 Ptr<CcnxApp>, Ptr<CcnxFace>)
105 {
106 m_receivedInterests++;
107 }
108
109 void
110 ReceivedNacks (std::string context,
111 Ptr<const CcnxInterestHeader>,
112 Ptr<CcnxApp>, Ptr<CcnxFace>)
113 {
114 m_receivedNacks++;
115 }
116
117 void
118 ReceivedData (std::string context,
119 Ptr<const CcnxContentObjectHeader>, Ptr<const Packet>,
120 Ptr<CcnxApp>, Ptr<CcnxFace>)
121 {
122 m_receivedData++;
123 }
124
125 uint64_t m_transmittedInterests;
126 uint64_t m_transmittedData;
127 uint64_t m_receivedInterests;
128 uint64_t m_receivedNacks;
129 uint64_t m_receivedData;
130};
131
132ostream&
133operator << (ostream &os, const AggregateTrace &trace)
134{
135 os << ">> (i): " << trace.m_transmittedInterests << "\n";
136 os << ">> (d): " << trace.m_transmittedData << "\n";
137 os << "<< (i): " << trace.m_receivedInterests << "\n";
138 os << "<< (d): " << trace.m_receivedData << "\n";
139 os << "<< (n): " << trace.m_receivedNacks << "\n";
140 return os;
Ilya Moiseenko816de832011-12-15 16:32:24 -0800141}
142
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800143// static void OnTransmittedInterest (std::string context, Ptr<const CcnxInterestHeader> header,
144// Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
145// {
146// transmittedInterests++;
147// }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800148
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800149// static void OnReceivedInterest (std::string context, Ptr<const CcnxInterestHeader> header,
150// Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
151// {
152// receivedInterests++;
153// }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800154
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800155// static void OnDroppedInterest (std::string context, Ptr<const CcnxInterestHeader> header, CcnxL3Protocol::DropReason reason,
156// Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
157// {
158// droppedInterests++;
159// }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800160
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800161// static void OnTransmittedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet,
162// CcnxL3Protocol::ContentObjectSource source, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
163// {
164// transmittedData++;
165// }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800166
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800167// static void OnReceivedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet,
168// Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
169// {
170// receivedData++;
171// }
172
173// static void OnDroppedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet,
174// CcnxL3Protocol::DropReason reason, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face )
175// {
176// droppedData++;
177// }
Ilya Moiseenko816de832011-12-15 16:32:24 -0800178
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800179int
180main (int argc, char *argv[])
181{
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800182 // Packet::EnableChecking();
183 // Packet::EnablePrinting();
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800184 string input ("./src/NDNabstraction/examples/abilene-topology.txt");
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800185
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800186 Time finishTime = Seconds (20.0);
187 string animationFile;
188 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800189 CommandLine cmd;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800190 cmd.AddValue ("finish", "Finish time", finishTime);
191 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
192 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800193 cmd.Parse (argc, argv);
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800194
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800195 ConfigStore config;
196 config.ConfigureDefaults ();
197
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800198 // ------------------------------------------------------------
199 // -- Read topology data.
200 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800201
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800202 AnnotatedTopologyReader reader ("/abilene");
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800203 reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800204 reader.SetFileName (input);
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800205
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800206 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800207
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800208 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800209 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800210 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
211 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800212 }
213
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800214 SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
215
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800216 // InternetStackHelper stack;
217 // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
218 // stack.SetRoutingHelper (ipv4RoutingHelper);
219 // stack.Install (nodes);
220
221 // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
222
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800223 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800224 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800225
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800226 // Install CCNx stack
227 NS_LOG_INFO ("Installing CCNx stack");
228 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800229 ccnxHelper.SetForwardingStrategy (strategy);
230 ccnxHelper.EnableLimits (false, Seconds(0.1));
231 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800232 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800233
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800234 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800235 CcnxConsumerHelper consumerHelper ("/5");
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800236 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800237
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800238 // CcnxProducerHelper producerHelper ("/5",1024);
239 // ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800240
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800241 // // Populate FIB based on IPv4 global routing controller
242 // ccnxHelper.InstallFakeGlobalRoutes ();
243 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng"));
244
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800245 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800246 // PrintFIBs ();
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800247
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800248 // Simulator::Schedule (Seconds (10.0), PrintTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800249
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800250 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800251
252 AnimationInterface *anim = 0;
253 if (animationFile != "")
254 {
255 anim = new AnimationInterface (animationFile);
256 anim->SetMobilityPollInterval (Seconds (1));
257 }
258
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800259 // NS_LOG_INFO ("Configure Tracing.");
260 AggregateTrace trace;
261 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/TransmittedInterests",
262 MakeCallback (&AggregateTrace::TransmittedInterests, &trace));
Ilya Moiseenko816de832011-12-15 16:32:24 -0800263
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800264 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedNacks",
265 MakeCallback (&AggregateTrace::ReceivedNacks, &trace));
266
267 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/ReceivedInterests",
268 MakeCallback (&AggregateTrace::ReceivedInterests, &trace));
269
270 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxProducer/TransmittedContentObjects",
271 MakeCallback (&AggregateTrace::TransmittedData, &trace));
272
273 Config::Connect ("/NodeList/*/ApplicationList/*/$ns3::CcnxConsumer/ReceivedContentObjects",
274 MakeCallback (&AggregateTrace::ReceivedData, &trace));
275
276 // Config::Connect("/NodeList/*/ns3::CcnxL3Protocol/TransmittedInterestTrace",
277 // MakeCallback (&OnTransmittedInterest));
278 // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedInterestTrace",
279 // MakeCallback (&OnReceivedInterest));
280 // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedInterestTrace",
281 // MakeCallback (&OnDroppedInterest));
282
283 // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedDataTrace",
284 // MakeCallback (&OnReceivedData));
285 // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/TransmittedDataTrace",
286 // MakeCallback (&OnTransmittedData));
287 // Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedDataTrace",
288 // MakeCallback (&OnDroppedData));
289
290 config.ConfigureAttributes ();
291
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800292 NS_LOG_INFO ("Run Simulation.");
293 Simulator::Run ();
294 Simulator::Destroy ();
295 NS_LOG_INFO ("Done.");
Ilya Moiseenko816de832011-12-15 16:32:24 -0800296
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800297 // NS_LOG_INFO("Total received interests = " << receivedInterests);
298 // NS_LOG_INFO("Total transmitted interests = " << transmittedInterests);
299 // NS_LOG_INFO("Total dropped interests = " << droppedInterests);
300 // NS_LOG_INFO("Total received data = " << receivedData);
301 // NS_LOG_INFO("Total transmitted data = " << transmittedData);
302 // NS_LOG_INFO("Total dropped data = " << droppedData);
303 NS_LOG_INFO (trace);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800304 return 0;
305}