blob: 11f930fabf0a7b1d70230ef7fbe6a4da2b7bac9c [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 Afanasyev120bf312011-12-19 01:24:47 -080096 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/synthetic", "c1"));
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080097
Alexander Afanasyev120bf312011-12-19 01:24:47 -080098 consumerHelper.SetPrefix ("/7");
Alexander Afanasyev011b8592011-12-21 14:45:27 -080099 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800100 ApplicationContainer consumers2 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c2"));
101
102 consumerHelper.SetPrefix ("/8");
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800103 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800104 ApplicationContainer consumers3 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c3"));
105
106 consumerHelper.SetPrefix ("/10");
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800107 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800108 ApplicationContainer consumers4 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c4"));
109
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800110 consumers.Start (Seconds (0));
111 consumers2.Start (Seconds (10));
112 consumers3.Start (Seconds (20));
113 consumers4.Start (Seconds (30));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800114
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800115 /////////////////////////////////////////////
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800116
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800117 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
118 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
119
120 producerHelper.SetPrefix ("/6");
121 producerHelper.Install (Names::Find<Node> ("/synthetic", "p1"));
122
123 producerHelper.SetPrefix ("/7");
124 producerHelper.Install (Names::Find<Node> ("/synthetic", "p2"));
125
126 producerHelper.SetPrefix ("/8");
127 producerHelper.Install (Names::Find<Node> ("/synthetic", "p3"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800128
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800129 producerHelper.SetPrefix ("/10");
130 producerHelper.Install (Names::Find<Node> ("/synthetic", "p4"));
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -0800131
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800132 // Populate FIB based on IPv4 global routing controller
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800133 ccnxHelper.InstallFakeGlobalRoutes ();
134 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p1"));
135 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p2"));
136 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p3"));
137 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p4"));
138
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800139 Simulator::Schedule (Seconds (10.0), PrintTime);
140
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800141 Simulator::Stop (finishTime);
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800142
Alexander Afanasyevc86c2832011-12-23 02:56:22 -0800143 CcnxTraceHelper traceHelper;
144 // traceHelper.EnableAggregateAppAll ("ns3::CcnxConsumer");
145 // traceHelper.EnableAggregateAppAll ("ns3::CcnxProducer");
146 // traceHelper.EnableAggregateL3All ();
147 // traceHelper.SetL3TraceFile ("trace-l3.log");
148 // traceHelper.SetAppTraceFile ("trace-app.log");
149 traceHelper.EnableRateL3All ("rate-trace.log");
150
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800151 NS_LOG_INFO ("Run Simulation.");
152 Simulator::Run ();
153 Simulator::Destroy ();
154 NS_LOG_INFO ("Done.");
155
156 return 0;
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -0800157}