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-grid.py |
| 21 | |
| 22 | from ns.core import * |
| 23 | from ns.network import * |
| 24 | from ns.point_to_point import * |
| 25 | from ns.point_to_point_layout import * |
| 26 | from ns.ndnSIM import * |
| 27 | |
| 28 | # |
| 29 | # This scenario simulates a grid topology (using PointToPointGrid module) |
| 30 | # |
| 31 | # (consumer) -- ( ) ----- ( ) |
| 32 | # | | | |
| 33 | # ( ) ------ ( ) ----- ( ) |
| 34 | # | | | |
| 35 | # ( ) ------ ( ) -- (producer) |
| 36 | # |
| 37 | # All links are 1Mbps with propagation 10ms delay. |
| 38 | # |
| 39 | # FIB is populated using NdnGlobalRoutingHelper. |
| 40 | # |
| 41 | # Consumer requests data from producer with frequency 100 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 --pyrun=src/ndnSIM/examples/ndn-grid.py |
| 50 | # |
| 51 | |
| 52 | Config.SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps")) |
| 53 | Config.SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms")) |
Alexander Afanasyev | 77f84c6 | 2018-10-08 13:37:42 -0400 | [diff] [blame^] | 54 | Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p")) |
Alexander Afanasyev | e316ab2 | 2015-01-03 21:02:08 -0800 | [diff] [blame] | 55 | |
| 56 | import sys; cmd = CommandLine(); cmd.Parse(sys.argv); |
| 57 | |
| 58 | p2p = PointToPointHelper () |
| 59 | grid = PointToPointGridHelper (3,3,p2p) |
| 60 | grid.BoundingBox(100,100,200,200) |
| 61 | |
| 62 | ####################################################### |
| 63 | |
| 64 | ndnHelper = ndn.StackHelper() |
| 65 | ndnHelper.InstallAll(); |
| 66 | |
| 67 | |
| 68 | # Getting containers for the consumer/producer |
| 69 | producer = grid.GetNode(2, 2) |
| 70 | consumerNodes = NodeContainer() |
| 71 | consumerNodes.Add(grid.GetNode(0,0)) |
| 72 | |
| 73 | |
| 74 | cHelper = ndn.AppHelper("ns3::ndn::ConsumerCbr") |
| 75 | cHelper.SetPrefix("/prefix") |
| 76 | cHelper.SetAttribute("Frequency", StringValue("10")) |
| 77 | out = cHelper.Install(consumerNodes) |
| 78 | |
| 79 | pHelper = ndn.AppHelper("ns3::ndn::Producer") |
| 80 | pHelper.SetPrefix("/prefix") |
| 81 | pHelper.SetAttribute("PayloadSize", StringValue("1024")); |
| 82 | pHelper.Install(producer) |
| 83 | |
| 84 | ndnGlobalRoutingHelper = ndn.GlobalRoutingHelper() |
| 85 | ndnGlobalRoutingHelper.InstallAll() |
| 86 | |
| 87 | # Add /prefix origins to ndn::GlobalRouter |
| 88 | ndnGlobalRoutingHelper.AddOrigin("/prefix", producer) |
| 89 | |
| 90 | # Calculate and install FIBs |
| 91 | ndnGlobalRoutingHelper.CalculateRoutes() |
| 92 | |
| 93 | |
| 94 | # ####################################################### |
| 95 | |
| 96 | Simulator.Stop(Seconds(20.0)) |
| 97 | Simulator.Run() |
| 98 | |
| 99 | # # To access FIB, PIT, CS, uncomment the following lines |
| 100 | |
| 101 | # l3Protocol = ndn.L3Protocol.getL3Protocol(grid.GetNode(0,0)) |
| 102 | # forwarder = l3Protocol.getForwarder() |
| 103 | |
| 104 | # fib = forwarder.getFib() |
| 105 | # print "Contents of FIB (%d):" % fib.size() |
| 106 | # for i in fib: |
| 107 | # print " - %s:" % i.getPrefix() |
| 108 | # for nh in i.getNextHops(): |
| 109 | # print " - %s%d (cost: %d)" % (nh.getFace(), nh.getFace().getId(), nh.getCost()) |
| 110 | |
| 111 | # pit = forwarder.getPit() |
| 112 | # print "Contents of PIT (%d):" % pit.size() |
| 113 | # for i in pit: |
| 114 | # print " - %s" % i.getName() |
| 115 | |
| 116 | # cs = forwarder.getCs() |
| 117 | # print "Contents of CS (%d):" % cs.size() |
| 118 | # for i in cs: |
| 119 | # print " - %s" % i.getName() |
| 120 | |
| 121 | Simulator.Destroy() |
| 122 | |
| 123 | # # or run using the visualizer |
| 124 | # import visualizer |
| 125 | # visualizer.start() |