blob: 2c7b65412be2ccd98e023a21e3bdffb696303d2d [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 Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -080019
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080020// ndn-tree-tracers.cpp
Alexander Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -080035 * | | | |
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080036 * \ / \ /
37 * \ / \ / 10Mbps / 1ms
38 * \ / \ /
39 * | | | |
40 * v v v v
Alexander Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -080049 * v v
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080050 * /--------\
51 * | root |
Alexander Afanasyev59314802012-11-26 14:56:04 -080052 * \--------/
53 *
54 *
55 * To run scenario and see what is happening, use the following command:
56 *
57 * ./waf --run=ndn-tree-tracers
58 */
59
60int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061main(int argc, char* argv[])
Alexander Afanasyev59314802012-11-26 14:56:04 -080062{
63 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080064 cmd.Parse(argc, argv);
Alexander Afanasyev59314802012-11-26 14:56:04 -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 Afanasyev59314802012-11-26 14:56:04 -080069
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080070 // Install NDN stack on all nodes
71 ndn::StackHelper ndnHelper;
72 ndnHelper.InstallAll();
73
74 // Choosing forwarding strategy
75 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
Alexander Afanasyev59314802012-11-26 14:56:04 -080076
77 // Installing global routing interface on all nodes
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080078 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
79 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyev59314802012-11-26 14:56:04 -080080
81 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 Ptr<Node> consumers[4] = {Names::Find<Node>("leaf-1"), Names::Find<Node>("leaf-2"),
83 Names::Find<Node>("leaf-3"), Names::Find<Node>("leaf-4")};
84 Ptr<Node> producer = Names::Find<Node>("root");
Alexander Afanasyev59314802012-11-26 14:56:04 -080085
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080086 for (int i = 0; i < 4; i++) {
87 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
88 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
Alexander Afanasyev59314802012-11-26 14:56:04 -080089
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 // Each consumer will express unique interests /root/<leaf-name>/<seq-no>
91 consumerHelper.SetPrefix("/root/" + Names::FindName(consumers[i]));
92 consumerHelper.Install(consumers[i]);
93 }
94
95 ndn::AppHelper producerHelper("ns3::ndn::Producer");
96 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
Alexander Afanasyev59314802012-11-26 14:56:04 -080097
98 // Register /root prefix with global routing controller and
99 // install producer that will satisfy Interests in /root namespace
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800100 ndnGlobalRoutingHelper.AddOrigins("/root", producer);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 producerHelper.SetPrefix("/root");
102 producerHelper.Install(producer);
Alexander Afanasyev59314802012-11-26 14:56:04 -0800103
104 // Calculate and install FIBs
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800105 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyev59314802012-11-26 14:56:04 -0800106
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 Simulator::Stop(Seconds(20.0));
Alexander Afanasyev59314802012-11-26 14:56:04 -0800108
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800109 ndn::L3RateTracer::InstallAll("rate-trace.txt", Seconds(0.5));
110
111 Simulator::Run();
112 Simulator::Destroy();
Alexander Afanasyev59314802012-11-26 14:56:04 -0800113
114 return 0;
115}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800116
117} // namespace ns3
118
119int
120main(int argc, char* argv[])
121{
122 return ns3::main(argc, argv);
123}