blob: d17f23a2d4eb5149fe87eff788f6b3c27911fbf9 [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 Moiseenko58d26672011-12-08 13:48:06 -080029
Alexander Afanasyev141d1312011-12-18 14:58:35 -080030#include "../helper/ccnx-trace-helper.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080031#include "ns3/annotated-topology-reader.h"
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080032#include "../utils/spring-mobility-helper.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080033
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080034#include "ns3/config-store.h"
35
Ilya Moiseenko58d26672011-12-08 13:48:06 -080036using namespace ns3;
37using namespace std;
38
39NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology");
40
Ilya Moiseenko816de832011-12-15 16:32:24 -080041
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080042void PrintTime ()
43{
44 NS_LOG_INFO (Simulator::Now ());
45
46 Simulator::Schedule (Seconds (10.0), PrintTime);
47}
48
49void PrintFIBs ()
50{
51 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
52 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
53 for (NodeList::Iterator node = NodeList::Begin ();
54 node != NodeList::End ();
55 node++)
56 {
57 // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
58
59 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
60 NS_ASSERT_MSG (fib != 0, "Fire alarm");
61 *routingStream->GetStream () << *fib << "\n\n";
62 }
63}
64
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080065
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -080066
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -080067
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -080068
Ilya Moiseenko816de832011-12-15 16:32:24 -080069
Ilya Moiseenko58d26672011-12-08 13:48:06 -080070int
71main (int argc, char *argv[])
72{
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080073 string input ("./src/NDNabstraction/examples/abilene-topology.txt");
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080074
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080075 Time finishTime = Seconds (20.0);
76 string animationFile;
77 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080078 CommandLine cmd;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080079 cmd.AddValue ("finish", "Finish time", finishTime);
80 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
81 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080082 cmd.Parse (argc, argv);
Ilya Moiseenko58d26672011-12-08 13:48:06 -080083
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -080084 ConfigStore config;
85 config.ConfigureDefaults ();
86
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080087 // ------------------------------------------------------------
88 // -- Read topology data.
89 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -080090
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080091 AnnotatedTopologyReader reader ("/abilene");
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080092 reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080093 reader.SetFileName (input);
Ilya Moiseenko58d26672011-12-08 13:48:06 -080094
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080095 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -080096
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080097 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -080098 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080099 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
100 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800101 }
102
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800103 SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
104
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800105 // InternetStackHelper stack;
106 // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
107 // stack.SetRoutingHelper (ipv4RoutingHelper);
108 // stack.Install (nodes);
109
110 // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
111
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800112 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800113 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800114
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800115 // Install CCNx stack
116 NS_LOG_INFO ("Installing CCNx stack");
117 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800118 ccnxHelper.SetForwardingStrategy (strategy);
119 ccnxHelper.EnableLimits (false, Seconds(0.1));
120 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800121 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800122
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800123 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800124 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
125 consumerHelper.SetPrefix ("/5");
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800126 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng"));
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800127
128 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
129 producerHelper.SetPrefix ("/5");
130 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
131
Alexander Afanasyevf8fd5902011-12-16 16:23:23 -0800132 ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800133
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800134 // // Populate FIB based on IPv4 global routing controller
135 // ccnxHelper.InstallFakeGlobalRoutes ();
136 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng"));
137
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800138 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800139 // PrintFIBs ();
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800140
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800141 // Simulator::Schedule (Seconds (10.0), PrintTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800142
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800143 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800144
145 AnimationInterface *anim = 0;
146 if (animationFile != "")
147 {
148 anim = new AnimationInterface (animationFile);
149 anim->SetMobilityPollInterval (Seconds (1));
150 }
151
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800152 // NS_LOG_INFO ("Configure Tracing.");
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800153 // CcnxAggregateAppTracer consumerTrace ("ns3::CcnxConsumer", "*");
154 // CcnxAggregateAppTracer producerTrace ("ns3::CcnxProducer", "*");
155 // CcnxAggregateL3Tracer ccnxTrace ("1");
156 CcnxTraceHelper traceHelper;
157 traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
158 traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
159 traceHelper.EnableAggregateL3All ();
160 traceHelper.SetL3TraceFile ("trace-l3.log");
161 traceHelper.SetAppTraceFile ("trace-app.log");
162
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800163 config.ConfigureAttributes ();
164
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800165 NS_LOG_INFO ("Run Simulation.");
166 Simulator::Run ();
167 Simulator::Destroy ();
168 NS_LOG_INFO ("Done.");
Ilya Moiseenko816de832011-12-15 16:32:24 -0800169
Alexander Afanasyev141d1312011-12-18 14:58:35 -0800170 // NS_LOG_INFO ("ConsumerTrace: \n" << consumerTrace);
171 // NS_LOG_INFO ("ProducerTrace: \n" << producerTrace);
172 // NS_LOG_INFO ("CcnxTrace: \n" << ccnxTrace);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800173 return 0;
174}