Export command.
( self )
| 1688 | warn( er, '\n' ) |
| 1689 | |
| 1690 | def exportScript( self ): |
| 1691 | "Export command." |
| 1692 | myFormats = [ |
| 1693 | ('Mininet Custom Topology','*.py'), |
| 1694 | ('All Files','*'), |
| 1695 | ] |
| 1696 | |
| 1697 | fileName = tkFileDialog.asksaveasfilename(filetypes=myFormats ,title="Export the topology as...") |
| 1698 | if len(fileName ) > 0: |
| 1699 | # debug( "Now saving under %s\n" % fileName ) |
| 1700 | f = open(fileName, 'w') # pylint: disable=consider-using-with |
| 1701 | |
| 1702 | f.write("#!/usr/bin/env python\n") |
| 1703 | f.write("\n") |
| 1704 | f.write("from mininet.net import Mininet\n") |
| 1705 | f.write("from mininet.node import Controller, RemoteController, OVSController\n") |
| 1706 | f.write("from mininet.node import CPULimitedHost, Host, Node\n") |
| 1707 | f.write("from mininet.node import OVSKernelSwitch, UserSwitch\n") |
| 1708 | if StrictVersion(MININET_VERSION) > StrictVersion('2.0'): |
| 1709 | f.write("from mininet.node import IVSSwitch\n") |
| 1710 | f.write("from mininet.cli import CLI\n") |
| 1711 | f.write("from mininet.log import setLogLevel, info\n") |
| 1712 | f.write("from mininet.link import TCLink, Intf\n") |
| 1713 | f.write("from subprocess import call\n") |
| 1714 | |
| 1715 | inBandCtrl = False |
| 1716 | for widget, item in self.widgetToItem.items(): |
| 1717 | name = widget[ 'text' ] |
| 1718 | tags = self.canvas.gettags( item ) |
| 1719 | |
| 1720 | if 'Controller' in tags: |
| 1721 | opts = self.controllers[name] |
| 1722 | controllerType = opts['controllerType'] |
| 1723 | if controllerType == 'inband': |
| 1724 | inBandCtrl = True |
| 1725 | |
| 1726 | if inBandCtrl: |
| 1727 | f.write("\n") |
| 1728 | f.write("class InbandController( RemoteController ):\n") |
| 1729 | f.write("\n") |
| 1730 | f.write(" def checkListening( self ):\n") |
| 1731 | f.write(" \"Overridden to do nothing.\"\n") |
| 1732 | f.write(" return\n") |
| 1733 | |
| 1734 | f.write("\n") |
| 1735 | f.write("def myNetwork():\n") |
| 1736 | f.write("\n") |
| 1737 | f.write(" net = Mininet( topo=None,\n") |
| 1738 | if len(self.appPrefs['dpctl']) > 0: |
| 1739 | f.write(" listenPort="+self.appPrefs['dpctl']+",\n") |
| 1740 | f.write(" build=False,\n") |
| 1741 | f.write(" ipBase='"+self.appPrefs['ipBase']+"')\n") |
| 1742 | f.write("\n") |
| 1743 | f.write(" info( '*** Adding controller\\n' )\n") |
| 1744 | for widget, item in self.widgetToItem.items(): |
| 1745 | name = widget[ 'text' ] |
| 1746 | tags = self.canvas.gettags( item ) |
| 1747 |