def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--topo', choices=TOPOS.keys(), default='simple_bgp_network', help='the topology that you want to start') parser.add_argument('--log', choices=LEVELS.keys(), default='info', help='The level of details in the logs') return parser.parse_args()
def initParser(): parser = argparse.ArgumentParser( description="Start a mininet for interoperability") parser.add_argument('--topo', '-t', help="choose a JSON file defining the topology", type=argparse.FileType('r'), default='topo.json') parser.add_argument('--cli', help="enable mininet cli to debug", action='store_true') parser.add_argument('--notest', help="do not run interop tests", action='store_true') parser.add_argument('--verbosity', '-v', choices=list(LEVELS.keys()), default='output', help='|'.join(LEVELS.keys())) return parser.parse_args()
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--topo', choices=TOPOS.keys(), default='simple_ospf_network', help='The topology that you want to start.') parser.add_argument('--log', choices=LEVELS.keys(), default='info', help='The level of details in the logs.') parser.add_argument('--args', help='Additional arguments to give' 'to the topology constructor (key=val, key=val, ...)', default='') return parser.parse_args()
def parseArgs(self): """Parse command-line args and return options object. returns: opts parse options dict""" if "--custom" in sys.argv: index = sys.argv.index("--custom") if len(sys.argv) > index + 1: filename = sys.argv[index + 1] self.parseCustomFile(filename) else: raise Exception("Custom file name not found") desc = ( "The %prog utility creates Mininet network from the\n" "command line. It can create parametrized topologies,\n" "invoke the Mininet CLI, and run tests." ) usage = "%prog [options]\n" "(type %prog -h for details)" opts = OptionParser(description=desc, usage=usage) addDictOption(opts, SWITCHES, SWITCHDEF, "switch") addDictOption(opts, HOSTS, HOSTDEF, "host") addDictOption(opts, CONTROLLERS, CONTROLLERDEF, "controller") addDictOption(opts, LINKS, LINKDEF, "link") addDictOption(opts, TOPOS, TOPODEF, "topo") opts.add_option("--clean", "-c", action="store_true", default=False, help="clean and exit") opts.add_option( "--custom", type="string", default=None, help="read custom topo and node params from .py" + "file" ) opts.add_option("--test", type="choice", choices=TESTS, default=TESTS[0], help="|".join(TESTS)) opts.add_option("--xterms", "-x", action="store_true", default=False, help="spawn xterms for each node") opts.add_option("--ipbase", "-i", type="string", default="10.0.0.0/8", help="base IP address for hosts") opts.add_option("--mac", action="store_true", default=False, help="automatically set host MACs") opts.add_option("--arp", action="store_true", default=False, help="set all-pairs ARP entries") opts.add_option( "--verbosity", "-v", type="choice", choices=LEVELS.keys(), default="info", help="|".join(LEVELS.keys()) ) opts.add_option("--innamespace", action="store_true", default=False, help="sw and ctrl in namespace?") opts.add_option("--listenport", type="int", default=6634, help="base port for passive switch listening") opts.add_option( "--nolistenport", action="store_true", default=False, help="don't use passive listening " + "port" ) opts.add_option("--pre", type="string", default=None, help="CLI script to run before tests") opts.add_option("--post", type="string", default=None, help="CLI script to run after tests") opts.add_option( "--pin", action="store_true", default=False, help="pin hosts to CPU cores " "(requires --host cfs or --host rt)", ) opts.add_option("--version", action="callback", callback=version) self.options, self.args = opts.parse_args()
def parseArgs( self ): """Parse command-line args and return options object. returns: opts parse options dict""" if '--custom' in sys.argv: index = sys.argv.index( '--custom' ) if len( sys.argv ) > index + 1: filename = sys.argv[ index + 1 ] self.parseCustomFile( filename ) else: raise Exception( 'Custom file name not found' ) desc = ( "The %prog utility creates Mininet network from the\n" "command line. It can create parametrized topologies,\n" "invoke the Mininet CLI, and run tests." ) usage = ( '%prog [options]\n' '(type %prog -h for details)' ) opts = OptionParser( description=desc, usage=usage ) addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' ) addDictOption( opts, HOSTS, HOSTDEF, 'host' ) addDictOption( opts, CONTROLLERS, CONTROLLERDEF, 'controller' ) addDictOption( opts, LINKS, LINKDEF, 'link' ) addDictOption( opts, TOPOS, TOPODEF, 'topo' ) opts.add_option( '--clean', '-c', action='store_true', default=False, help='clean and exit' ) opts.add_option( '--custom', type='string', default=None, help='read custom topo and node params from .py' + 'file' ) opts.add_option( '--test', type='choice', choices=TESTS, default=TESTS[ 0 ], help='|'.join( TESTS ) ) opts.add_option( '--xterms', '-x', action='store_true', default=False, help='spawn xterms for each node' ) opts.add_option( '--ipbase', '-i', type='string', default='10.0.0.0/8', help='base IP address for hosts' ) opts.add_option( '--mac', action='store_true', default=False, help='automatically set host MACs' ) opts.add_option( '--arp', action='store_true', default=False, help='set all-pairs ARP entries' ) opts.add_option( '--verbosity', '-v', type='choice', choices=LEVELS.keys(), default = 'info', help = '|'.join( LEVELS.keys() ) ) opts.add_option( '--innamespace', action='store_true', default=False, help='sw and ctrl in namespace?' ) opts.add_option( '--listenport', type='int', default=6634, help='base port for passive switch listening' ) opts.add_option( '--nolistenport', action='store_true', default=False, help="don't use passive listening " + "port") opts.add_option( '--pre', type='string', default=None, help='CLI script to run before tests' ) opts.add_option( '--post', type='string', default=None, help='CLI script to run after tests' ) opts.add_option( '--pin', action='store_true', default=False, help="pin hosts to CPU cores " "(requires --host cfs or --host rt)" ) opts.add_option( '--version', action='callback', callback=version ) self.options, self.args = opts.parse_args()
print MiniNAM, Mininet and Miniattack version. """ # Define versions as parameters (make versions accessible for the rest of the application) ctx.params["mininam_version"] = MiniNAM.MININAM_VERSION ctx.params["mininet_version"] = re.sub(r'[^\d\.]', '', VERSION) ctx.params["miniattack_version"] = MINIATTACK_VERSION # http://click.pocoo.org/5/options/#callbacks-and-eager-options if not value or ctx.resilient_parsing: return click.echo(ctx.info_name + ", version " + ctx.params["miniattack_version"] + "\nMininet, version " + ctx.params["mininet_version"] + "\nMiniNAM, version " + ctx.params["mininam_version"]) ctx.exit() @click.group(context_settings=CONTEXT_SETTINGS) @click.option("--version", default=False, is_flag=True, callback=print_version, expose_value=False, is_eager=True) @click.option("--verbosity", "-v", default="info", type=click.Choice(LEVELS.keys()), help="set Verbosity/Debug Level") def cli(**kwargs): # Set Verbosity Level lg.setLogLevel(kwargs["verbosity"]) pass class TopologyHelper: """ This class will let you create Mininet Topologies with ease. e.g. topo = TopologyHelper.SingleLxbrTopo(n=3) net = topo.start() """ class SingleLxbrTopo(Topo): "Single LinuxBridge connected to n hosts."