blob: 971bbe15674513a8f106b45bc730dc13d6fd0ae4 [file] [log] [blame]
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -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 Afanasyev8f5a9bb2011-12-18 19:49:02 -080028#include "../utils/spring-mobility-helper.h"
Alexander Afanasyevc86c2832011-12-23 02:56:22 -080029#include "../helper/ccnx-trace-helper.h"
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080030
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080031#include <sstream>
32#include "ns3/annotated-topology-reader.h"
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080033
34#include "ns3/config-store.h"
35
36using namespace ns3;
37using namespace std;
38
39NS_LOG_COMPONENT_DEFINE ("CcnxSyntheticTopology");
40
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080041void PrintTime ()
42{
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080043 NS_LOG_INFO (Simulator::Now ());
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080044
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080045 Simulator::Schedule (Seconds (10.0), PrintTime);
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080046}
47
Alexander Afanasyev120bf312011-12-19 01:24:47 -080048int
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080049main (int argc, char *argv[])
50{
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080051 string input ("./src/NDNabstraction/examples/synthetic-topology.txt");
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080052
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080053 Time finishTime = Seconds (20.0);
54 string strategy = "ns3::CcnxFloodingStrategy";
55 CommandLine cmd;
56 cmd.AddValue ("finish", "Finish time", finishTime);
57 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
58 cmd.Parse (argc, argv);
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080059
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080060 ConfigStore config;
61 config.ConfigureDefaults ();
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080062
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080063 // ------------------------------------------------------------
64 // -- Read topology data.
65 // --------------------------------------------
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080066
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080067 AnnotatedTopologyReader reader ("/synthetic");
Alexander Afanasyev120bf312011-12-19 01:24:47 -080068 // reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080069 reader.SetFileName (input);
70 NodeContainer nodes = reader.Read ();
Alexander Afanasyev120bf312011-12-19 01:24:47 -080071 // SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080072
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080073 InternetStackHelper stack;
74 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
75 stack.SetRoutingHelper (ipv4RoutingHelper);
76 stack.Install (nodes);
Alexander Afanasyev120bf312011-12-19 01:24:47 -080077
78 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
79
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080080 NS_LOG_INFO("Nodes = " << nodes.GetN());
81 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080082
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080083 // Install CCNx stack
84 NS_LOG_INFO ("Installing CCNx stack");
85 CcnxStackHelper ccnxHelper;
86 ccnxHelper.SetForwardingStrategy (strategy);
87 ccnxHelper.EnableLimits (true, Seconds(0.1));
Alexander Afanasyev120bf312011-12-19 01:24:47 -080088 ccnxHelper.SetDefaultRoutes (false);
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080089 ccnxHelper.InstallAll ();
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080090
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080091 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyev4975f732011-12-20 17:52:19 -080092 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
93
94 consumerHelper.SetPrefix ("/6");
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080095 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -080096 consumerHelper.SetAttribute ("Size", StringValue ("1.0"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -080097 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/synthetic", "c1"));
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080098
Alexander Afanasyev120bf312011-12-19 01:24:47 -080099 consumerHelper.SetPrefix ("/7");
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800100 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800101 ApplicationContainer consumers2 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c2"));
102
103 consumerHelper.SetPrefix ("/8");
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800104 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800105 ApplicationContainer consumers3 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c3"));
106
107 consumerHelper.SetPrefix ("/10");
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800108 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800109 ApplicationContainer consumers4 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c4"));
110
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800111 consumers.Start (Seconds (0));
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800112 consumers2.Start (Seconds (2.5));
113 consumers3.Start (Seconds (5));
114 consumers4.Start (Seconds (7.5));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800115
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800116 /////////////////////////////////////////////
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800117
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800118 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
119 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
120
121 producerHelper.SetPrefix ("/6");
122 producerHelper.Install (Names::Find<Node> ("/synthetic", "p1"));
123
124 producerHelper.SetPrefix ("/7");
125 producerHelper.Install (Names::Find<Node> ("/synthetic", "p2"));
126
127 producerHelper.SetPrefix ("/8");
128 producerHelper.Install (Names::Find<Node> ("/synthetic", "p3"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800129
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800130 producerHelper.SetPrefix ("/10");
131 producerHelper.Install (Names::Find<Node> ("/synthetic", "p4"));
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -0800132
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800133 // Populate FIB based on IPv4 global routing controller
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800134 ccnxHelper.InstallFakeGlobalRoutes ();
135 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p1"));
136 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p2"));
137 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p3"));
138 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p4"));
139
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800140 Simulator::Schedule (Seconds (10.0), PrintTime);
141
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800142 Simulator::Stop (finishTime);
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800143
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800144 CcnxTraceHelper traceHelper;
145 // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
146 // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
147 // traceHelper.EnableAggregateL3All ();
148 // traceHelper.SetL3TraceFile ("trace-l3.log");
149 // traceHelper.SetAppTraceFile ("trace-app.log");
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800150 // traceHelper.EnableRateL3All ("rate-trace.log");
151 traceHelper.EnableSeqsAppAll ("ns3::CcnxConsumer", "consumers-seqs.log");
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800152
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800153 NS_LOG_INFO ("Run Simulation.");
154 Simulator::Run ();
155 Simulator::Destroy ();
156 NS_LOG_INFO ("Done.");
157
158 return 0;
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -0800159}