blob: a252a5824a7f72dea73098580bf7ddee69536778 [file] [log] [blame]
Alexander Lane9944cf52018-05-17 12:16:50 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Saurab Dulal576a4192020-08-25 00:55:22 -05003# Copyright (C) 2015-2020, The University of Memphis,
Alexander Lane9944cf52018-05-17 12:16:50 -05004# 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
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050026# Todo: convert to app
27
28class NDNPingClient(object):
Alexander Lane9944cf52018-05-17 12:16:50 -050029 @staticmethod
Alexander Laneea2d5d62019-10-04 16:48:52 -050030 def ping(source, prefix, nPings=1, interval=None, timeout=None, starting_seq_num=None,
Alexander Lane9944cf52018-05-17 12:16:50 -050031 identifier=None, allow_stale_data=False, print_timestamp=True, sleepTime=0.2):
Alexander Laneea2d5d62019-10-04 16:48:52 -050032 print('Scheduling ping(s) from {} for {}'.format(source.name, prefix))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050033 # Use '&' to run in background and perform parallel pings
Alexander Laneea2d5d62019-10-04 16:48:52 -050034 source.cmd("mkdir ping-data")
35 source.cmd('ndnping{1}{2}{3}{4}{5}{6}{7} {0} >> ping-data/{8}.txt &'
Alexander Lane9944cf52018-05-17 12:16:50 -050036 .format(
Alexander Laneea2d5d62019-10-04 16:48:52 -050037 prefix,
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050038 ' -c {}'.format(nPings),
39 ' -i {}'.format(interval) if interval else '',
40 ' -o {}'.format(timeout) if timeout else '',
41 ' -n {}'.format(starting_seq_num) if starting_seq_num else '',
42 ' -p {}'.format(identifier) if identifier else '',
43 ' -a' if allow_stale_data else '',
Alexander Laneea2d5d62019-10-04 16:48:52 -050044 ' -t' if print_timestamp else '',
45 str.replace(prefix[1:], "/", "-")
Alexander Lane9944cf52018-05-17 12:16:50 -050046 ))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050047 time.sleep(sleepTime)