blob: 459b3d224bd54ac026535aa7332b4fd4e57d964d [file] [log] [blame]
dulalsaurab20855442021-05-21 20:37:03 +00001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015-2021, The University of Memphis,
4# Arizona Board of Regents,
5# Regents of the University of California.
6#
7# This file is part of Mini-NDN.
8# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
9#
10# Mini-NDN is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# Mini-NDN is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with Mini-NDN, e.g., in COPYING.md file.
22# If not, see <http://www.gnu.org/licenses/>.
23
24from time import sleep
25
26from mininet.log import setLogLevel, info
27from minindn.minindn import Minindn
28from minindn.util import MiniNDNCLI
29from minindn.apps.app_manager import AppManager
30from minindn.apps.nfd import Nfd
31from minindn.apps.nlsr import Nlsr
32
33
34"""
35This example demonstrates a basic consumer-producer using Mini-NDN. It uses ndnpeek and ndnpoke as
36a consumer and a producer respectively. If you want to build your own consumer/producer program, you
37can take help from here: https://github.com/named-data/ndn-cxx/tree/master/examples and
38here: https://github.com/dulalsaurab/multicast-supression-ndn/tree/main/ndn-src/consumer-producer
39"""
40
41if __name__ == '__main__':
42 setLogLevel('info')
43
44 Minindn.cleanUp()
45 Minindn.verifyDependencies()
46 ndn = Minindn()
47 ndn.start()
48
49 info('Starting nfd and nlsr on nodes')
50 nfds = AppManager(ndn, ndn.net.hosts, Nfd)
51 nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr)
52 sleep(90)
53
54 # Default topology is used in this experiment "/topologies/default-topology.conf"
55 # lets make node "a" as a producer node, and node "c" as a consumer node
56 producer = ndn.net['a']
57 consumer = ndn.net['c']
58
59 # start producer
60 producerPrefix = "/example"
61 producer.cmd('nlsrc advertise {}'.format(producerPrefix))
62 sleep(5) # sleep for routing convergence
63
64 # Make sure that basic consumer/producer example are compiled and installed in the system
65 info('Starting consumer and producer application')
66 producer.cmd("echo 'HELLO WORLD' | ndnpoke {} &> producer.log &".format(producerPrefix))
67 consumer.cmd("ndnpeek -p {} &> consumer.log &".format(producerPrefix))
68
69 MiniNDNCLI(ndn.net)
70 ndn.stop()