blob: c0c1f1606e24ba8512c37d8accf6d83e623b3e0a [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"
Ilya Moiseenko816de832011-12-15 16:32:24 -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
36using namespace ns3;
37using namespace std;
38
39NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology");
40
Ilya Moiseenko816de832011-12-15 16:32:24 -080041int transmittedInterests = 0;
42int receivedInterests = 0;
43int droppedInterests = 0;
44
45int transmittedData = 0;
46int receivedData = 0;
47int droppedData = 0;
48
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080049void PrintTime ()
50{
51 NS_LOG_INFO (Simulator::Now ());
52
53 Simulator::Schedule (Seconds (10.0), PrintTime);
54}
55
56void PrintFIBs ()
57{
58 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
59 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
60 for (NodeList::Iterator node = NodeList::Begin ();
61 node != NodeList::End ();
62 node++)
63 {
64 // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
65
66 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
67 NS_ASSERT_MSG (fib != 0, "Fire alarm");
68 *routingStream->GetStream () << *fib << "\n\n";
69 }
70}
71
Ilya Moiseenko816de832011-12-15 16:32:24 -080072static void OnTransmittedInterest (std::string context, Ptr<const CcnxInterestHeader> header,
73 Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
74{
75 transmittedInterests++;
76}
77
78static void OnReceivedInterest (std::string context, Ptr<const CcnxInterestHeader> header,
79 Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
80{
81 receivedInterests++;
82}
83
84static void OnDroppedInterest (std::string context, Ptr<const CcnxInterestHeader> header, CcnxL3Protocol::DropReason reason,
85 Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
86{
87 droppedInterests++;
88}
89
90static void OnTransmittedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet,
91 CcnxL3Protocol::ContentObjectSource source, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
92{
93 transmittedData++;
94}
95
96static void OnReceivedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet,
97 Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face)
98{
99 receivedData++;
100}
101
102static void OnDroppedData (std::string context, Ptr<const CcnxContentObjectHeader> header, Ptr<const Packet> packet,
103 CcnxL3Protocol::DropReason reason, Ptr<Ccnx> ccnx, Ptr<const CcnxFace> face )
104{
105 droppedData++;
106}
107
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800108int
109main (int argc, char *argv[])
110{
Ilya Moiseenko816de832011-12-15 16:32:24 -0800111 Packet::EnableChecking();
112 Packet::EnablePrinting();
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800113 string input ("./src/NDNabstraction/examples/abilene-topology.txt");
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800114
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800115 Time finishTime = Seconds (20.0);
116 string animationFile;
117 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800118 CommandLine cmd;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800119 cmd.AddValue ("finish", "Finish time", finishTime);
120 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
121 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800122 cmd.Parse (argc, argv);
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800123
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800124 // ------------------------------------------------------------
125 // -- Read topology data.
126 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800127
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800128 AnnotatedTopologyReader reader ("/abilene");
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800129 reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800130 reader.SetFileName (input);
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800131
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800132 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800133
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800134 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800135 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800136 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
137 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800138 }
139
Ilya Moiseenko816de832011-12-15 16:32:24 -0800140 int droppedInterests[nodes.GetN()];
141 int congestedInterests[nodes.GetN()];
142 int sentInterests[nodes.GetN()];
143 (void)droppedInterests;
144 (void)sentInterests;
145 (void)congestedInterests;
146
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800147 SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
148
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800149 // InternetStackHelper stack;
150 // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
151 // stack.SetRoutingHelper (ipv4RoutingHelper);
152 // stack.Install (nodes);
153
154 // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
155
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800156 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800157 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800158
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800159 // Install CCNx stack
160 NS_LOG_INFO ("Installing CCNx stack");
161 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800162 ccnxHelper.SetForwardingStrategy (strategy);
163 ccnxHelper.EnableLimits (false, Seconds(0.1));
164 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800165 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800166
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800167 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800168 CcnxConsumerHelper consumerHelper ("/5");
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800169 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800170
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800171 CcnxProducerHelper producerHelper ("/5",1024);
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800172 ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800173
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800174 // // Populate FIB based on IPv4 global routing controller
175 // ccnxHelper.InstallFakeGlobalRoutes ();
176 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng"));
177
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800178 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800179 // PrintFIBs ();
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800180
181 Simulator::Schedule (Seconds (10.0), PrintTime);
182
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800183 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800184
185 AnimationInterface *anim = 0;
186 if (animationFile != "")
187 {
188 anim = new AnimationInterface (animationFile);
189 anim->SetMobilityPollInterval (Seconds (1));
190 }
191
Ilya Moiseenko816de832011-12-15 16:32:24 -0800192 NS_LOG_INFO ("Configure Tracing.");
193 // first, pcap tracing in non-promiscuous mode
194 //ccnxHelper.EnablePcapAll ("csma-ping", false);
195 // then, print what the packet sink receives.
196 //Config::ConnectWithoutContext ("/NodeList/3/ApplicationList/0/$ns3::PacketSink/Rx",
197 // MakeCallback (&SinkRx));
198 // finally, print the ping rtts.
199 //Packet::EnablePrinting ();
200 Config::Connect("/NodeList/*/ns3::CcnxL3Protocol/TransmittedInterestTrace",
201 MakeCallback (&OnTransmittedInterest));
202 Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedInterestTrace",
203 MakeCallback (&OnReceivedInterest));
204 Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedInterestTrace",
205 MakeCallback (&OnDroppedInterest));
206
207 Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/ReceivedDataTrace",
208 MakeCallback (&OnReceivedData));
209 Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/TransmittedDataTrace",
210 MakeCallback (&OnTransmittedData));
211 Config::Connect ("/NodeList/*/ns3::CcnxL3Protocol/DroppedDataTrace",
212 MakeCallback (&OnDroppedData));
213
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800214 NS_LOG_INFO ("Run Simulation.");
215 Simulator::Run ();
216 Simulator::Destroy ();
217 NS_LOG_INFO ("Done.");
Ilya Moiseenko816de832011-12-15 16:32:24 -0800218
219 NS_LOG_INFO("Total received interests = " << receivedInterests);
220 NS_LOG_INFO("Total transmitted interests = " << transmittedInterests);
221 NS_LOG_INFO("Total dropped interests = " << droppedInterests);
222 NS_LOG_INFO("Total received data = " << receivedData);
223 NS_LOG_INFO("Total transmitted data = " << transmittedData);
224 NS_LOG_INFO("Total dropped data = " << droppedData);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800225 return 0;
226}