blob: 9c5e6b2e32aa2c8e48aa38a76a3b6f00b97e02d8 [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"
25#include "ns3/NDNabstraction-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
30NS_LOG_COMPONENT_DEFINE ("CcnxGrid");
31
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 *
45 * FIB is populated based on hacks of GlobalRoutingController: in
46 * addition to normal assignment of IP addresses for every NetDevice
47 * interface, every node is assigned an IP address that numerically
48 * equals to node id (i.e., if node id is 15, the special address is
49 * 0.0.0.15/255.255.255.255).
50 *
51 * Consumer requests data from producer with frequency 10 interests per second
52 * (interests contain constantly increasing sequence number).
53 *
54 * For every received interest, producer replies with a data packet, containing
55 * 1024 bytes of virtual payload.
56 *
57 * Simulation time is 20 seconds, unless --finish parameter is specified
58 *
59 * To run scenario and see what is happening, use the following command:
60 *
61 * NS_LOG=CcnxSimple:CcnxConsumer ./waf --run=ccnx-grid
62 */
Alexander Afanasyev176ed062011-11-15 23:49:22 -080063
Alexander Afanasyev9d313d42011-11-25 13:36:15 -080064
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070065int
66main (int argc, char *argv[])
67{
Alexander Afanasyev176ed062011-11-15 23:49:22 -080068 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080069 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -080070 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
Ilya Moiseenkoc9266042011-11-02 17:49:21 -070071
Alexander Afanasyeva514d632012-02-14 18:54:14 -080072 // Set maximum number of packets that will be cached (default 100)
73 Config::SetDefault ("ns3::CcnxContentStore::Size", StringValue ("1000"));
74
75 uint32_t nGrid = 3;
76 Time finishTime = Seconds (20.0);
Alexander Afanasyev23d2b542011-12-07 18:54:46 -080077
Alexander Afanasyev176ed062011-11-15 23:49:22 -080078 CommandLine cmd;
79 cmd.AddValue ("nGrid", "Number of grid nodes", nGrid);
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080080 cmd.AddValue ("finish", "Finish time", finishTime);
Alexander Afanasyev176ed062011-11-15 23:49:22 -080081 cmd.Parse (argc, argv);
82
83 PointToPointHelper p2p;
84
Alexander Afanasyev176ed062011-11-15 23:49:22 -080085 PointToPointGridHelper grid (nGrid, nGrid, p2p);
86 grid.BoundingBox(100,100,200,200);
87
Alexander Afanasyevd8599792012-04-17 22:26:29 -070088 // Install CCNx stack on all nodes
89 NS_LOG_INFO ("Installing CCNx stack on all nodes");
Alexander Afanasyev11453142011-11-25 16:13:33 -080090 CcnxStackHelper ccnxHelper;
Alexander Afanasyev176ed062011-11-15 23:49:22 -080091 ccnxHelper.InstallAll ();
92
Alexander Afanasyevd8599792012-04-17 22:26:29 -070093 CcnxGlobalRoutingHelper ccnxGlobalRoutingHelper;
94 ccnxGlobalRoutingHelper.InstallAll ();
95
96 // Getting containers for the consumer/producer
Alexander Afanasyev176ed062011-11-15 23:49:22 -080097 Ptr<Node> producer = grid.GetNode (nGrid-1, nGrid-1);
98 NodeContainer consumerNodes;
99 consumerNodes.Add (grid.GetNode (0,0));
100
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700101 // Install CCNx applications
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800102 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700103 std::string prefix = "/prefix";
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800104
Alexander Afanasyeve1a065d2012-01-10 15:55:14 -0800105 CcnxAppHelper consumerHelper ("ns3::CcnxConsumerCbr");
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700106 consumerHelper.SetPrefix (prefix);
Alexander Afanasyeva514d632012-02-14 18:54:14 -0800107 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800108 ApplicationContainer consumers = consumerHelper.Install (consumerNodes);
109
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800110 CcnxAppHelper producerHelper ("ns3::CcnxProducer");
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700111 producerHelper.SetPrefix (prefix);
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800112 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800113 ApplicationContainer producers = producerHelper.Install (producer);
Alexander Afanasyevd8599792012-04-17 22:26:29 -0700114
115 // Add /prefix origins to CcnxGlobalRouter
116 ccnxGlobalRoutingHelper.AddOrigins (prefix, producer);
117
118 // Calculate and install FIBs
119 ccnxGlobalRoutingHelper.CalculateRoutes ();
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800120
Alexander Afanasyeva46844b2011-11-21 19:13:26 -0800121 Simulator::Stop (finishTime);
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700122
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800123 NS_LOG_INFO ("Run Simulation.");
124 Simulator::Run ();
125 Simulator::Destroy ();
126 NS_LOG_INFO ("Done!");
Ilya Moiseenkoc9266042011-11-02 17:49:21 -0700127
Alexander Afanasyev176ed062011-11-15 23:49:22 -0800128 return 0;
Alexander Afanasyev3ba44e52011-11-10 16:38:10 -0800129}