blob: 3518873f5e5347cbc3436fbd231e3ddf836aeacb [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-congestion-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 *
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080032 * /------\ /------\
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080033 * | Src1 |<--+ +-->| Dst1 |
34 * \------/ \ / \------/
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080035 * \ /
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080036 * +-->/------\ "bottleneck" /------\<-+
37 * | Rtr1 |<===============>| Rtr2 |
38 * +-->\------/ \------/<-+
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080039 * / \
40 * /------\ / \ /------\
41 * | Src2 |<--+ +-->| Dst2 |
42 * \------/ \------/
43 *
44 * To run scenario and see what is happening, use the following command:
45 *
46 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
47 */
48
49int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080050main(int argc, char* argv[])
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080051{
52 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 cmd.Parse(argc, argv);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080054
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080055 AnnotatedTopologyReader topologyReader("", 25);
56 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-6-node.txt");
57 topologyReader.Read();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080058
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070059 // Install NDN stack on all nodes
60 ndn::StackHelper ndnHelper;
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080061 ndnHelper.SetContentStoreChoice(false);
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080062 ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "10000");
63 ndnHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080064
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080065 // Choosing forwarding strategy
66 ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
67
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080068 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070069 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080070 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080071
72 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080073 Ptr<Node> consumer1 = Names::Find<Node>("Src1");
74 Ptr<Node> consumer2 = Names::Find<Node>("Src2");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080075
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080076 Ptr<Node> producer1 = Names::Find<Node>("Dst1");
77 Ptr<Node> producer2 = Names::Find<Node>("Dst2");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080078
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
80 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080081
82 // on the first consumer node install a Consumer application
83 // that will express interests in /dst1 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 consumerHelper.SetPrefix("/dst1");
85 consumerHelper.Install(consumer1);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080086
87 // on the second consumer node install a Consumer application
88 // that will express interests in /dst2 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080089 consumerHelper.SetPrefix("/dst2");
90 consumerHelper.Install(consumer2);
91
92 ndn::AppHelper producerHelper("ns3::ndn::Producer");
93 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080094
95 // Register /dst1 prefix with global routing controller and
96 // install producer that will satisfy Interests in /dst1 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080097 ndnGlobalRoutingHelper.AddOrigins("/dst1", producer1);
98 producerHelper.SetPrefix("/dst1");
99 producerHelper.Install(producer1);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800100
101 // Register /dst2 prefix with global routing controller and
102 // install producer that will satisfy Interests in /dst2 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 ndnGlobalRoutingHelper.AddOrigins("/dst2", producer2);
104 producerHelper.SetPrefix("/dst2");
105 producerHelper.Install(producer2);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800106
107 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800108 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800109
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800110 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800111
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800112 Simulator::Run();
113 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800114
115 return 0;
116}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800117
118
119} // namespace ns3
120
121int
122main(int argc, char* argv[])
123{
124 return ns3::main(argc, argv);
125}