Exemplo n.º 1
0
def runTopo(topoFile, simParams, hostOptions, checkLevel, controller, switch):
    topo = CustomTopo(topoFilePath = topoFile, simParams = simParams, hostOptions = hostOptions)
    if checkLevel > 1:
        topo.setNetOption('link', TCLink)
    # net = CustomMininet(topo = topo, controller = Beacon, autoSetMacs = True, **topo.getNetOptions())
    # net = CustomMininet(topo = topo, controller = Beacon, **topo.getNetOptions())
    net = CustomMininet(topo = topo, controller = controller, switch = switch, **topo.getNetOptions())
    global netprobes
    netprobes = collections.OrderedDict()
    try:
        lg.output('Constructing virtual network..\n')
        start(net)
        check(net, checkLevel)
        lg.output("Starting hosts")
        lg.info(": ")
        for host in net.hosts:
            lg.info("%s " % host.name)
            if host.monitor_rules is not None:
                monitor.start(host, host.monitor_rules)
            if host.command is not None:
                lg.info("cmd ")
                host.command = host.command.format(commandOpts = host.commandOpts, name = host.name).format(name = host.name)
                if host.isXHost:
                    t = makeTerm(host, cmd = host.command)
                    if len(t) < 1:
                        lg.error("Error while starting terminal for host %s\n" % host.name)
                        continue
                    if len(t) == 2:
                        tunnel, term = t
                    else:
                        term = t
                    try:
                        if term.poll() is not None:
                            lg.error(
                                "Terminal with command %s ended early for host %s : %s\n" % (host.command, host.name, repr(term.communicate())))
                    except:
                        pass
                    netprobes[host.name] = term
                else:
                    netprobes[host.name] = runCommand(host)
                    # print(netprobes[host.name].communicate())
            else:
                if host.isXHost:
                    makeTerm(host)
                    lg.info("term ")
            lg.info("done ")
        lg.output("\n")
        EventsManager.startClock(net)
        interract(net)
        mon = False
        counter = monitor.Counter()
        for host in net.hosts:
            if host.monitor_rules is not None:
                monitor.collect(host, monitor_file, counter)
                monitor.stop(host, host.monitor_rules)
                mon = True
        for name, probe in netprobes.iteritems():
            lg.info("Send sigint to probe %s\n" % name)
            import signal

            try:
                probe.send_signal(signal.SIGINT)
                time.sleep(0.05)
            except OSError as e:
                lg.error("Failed to send SIGINT to %s : %s\n" % ( name, e))
        if mon:
            monitor.writeSummary(monitor_file, counter)
    finally:
        stop(net)
        # cleanup !
        lg.info("Stopping remaining processes...\n")
        kill = 0
        for name, probe in netprobes.iteritems():
            if probe.poll() is None:
                kill += 1
        if kill > 0:
            lg.info("Found %s process(es) to kill\n" % kill)
            time.sleep(3)
            for name, probe in netprobes.iteritems():
                if probe.poll() is None:
                    try:
                        lg.info("Send terminate signal to %s\n" % name)
                        probe.terminate()
                        time.sleep(0.001)
                    except OSError as e:
                        lg.error("Failed to terminate %s : %s\n" % (name, e))
            time.sleep(3)
            for name, probe in netprobes.iteritems():
                if probe.poll() is None:
                    try:
                        lg.info("Send kill signal to %s\n" % name)
                        probe.kill()
                    except OSError as e:
                        lg.error("Failed to kill %s : %s\n" % (name, e))
        lg.output("\nAll done\n")
Exemplo n.º 2
0
def run(threshold):
    watcher = monitor.start()
    detector = HardKeyPressDetector(watcher, threshold)
    _ = raw_input('\n(Press ENTER to quit).\n')
    monitor.stop()
Exemplo n.º 3
0
def runTopo(topoFile, simParams, hostOptions, checkLevel, controller, switch):
    topo = CustomTopo(topoFilePath=topoFile,
                      simParams=simParams,
                      hostOptions=hostOptions)
    if checkLevel > 1:
        topo.setNetOption('link', TCLink)
    # net = CustomMininet(topo = topo, controller = Beacon, autoSetMacs = True, **topo.getNetOptions())
    # net = CustomMininet(topo = topo, controller = Beacon, **topo.getNetOptions())
    net = CustomMininet(topo=topo,
                        controller=controller,
                        switch=switch,
                        **topo.getNetOptions())
    global netprobes
    netprobes = collections.OrderedDict()
    try:
        lg.output('Constructing virtual network..\n')
        start(net)
        check(net, checkLevel)
        lg.output("Starting hosts")
        lg.info(": ")
        for host in net.hosts:
            lg.info("%s " % host.name)
            if host.monitor_rules is not None:
                monitor.start(host, host.monitor_rules)
            if host.command is not None:
                lg.info("cmd ")
                host.command = host.command.format(
                    commandOpts=host.commandOpts,
                    name=host.name).format(name=host.name)
                if host.isXHost:
                    t = makeTerm(host, cmd=host.command)
                    if len(t) < 1:
                        lg.error(
                            "Error while starting terminal for host %s\n" %
                            host.name)
                        continue
                    if len(t) == 2:
                        tunnel, term = t
                    else:
                        term = t
                    try:
                        if term.poll() is not None:
                            lg.error(
                                "Terminal with command %s ended early for host %s : %s\n"
                                % (host.command, host.name,
                                   repr(term.communicate())))
                    except:
                        pass
                    netprobes[host.name] = term
                else:
                    netprobes[host.name] = runCommand(host)
                    # print(netprobes[host.name].communicate())
            else:
                if host.isXHost:
                    makeTerm(host)
                    lg.info("term ")
            lg.info("done ")
        lg.output("\n")
        EventsManager.startClock(net)
        interract(net)
        mon = False
        counter = monitor.Counter()
        for host in net.hosts:
            if host.monitor_rules is not None:
                monitor.collect(host, monitor_file, counter)
                monitor.stop(host, host.monitor_rules)
                mon = True
        for name, probe in netprobes.iteritems():
            lg.info("Send sigint to probe %s\n" % name)
            import signal

            try:
                probe.send_signal(signal.SIGINT)
                time.sleep(0.05)
            except OSError as e:
                lg.error("Failed to send SIGINT to %s : %s\n" % (name, e))
        if mon:
            monitor.writeSummary(monitor_file, counter)
    finally:
        stop(net)
        # cleanup !
        lg.info("Stopping remaining processes...\n")
        kill = 0
        for name, probe in netprobes.iteritems():
            if probe.poll() is None:
                kill += 1
        if kill > 0:
            lg.info("Found %s process(es) to kill\n" % kill)
            time.sleep(3)
            for name, probe in netprobes.iteritems():
                if probe.poll() is None:
                    try:
                        lg.info("Send terminate signal to %s\n" % name)
                        probe.terminate()
                        time.sleep(0.001)
                    except OSError as e:
                        lg.error("Failed to terminate %s : %s\n" % (name, e))
            time.sleep(3)
            for name, probe in netprobes.iteritems():
                if probe.poll() is None:
                    try:
                        lg.info("Send kill signal to %s\n" % name)
                        probe.kill()
                    except OSError as e:
                        lg.error("Failed to kill %s : %s\n" % (name, e))
        lg.output("\nAll done\n")
Exemplo n.º 4
0
	def stopMonitor(self):
		self.monitorButton.config(text="Start\nMonitor", command=lambda: self.startMonitor())
		monitor.stop()
		self.updateMap()
		self.updateNodelist()