Project

General

Profile

Bug #4792 ยป test.py

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

 
1
from ndn.experiments.experiment import Experiment
2
import os
3
from time import sleep
4
from subprocess import PIPE
5

    
6
class ReproductionTest(Experiment):
7
    def __init__(self, args):
8
        Experiment.__init__(self, args)
9
        self.log_directory = "/tmp/minindn/logs/"
10
        if not os.path.exists(self.log_directory):
11
            os.makedirs(self.log_directory)
12
        self.log_dict = {"a":open("/tmp/minindn/logs/permanent-faceA.log", "a"), "b":open("/tmp/minindn/logs/permanent-faceB.log", "a")}
13
        self.env_dict = self.createEnvDict(self.net.hosts)
14
        self.host_A = self.net.hosts[0]
15
        self.host_B = self.net.hosts[1]
16
        self.exit_status = False
17
        print("Setup complete")
18

    
19
    def start(self):
20
        self.run()
21

    
22
    def run(self):
23
        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"])
24
        a.wait()
25
        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"])
26
        b.wait()
27
        print(self.host_A.cmd("nfdc face list"))
28
        print(self.host_A.cmd("nfdc route list"))
29

    
30
    def createEnv(self, host):
31
        '''Creates environment variables for a given host'''
32
        out = host.popen("printenv").stdout.read()
33
        env = {}
34
        for elem in out.split("\n"):
35
            if elem != "":
36
                tmp=elem.split("=")
37
                env[tmp[0]] = tmp[1]
38
        env["HOME"] = host.homeFolder
39
        return env
40

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

    
48
    def interfaceGetter(self, host, other_host):
49
        for intf in host.intfList():
50
            link = intf.link
51
            if link.intf2.node.name == other_host.name:
52
                return (link.intf2.IP(), link.intf1.IP())
53
            elif link.intf1.node.name == other_host.name:
54
                return (link.intf1.IP(), link.intf2.IP())
55
        raise Exception("Could not find IP for Host {}".format(other_host.name))
56

    
57

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