blob: 4b6f193a9dcf4e75641c41417bd2008ba13921e1 [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.
4 *
5 * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6 * contributors.
7 *
8 * 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.
11 *
12 * 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.
15 *
16 * 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 **/
19
20// ndn-multiple-strategies.cpp
21
Spyridon Mastorakis41fbfe12014-11-24 23:26:09 -080022#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/point-to-point-layout-module.h"
26#include "ns3/ndnSIM-module.h"
27
28using namespace ns3;
29using ns3::ndn::StackHelper;
30using ns3::ndn::AppHelper;
31using ns3::ndn::GlobalRoutingHelper;
32using ns3::ndn::StrategyChoiceHelper;
33;
34
35/**
36 * This scenario simulates a grid topology (using PointToPointGrid module)
37 *
38 * The first six nodes use the best route forwarding strategy, whereas
39 * the three remaining nodes use the broadcast forwarding strategy.
40 *
41 * (consumer) -- ( ) ----- ( )
42 * | | |
43 * ( ) ------ ( ) ----- ( )
44 * | | |
45 * ( ) ------ ( ) -- (producer)
46 *
47 * All links are 1Mbps with propagation 10ms delay.
48 *
49 * FIB is populated using NdnGlobalRoutingHelper.
50 *
51 * Consumer requests data from producer with frequency 100 interests per second
52 * (interests contain constantly increasing sequence number).
53 *
54 * For every received interest, producer replies with a data packet, containing
55 * 1024 bytes of virtual payload.
56 *
57 * To run scenario and see what is happening, use the following command:
58 *
59 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-multiple-strategies
60 */
61
62int
63main(int argc, char* argv[])
64{
65 // Setting default parameters for PointToPoint links and channels
66 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
67 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
68 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("10"));
69
70 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
71 CommandLine cmd;
72 cmd.Parse(argc, argv);
73
74 // Creating 3x3 topology
75 PointToPointHelper p2p;
76 PointToPointGridHelper grid(3, 3, p2p);
77 grid.BoundingBox(100, 100, 200, 200);
78
79 // Install NDN stack on all nodes
80 StackHelper ndnHelper;
81 ndnHelper.InstallAll();
82
83 // Installing global routing interface on all nodes
84 GlobalRoutingHelper ndnGlobalRoutingHelper;
85 ndnGlobalRoutingHelper.InstallAll();
86
87 // Getting containers for the consumer/producer
88 Ptr<Node> producer = grid.GetNode(2, 2);
89 NodeContainer consumerNodes;
90 consumerNodes.Add(grid.GetNode(0, 0));
91
92 // Install NDN applications
93 std::string prefix = "/prefix";
94
95 // Install different forwarding strategies
96 StrategyChoiceHelper strategyChoiceHelper;
97 for (int row = 0; row < 3; row++) {
98 for (int column = 0; column < 3; column++) {
99 if (row < 2)
100 strategyChoiceHelper.Install(grid.GetNode(row, column), "/prefix",
101 "/localhost/nfd/strategy/best-route");
102 else
103 strategyChoiceHelper.Install(grid.GetNode(row, column), "/prefix",
104 "/localhost/nfd/strategy/broadcast");
105 }
106 }
107
108 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
109 consumerHelper.SetPrefix(prefix);
110 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
111 consumerHelper.Install(consumerNodes);
112
113 AppHelper producerHelper("ns3::ndn::Producer");
114 producerHelper.SetPrefix(prefix);
115 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
116 producerHelper.Install(producer);
117
118 // Add /prefix origins to ndn::GlobalRouter
119 ndnGlobalRoutingHelper.AddOrigins(prefix, producer);
120
121 // Calculate and install FIBs
122 GlobalRoutingHelper::CalculateRoutes();
123
124 Simulator::Stop(Seconds(20.0));
125 Simulator::Run();
126 Simulator::Destroy();
127
128 return 0;
129}