blob: a37d24553d02ee4a77cb16a4ad984f17362d1c61 [file] [log] [blame]
Ilya Moiseenkoc9266042011-11-02 17:49:21 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
Alexander Afanasyeva514d632012-02-14 18:54:14 -080019 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070020 */
21
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
Alexander Afanasyev4885eea2012-06-01 12:28:15 -070025#include "ns3/ndnSIM-module.h"
Alexander Afanasyev176ed062011-11-15 23:49:22 -080026#include "ns3/point-to-point-grid.h"
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070027
28using namespace ns3;
29
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070030NS_LOG_COMPONENT_DEFINE ("ndn.Grid");
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070031
Alexander Afanasyeva514d632012-02-14 18:54:14 -080032/**
33 * This scenario simulates a grid topology (using PointToPointGrid module)
34 *
35 * (consumer) -- ( ) ----- ( )
36 * | | |
37 * ( ) ------ ( ) ----- ( )
38 * | | |
39 * ( ) ------ ( ) -- (producer)
40 *
41 * Grid size could be specified using --nGrid parameter (default 3)
42 *
43 * All links are 1Mbps with propagation 10ms delay.
44 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070045 * FIB is populated using NdnGlobalRoutingHelper.
Alexander Afanasyeva514d632012-02-14 18:54:14 -080046 *
47 * Consumer requests data from producer with frequency 10 interests per second
48 * (interests contain constantly increasing sequence number).
49 *
50 * For every received interest, producer replies with a data packet, containing
51 * 1024 bytes of virtual payload.
52 *
53 * Simulation time is 20 seconds, unless --finish parameter is specified
54 *
55 * To run scenario and see what is happening, use the following command:
56 *
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 * NS_LOG=NdnSimple:NdnConsumer ./waf --run=ndn-grid
Alexander Afanasyeva514d632012-02-14 18:54:14 -080058 */
Alexander Afanasyev176ed062011-11-15 23:49:22 -080059
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080060
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070061int
62main (int argc, char *argv[])
63{
Alexander Afanasyev176ed062011-11-15 23:49:22 -080064 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080065 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080066 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
Alexander Afanasyeva514d632012-02-14 18:54:14 -080067
68 uint32_t nGrid = 3;
69 Time finishTime = Seconds (20.0);
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080070
Alexander Afanasyev176ed062011-11-15 23:49:22 -080071 CommandLine cmd;
72 cmd.AddValue ("nGrid", "Number of grid nodes", nGrid);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080073 cmd.AddValue ("finish", "Finish time", finishTime);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080074 cmd.Parse (argc, argv);
75
76 PointToPointHelper p2p;
77
Alexander Afanasyev176ed062011-11-15 23:49:22 -080078 PointToPointGridHelper grid (nGrid, nGrid, p2p);
79 grid.BoundingBox(100,100,200,200);
80
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070081 // Install NDN stack on all nodes
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070082 NS_LOG_INFO ("Installing Ndn stack on all nodes");
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070083 ndn::StackHelper ndnHelper;
84 ndnHelper.SetContentStore ("ns3::ndn::cs::Lru", "Size", "10");
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070085 ndnHelper.InstallAll ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -080086
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070087 ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070088 ndnGlobalRoutingHelper.InstallAll ();
Alexander Afanasyevd8599792012-04-17 22:26:29 -070089
90 // Getting containers for the consumer/producer
Alexander Afanasyev176ed062011-11-15 23:49:22 -080091 Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1);
92 NodeContainer consumerNodes;
93 consumerNodes.Add (grid.GetNode (0,0));
94
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070095 // Install Ndn applications
Alexander Afanasyev176ed062011-11-15 23:49:22 -080096 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyevd8599792012-04-17 22:26:29 -070097 std::string prefix = "/prefix";
Alexander Afanasyev176ed062011-11-15 23:49:22 -080098
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -070099 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700100 consumerHelper.SetPrefix (prefix);
Alexander Afanasyeve55d1e32012-07-19 15:33:05 -0700101 consumerHelper.SetAttribute ("Frequency", StringValue ("100")); // 10 interests a second
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800102 ApplicationContainer consumers = consumerHelper.Install (consumerNodes);
103
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700104 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700105 producerHelper.SetPrefix (prefix);
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800106 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800107 ApplicationContainer producers = producerHelper.Install (producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700108
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700109 // Add /prefix origins to ndn::GlobalRouter
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700110 ndnGlobalRoutingHelper.AddOrigins (prefix, producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700111
112 // Calculate and install FIBs
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700113 ndnGlobalRoutingHelper.CalculateRoutes ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800114
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800115 Simulator::Stop (finishTime);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700116
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800117 NS_LOG_INFO ("Run Simulation.");
118 Simulator::Run ();
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700119
120 for (NodeList::Iterator node = NodeList::Begin ();
121 node != NodeList::End ();
122 node ++)
123 {
124 std::cout << "Node #" << (*node)->GetId () << std::endl;
Alexander Afanasyevcf6dc922012-08-10 16:55:27 -0700125 (*node)->GetObject<ndn::ContentStore> ()->Print (std::cout);
Alexander Afanasyev9a989702012-06-29 17:44:00 -0700126 std::cout << std::endl;
127 }
128
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800129 Simulator::Destroy ();
130 NS_LOG_INFO ("Done!");
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700131
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800132 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800133}