blob: cefb2327fef7841321fdeee3eff90f33a277bbf5 [file] [log] [blame]
Alexander Afanasyevc3cc0b32012-12-12 18:41:20 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
20// ndn-simple.cc
21#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
24#include "ns3/ndnSIM-module.h"
25
26using namespace ns3;
27
28/**
29 * This scenario simulates a very simple network topology:
30 *
31 *
32 * +----------+ 1Mbps +--------+ 1Mbps +----------+
33 * | consumer | <------------> | router | <------------> | producer |
34 * +----------+ 10ms +--------+ 10ms +----------+
35 *
36 * This scenario demonstrates how to use content store that responds to Freshness parameter set in ContentObjects.
37 * That is, if producer set Freshness field to 2 seconds, the corresponding content object will not be cached
38 * more than 2 seconds (can be cached for a shorter time, if entry is evicted earlier)
39 *
40 * NS_LOG=DumbRequester ./waf --run ndn-simple-with-content-freshness
41 */
42
43int
44main (int argc, char *argv[])
45{
46 // setting default parameters for PointToPoint links and channels
47 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
48 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
49 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
50
51 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
52 CommandLine cmd;
53 cmd.Parse (argc, argv);
54
55 // Creating nodes
56 NodeContainer nodes;
57 nodes.Create (3);
58
59 // Connecting nodes using two links
60 PointToPointHelper p2p;
61 p2p.Install (nodes.Get (0), nodes.Get (1));
62 p2p.Install (nodes.Get (1), nodes.Get (2));
63
64 // Install CCNx stack on all nodes
65 ndn::StackHelper ccnxHelper;
66 ccnxHelper.SetDefaultRoutes (true);
67 ccnxHelper.SetContentStore ("ns3::ndn::cs::Freshness::Lru",
68 "MaxSize", "2"); // allow just 2 entries to be cached
69 ccnxHelper.InstallAll ();
70
71 // Installing applications
72
73 // Consumer
74 ndn::AppHelper consumerHelper ("DumbRequester");
75
76 // /*
77 // 1) at time 1 second requests Data from a producer that does not specify freshness
78 // 2) at time 10 seconds requests the same Data packet as client 1
79
80 // 3) at time 2 seconds requests Data from a producer that specifies freshness set to 2 seconds
81 // 4) at time 12 seconds requests the same Data packet as client 3
82
83 // Expectation:
84 // Interests from 1, 3 and 4 will reach producers
85 // Interset from 2 will be served from cache
86 // */
87
88 ApplicationContainer apps;
89
90 consumerHelper.SetPrefix ("/no-freshness");
91 apps = consumerHelper.Install (nodes.Get (0));
92 apps.Start (Seconds (0.1));
93 apps.Stop (Seconds (10.0));
94
95 consumerHelper.SetPrefix ("/with-freshness");
96 apps = consumerHelper.Install (nodes.Get (0));
97 apps.Start (Seconds (20.1));
98 apps.Stop (Seconds (30.0));
99
100 // Producer
101 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
102 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
103
104 producerHelper.SetAttribute ("Freshness", TimeValue (Seconds (0))); // unlimited freshness
105 producerHelper.SetPrefix ("/no-freshness");
106 producerHelper.Install (nodes.Get (2)); // last node
107
108 producerHelper.SetAttribute ("Freshness", TimeValue (Seconds (2.0))); // freshness 2 seconds (!!! freshness granularity is 1 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}