Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 27 | namespace 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 | * |
| 42 | * NS_LOG=DumbRequester ./waf --run ndn-simple-with-content-freshness |
| 43 | */ |
| 44 | |
| 45 | int |
| 46 | main(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")); |
Spyridon Mastorakis | f98a341 | 2017-10-30 11:47:58 -0700 | [diff] [blame^] | 51 | Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20)); |
Alexander Afanasyev | afe47fe | 2015-01-06 18:29:39 -0800 | [diff] [blame] | 52 | |
| 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); |
| 69 | ndnHelper.SetOldContentStore("ns3::ndn::cs::Freshness::Lru", "MaxSize", |
| 70 | "2"); // allow just 2 entries to be cached |
| 71 | 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 | |
| 102 | producerHelper.SetAttribute("Freshness", TimeValue(Seconds(-1.0))); // unlimited freshness |
| 103 | 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 | |
| 121 | int |
| 122 | main(int argc, char* argv[]) |
| 123 | { |
| 124 | return ns3::main(argc, argv); |
| 125 | } |