blob: 5cac62be295295ead18f4713e046b2762f5963bf [file] [log] [blame]
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2011-2015 Regents of the University of California.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -08004 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08005 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -08007 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -08008 * ndnSIM is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080011 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080012 * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080015 *
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080016 * You should have received a copy of the GNU General Public License along with
17 * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 **/
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080019
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080020// ndn-tree-cs-tracers.cpp
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080021
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/ndnSIM-module.h"
25
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080026namespace ns3 {
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080027
28/**
29 * This scenario simulates a tree topology (using topology reader module)
30 *
31 * /------\ /------\ /------\ /------\
32 * |leaf-1| |leaf-2| |leaf-3| |leaf-4|
33 * \------/ \------/ \------/ \------/
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080034 * ^ ^ ^ ^
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080035 * | | | |
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080036 * \ / \ /
37 * \ / \ / 10Mbps / 1ms
38 * \ / \ /
39 * | | | |
40 * v v v v
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080041 * /-------\ /-------\
42 * | rtr-1 | | rtr-2 |
43 * \-------/ \-------/
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080044 * ^ ^
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080045 * | |
46 * \ / 10 Mpbs / 1ms
47 * +--------+ +--------+
48 * | |
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080049 * v v
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080050 * /--------\
51 * | root |
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080052 * \--------/
53 *
54 *
55 * To run scenario and see what is happening, use the following command:
56 *
57 * ./waf --run=ndn-tree-cs-tracers
58 */
59
60int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061main(int argc, char* argv[])
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080062{
63 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 cmd.Parse(argc, argv);
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080065
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080066 AnnotatedTopologyReader topologyReader("", 1);
67 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-tree.txt");
68 topologyReader.Read();
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080069
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080070 // Install NDN stack on all nodes
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080071 ndn::StackHelper ndnHelper;
Alexander Afanasyev25e4d8f2019-07-29 13:44:04 -040072 ndnHelper.setPolicy("nfd::cs::lru");
73 ndnHelper.setCsSize(100);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 ndnHelper.InstallAll();
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080075
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080076 // Choosing forwarding strategy
77 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
78
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080079 // Installing global routing interface on all nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080080 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
81 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080082
83 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
85 Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
86 Ptr<Node> producer = Names::Find<Node>("root");
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080087
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 for (int i = 0; i < 4; i++) {
89 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
90 consumerHelper.SetAttribute("Frequency", StringValue("10")); // 100 interests a second
Alexander Afanasyevf4a03592012-12-10 16:12:34 -080091
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 // Each consumer will express the same data /root/<seq-no>
93 consumerHelper.SetPrefix("/root");
94 ApplicationContainer app = consumerHelper.Install(consumers[i]);
95 app.Start(Seconds(0.01 * i));
96 }
97
98 ndn::AppHelper producerHelper("ns3::ndn::Producer");
99 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800100
101 // Register /root prefix with global routing controller and
102 // install producer that will satisfy Interests in /root namespace
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800103 ndnGlobalRoutingHelper.AddOrigins("/root", producer);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800104 producerHelper.SetPrefix("/root");
105 producerHelper.Install(producer);
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800106
107 // Calculate and install FIBs
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800108 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800109
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800111
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 ndn::CsTracer::InstallAll("cs-trace.txt", Seconds(1));
113
114 Simulator::Run();
115 Simulator::Destroy();
Alexander Afanasyevf4a03592012-12-10 16:12:34 -0800116
117 return 0;
118}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800119
120} // namespace ns3
121
122int
123main(int argc, char* argv[])
124{
125 return ns3::main(argc, argv);
126}