blob: 12a3910fcaf8186053dde361351dd16f961dea83 [file] [log] [blame]
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011-2012 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080020
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080021// ndn-grid-topo-plugin.cc
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080022
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080023#include "ns3/core-module.h"
24#include "ns3/network-module.h"
25#include "ns3/ndnSIM-module.h"
26
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080027namespace ns3 {
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080028
29/**
30 * This scenario simulates a grid topology (using topology reader module)
31 *
32 * (consumer) -- ( ) ----- ( )
33 * | | |
34 * ( ) ------ ( ) ----- ( )
35 * | | |
36 * ( ) ------ ( ) -- (producer)
37 *
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080038 * All links are 1Mbps with propagation 10ms delay.
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080039 *
40 * FIB is populated using NdnGlobalRoutingHelper.
41 *
42 * Consumer requests data from producer with frequency 10 interests per second
43 * (interests contain constantly increasing sequence number).
44 *
45 * For every received interest, producer replies with a data packet, containing
46 * 1024 bytes of virtual payload.
47 *
48 * To run scenario and see what is happening, use the following command:
49 *
50 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-grid-topo-plugin
51 */
52
53int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054main(int argc, char* argv[])
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080055{
56 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 cmd.Parse(argc, argv);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080058
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 AnnotatedTopologyReader topologyReader("", 25);
60 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-grid-3x3.txt");
61 topologyReader.Read();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080062
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070063 // Install NDN stack on all nodes
64 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 ndnHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080066
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080067 // Set BestRoute strategy
68 ndn::StrategyChoiceHelper::InstallAll("/", "/localhost/nfd/strategy/best-route");
69
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080070 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070071 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080072 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080073
74 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 Ptr<Node> producer = Names::Find<Node>("Node8");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080076 NodeContainer consumerNodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 consumerNodes.Add(Names::Find<Node>("Node0"));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080078
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070079 // Install NDN applications
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080080 std::string prefix = "/prefix";
81
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
83 consumerHelper.SetPrefix(prefix);
84 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
85 consumerHelper.Install(consumerNodes);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080086
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 ndn::AppHelper producerHelper("ns3::ndn::Producer");
88 producerHelper.SetPrefix(prefix);
89 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
90 producerHelper.Install(producer);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080091
92 // Add /prefix origins to ndn::GlobalRouter
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080093 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080094
95 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080097
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080099
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800100 Simulator::Run();
101 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800102
103 return 0;
104}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800105
106} // namespace ns3
107
108int
109main(int argc, char* argv[])
110{
111 return ns3::main(argc, argv);
112}