blob: 0a6a58bcc9aca0368755f4071a83c35dfccf5cca [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 */
20// ndn-congestion-topo-plugin.cc
21#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/ndnSIM-module.h"
24
25using namespace ns3;
26
27/**
28 * This scenario simulates a grid topology (using topology reader module)
29 *
30 * /------\ /------\
31 * | Src1 |<--+ +-->| Dst1 |
32 * \------/ \ / \------/
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080033 * \ /
34 * +-->/------\ "bottleneck" /------\<-+
35 * | Rtr1 |<===============>| Rtr2 |
36 * +-->\------/ \------/<-+
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080037 * / \
38 * /------\ / \ /------\
39 * | Src2 |<--+ +-->| Dst2 |
40 * \------/ \------/
41 *
42 * To run scenario and see what is happening, use the following command:
43 *
44 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-congestion-topo-plugin
45 */
46
47int
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080048main(int argc, char* argv[])
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080049{
50 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080051 cmd.Parse(argc, argv);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080052
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053 AnnotatedTopologyReader topologyReader("", 25);
54 topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-6-node.txt");
55 topologyReader.Read();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080056
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070057 // Install NDN stack on all nodes
58 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080059 ndnHelper.SetForwardingStrategy("ns3::ndn::fw::BestRoute");
60 ndnHelper.SetContentStore("ns3::ndn::cs::Lru", "MaxSize", "10000");
61 ndnHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080062
63 // Installing global routing interface on all nodes
Alexander Afanasyev9fb2e3d2013-03-30 21:11:07 -070064 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080065 ndnGlobalRoutingHelper.InstallAll();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080066
67 // Getting containers for the consumer/producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080068 Ptr<Node> consumer1 = Names::Find<Node>("Src1");
69 Ptr<Node> consumer2 = Names::Find<Node>("Src2");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080070
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 Ptr<Node> producer1 = Names::Find<Node>("Dst1");
72 Ptr<Node> producer2 = Names::Find<Node>("Dst2");
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080073
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080074 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
75 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080076
77 // on the first consumer node install a Consumer application
78 // that will express interests in /dst1 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080079 consumerHelper.SetPrefix("/dst1");
80 consumerHelper.Install(consumer1);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080081
82 // on the second consumer node install a Consumer application
83 // that will express interests in /dst2 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080084 consumerHelper.SetPrefix("/dst2");
85 consumerHelper.Install(consumer2);
86
87 ndn::AppHelper producerHelper("ns3::ndn::Producer");
88 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080089
90 // Register /dst1 prefix with global routing controller and
91 // install producer that will satisfy Interests in /dst1 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080092 ndnGlobalRoutingHelper.AddOrigins("/dst1", producer1);
93 producerHelper.SetPrefix("/dst1");
94 producerHelper.Install(producer1);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -080095
96 // Register /dst2 prefix with global routing controller and
97 // install producer that will satisfy Interests in /dst2 namespace
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080098 ndnGlobalRoutingHelper.AddOrigins("/dst2", producer2);
99 producerHelper.SetPrefix("/dst2");
100 producerHelper.Install(producer2);
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800101
102 // Calculate and install FIBs
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800103 ndn::GlobalRoutingHelper::CalculateRoutes();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800104
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800105 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800106
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -0800107 Simulator::Run();
108 Simulator::Destroy();
Alexander Afanasyevaa1c4c32012-11-21 16:17:03 -0800109
110 return 0;
111}