Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
| 23 | #include "ns3/point-to-point-module.h" |
Alexander Afanasyev | 4885eea | 2012-06-01 12:28:15 -0700 | [diff] [blame] | 24 | #include "ns3/ndnSIM-module.h" |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 25 | |
| 26 | using 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 | * Simulation time is 20 seconds, unless --finish parameter is specified |
| 44 | * |
| 45 | * To run scenario and see what is happening, use the following command: |
| 46 | * |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 47 | * NS_LOG=ndn.Simple:ndn.Consumer ./waf --run=ndn-simple |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 48 | */ |
| 49 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 50 | NS_LOG_COMPONENT_DEFINE ("ndn.Simple"); |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 51 | |
| 52 | int |
| 53 | main (int argc, char *argv[]) |
| 54 | { |
| 55 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 56 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
| 57 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
| 58 | |
| 59 | Time finishTime = Seconds (20.0); |
| 60 | |
| 61 | CommandLine cmd; |
| 62 | cmd.AddValue ("finish", "Finish time", finishTime); |
| 63 | cmd.Parse (argc, argv); |
| 64 | |
| 65 | // Creating nodes |
| 66 | NodeContainer nodes; |
| 67 | nodes.Create (3); |
| 68 | |
| 69 | // Connecting nodes using two links |
| 70 | PointToPointHelper p2p; |
| 71 | p2p.Install (nodes.Get (0), nodes.Get (1)); |
| 72 | p2p.Install (nodes.Get (1), nodes.Get (2)); |
| 73 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 74 | // Install Ndn stack on all nodes |
| 75 | NS_LOG_INFO ("Installing Ndn stack"); |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 76 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 77 | ndnHelper.SetDefaultRoutes (true); |
| 78 | ndnHelper.InstallAll (); |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 79 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 80 | NS_LOG_INFO ("Installing Ndn applications"); |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 81 | ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr"); |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 82 | // Consumer will request /prefix/0, /prefix/1, ... |
Alexander Afanasyev | b0c4389 | 2012-06-13 00:52:58 -0700 | [diff] [blame] | 83 | consumerHelper.SetPrefix ("/prefix/0"); |
| 84 | consumerHelper.SetAttribute ("Frequency", StringValue ("1")); // 10 interests a second |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 85 | ApplicationContainer consumers = consumerHelper.Install (nodes.Get (0)); // first node |
Alexander Afanasyev | b0c4389 | 2012-06-13 00:52:58 -0700 | [diff] [blame] | 86 | consumers.Stop (Seconds (0.3)); |
| 87 | |
| 88 | consumerHelper.SetPrefix ("/prefix"); |
| 89 | consumers = consumerHelper.Install (nodes.Get (0)); // first node |
| 90 | consumers.Start (Seconds (1)); |
| 91 | consumers.Stop (Seconds (1.3)); |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 92 | |
Alexander Afanasyev | cf6dc92 | 2012-08-10 16:55:27 -0700 | [diff] [blame] | 93 | ndn::AppHelper producerHelper ("ns3::ndn::Producer"); |
Alexander Afanasyev | f04d451 | 2012-02-14 18:42:47 -0800 | [diff] [blame] | 94 | // Producer will reply to all requests starting with /prefix |
| 95 | producerHelper.SetPrefix ("/prefix"); |
| 96 | producerHelper.SetAttribute ("PayloadSize", StringValue("1024")); |
| 97 | ApplicationContainer producers = producerHelper.Install (nodes.Get (2)); // last node |
| 98 | |
| 99 | Simulator::Stop (finishTime); |
| 100 | |
| 101 | NS_LOG_INFO ("Run Simulation."); |
| 102 | Simulator::Run (); |
| 103 | Simulator::Destroy (); |
| 104 | NS_LOG_INFO ("Done!"); |
| 105 | |
| 106 | return 0; |
| 107 | } |