blob: 355d37d8900baab7c7e5701c31592fafddc82f80 [file] [log] [blame]
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -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-simple-with-different-sizes-content-store.cc
21
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/ndnSIM-module.h"
26
27namespace ns3 {
28
29/**
30 * This scenario simulates a very simple network topology:
31 *
32 *
33 * +----------+ 1Mbps +--------+ 1Mbps +----------+
34 * | consumer | <------------> | router | <------------> | producer |
35 * +----------+ 10ms +--------+ 10ms +----------+
36 *
37 * This scenario demonstrates how to use content store that responds to Freshness parameter set in
38 *Datas.
39 * That is, if producer set Freshness field to 2 seconds, the corresponding content object will not
40 *be cached
41 * more than 2 seconds (can be cached for a shorter time, if entry is evicted earlier)
42 *
43 * NS_LOG=ndn.Consumer ./waf --run ndn-simple-with-different-sizes-content-store
44 */
45
46int
47main(int argc, char* argv[])
48{
49 // setting default parameters for PointToPoint links and channels
50 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
51 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
Alexander Afanasyev77f84c62018-10-08 13:37:42 -040052 Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p"));
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080053
54 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
55 CommandLine cmd;
56 cmd.Parse(argc, argv);
57
58 // Creating nodes
59 NodeContainer nodes;
60 nodes.Create(3);
61
62 // Connecting nodes using two links
63 PointToPointHelper p2p;
64 p2p.Install(nodes.Get(0), nodes.Get(1));
65 p2p.Install(nodes.Get(1), nodes.Get(2));
66
67 // Install NDN stack on all nodes
68 ndn::StackHelper ndnHelper;
69 ndnHelper.SetDefaultRoutes(true);
70 ndnHelper.SetOldContentStore(
71 "ns3::ndn::cs::Freshness::Lru"); // don't set up max size here, will use default value = 100
72 ndnHelper.InstallAll();
73
74 // set up max sizes, after NDN stack is installed
75 Config::Set("/NodeList/0/$ns3::ndn::ContentStore/MaxSize",
76 UintegerValue(
77 1)); // number after nodeList is global ID of the node (= node->GetId ())
78 Config::Set("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue(2));
79 Config::Set("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue(200));
80
81 // Installing applications
82
83 // Consumer
84 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
85 // Consumer will request /prefix/0, /prefix/1, ...
86 consumerHelper.SetPrefix("/prefix");
87 consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
88 consumerHelper.Install(nodes.Get(0)); // first node
89
90 // Producer
91 ndn::AppHelper producerHelper("ns3::ndn::Producer");
92 // Producer will reply to all requests starting with /prefix
93 producerHelper.SetPrefix("/prefix");
94 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
95 producerHelper.Install(nodes.Get(2)); // last node
96
97 Simulator::Stop(Seconds(20.0));
98
99 Simulator::Run();
100 Simulator::Destroy();
101
102 return 0;
103}
104
105} // namespace ns3
106
107int
108main(int argc, char* argv[])
109{
110 return ns3::main(argc, argv);
111}