blob: b1a40810dc0abd3beb7a86e75c2886b820b62990 [file] [log] [blame]
dulalsaurab0ed77722020-09-24 22:32:58 +00001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
dulalsaurab578f2ec2021-06-10 20:55:26 +00003# Copyright (C) 2015-2021, The University of Memphis,
dulalsaurab0ed77722020-09-24 22:32:58 +00004# 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
24import time
25
26# Todo: convert to app
27
28class NDNPing(object):
29 @staticmethod
30 def ping(source, prefix, pingDataFile="output-client", nPings=1, interval=None, timeout=None,
dulalsaurab578f2ec2021-06-10 20:55:26 +000031 starting_seq_num=None, identifier=None, allow_stale_data=False, print_timestamp=True,
32 sleepTime=0.2):
dulalsaurab0ed77722020-09-24 22:32:58 +000033 print('Scheduling ping(s) from {} for {}'.format(source.name, prefix))
34 # Use '&' to run in background and perform parallel pings
35 source.cmd("mkdir -p ping-data")
36 source.cmd('ndnping{1}{2}{3}{4}{5}{6}{7} {0} >> ping-data/{8}.txt &'
37 .format(
38 prefix,
39 ' -c {}'.format(nPings),
40 ' -i {}'.format(interval) if interval else '',
41 ' -o {}'.format(timeout) if timeout else '',
42 ' -n {}'.format(starting_seq_num) if starting_seq_num else '',
43 ' -p {}'.format(identifier) if identifier else '',
44 ' -a' if allow_stale_data else '',
45 ' -t' if print_timestamp else '',
46 pingDataFile
47 ))
48 time.sleep(sleepTime)
49
dulalsaurab578f2ec2021-06-10 20:55:26 +000050 @staticmethod
51 def startPingServer(source, prefix, pingDataFile="output-server", freshness=None, satisfy=None,
52 size=None, timestamp=False, quiet=False):
dulalsaurab0ed77722020-09-24 22:32:58 +000053 """
54 Start a pingserver
55 :param string preifx: prefix to start pingserver on
56 :param int freshness: FreshnessPeriod of the ping response, in milliseconds
57 :param int satisfy: maximum number of pings to satisfy
58 :param int size: size of response payload
59 :param boolean timestamp: prepend a timestamp to each log message
60 :param boolean quite: do not print a log message each time a ping packet is received
61 """
62 print('Staring ping server on prefix {}'.format(prefix))
63 source.cmd("mkdir -p ping-data")
64 cmd = 'ndnpingserver {1}{2}{3}{4}{5} {0}>> ping-data/{6}.txt &'.format(
65 prefix,
66 '-f {}'.format(freshness) if freshness else '',
67 '-p {}'.format(satisfy) if satisfy else '',
68 '-s {}'.format(size) if size else '',
69 '{}'.format('-t') if timestamp else '',
70 '{}'.format('-q') if quiet else '',
71 pingDataFile
72 )
73 source.cmd(cmd)