blob: f18b85a9f8bf3aabf2365d7422f6740218b14366 [file] [log] [blame]
Alexander Afanasyev1fb9fed2013-02-01 23:18:04 -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-pit-policies.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 *
37 * Consumer requests data from producer with frequency 10 interests per second
38 * (interests contain constantly increasing sequence number).
39 *
40 * For every received interest, producer replies with a data packet, containing
41 * 1024 bytes of virtual payload.
42 *
43 * To run scenario and see what is happening, use the following command:
44 *
45 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-pit-policies
46 */
47
48int
49main (int argc, char *argv[])
50{
51 // setting default parameters for PointToPoint links and channels
52 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
53 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
54 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
55
56 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
57 CommandLine cmd;
58 cmd.Parse (argc, argv);
59
60 // Creating nodes
61 NodeContainer nodes;
62 nodes.Create (3);
63
64 // Connecting nodes using two links
65 PointToPointHelper p2p;
66 p2p.Install (nodes.Get (0), nodes.Get (1));
67 p2p.Install (nodes.Get (1), nodes.Get (2));
68
69 // Install NDN stack on all nodes
70 ndn::StackHelper ndnHelper;
71 ndnHelper.SetPit ("ns3::ndn::pit::SerializedSize",
72 "MaxSize", "300"); // 1000 bytes ~ 10 entries
73 ndnHelper.SetDefaultRoutes (true);
74 ndnHelper.InstallAll ();
75
76 // Installing applications
77
78 // Consumer
79 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
80 // Consumer will request /prefix/0, /prefix/1, ...
81 consumerHelper.SetPrefix ("/prefix");
82 consumerHelper.SetAttribute ("LifeTime", StringValue ("2s"));
83 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
84 consumerHelper.Install (nodes.Get (0)); // first node
85
86 Simulator::Stop (Seconds (5.0));
87
88 Simulator::Run ();
89 Simulator::Destroy ();
90
91 return 0;
92}