blob: 1609f7b2b9e5b353f9402c7555f2edac502d111e [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 Mastorakis4909d0a2014-11-27 22:17:41 -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 * In this scenario, thanks to NFD, we can choose a different forwarding
39 * strategy for each prefix in each node.
40 *
41 * (consumer) -- ( ) -- (producer)
42 * | | |
43 * ( ) ------ ( ) ----- ( )
44 * | | |
45 * (consumer) -- ( ) -- (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-different-strategy-per-prefix
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
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 pointers to the producer/consumer nodes
88 Ptr<Node> producer1 = grid.GetNode(2, 2);
89 Ptr<Node> producer2 = grid.GetNode(0, 2);
90 Ptr<Node> consumer1 = grid.GetNode(0, 0);
91 Ptr<Node> consumer2 = grid.GetNode(2, 0);
92
93 // Define two name prefixes
94 std::string prefix1 = "/prefix1";
95 std::string prefix2 = "/prefix2";
96
97 // Install different forwarding strategies for prefix1, prefix2
98 StrategyChoiceHelper strategyChoiceHelper;
99 strategyChoiceHelper.InstallAll(prefix1, "/localhost/nfd/strategy/broadcast");
100 strategyChoiceHelper.InstallAll(prefix2, "/localhost/nfd/strategy/best-route");
101
102 // Install NDN applications
103 AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
104 consumerHelper.SetPrefix(prefix1);
105 consumerHelper.SetAttribute("Frequency", StringValue("100")); // 100 interests a second
106 consumerHelper.Install(consumer1);
107
108 consumerHelper.SetPrefix(prefix2);
109 consumerHelper.Install(consumer2);
110
111 AppHelper producerHelper("ns3::ndn::Producer");
112 producerHelper.SetPrefix(prefix1);
113 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
114 producerHelper.Install(producer1);
115
116 producerHelper.SetPrefix(prefix2);
117 producerHelper.Install(producer2);
118
119 // Add /prefix1 and /prefix2 origins to ndn::GlobalRouter
120 ndnGlobalRoutingHelper.AddOrigins(prefix1, producer1);
121 ndnGlobalRoutingHelper.AddOrigins(prefix2, producer2);
122
123 // Calculate and install FIBs
124 GlobalRoutingHelper::CalculateRoutes();
125
126 Simulator::Stop(Seconds(20.0));
127 Simulator::Run();
128 Simulator::Destroy();
129
130 return 0;
131}