blob: 64e385cbaa3eece3723600e01005e47d2fb11223 [file] [log] [blame]
Shockb0f83152012-12-25 14:16:47 +08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011-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-grid.cc
21#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
24#include "ns3/point-to-point-layout-module.h"
25#include "ns3/ndnSIM-module.h"
26
27using namespace ns3;
28
29/**
30 * This scenario simulates a grid topology (using PointToPointGrid module)
31 *
32 * (consumer) -- ( ) ----- ( )
33 * | | |
34 * ( ) ------ ( ) ----- ( )
35 * | | |
36 * ( ) ------ ( ) -- (producer)(2,2)
37 *
38 * All links are 1Mbps with propagation 10ms delay.
39 *
40 * FIB is populated using NdnGlobalRoutingHelper.
41 *
42 * Consumer requests data from producer with frequency 100 interests per second
43 * (interests contain constantly increasing sequence number).
44 *
45 * For every received interest, producer replies with a data packet, containing
46 * 1024 bytes of virtual payload.
47 *
48 * To run scenario and see what is happening, use the following command:
49 *
Alexander Afanasyev13800102012-12-25 00:30:31 -080050 * NS_LOG=ndn.Consumer:ndn.ConsumerZipfMandelbrot:ndn.Producer ./waf --run=ndn-zipf-mandelbrot
Shockb0f83152012-12-25 14:16:47 +080051 */
52
53int
54main (int argc, char *argv[])
55{
Alexander Afanasyev13800102012-12-25 00:30:31 -080056 //LogComponentEnable("ndn.CbisGlobalRoutingHelper", LOG_LEVEL_INFO);
Shockb0f83152012-12-25 14:16:47 +080057 // Setting default parameters for PointToPoint links and channels
58 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
59 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("1ms"));
60 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("10"));
61
62 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
63 CommandLine cmd;
64 cmd.Parse (argc, argv);
65
66 // Creating 3x3 topology
67 PointToPointHelper p2p;
68 PointToPointGridHelper grid (3, 3, p2p);
69 grid.BoundingBox(100,100,200,200);
70
71 // Install CCNx stack on all nodes
72 ndn::StackHelper ccnxHelper;
73 ccnxHelper.SetForwardingStrategy ("ns3::ndn::fw::SmartFlooding");
74 ccnxHelper.SetContentStore ("ns3::ndn::cs::Lru", "MaxSize", "10");
75 ccnxHelper.InstallAll ();
76
77 // Installing global routing interface on all nodes
78 //ndn::CbisGlobalRoutingHelper ccnxGlobalRoutingHelper;
79 ndn::GlobalRoutingHelper ccnxGlobalRoutingHelper;
80 ccnxGlobalRoutingHelper.InstallAll ();
81
82 // Getting containers for the consumer/producer
83 Ptr<Node> producer = grid.GetNode (2, 2);
84 NodeContainer consumerNodes;
85 consumerNodes.Add (grid.GetNode (0,0));
86
87 // Install CCNx applications
88 std::string prefix = "/prefix";
89
90 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerZipfMandelbrot");
91 //ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
92 consumerHelper.SetPrefix (prefix);
93 consumerHelper.SetAttribute ("Frequency", StringValue ("100")); // 100 interests a second
Alexander Afanasyev13800102012-12-25 00:30:31 -080094 consumerHelper.SetAttribute ("NumberOfContents", StringValue ("100")); // 10 different contents
Shockb0f83152012-12-25 14:16:47 +080095 //consumerHelper.SetAttribute ("Randomize", StringValue ("uniform")); // 100 interests a second
96 consumerHelper.Install (consumerNodes);
97
98 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
99 producerHelper.SetPrefix (prefix);
100 producerHelper.SetAttribute ("PayloadSize", StringValue("100"));
101 producerHelper.Install (producer);
102 ccnxGlobalRoutingHelper.AddOrigins (prefix, producer);
103
Shockb0f83152012-12-25 14:16:47 +0800104 // Calculate and install FIBs
105 ccnxGlobalRoutingHelper.CalculateRoutes ();
106
Shockb0f83152012-12-25 14:16:47 +0800107 Simulator::Stop (Seconds (10.0));
108
109 Simulator::Run ();
110 Simulator::Destroy ();
111
112 return 0;
113}