Bug fix on ndnpingclient and experiment script

Mininet host object is passed as a prefix from experiment
to ndnpingclient, string replacement operation on the
prefix fails at the client which crashes the Mini-NDN

Change-Id: I36c1f9e2e455321d8c650fd9711088b7e5ef2b22
This commit is contained in:
dulalsaurab committed 2021-05-13 20:16:42 +00:00
1 parent eef6ee890e
commit 0ed7772f3f
3 files changed
+49 -9

No files matched your search

+6 -3
View File
@@ -28,7 +28,8 @@ from itertools import cycle
from mininet.log import info
from minindn.helpers.nfdc import Nfdc
from minindn.helpers.ndnpingclient import NDNPingClient
from minindn.helpers.ndnping import NDNPing
from minindn.util import getSafeName
class Experiment(object):
@staticmethod
@@ -70,7 +71,8 @@ class Experiment(object):
for host in hosts:
host.cmd('mkdir -p ping-data')
Nfdc.setStrategy(host, '/ndn/', strategy)
host.cmd('ndnpingserver /ndn/{}-site/{} > ping-server &'.format(host.name, host.name))
prefix = getSafeName('/ndn/{}-site/{}'.format(host.name, host.name))
NDNPing.startPingServer(host, prefix)
@staticmethod
def startPctPings(net, nPings, pctTraffic=1.0):
@@ -95,7 +97,8 @@ class Experiment(object):
# Do not ping self
if host.name != other.name:
NDNPingClient.ping(host, other, nPings)
destPrefix = getSafeName('/ndn/{}-site/{}'.format(other.name, other.name))
NDNPing.ping(host, destPrefix, other.name, nPings)
nodesPingedList.append(other)
# Always increment because in 100% case a node should not ping itself
@@ -25,13 +25,13 @@ import time
# Todo: convert to app
class NDNPingClient(object):
class NDNPing(object):
@staticmethod
def ping(source, prefix, nPings=1, interval=None, timeout=None, starting_seq_num=None,
identifier=None, allow_stale_data=False, print_timestamp=True, sleepTime=0.2):
def ping(source, prefix, pingDataFile="output-client", nPings=1, interval=None, timeout=None,
starting_seq_num=None, identifier=None, allow_stale_data=False, print_timestamp=True, sleepTime=0.2):
print('Scheduling ping(s) from {} for {}'.format(source.name, prefix))
# Use '&' to run in background and perform parallel pings
source.cmd("mkdir ping-data")
source.cmd("mkdir -p ping-data")
source.cmd('ndnping{1}{2}{3}{4}{5}{6}{7} {0} >> ping-data/{8}.txt &'
.format(
prefix,
@@ -42,6 +42,30 @@ class NDNPingClient(object):
' -p {}'.format(identifier) if identifier else '',
' -a' if allow_stale_data else '',
' -t' if print_timestamp else '',
str.replace(prefix[1:], "/", "-")
pingDataFile
))
time.sleep(sleepTime)
def startPingServer(source, prefix, pingDataFile="output-server", freshness=None, satisfy=None,
size=None, timestamp=False, quiet=False):
"""
Start a pingserver
:param string preifx: prefix to start pingserver on
:param int freshness: FreshnessPeriod of the ping response, in milliseconds
:param int satisfy: maximum number of pings to satisfy
:param int size: size of response payload
:param boolean timestamp: prepend a timestamp to each log message
:param boolean quite: do not print a log message each time a ping packet is received
"""
print('Staring ping server on prefix {}'.format(prefix))
source.cmd("mkdir -p ping-data")
cmd = 'ndnpingserver {1}{2}{3}{4}{5} {0}>> ping-data/{6}.txt &'.format(
prefix,
'-f {}'.format(freshness) if freshness else '',
'-p {}'.format(satisfy) if satisfy else '',
'-s {}'.format(size) if size else '',
'{}'.format('-t') if timestamp else '',
'{}'.format('-q') if quiet else '',
pingDataFile
)
source.cmd(cmd)
+14 -1
View File
@@ -24,6 +24,8 @@
import sys
from os.path import isfile
from subprocess import call
from six.moves.urllib.parse import quote
from mininet.cli import CLI
from mn_wifi.cli import CLI as CLI_wifi
@@ -31,6 +33,17 @@ sshbase = ['ssh', '-q', '-t', '-i/home/mininet/.ssh/id_rsa']
scpbase = ['scp', '-i', '/home/mininet/.ssh/id_rsa']
devnull = open('/dev/null', 'w')
def getSafeName(namePrefix):
"""
Check if the prefix/string is safe to use with ndn commands or not.
return safe prefix.
:param namePrefix: name of the prefix
"""
# remove redundant "/"es, multiple "/"es are an invalid representation for empty name component
# https://named-data.net/doc/NDN-packet-spec/current/changelog.html#version-0-3
namePrefix= "/" + ("/".join(filter(None, namePrefix.split("/"))))
return quote(namePrefix, safe='/')
def ssh(login, cmd):
rcmd = sshbase + [login, cmd]
call(rcmd, stdout=devnull, stderr=devnull)
@@ -80,4 +93,4 @@ class MiniNDNCLI(CLI):
class MiniNDNWifiCLI(CLI_wifi):
prompt = 'mini-ndn-wifi> '
def __init__(self, mininet, stdin=sys.stdin, script=None):
CLI_wifi.__init__(self, mininet, stdin, script)
CLI_wifi.__init__(self, mininet, stdin, script)