Project

General

Profile

Bug #4792 ยป test.py

Alexander Lane, 12/17/2018 02:34 PM

 
from ndn.experiments.experiment import Experiment
import os
from time import sleep
from subprocess import PIPE

class ReproductionTest(Experiment):
def __init__(self, args):
Experiment.__init__(self, args)
self.log_directory = "/tmp/minindn/logs/"
if not os.path.exists(self.log_directory):
os.makedirs(self.log_directory)
self.log_dict = {"a":open("/tmp/minindn/logs/permanent-faceA.log", "a"), "b":open("/tmp/minindn/logs/permanent-faceB.log", "a")}
self.env_dict = self.createEnvDict(self.net.hosts)
self.host_A = self.net.hosts[0]
self.host_B = self.net.hosts[1]
self.exit_status = False
print("Setup complete")

def start(self):
self.run()

def run(self):
a = self.host_A.popen(["nfdc", "face", "create," "udp://{}".format(self.interfaceGetter(self.host_A, self.host_B)), "persistency", "permanent"], stdout=self.log_dict["a"], env=self.env_dict["a"])
a.wait()
b = self.host_A.popen(["nfdc", "route", "add", "ndn:/name/B", "udp://{}:6363".format(self.interfaceGetter(self.host_A, self.host_B))], stdout=self.log_dict["a"], env=self.env_dict["a"])
b.wait()
print(self.host_A.cmd("nfdc face list"))
print(self.host_A.cmd("nfdc route list"))

def createEnv(self, host):
'''Creates environment variables for a given host'''
out = host.popen("printenv").stdout.read()
env = {}
for elem in out.split("\n"):
if elem != "":
tmp=elem.split("=")
env[tmp[0]] = tmp[1]
env["HOME"] = host.homeFolder
return env

def createEnvDict(self, hostList):
'''Create a dictionary of environment variables for a given host, using the host name as a key'''
envDict = dict()
for host in hostList:
envDict[host.name] = self.createEnv(host)
return envDict

def interfaceGetter(self, host, other_host):
for intf in host.intfList():
link = intf.link
if link.intf2.node.name == other_host.name:
return (link.intf2.IP(), link.intf1.IP())
elif link.intf1.node.name == other_host.name:
return (link.intf1.IP(), link.intf2.IP())
raise Exception("Could not find IP for Host {}".format(other_host.name))


Experiment.register("reproduce", ReproductionTest)
    (1-1/1)