blob: b9cfa3219358015ce99120d0aeaff9f2377c6638 [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-content-freshness.cpp
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 * data packets. In other words, if the producer set FreshnessPeriod field to 2 seconds, the
39 * corresponding data packet will not be considered fresh for more than 2 seconds (can be cached
40 * for a shorter time, if entry is evicted earlier)
41 *
Spyridon Mastorakise674a012018-04-23 08:18:30 -070042 * NS_LOG=OneInterestRequester ./waf --run ndn-simple-with-content-freshness
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080043 */
44
45int
46main(int argc, char* argv[])
47{
48 // setting default parameters for PointToPoint links and channels
49 Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
50 Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
Alexander Afanasyevf007a992022-05-05 15:57:08 -040051 Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize", StringValue("20p"));
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080052
53 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
54 CommandLine cmd;
55 cmd.Parse(argc, argv);
56
57 // Creating nodes
58 NodeContainer nodes;
59 nodes.Create(3);
60
61 // Connecting nodes using two links
62 PointToPointHelper p2p;
63 p2p.Install(nodes.Get(0), nodes.Get(1));
64 p2p.Install(nodes.Get(1), nodes.Get(2));
65
66 // Install Ndn stack on all nodes
67 ndn::StackHelper ndnHelper;
68 ndnHelper.SetDefaultRoutes(true);
Xinyu Mad616c8e2018-04-24 13:42:57 +090069 ndnHelper.setCsSize(2); // allow just 2 entries to be cached
70 ndnHelper.setPolicy("nfd::cs::lru");
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -080071 ndnHelper.InstallAll();
72
73 // Installing applications
74
75 // Consumer
76 ndn::AppHelper consumerHelper("OneInterestRequester");
77
78 // /*
79 // 1) at time 1 second requests Data from a producer that does not specify freshness
80 // 2) at time 10 seconds requests the same Data packet as client 1
81
82 // 3) at time 2 seconds requests Data from a producer that specifies freshness set to 2 seconds
83 // 4) at time 12 seconds requests the same Data packet as client 3
84
85 // Expectation:
86 // Interests from 1, 3 and 4 will reach producers
87 // Interset from 2 will be served from cache
88 // */
89
90 consumerHelper.SetPrefix("/no-freshness");
91 consumerHelper.Install(nodes.Get(0)).Start(Seconds(1));
92 consumerHelper.Install(nodes.Get(0)).Start(Seconds(10));
93
94 consumerHelper.SetPrefix("/with-freshness");
95 consumerHelper.Install(nodes.Get(0)).Start(Seconds(2));
96 consumerHelper.Install(nodes.Get(0)).Start(Seconds(12));
97
98 // Producer
99 ndn::AppHelper producerHelper("ns3::ndn::Producer");
100 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
101
Xinyu Mad616c8e2018-04-24 13:42:57 +0900102 producerHelper.SetAttribute("Freshness", TimeValue(Years(100))); // freshness long enough
Alexander Afanasyevafe47fe2015-01-06 18:29:39 -0800103 producerHelper.SetPrefix("/no-freshness");
104 producerHelper.Install(nodes.Get(2)); // last node
105
106 producerHelper.SetAttribute("Freshness", TimeValue(Seconds(2.0))); // freshness 2 seconds (!!!
107 // freshness granularity is 1
108 // seconds !!!)
109 producerHelper.SetPrefix("/with-freshness");
110 producerHelper.Install(nodes.Get(2)); // last node
111
112 Simulator::Stop(Seconds(30.0));
113
114 Simulator::Run();
115 Simulator::Destroy();
116
117 return 0;
118}
119} // namespace ns3
120
121int
122main(int argc, char* argv[])
123{
124 return ns3::main(argc, argv);
125}