示例#1
0
    def daemonize_script(self, script, args):
        """Call MaxiNet Script (non-blocking)

        Args:
            cmd: name of script to call
        """
        cmd = Tools.get_script_dir()+script+" "+args
        p = subprocess.Popen(cmd, shell=True)
        atexit.register(p.terminate)
示例#2
0
    def script_check_output(self, cmd):
        """Call MaxiNet Script and return output

        Args:
            cmd: name of script to call
        Returns:
            Shell output of script
        """
        # Prefix command by our worker directory
        cmd = Tools.get_script_dir() + cmd
        return self.check_output(cmd)
示例#3
0
# This limitation does (of course) NOT hold for links between switches.
#
# Dynamic adding and removing of nodes also does not work when using the
# UserSwitch.

import time

from src.mininet.topo import Topo
from src.mininet.node import OVSSwitch

from src.maxinet.Frontend import maxinet_main
from src.maxinet.tools import Tools

# create topology
topo = Topo()
topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1))
topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2))
topo.addSwitch("s1", dpid=Tools.makeDPID(1))
topo.addLink("h1", "s1")
topo.addLink("h2", "s1")

# start cluster
cluster = maxinet_main.Cluster(minWorkers=2, maxWorkers=2)

# start experiment with OVSSwitch on cluster
exp = maxinet_main.Experiment(cluster, topo, switch=OVSSwitch)
exp.setup()

print "waiting 5 seconds for routing algorithms on the controller to converge"
time.sleep(5)
示例#4
0
    def start(self, ip, port, password, retry=float("inf")):
        """Start WorkerServer and ssh daemon and connect to nameserver."""

        self.logger.info("Cleaning previously created interfaces...")
        print subprocess.check_output(["mn", "-c"]).strip()

        self.logger.info("starting up and connecting to  %s:%d"
                         % (ip, port))

        #store for reconnection attempts
        self._ip = ip
        self._port = port
        self._password = password

        #Pyro4.config.HMAC_KEY = password
        tries=1
        self._ns = None
        while not self._ns:
            try:
                self._ns = Pyro4.locateNS(ip, port, hmac_key=password)
            except Pyro4.errors.NamingError:
                if tries < retry:
                    self.logger.warn("Unable to locate Nameserver. Trying again in 5 seconds...")
                    time.sleep(5)
                    tries += 1
                else:
                    self.logger.error("Unable to locate Nameserver.")
                    sys.exit()
        self.config = Pyro4.Proxy(self._ns.lookup("config"))
        self.config._pyroHmacKey=password
        self.ip = self.config.get_worker_ip(self.get_hostname())
        if(not self.ip):
            self.ip = Tools.guess_ip()
            if not self.config.has_section(self.get_hostname()):
                self.config.add_section(self.get_hostname())
            self.config.set(self.get_hostname(), "ip", self.ip)
            self.logger.warn("""FrontendServer did not know IP of this host (check configuration for hostname).
                             Guessed: %s""" % self.ip)
        self.logger.info("configuring and starting ssh daemon...")
        self.sshManager = SSH_Manager(folder=self.ssh_folder, ip=self.ip, port=self.config.get_sshd_port(), user=self.config.get("all", "sshuser"))
        self.sshManager.start_sshd()
        self._pyrodaemon = Pyro4.Daemon(host=self.ip)
        self._pyrodaemon._pyroHmacKey=password
        uri = self._pyrodaemon.register(self)
        self._ns.register(self._get_pyroname(), uri)
        uri = self._pyrodaemon.register(self.mnManager)
        self._ns.register(self._get_pyroname()+".mnManager", uri)
        uri = self._pyrodaemon.register(self.sshManager)
        self._ns.register(self._get_pyroname()+".sshManager", uri)
        atexit.register(self._stop)
        self.logger.info("looking for manager application...")
        manager_uri = self._ns.lookup("MaxiNetManager")
        if(manager_uri):
            self._manager = Pyro4.Proxy(manager_uri)
            self._manager._pyroHmacKey=self._password
            self.logger.info("signing in...")
            if(self._manager.worker_signin(self._get_pyroname(), self.get_hostname())):
                self.logger.info("done. Entering requestloop.")
                self._started = True
                self._looping_thread = threading.Thread(target=self._pyrodaemon.requestLoop)
                self._looping_thread.daemon = True
                self._looping_thread.start()
            else:
                self.logger.error("signin failed.")
        else:
            self.logger.error("no manager found.")
示例#5
0
文件: sshd.py 项目: heitorgo1/myfog
# emulated hosts.
#

import subprocess

from src.mininet.node import OVSSwitch
from src.mininet.topo import Topo

from src.maxinet.Frontend import maxinet_main
from src.maxinet.tools import Tools

topo = Topo()

topo.addSwitch("s1")
topo.addSwitch("s2")
topo.addHost("h1", ip=Tools.makeIP(1), mac=Tools.makeMAC(1))
topo.addHost("h2", ip=Tools.makeIP(2), mac=Tools.makeMAC(2))
topo.addLink("h1", "s1")
topo.addLink("s1", "s2")
topo.addLink("h2", "s2")

cluster = maxinet_main.Cluster()

# we need to add the root node after the simulation has started as we do
# not know which worker id the frontend machine will get. Therefore we
# need a dynamic topology which is only supported in openvswitch
exp = maxinet_main.Experiment(cluster, topo, switch=OVSSwitch)
exp.setup()

# Start ssh servers
h1 = exp.get("h1")