dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 1 | # -*- 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 | |
| 24 | |
| 25 | """ |
| 26 | This example demonstrates the functionality of the Traffic generator. It consists of a traffic |
| 27 | server and client. The server will listen for interest on the prefix specified in the server |
awlane | a169f57 | 2022-04-08 17:21:29 -0500 | [diff] [blame] | 28 | configuration file. The client will send a designated number of interests to the server and |
dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 29 | get the data back. |
| 30 | More details on traffic generator here: https://github.com/named-data/ndn-traffic-generator |
| 31 | """ |
| 32 | |
| 33 | from time import sleep |
| 34 | |
| 35 | from mininet.log import setLogLevel, info |
| 36 | from minindn.minindn import Minindn |
| 37 | from minindn.util import MiniNDNCLI |
| 38 | from minindn.apps.app_manager import AppManager |
| 39 | from minindn.apps.nfd import Nfd |
| 40 | from minindn.apps.nlsr import Nlsr |
| 41 | from minindn.util import copyExistentFile |
| 42 | from examples.nlsr.nlsr_common import getParser |
| 43 | |
| 44 | def trafficServer(node, serverConfFile): |
| 45 | """ |
| 46 | Start traffic server |
| 47 | :parma mininet.node.Host node: mininet node object |
| 48 | :param string serverConfFile: server configuration file |
| 49 | """ |
| 50 | info ("Starting traffic server \n") |
| 51 | # c = 10, i.e maximum number of Interests to respond |
| 52 | cmd = 'ndn-traffic-server -c {} {} &> traffic-server.log &'.format(10, serverConfFile) |
| 53 | node.cmd(cmd) |
| 54 | sleep(10) |
| 55 | |
| 56 | # The server configuration file uses /example prefix to advertise its service |
| 57 | # thus, server needs to advertise this prefix for the client to reach it |
| 58 | serverPrefix = "/example" |
| 59 | server.cmd('nlsrc advertise {}'.format(serverPrefix)) |
| 60 | sleep(5) # sleep for routing convergence |
| 61 | |
| 62 | def trafficClient(node, clientConfFile): |
| 63 | """ |
| 64 | Start traffic client |
| 65 | :parma mininet.node.Host node: The expiration period in milliseconds, or None if not specified. |
| 66 | :param string clientConfFile: client configuration file |
| 67 | """ |
| 68 | info ("Starting ndn traffic client \n") |
| 69 | # c = 10, total number of Interests to be generated each at 200ms interval |
| 70 | cmd = 'ndn-traffic-client -c {} -i {} {} &> traffic-client.log &'.format(10, 200, clientConfFile) |
| 71 | node.cmd(cmd) |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | setLogLevel('info') |
| 75 | |
| 76 | # Traffic generator configuration files. For this example, we are using default conf files. |
| 77 | # More details on configuration files here: https://github.com/named-data/ndn-traffic-generator |
| 78 | possibleServerConfPath = ["/etc/ndn/ndn-traffic-server.conf.sample", "/usr/local/etc/ndn/ndn-traffic-server.conf.sample"] |
| 79 | possibleClientConfPath = ["/etc/ndn/ndn-traffic-client.conf.sample", "/usr/local/etc/ndn/ndn-traffic-client.conf.sample"] |
| 80 | |
| 81 | Minindn.cleanUp() |
| 82 | Minindn.verifyDependencies() |
| 83 | ndn = Minindn(parser=getParser()) |
| 84 | ndn.start() |
| 85 | |
| 86 | nfds = AppManager(ndn, ndn.net.hosts, Nfd) |
| 87 | nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr) |
| 88 | sleep(90) |
| 89 | |
| 90 | # Default topology is used in this experiment "/topologies/default-topology.conf" |
| 91 | # lets make node "a" as a traffic-server node, and node "c" as a traffic-client node |
| 92 | server = ndn.net['a'] |
| 93 | client = ndn.net['c'] |
awlane | a169f57 | 2022-04-08 17:21:29 -0500 | [diff] [blame] | 94 | serverConf = '{}/{}/server-conf'.format(ndn.workDir, server.name) |
| 95 | clientConf = '{}/{}/client-conf'.format(ndn.workDir, client.name) |
dulalsaurab | 2085544 | 2021-05-21 20:37:03 +0000 | [diff] [blame] | 96 | |
| 97 | copyExistentFile(server, possibleServerConfPath, serverConf) |
| 98 | copyExistentFile(server, possibleClientConfPath, clientConf) |
| 99 | |
| 100 | trafficServer(server, serverConf) |
| 101 | trafficClient(client, clientConf) |
| 102 | # default location for the results: /tmp/minindn/ |
| 103 | |
| 104 | MiniNDNCLI(ndn.net) |
| 105 | ndn.stop() |