Alexander Afanasyev | e316ab2 | 2015-01-03 21:02:08 -0800 | [diff] [blame] | 1 | ## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | # |
| 3 | # Copyright (c) 2011-2015 Regents of the University of California. |
| 4 | # |
| 5 | # This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | # contributors. |
| 7 | # |
| 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. |
| 11 | # |
| 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. |
| 15 | # |
| 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 | # |
| 19 | |
| 20 | # ndn-simple.py |
| 21 | |
| 22 | from ns.core import * |
| 23 | from ns.network import * |
| 24 | from ns.point_to_point import * |
| 25 | from ns.ndnSIM import * |
| 26 | |
| 27 | # |
| 28 | # This scenario simulates a very simple network topology: |
| 29 | # |
| 30 | # |
| 31 | # +----------+ 1Mbps +--------+ 1Mbps +----------+ |
| 32 | # | consumer | <------------> | router | <------------> | producer | |
| 33 | # +----------+ 10ms +--------+ 10ms +----------+ |
| 34 | # |
| 35 | # |
| 36 | # Consumer requests data from producer with frequency 10 interests per second |
| 37 | # (interests contain constantly increasing sequence number). |
| 38 | # |
| 39 | # For every received interest, producer replies with a data packet, containing |
| 40 | # 1024 bytes of virtual payload. |
| 41 | # |
| 42 | # To run scenario and see what is happening, use the following command: |
| 43 | # |
| 44 | # NS_LOG=ndn.Consumer:ndn.Producer ./waf --pyrun=src/ndnSIM/examples/ndn-simple.py |
| 45 | # |
| 46 | |
| 47 | # Set default parameters for PointToPoint links and channels |
| 48 | Config.SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")) |
| 49 | Config.SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")) |
Alexander Afanasyev | dc3c3a3 | 2019-02-17 20:17:32 -0500 | [diff] [blame^] | 50 | Config.SetDefault("ns3::QueueBase::MaxSize", StringValue("20p")) |
Alexander Afanasyev | e316ab2 | 2015-01-03 21:02:08 -0800 | [diff] [blame] | 51 | |
| 52 | # Read optional command-line parameters (e.g., enable visualizer with ./waf --pyrun=<> --visualize |
| 53 | import sys; cmd = CommandLine(); cmd.Parse(sys.argv); |
| 54 | |
| 55 | # Creating nodes |
| 56 | nodes = NodeContainer() |
| 57 | nodes.Create(3) |
| 58 | |
| 59 | # Connecting nodes using two links |
| 60 | p2p = PointToPointHelper() |
| 61 | p2p.Install(nodes.Get(0), nodes.Get(1)) |
| 62 | p2p.Install(nodes.Get(1), nodes.Get(2)) |
| 63 | |
| 64 | # Install NDN stack on all nodes |
| 65 | ndnHelper = ndn.StackHelper() |
| 66 | ndnHelper.SetDefaultRoutes(True) |
| 67 | ndnHelper.InstallAll() |
| 68 | |
| 69 | # Choosing forwarding strategy |
Alexander Afanasyev | c3c7f04 | 2015-08-21 11:38:00 -0700 | [diff] [blame] | 70 | ndn.StrategyChoiceHelper.InstallAll("/prefix", "/localhost/nfd/strategy/multicast") |
Alexander Afanasyev | e316ab2 | 2015-01-03 21:02:08 -0800 | [diff] [blame] | 71 | |
| 72 | # Installing applications |
| 73 | |
| 74 | # Consumer |
| 75 | consumerHelper = ndn.AppHelper("ns3::ndn::ConsumerCbr") |
| 76 | # Consumer will request /prefix/0, /prefix/1, ... |
| 77 | consumerHelper.SetPrefix("/prefix") |
| 78 | consumerHelper.SetAttribute("Frequency", StringValue("10")) # 10 interests a second |
| 79 | consumerHelper.Install(nodes.Get(0)) # first node |
| 80 | |
| 81 | # Producer |
| 82 | producerHelper = ndn.AppHelper("ns3::ndn::Producer") |
| 83 | # Producer will reply to all requests starting with /prefix |
| 84 | producerHelper.SetPrefix("/prefix") |
| 85 | producerHelper.SetAttribute("PayloadSize", StringValue("1024")) |
| 86 | producerHelper.Install(nodes.Get(2)) # last node |
| 87 | |
| 88 | Simulator.Stop(Seconds(20.0)) |
| 89 | |
| 90 | Simulator.Run() |
| 91 | Simulator.Destroy() |