blob: b25d45263b62d0bb5f528af3f9f3cef041306c17 [file] [log] [blame]
Alexander Afanasyev4c6bc582013-02-07 10:13:48 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2012-2013 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-with-different-sizes-content-store.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=ndn.Consumer ./waf --run ndn-simple-with-different-sizes-content-store
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"); // don't set up max size here, will use default value = 100
68 ccnxHelper.InstallAll ();
69
70 // set up max sizes, after NDN stack is installed
71 Config::Set ("/NodeList/0/$ns3::ndn::ContentStore/MaxSize", UintegerValue (1)); // number after nodeList is global ID of the node (= node->GetId ())
72 Config::Set ("/NodeList/1/$ns3::ndn::ContentStore/MaxSize", UintegerValue (2));
73 Config::Set ("/NodeList/2/$ns3::ndn::ContentStore/MaxSize", UintegerValue (200));
74
75 // Installing applications
76
77 // Consumer
78 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
79 // Consumer will request /prefix/0, /prefix/1, ...
80 consumerHelper.SetPrefix ("/prefix");
81 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
82 consumerHelper.Install (nodes.Get (0)); // first node
83
84 // Producer
85 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
86 // Producer will reply to all requests starting with /prefix
87 producerHelper.SetPrefix ("/prefix");
88 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
89 producerHelper.Install (nodes.Get (2)); // last node
90
91 Simulator::Stop (Seconds (20.0));
92
93 Simulator::Run ();
94 Simulator::Destroy ();
95
96 return 0;
97}