Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 20 | // ndn-csma.cpp |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 21 | |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/network-module.h" |
| 24 | #include "ns3/csma-module.h" |
| 25 | #include "ns3/ndnSIM-module.h" |
| 26 | |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 27 | namespace ns3 { |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * This scenario simulates a very simple network topology: |
| 31 | * |
| 32 | * CSMA bus (1Mbps, 10ms) |
| 33 | * +--------------------------+--------------------------+ |
| 34 | * | | | |
| 35 | * |
| 36 | * +----------+ +--------+ +----------+ |
| 37 | * | consumer | | router | | producer | |
| 38 | * +----------+ +--------+ +----------+ |
| 39 | * |
| 40 | * |
| 41 | * Consumer requests data from producer with frequency 10 interests per second |
| 42 | * (interests contain constantly increasing sequence number). |
| 43 | * |
| 44 | * For every received interest, producer replies with a data packet, containing |
| 45 | * 1024 bytes of virtual payload. |
| 46 | * |
| 47 | * To run scenario and see what is happening, use the following command: |
| 48 | * |
| 49 | * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-csma |
| 50 | */ |
| 51 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 52 | int |
| 53 | main(int argc, char* argv[]) |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 54 | { |
| 55 | // setting default parameters for PointToPoint links and channels |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | Config::SetDefault("ns3::CsmaChannel::DataRate", StringValue("1Mbps")); |
| 57 | Config::SetDefault("ns3::CsmaChannel::Delay", StringValue("10ms")); |
Spyridon Mastorakis | f98a341 | 2017-10-30 11:47:58 -0700 | [diff] [blame] | 58 | Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20)); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 59 | |
| 60 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 61 | CommandLine cmd; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | cmd.Parse(argc, argv); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 63 | |
| 64 | // Creating nodes |
| 65 | NodeContainer nodes; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 66 | nodes.Create(3); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 67 | |
| 68 | // Connecting nodes using two links |
| 69 | CsmaHelper csma; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 70 | csma.Install(nodes); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 71 | |
| 72 | // Install NDN stack on all nodes |
| 73 | ndn::StackHelper ndnHelper; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 74 | ndnHelper.SetDefaultRoutes(true); |
| 75 | ndnHelper.InstallAll(); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 76 | |
| 77 | // Installing applications |
| 78 | |
| 79 | // Consumer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 80 | ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr"); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 81 | // Consumer will request /prefix/0, /prefix/1, ... |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 82 | consumerHelper.SetPrefix("/prefix"); |
| 83 | consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second |
| 84 | consumerHelper.Install(nodes.Get(0)); // first node |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 85 | |
| 86 | // Producer |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 87 | ndn::AppHelper producerHelper("ns3::ndn::Producer"); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 88 | // Producer will reply to all requests starting with /prefix |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | producerHelper.SetPrefix("/prefix"); |
| 90 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 91 | producerHelper.Install(nodes.Get(2)); // last node |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 92 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 93 | Simulator::Stop(Seconds(20.0)); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | Simulator::Run(); |
| 96 | Simulator::Destroy(); |
Alexander Afanasyev | fff8498 | 2013-05-30 09:19:46 -0700 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
Spyridon Mastorakis | db8280f | 2014-11-21 20:00:17 -0800 | [diff] [blame] | 100 | |
| 101 | } // namespace ns3 |
| 102 | |
| 103 | int |
| 104 | main(int argc, char* argv[]) |
| 105 | { |
| 106 | return ns3::main(argc, argv); |
| 107 | } |