blob: 0b03c7c27b8e252f2137da7fcb6c8b9da82619f6 [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"
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080029
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080030#include <sstream>
31#include "ns3/annotated-topology-reader.h"
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080032
33#include "ns3/config-store.h"
34
35using namespace ns3;
36using namespace std;
37
38NS_LOG_COMPONENT_DEFINE ("CcnxSyntheticTopology");
39
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080040void PrintTime ()
41{
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080042 NS_LOG_INFO (Simulator::Now ());
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080043
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080044 Simulator::Schedule (Seconds (10.0), PrintTime);
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080045}
46
Alexander Afanasyev120bf312011-12-19 01:24:47 -080047int
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080048main (int argc, char *argv[])
49{
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080050 string input ("./src/NDNabstraction/examples/synthetic-topology.txt");
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080051
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080052 Time finishTime = Seconds (20.0);
53 string strategy = "ns3::CcnxFloodingStrategy";
54 CommandLine cmd;
55 cmd.AddValue ("finish", "Finish time", finishTime);
56 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
57 cmd.Parse (argc, argv);
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080058
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080059 ConfigStore config;
60 config.ConfigureDefaults ();
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080061
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080062 // ------------------------------------------------------------
63 // -- Read topology data.
64 // --------------------------------------------
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080065
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080066 AnnotatedTopologyReader reader ("/synthetic");
Alexander Afanasyev120bf312011-12-19 01:24:47 -080067 // reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080068 reader.SetFileName (input);
69 NodeContainer nodes = reader.Read ();
Alexander Afanasyev120bf312011-12-19 01:24:47 -080070 // SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080071
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080072 InternetStackHelper stack;
73 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
74 stack.SetRoutingHelper (ipv4RoutingHelper);
75 stack.Install (nodes);
Alexander Afanasyev120bf312011-12-19 01:24:47 -080076
77 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
78
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080079 NS_LOG_INFO("Nodes = " << nodes.GetN());
80 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080081
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080082 // Install CCNx stack
83 NS_LOG_INFO ("Installing CCNx stack");
84 CcnxStackHelper ccnxHelper;
85 ccnxHelper.SetForwardingStrategy (strategy);
86 ccnxHelper.EnableLimits (true, Seconds(0.1));
Alexander Afanasyev120bf312011-12-19 01:24:47 -080087 ccnxHelper.SetDefaultRoutes (false);
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080088 ccnxHelper.InstallAll ();
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080089
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -080090 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyev4975f732011-12-20 17:52:19 -080091 CcnxAppHelper consumerHelper ("ns3::CcnxConsumer");
92
93 consumerHelper.SetPrefix ("/6");
Alexander Afanasyev011b8592011-12-21 14:45:27 -080094 consumerHelper.SetAttribute ("MeanRate", StringValue ("1Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -080095 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/synthetic", "c1"));
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -080096
Alexander Afanasyev120bf312011-12-19 01:24:47 -080097 consumerHelper.SetPrefix ("/7");
Alexander Afanasyev011b8592011-12-21 14:45:27 -080098 consumerHelper.SetAttribute ("MeanRate", StringValue ("2Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -080099 ApplicationContainer consumers2 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c2"));
100
101 consumerHelper.SetPrefix ("/8");
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800102 consumerHelper.SetAttribute ("MeanRate", StringValue ("3Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800103 ApplicationContainer consumers3 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c3"));
104
105 consumerHelper.SetPrefix ("/10");
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800106 consumerHelper.SetAttribute ("MeanRate", StringValue ("10Mbps"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800107 ApplicationContainer consumers4 = consumerHelper.Install(Names::Find<Node> ("/synthetic", "c4"));
108
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800109 consumers.Start (Seconds (0));
110 consumers2.Start (Seconds (10));
111 consumers3.Start (Seconds (20));
112 consumers4.Start (Seconds (30));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800113
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800114 /////////////////////////////////////////////
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800115
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800116 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
117 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
118
119 producerHelper.SetPrefix ("/6");
120 producerHelper.Install (Names::Find<Node> ("/synthetic", "p1"));
121
122 producerHelper.SetPrefix ("/7");
123 producerHelper.Install (Names::Find<Node> ("/synthetic", "p2"));
124
125 producerHelper.SetPrefix ("/8");
126 producerHelper.Install (Names::Find<Node> ("/synthetic", "p3"));
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800127
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800128 producerHelper.SetPrefix ("/10");
129 producerHelper.Install (Names::Find<Node> ("/synthetic", "p4"));
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -0800130
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800131 // Populate FIB based on IPv4 global routing controller
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800132 ccnxHelper.InstallFakeGlobalRoutes ();
133 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p1"));
134 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p2"));
135 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p3"));
136 ccnxHelper.InstallRouteTo (Names::Find<Node> ("/synthetic", "p4"));
137
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800138 Simulator::Schedule (Seconds (10.0), PrintTime);
139
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800140 Simulator::Stop (finishTime);
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800141
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800142 NS_LOG_INFO ("Run Simulation.");
143 Simulator::Run ();
144 Simulator::Destroy ();
145 NS_LOG_INFO ("Done.");
146
147 return 0;
Ilya Moiseenko6f5e8fa2011-12-16 15:20:19 -0800148}