Advertisement
Guest User

Simple ns-3 scenario for queue investigation

a guest
Dec 11th, 2012
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. // ndn-simple.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.  
  26. using namespace ns3;
  27.  
  28. /**
  29.  *      +----------+     1Mbps      +--------+     1Mbps      +----------+
  30.  *      | consumer | <------------> | router | <------------> | producer |
  31.  *      +----------+         10ms   +--------+          10ms  +----------+
  32.  */
  33.  
  34. int
  35. main (int argc, char *argv[])
  36. {
  37.   // setting default parameters for PointToPoint links and channels
  38.   Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
  39.   Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
  40.   Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
  41.  
  42.   // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  43.   CommandLine cmd;
  44.   cmd.Parse (argc, argv);
  45.  
  46.   // Creating nodes
  47.   NodeContainer nodes;
  48.   nodes.Create (3);
  49.  
  50.   // Connecting nodes using two links
  51.   PointToPointHelper p2p;
  52.   NetDeviceContainer devices;
  53.  
  54.   devices = p2p.Install (nodes.Get (0), nodes.Get (1));
  55.   devices.Get (0)->SetAttribute ("TxQueue", PointerValue (CreateObject<DropTailQueue> ()));
  56.   devices.Get (1)->SetAttribute ("TxQueue", PointerValue (CreateObject<DropTailQueue> ()));
  57.  
  58.   // p2p.SetDeviceAttribute ("TxQueue", PointerValue (CreateObject<RedQueue> ()));
  59.   devices = p2p.Install (nodes.Get (1), nodes.Get (2));
  60.   devices.Get (0)->SetAttribute ("TxQueue", PointerValue (CreateObject<RedQueue> ()));
  61.   devices.Get (1)->SetAttribute ("TxQueue", PointerValue (CreateObject<RedQueue> ()));
  62.  
  63.   // Install CCNx stack on all nodes
  64.   ndn::StackHelper ccnxHelper;
  65.   ccnxHelper.SetDefaultRoutes (true);
  66.   ccnxHelper.InstallAll ();
  67.  
  68.   // Installing applications
  69.  
  70.   // Consumer
  71.   ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerBatches");
  72.   // Consumer will request /prefix/0, /prefix/1, ...
  73.   consumerHelper.SetPrefix ("/prefix");
  74.   consumerHelper.SetAttribute ("Batches", StringValue("1s 1"));
  75.   consumerHelper.Install (nodes.Get (0)); // first node
  76.  
  77.   // Producer
  78.   ndn::AppHelper producerHelper ("ns3::ndn::Producer");
  79.   // Producer will reply to all requests starting with /prefix
  80.   producerHelper.SetPrefix ("/prefix");
  81.   producerHelper.Install (nodes.Get (2)); // last node
  82.  
  83.   Simulator::Stop (Seconds (2.0));
  84.  
  85.   Simulator::Run ();
  86.   Simulator::Destroy ();
  87.  
  88.   return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement