Exemplo n.º 1
0
    def __init__(self, net, parent=None, width=4):
        Frame.__init__(self, parent)
        self.top = self.winfo_toplevel()
        self.top.title('Mininet')
        self.net = net
        self.menubar = self.createMenuBar()
        cframe = self.cframe = Frame(self)
        self.consoles = {}  # consoles themselves
        titles = {
            'hosts': 'Host',
            'switches': 'Switch',
            'controllers': 'Controller'
        }
        for name in titles:
            nodes = getattr(net, name)
            frame, consoles = self.createConsoles(cframe, nodes, width,
                                                  titles[name])
            self.consoles[name] = Object(frame=frame, consoles=consoles)
        self.selected = None
        self.select('hosts')
        self.cframe.pack(expand=True, fill='both')
        cleanUpScreens()
        # Close window gracefully
        Wm.wm_protocol(self.top, name='WM_DELETE_WINDOW', func=self.quit)

        # Initialize graph
        graph = Graph(cframe)
        self.consoles['graph'] = Object(frame=graph, consoles=[graph])
        self.graph = graph
        self.graphVisible = False
        self.updates = 0
        self.hostCount = len(self.consoles['hosts'].consoles)
        self.bw = 0

        self.pack(expand=True, fill='both')
Exemplo n.º 2
0
 def startTerms(self):
     "Start a terminal for each node."
     if 'DISPLAY' not in os.environ:
         error("Error starting terms: Cannot connect to display\n")
         return
     info("*** Running terms on %s\n" % os.environ['DISPLAY'])
     cleanUpScreens()
     self.terms += makeTerms(self.controllers, 'controller')
     self.terms += makeTerms(self.switches, 'switch')
     self.terms += makeTerms(self.hosts, 'host')
Exemplo n.º 3
0
 def stopXterms(self):
     "Kill each xterm."
     for term in self.terms:
         os.kill(term.pid, signal.SIGKILL)
     cleanUpScreens()
Exemplo n.º 4
0
    def cleanup(cls):
        """Clean up junk which might be left over from old runs;
           do fast stuff before slow dp and link removal!"""

        info("*** Removing excess controllers/ofprotocols/ofdatapaths/"
             "pings/noxes\n")
        zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
        zombies += 'ovs-openflowd ovs-controller udpbwtest mnexec ivs'
        # Note: real zombie processes can't actually be killed, since they
        # are already (un)dead. Then again,
        # you can't connect to them either, so they're mostly harmless.
        # Send SIGTERM first to give processes a chance to shutdown cleanly.
        sh('killall ' + zombies + ' 2> /dev/null')
        time.sleep(1)
        sh('killall -9 ' + zombies + ' 2> /dev/null')

        # And kill off sudo mnexec
        sh('pkill -9 -f "sudo mnexec"')

        info("*** Removing junk from /tmp\n")
        sh('rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log')

        info("*** Removing old X11 tunnels\n")
        cleanUpScreens()

        info("*** Removing excess kernel datapaths\n")
        dps = sh("ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'").splitlines()
        for dp in dps:
            if dp:
                sh('dpctl deldp ' + dp)

        info("***  Removing OVS datapaths\n")
        dps = sh("ovs-vsctl --timeout=1 list-br").strip().splitlines()
        if dps:
            sh("ovs-vsctl " + " -- ".join("--if-exists del-br " + dp
                                          for dp in dps if dp))
        # And in case the above didn't work...
        dps = sh("ovs-vsctl --timeout=1 list-br").strip().splitlines()
        for dp in dps:
            sh('ovs-vsctl del-br ' + dp)

        info("*** Removing all links of the pattern foo-ethX\n")
        links = sh(
            "ip link show | "
            "egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'").splitlines()
        # Delete blocks of links
        n = 1000  # chunk size
        for i in xrange(0, len(links), n):
            cmd = ';'.join('ip link del %s' % link for link in links[i:i + n])
            sh('( %s ) 2> /dev/null' % cmd)

        if 'tap9' in sh('ip link show'):
            info("*** Removing tap9 - assuming it's from cluster edition\n")
            sh('ip link del tap9')

        info("*** Killing stale mininet node processes\n")
        killprocs('mininet:')

        info("*** Shutting down stale tunnels\n")
        killprocs('Tunnel=Ethernet')
        killprocs('.ssh/mn')
        sh('rm -f ~/.ssh/mn/*')

        # Call any additional cleanup code if necessary
        for callback in cls.callbacks:
            callback()

        # Containernet should also cleanup pending Docker
        cmd = "docker rm -f $( docker ps --filter 'label=com.containernet' -a -q)"
        call(cmd,
             shell=True,
             stdout=open(os.devnull, 'wb'),
             stderr=open(os.devnull, 'wb'))

        # cleanup any remaining iptables rules from external SAPs with NAT
        # we use iptc module to iterate through the loops, but due to a bug, we cannot use iptc to delete the rules
        # we rely on iptables CLI to delete the found rules
        info("***  Removing SAP NAT rules\n")
        table = iptc.Table(iptc.Table.NAT)
        chain = iptc.Chain(table, 'POSTROUTING')

        for rule in chain.rules:
            if SAP_PREFIX in str(rule.out_interface):
                src_CIDR = str(ipaddress.IPv4Network(unicode(rule.src)))
                rule0_ = "iptables -t nat -D POSTROUTING ! -o {0} -s {1} -j MASQUERADE".\
                    format(rule.out_interface.strip('!'), src_CIDR)
                p = Popen(shlex.split(rule0_))
                p.communicate()
                info("delete NAT rule from SAP: {1} - {0} - {2}\n".format(
                    rule.out_interface, rule.in_interface, src_CIDR))

        table = iptc.Table(iptc.Table.FILTER)
        chain = iptc.Chain(table, 'FORWARD')
        for rule in chain.rules:
            src_CIDR = str(ipaddress.IPv4Network(unicode(rule.src)))
            if SAP_PREFIX in str(rule.out_interface):
                rule1_ = "iptables -D FORWARD -o {0} -j ACCEPT".format(
                    rule.out_interface)
                p = Popen(shlex.split(rule1_))
                p.communicate()
                info("delete FORWARD rule from SAP: {1} - {0} - {2}\n".format(
                    rule.out_interface, rule.in_interface, src_CIDR))

            if SAP_PREFIX in str(rule.in_interface):
                rule2_ = "iptables -D FORWARD -i {0} -j ACCEPT".format(
                    rule.in_interface)
                p = Popen(shlex.split(rule2_))
                p.communicate()
                info("delete FORWARD rule from SAP: {1} - {0} - {2}\n".format(
                    rule.out_interface, rule.in_interface, src_CIDR))

        info("*** Cleanup complete.\n")