Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
- /*
- * Copyright (c) 2012 University of California, Los Angeles
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
- // ndn-simple.cc
- #include "ns3/core-module.h"
- #include "ns3/network-module.h"
- #include "ns3/point-to-point-module.h"
- #include "ns3/ndnSIM-module.h"
- using namespace ns3;
- /**
- * +----------+ 1Mbps +--------+ 1Mbps +----------+
- * | consumer | <------------> | router | <------------> | producer |
- * +----------+ 10ms +--------+ 10ms +----------+
- */
- int
- main (int argc, char *argv[])
- {
- // setting default parameters for PointToPoint links and channels
- Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
- Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
- Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
- // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
- CommandLine cmd;
- cmd.Parse (argc, argv);
- // Creating nodes
- NodeContainer nodes;
- nodes.Create (3);
- // Connecting nodes using two links
- PointToPointHelper p2p;
- NetDeviceContainer devices;
- devices = p2p.Install (nodes.Get (0), nodes.Get (1));
- devices.Get (0)->SetAttribute ("TxQueue", PointerValue (CreateObject<DropTailQueue> ()));
- devices.Get (1)->SetAttribute ("TxQueue", PointerValue (CreateObject<DropTailQueue> ()));
- // p2p.SetDeviceAttribute ("TxQueue", PointerValue (CreateObject<RedQueue> ()));
- devices = p2p.Install (nodes.Get (1), nodes.Get (2));
- devices.Get (0)->SetAttribute ("TxQueue", PointerValue (CreateObject<RedQueue> ()));
- devices.Get (1)->SetAttribute ("TxQueue", PointerValue (CreateObject<RedQueue> ()));
- // Install CCNx stack on all nodes
- ndn::StackHelper ccnxHelper;
- ccnxHelper.SetDefaultRoutes (true);
- ccnxHelper.InstallAll ();
- // Installing applications
- // Consumer
- ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerBatches");
- // Consumer will request /prefix/0, /prefix/1, ...
- consumerHelper.SetPrefix ("/prefix");
- consumerHelper.SetAttribute ("Batches", StringValue("1s 1"));
- consumerHelper.Install (nodes.Get (0)); // first node
- // Producer
- ndn::AppHelper producerHelper ("ns3::ndn::Producer");
- // Producer will reply to all requests starting with /prefix
- producerHelper.SetPrefix ("/prefix");
- producerHelper.Install (nodes.Get (2)); // last node
- Simulator::Stop (Seconds (2.0));
- Simulator::Run ();
- Simulator::Destroy ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement