blob: f13dd432e4542a7b11048933a2bf97cf9bf1938c [file] [log] [blame]
Alexander Afanasyeve316ab22015-01-03 21:02:08 -08001## -*- 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
22from ns.core import *
23from ns.network import *
24from ns.point_to_point import *
25from ns.point_to_point_layout import *
26from 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
52Config.SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("10Mbps"))
53Config.SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"))
Alexander Afanasyevf007a992022-05-05 15:57:08 -040054Config::SetDefault("ns3::DropTailQueue<Packet>::MaxSize", StringValue("20p"))
Alexander Afanasyeve316ab22015-01-03 21:02:08 -080055
56import sys; cmd = CommandLine(); cmd.Parse(sys.argv);
57
58p2p = PointToPointHelper ()
59grid = PointToPointGridHelper (3,3,p2p)
60grid.BoundingBox(100,100,200,200)
61
62#######################################################
63
64ndnHelper = ndn.StackHelper()
65ndnHelper.InstallAll();
66
67
68# Getting containers for the consumer/producer
69producer = grid.GetNode(2, 2)
70consumerNodes = NodeContainer()
71consumerNodes.Add(grid.GetNode(0,0))
72
73
74cHelper = ndn.AppHelper("ns3::ndn::ConsumerCbr")
75cHelper.SetPrefix("/prefix")
76cHelper.SetAttribute("Frequency", StringValue("10"))
77out = cHelper.Install(consumerNodes)
78
79pHelper = ndn.AppHelper("ns3::ndn::Producer")
80pHelper.SetPrefix("/prefix")
81pHelper.SetAttribute("PayloadSize", StringValue("1024"));
82pHelper.Install(producer)
83
84ndnGlobalRoutingHelper = ndn.GlobalRoutingHelper()
85ndnGlobalRoutingHelper.InstallAll()
86
87# Add /prefix origins to ndn::GlobalRouter
88ndnGlobalRoutingHelper.AddOrigin("/prefix", producer)
89
90# Calculate and install FIBs
91ndnGlobalRoutingHelper.CalculateRoutes()
92
93
94# #######################################################
95
96Simulator.Stop(Seconds(20.0))
97Simulator.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
121Simulator.Destroy()
122
123# # or run using the visualizer
124# import visualizer
125# visualizer.start()