blob: ba40c7af827469e63c1dabbe735c52b1b9a27ea0 [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 Afanasyevaa1c4c32012-11-21 16:17:03 -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 Afanasyevaa1c4c32012-11-21 16:17:03 -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 Afanasyevaa1c4c32012-11-21 16:17:03 -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 Afanasyevaa1c4c32012-11-21 16:17:03 -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 **/
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080019
Alexander Afanasyev60a7b622014-12-20 17:04:07 -080020// ndn-congestion-topo-plugin.cpp
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080021
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080022#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 Afanasyevaa1c4c32012-11-21 16:17:03 -080027
28/**
29 * This scenario simulates a grid topology (using topology reader module)
30 *
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080031 * /------\ /------\
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080032 * | Src1 |<--+ +-->| Dst1 |
33 * \------/ \ / \------/
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080034 * \ /
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080035 * +-->/------\ "bottleneck" /------\<-+
36 * | Rtr1 |<===============>| Rtr2 |
37 * +-->\------/ \------/<-+
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080038 * / \
39 * /------\ / \ /------\
40 * | Src2 |<--+ +-->| Dst2 |
41 * \------/ \------/
42 *
43 * To run scenario and see what is happening, use the following command:
44 *
45 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
46 */
47
48int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080049main(int argc, char* argv[])
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080050{
51 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080052 cmd.Parse(argc, argv);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080053
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080054 AnnotatedTopologyReader topologyReader("", 25);
55 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-6-node.txt");
56 topologyReader.Read();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080057
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070058 // Install NDN stack on all nodes
59 ndn::StackHelper ndnHelper;
Alexander Afanasyevdde1e812015-01-06 14:26:09 -080060 ndnHelper.SetOldContentStore("ns3::ndn::cs::Lru", "MaxSize", "10000");
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080061 ndnHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080062
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080063 // Choosing forwarding strategy
64 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
65
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080066 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070067 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080069
70 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 Ptr<Node> consumer1 = Names::Find<Node>("Src1");
72 Ptr<Node> consumer2 = Names::Find<Node>("Src2");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080073
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 Ptr<Node> producer1 = Names::Find<Node>("Dst1");
75 Ptr<Node> producer2 = Names::Find<Node>("Dst2");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080076
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080077 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
78 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080079
80 // on the first consumer node install a Consumer application
81 // that will express interests in /dst1 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080082 consumerHelper.SetPrefix("/dst1");
83 consumerHelper.Install(consumer1);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080084
85 // on the second consumer node install a Consumer application
86 // that will express interests in /dst2 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080087 consumerHelper.SetPrefix("/dst2");
88 consumerHelper.Install(consumer2);
89
90 ndn::AppHelper producerHelper("ns3::ndn::Producer");
91 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080092
93 // Register /dst1 prefix with global routing controller and
94 // install producer that will satisfy Interests in /dst1 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080095 ndnGlobalRoutingHelper.AddOrigins("/dst1", producer1);
96 producerHelper.SetPrefix("/dst1");
97 producerHelper.Install(producer1);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080098
99 // Register /dst2 prefix with global routing controller and
100 // install producer that will satisfy Interests in /dst2 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800101 ndnGlobalRoutingHelper.AddOrigins("/dst2", producer2);
102 producerHelper.SetPrefix("/dst2");
103 producerHelper.Install(producer2);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800104
105 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800106 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800107
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800109
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 Simulator::Run();
111 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800112
113 return 0;
114}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800115
116
117} // namespace ns3
118
119int
120main(int argc, char* argv[])
121{
122 return ns3::main(argc, argv);
123}