├── .gitignore ├── INSTALL ├── INSTALL_mininet ├── LICENSE ├── Makefile ├── README.md ├── README_mininet.md ├── bin ├── miniccnx ├── miniccnxedit └── mn ├── ccn_utils ├── generate_linear.py ├── generate_mesh.py ├── miniccnx.conf ├── miniccnx.conf_16 ├── miniccnx.conf_2hops ├── miniccnx.conf_bkp ├── miniccnx.conf_bkp2 ├── miniccnx.conf_bkp3 └── miniccnx.conf_bw_3 ├── custom ├── README ├── carlos-topo.py └── topo-2sw-2host.py ├── doc └── doxygen.cfg ├── examples ├── README ├── README.md ├── __init__.py ├── baresshd.py ├── bind.py ├── cluster.py ├── clusterSanity.py ├── clustercli.py ├── clusterdemo.py ├── consoles.py ├── controllers.py ├── controllers2.py ├── controlnet.py ├── cpu.py ├── emptynet.py ├── hwintf.py ├── intfoptions.py ├── limit.py ├── linearbandwidth.py ├── linuxrouter.py ├── miniedit.py ├── mobility.py ├── multilink.py ├── multiping.py ├── multipoll.py ├── multitest.py ├── nat.py ├── natnet.py ├── numberedports.py ├── popen.py ├── popenpoll.py ├── scratchnet.py ├── scratchnetuser.py ├── simpleperf.py ├── sshd.py ├── test │ ├── runner.py │ ├── test_baresshd.py │ ├── test_bind.py │ ├── test_clusterSanity.py │ ├── test_controllers.py │ ├── test_controlnet.py │ ├── test_cpu.py │ ├── test_emptynet.py │ ├── test_hwintf.py │ ├── test_intfoptions.py │ ├── test_limit.py │ ├── test_linearbandwidth.py │ ├── test_linuxrouter.py │ ├── test_mobility.py │ ├── test_multilink.py │ ├── test_multiping.py │ ├── test_multipoll.py │ ├── test_multitest.py │ ├── test_nat.py │ ├── test_natnet.py │ ├── test_numberedports.py │ ├── test_popen.py │ ├── test_scratchnet.py │ ├── test_simpleperf.py │ ├── test_sshd.py │ ├── test_tree1024.py │ ├── test_treeping64.py │ └── test_vlanhost.py ├── tree1024.py ├── treeping64.py └── vlanhost.py ├── mininet ├── __init__.py ├── clean.py ├── cli.py ├── examples ├── link.py ├── log.py ├── moduledeps.py ├── net.py ├── node.py ├── nodelib.py ├── term.py ├── test │ ├── runner.py │ ├── test_hifi.py │ ├── test_nets.py │ ├── test_switchdpidassignment.py │ └── test_walkthrough.py ├── topo.py ├── topolib.py └── util.py ├── mnexec.c ├── ospfn ├── NDN Testbed.kml ├── caida-ucsd │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── clean.sh ├── csu │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── delay ├── distance ├── dump.txt ├── miniccnx.conf ├── neu │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── ospfn-start.sh ├── parc │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── pku │ ├── log.pku │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── remap │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── routing.sh ├── spp-atla │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── spp-hous │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── spp-kans │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── spp-salt │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── spp-wash │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── ua │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── uci │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── ucla │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── uiuc │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── um │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf └── washu │ ├── ospfd.conf │ ├── ospfn-start.sh │ ├── ospfn.conf │ ├── routing.sh │ └── zebra.conf ├── setup.py ├── sources ├── __init__.py ├── ccndparser.py ├── conf_parser.py ├── metrics.py └── miniccnx.py └── util ├── build-ovs-packages.sh ├── clustersetup.sh ├── colorfilters ├── doxify.py ├── install.sh ├── kbuild ├── kbuild ├── tun.patch └── version_vars.patch ├── m ├── nox-patches ├── 0001-OpenFlow-tutorial-port-nox-destiny.patch ├── 0002-nox-ubuntu12-hacks.patch └── README ├── old_install.sh ├── openflow-patches ├── README ├── controller.patch └── datapath.patch ├── sch_htb-ofbuf ├── Makefile ├── README └── sch_htb.c ├── sysctl_addon ├── unpep8 ├── versioncheck.py └── vm ├── .bash_profile ├── build.py └── install-mininet-vm.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | mnexec 3 | *.pyc 4 | *~ 5 | *.1 6 | *.xcodeproj 7 | *.xcworkspace 8 | \#*\# 9 | mininet.egg-info 10 | build 11 | dist 12 | doc/html 13 | doc/latex 14 | trunk 15 | data 16 | trash 17 | measures 18 | debian 19 | .fuse* 20 | .project 21 | .pydev* 22 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | In order to install **Mini-CCNx**, follow the steps below. All of them are required! 2 | 3 | ### What equipment will I need ? 4 | 5 | Basically, you'll need a laptop/desktop with a recent Linux distro (Ubuntu, Fedora). We recommend Ubuntu. For this guide, the _Ubuntu 12.04 LTS_ was used. Also, note that you'll need administrative privileges in order to download and install extra packages and also to execute **Mini-CCNx**. 6 | 7 | ### Installing CCNx 8 | 9 | Each node in **Mini-CCNx** will run the official implementation of CCNx. Let's get it. 10 | 11 | In the [Project CCNx](www.ccnx.org) webpage, you'll find all the details for installing the CCNx. See [Installing CCNx](https://www.ccnx.org/wiki/CCNx/InstallingCCNx). To use **Mini-CCNx** you won't need to create the init script as outlined in the prior link. But please, pay attention to the necessary pre-requisite packages, as they are, indeed, necessary. 12 | 13 | Now, to **Mini-CCNx** itself. 14 | 15 | ### Downloading and installing **Mini-CCNx** 16 | 17 | If you don't have it yet, you'll need to have _git_ installed first. In Ubuntu, that would be: 18 | 19 | `sudo apt-get install git` 20 | 21 | Now, let's get the source code of **Mini-CCNx**. 22 | Go to your home directory and use the following command: 23 | 24 | `git clone git://github.com/carlosmscabral/mn-ccnx` 25 | 26 | As result, there will be a directory named _mn-ccnx_ in your home directory, containing all the source code. 27 | 28 | Still in your home directory, use the utility install script with the _-fnv_ options: 29 | 30 | `sudo ./mn-ccnx/util/install.sh -fnv` 31 | 32 | Pre-requisite packages will be downloaded and installed during the process. 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mininet 2.3.0d1 License 2 | 3 | Copyright (c) 2013-2016 Open Networking Laboratory 4 | Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of 5 | The Leland Stanford Junior University 6 | 7 | Original authors: Bob Lantz and Brandon Heller 8 | 9 | We are making Mininet available for public use and benefit with the 10 | expectation that others will use, modify and enhance the Software and 11 | contribute those enhancements back to the community. However, since we 12 | would like to make the Software available for broadest use, with as few 13 | restrictions as possible permission is hereby granted, free of charge, to 14 | any person obtaining a copy of this Software to deal in the Software 15 | under the copyrights without restriction, including without limitation 16 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 | and/or sell copies of the Software, and to permit persons to whom the 18 | Software is furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included 21 | in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 26 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 27 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 28 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 29 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | 31 | The name and trademarks of copyright holder(s) may NOT be used in 32 | advertising or publicity pertaining to the Software or any derivatives 33 | without specific, written prior permission. 34 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | MININET = mininet/*.py 2 | TEST = mininet/test/*.py 3 | EXAMPLES = mininet/examples/*.py 4 | MN = bin/mn 5 | PYMN = python -B bin/mn 6 | BIN = $(MN) 7 | PYSRC = $(MININET) $(TEST) $(EXAMPLES) $(BIN) 8 | MNEXEC = mnexec 9 | MANPAGES = mn.1 mnexec.1 10 | P8IGN = E251,E201,E302,E202,E126,E127,E203,E226 11 | BINDIR = /usr/bin 12 | MANDIR = /usr/share/man/man1 13 | DOCDIRS = doc/html doc/latex 14 | PDF = doc/latex/refman.pdf 15 | 16 | CFLAGS += -Wall -Wextra 17 | 18 | all: codecheck test 19 | 20 | clean: 21 | rm -rf build dist *.egg-info *.pyc $(MNEXEC) $(MANPAGES) $(DOCDIRS) 22 | 23 | codecheck: $(PYSRC) 24 | -echo "Running code check" 25 | util/versioncheck.py 26 | pyflakes $(PYSRC) 27 | pylint --rcfile=.pylint $(PYSRC) 28 | # Exclude miniedit from pep8 checking for now 29 | pep8 --repeat --ignore=$(P8IGN) `ls $(PYSRC) | grep -v miniedit.py` 30 | 31 | errcheck: $(PYSRC) 32 | -echo "Running check for errors only" 33 | pyflakes $(PYSRC) 34 | pylint -E --rcfile=.pylint $(PYSRC) 35 | 36 | test: $(MININET) $(TEST) 37 | -echo "Running tests" 38 | mininet/test/test_nets.py 39 | mininet/test/test_hifi.py 40 | 41 | slowtest: $(MININET) 42 | -echo "Running slower tests (walkthrough, examples)" 43 | mininet/test/test_walkthrough.py -v 44 | mininet/examples/test/runner.py -v 45 | 46 | mnexec: mnexec.c $(MN) mininet/net.py 47 | cc $(CFLAGS) $(LDFLAGS) -DVERSION=\"`PYTHONPATH=. $(PYMN) --version`\" $< -o $@ 48 | 49 | install: $(MNEXEC) $(MANPAGES) 50 | install $(MNEXEC) $(BINDIR) 51 | install $(MANPAGES) $(MANDIR) 52 | python setup.py install 53 | 54 | develop: $(MNEXEC) $(MANPAGES) 55 | # Perhaps we should link these as well 56 | install $(MNEXEC) $(BINDIR) 57 | install $(MANPAGES) $(MANDIR) 58 | python setup.py develop 59 | 60 | man: $(MANPAGES) 61 | 62 | mn.1: $(MN) 63 | PYTHONPATH=. help2man -N -n "create a Mininet network." \ 64 | --no-discard-stderr "$(PYMN)" -o $@ 65 | 66 | mnexec.1: mnexec 67 | help2man -N -n "execution utility for Mininet." \ 68 | -h "-h" -v "-v" --no-discard-stderr ./$< -o $@ 69 | 70 | .PHONY: doc 71 | 72 | doc: man 73 | doxygen doc/doxygen.cfg 74 | make -C doc/latex 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mini-CCNx: Rapid Prototyping for CCN networks 2 | ======================================================== 3 | 4 | ### What is Mini-CCNx? 5 | 6 | Mini-CCNx is a Mininet fork that aims at extending Mininet to support 7 | the emulation of CCNx nodes. 8 | 9 | 10 | ### Installation 11 | 12 | See `INSTALL` for installation instructions and details. 13 | 14 | ### Documentation 15 | 16 | [Mini-CCNx Wiki](https://github.com/carlosmscabral/mn-ccnx/wiki). 17 | 18 | ### Credits 19 | 20 | The Mininet Team: 21 | 22 | * Bob Lantz 23 | * Brandon Heller 24 | * Nikhil Handigol 25 | * Vimal Jeyakumar 26 | 27 | The Mini-CCNx team: 28 | 29 | * Carlos Cabral 30 | * Christian Esteve Rothenberg 31 | 32 | -------------------------------------------------------------------------------- /ccn_utils/generate_linear.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import optparse 4 | 5 | def parse_args(): 6 | usage="""Usage: generate_linear num_nodes [template_file] [delay] 7 | Generates template_file with a linear topology with num_nodes and 8 | delay in the links (10ms, 100ms, etc).If no template_file is given, 9 | will write to default file miniccnx.conf in the current directory. 10 | """ 11 | 12 | parser = optparse.OptionParser(usage) 13 | 14 | _, arg = parser.parse_args() 15 | 16 | if len(arg) > 3: 17 | print parser.usage 18 | quit() 19 | elif len(arg) == 0: 20 | print parser.usage 21 | quit() 22 | elif len(arg) == 1: 23 | num_nodes = int(parser.parse_args()[1][0]) 24 | temp_file = '' 25 | delay = '' 26 | elif len(arg) == 2: 27 | num_nodes, delay = int(parser.parse_args()[1][0]), parser.parse_args()[1][1] 28 | temp_file = '' 29 | else: 30 | print parser.parse_args() 31 | num_nodes,temp_file, delay = int(parser.parse_args()[1][0]), parser.parse_args()[1][1],parser.parse_args()[1][2] 32 | 33 | return num_nodes, temp_file, delay 34 | 35 | if __name__ == '__main__': 36 | 37 | n_nodes, t_file, delay = parse_args() 38 | 39 | if t_file == '': 40 | t_file = 'miniccnx.conf' 41 | 42 | temp_file = open(t_file,'w') 43 | 44 | temp_file.write('[hosts]\n') 45 | 46 | temp_file.write('[routers]\n') 47 | 48 | for i in range(n_nodes): 49 | if i == (n_nodes - 1): 50 | temp_file.write('s' + str(i) + ':\n') 51 | else: 52 | temp_file.write('s' + str(i) + ': ccnx:/,s' + str(i+1) + '\n') 53 | 54 | temp_file.write('[links]\n') 55 | 56 | for i in range(n_nodes-1): 57 | peer = i + 1 58 | if delay == '': 59 | temp_file.write('s' + str(i) + ':s' + str(peer) + '\n') 60 | else: 61 | temp_file.write('s' + str(i) + ':s' + str(peer) + ' delay=' + delay +'\n') 62 | 63 | temp_file.close() 64 | -------------------------------------------------------------------------------- /ccn_utils/generate_mesh.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import optparse 4 | 5 | def parse_args(): 6 | usage="""Usage: generate_mesh num_nodes [template_file] 7 | Generates template_file with a full mesh topology with num_nodes 8 | If no template_file is given, will write to default 9 | file miniccnx.conf in the current directory. 10 | """ 11 | 12 | parser = optparse.OptionParser(usage) 13 | 14 | _, arg = parser.parse_args() 15 | 16 | if len(arg) > 2: 17 | print parser.usage 18 | quit() 19 | elif len(arg) == 0: 20 | print parser.usage 21 | quit() 22 | elif len(arg) == 1: 23 | num_nodes = int(parser.parse_args()[1][0]) 24 | temp_file = '' 25 | else: 26 | print parser.parse_args() 27 | num_nodes,temp_file = int(parser.parse_args()[1][0]), parser.parse_args()[1][1] 28 | 29 | return num_nodes, temp_file 30 | 31 | if __name__ == '__main__': 32 | 33 | n_nodes, t_file = parse_args() 34 | 35 | if t_file == '': 36 | t_file = 'miniccnx.conf' 37 | 38 | temp_file = open(t_file,'w') 39 | 40 | temp_file.write('[hosts]\n') 41 | 42 | temp_file.write('[routers]\n') 43 | 44 | for i in range(n_nodes): 45 | temp_file.write('s' + str(i) + ':\n') 46 | 47 | temp_file.write('[links]\n') 48 | 49 | for i in range(n_nodes): 50 | peer = i + 1 51 | for j in range(peer,n_nodes): 52 | temp_file.write('s' + str(i) + ':s' + str(j) + '\n') 53 | 54 | temp_file.close() 55 | 56 | 57 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf: -------------------------------------------------------------------------------- 1 | [hosts] 2 | h1: _ ccnx:/,s1 3 | h2: _ cpu=0.1 4 | [routers] 5 | s1: ccnx:/videos,h2 6 | [links] 7 | h1:s1 bw=100 8 | h2:s1 bw=100 loss=1 delay=10ms 9 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf_16: -------------------------------------------------------------------------------- 1 | [hosts] 2 | c1: _ ccnx:/,s1 3 | c2: _ ccnx:/,s1 4 | c3: _ ccnx:/,s1 5 | c4: _ ccnx:/,s1 6 | c5: _ ccnx:/,s1 7 | c6: _ ccnx:/,s1 8 | c7: _ ccnx:/,s1 9 | c8: _ ccnx:/,s1 10 | c9: _ ccnx:/,s1 11 | c10: _ ccnx:/,s1 12 | c11: _ ccnx:/,s1 13 | c12: _ ccnx:/,s1 14 | c13: _ ccnx:/,s1 15 | c14: _ ccnx:/,s1 16 | c15: _ ccnx:/,s1 17 | c16: _ ccnx:/,s1 18 | h1: _ 19 | h2: _ 20 | h3: _ 21 | h4: _ 22 | h5: _ 23 | h6: _ 24 | h7: _ 25 | h8: _ 26 | h9: _ 27 | h10: _ 28 | h11: _ 29 | h12: _ 30 | h13: _ 31 | h14: _ 32 | h15: _ 33 | h16: _ 34 | [routers] 35 | s1: ccnx:/s/1,h1 ccnx:/s/2,h2 ccnx:/s/3,h3 ccnx:/s/4,h4 ccnx:/s/5,h5 ccnx:/s/6,h6 ccnx:/s/7,h7 ccnx:/s/8,h8 ccnx:/s/9,h9 ccnx:/s/10,h10 ccnx:/s/11,h11 ccnx:/s/12,h12 ccnx:/s/13,h13 ccnx:/s/14,h14 ccnx:/s/15,h15 ccnx:/s/16,h16 36 | [links] 37 | c1:s1 38 | c2:s1 39 | c3:s1 40 | c4:s1 41 | c5:s1 42 | c6:s1 43 | c7:s1 44 | c8:s1 45 | c9:s1 46 | c10:s1 47 | c11:s1 48 | c12:s1 49 | c13:s1 50 | c14:s1 51 | c15:s1 52 | c16:s1 53 | s1:h1 54 | s1:h2 55 | s1:h3 56 | s1:h4 57 | s1:h5 58 | s1:h6 59 | s1:h7 60 | s1:h8 61 | s1:h9 62 | s1:h10 63 | s1:h11 64 | s1:h12 65 | s1:h13 66 | s1:h14 67 | s1:h15 68 | s1:h16 69 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf_2hops: -------------------------------------------------------------------------------- 1 | [hosts] 2 | h1: _ ccnx:/,s1 3 | h2: _ ccnx:/,s1 4 | h3: _ ccnx:/,s1 5 | h4: _ ccnx:/,s1 6 | h5: _ ccnx:/,s1 7 | h6: _ ccnx:/,s1 8 | h7: _ ccnx:/,s1 9 | h8: _ ccnx:/,s1 10 | r1: _ 11 | r2: _ 12 | r3: _ 13 | r4: _ 14 | r5: _ 15 | r6: _ 16 | r7: _ 17 | r8: _ 18 | [routers] 19 | s1: ccnx:/,s2 20 | s2: ccnx:/,s3 21 | s3: ccnx:/s/1,r1 ccnx:/s/2,r2 ccnx:/s/3,r3 ccnx:/s/4,r4 ccnx:/s/5,r5 ccnx:/s/6,r6 ccnx:/s/7,r7 ccnx:/s/8,r8 22 | [links] 23 | h1:s1 24 | h2:s1 25 | h3:s1 26 | h4:s1 27 | h5:s1 28 | h6:s1 29 | h7:s1 30 | h8:s1 31 | s1:s2 32 | s2:s3 33 | r1:s3 34 | r2:s3 35 | r3:s3 36 | r4:s3 37 | r5:s3 38 | r6:s3 39 | r7:s3 40 | r8:s3 41 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf_bkp: -------------------------------------------------------------------------------- 1 | [hosts] 2 | h7: ./h7.sh ccnx:/,s5 3 | h9: _ ccnx:/,s3 4 | h6: ./h6.sh ccnx:/,s4 5 | h8: _ ccnx:/,s2 6 | [routers] 7 | s2: ccnx:/music,s1 8 | s3: ccnx:/music,s1 9 | s5: ccnx:/music/moveis,h7 10 | s4: ccnx:/music/skank,h6 11 | s1: ccnx:/music/skank,s4 ccnx:/music/moveis,s5 12 | [links] 13 | h6:s4 14 | s4:s1 15 | s1:s5 16 | s5:h7 17 | s1:s3 18 | s3:h9 19 | s1:s2 20 | s2:h8 21 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf_bkp2: -------------------------------------------------------------------------------- 1 | [hosts] 2 | h7: ./h7.sh ccnx:/,s5 3 | h9: _ ccnx:/,s3 4 | h6: ./h6.sh ccnx:/,s4 5 | h8: _ ccnx:/,s2 6 | [routers] 7 | s2: ccnx:/music,s1 8 | s3: ccnx:/music,s1 9 | s5: ccnx:/music/moveis,h7 10 | s4: ccnx:/music/skank,h6 11 | s1: ccnx:/music/skank,s4 ccnx:/music/moveis,s5 12 | [links] 13 | h6:s4 bw=1 14 | s4:s1 bw=1 15 | s1:s5 bw=1000 16 | s5:h7 bw=1000 loss=50 17 | s1:s3 bw=1 18 | s3:h9 bw=1 19 | s1:s2 bw=1 20 | s2:h8 bw=1 21 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf_bkp3: -------------------------------------------------------------------------------- 1 | [hosts] 2 | h7: _ ccnx:/,s2 3 | h4: _ ccnx:/,s3 4 | h6: _ ccnx:/,s1 5 | h8: _ ccnx:/,s2 6 | h5: _ ccnx:/,s1 7 | [routers] 8 | s3: ccnx:/music,s1 ccnx:/video,s2 9 | s1: ccnx:/,s3 ccnx:/music,h5 10 | s2: ccnx:/,s3 ccnx:/video,h7 11 | [links] 12 | h5:s1 bw=1000 13 | h6:s1 bw=1000 14 | s2:h7 bw=1000 15 | s2:h8 bw=1000 16 | s1:s3 bw=1000 17 | s2:s3 bw=1000 18 | h4:s3 bw=1000 19 | -------------------------------------------------------------------------------- /ccn_utils/miniccnx.conf_bw_3: -------------------------------------------------------------------------------- 1 | [hosts] 2 | c1: _ ccnx:/,s1 3 | c2: _ ccnx:/,s1 4 | c3: _ ccnx:/,s1 5 | h1: _ 6 | h2: _ 7 | h3: _ 8 | [routers] 9 | s1: ccnx:/1,h1 ccnx:/2,h2 ccnx:/3,h3 10 | [links] 11 | c1:s1 12 | c2:s1 13 | c3:s1 14 | s1:h1 15 | s1:h2 16 | s1:h3 17 | -------------------------------------------------------------------------------- /custom/README: -------------------------------------------------------------------------------- 1 | This directory should hold configuration files for custom mininets. 2 | 3 | See custom_example.py, which loads the default minimal topology. The advantage of defining a mininet in a separate file is that you then use the --custom option in mn to run the CLI or specific tests with it. 4 | 5 | To start up a mininet with the provided custom topology, do: 6 | sudo mn --custom custom_example.py --topo mytopo 7 | -------------------------------------------------------------------------------- /custom/carlos-topo.py: -------------------------------------------------------------------------------- 1 | """Custom topology example 2 | 3 | Two directly connected switches plus a host for each switch: 4 | 5 | host --- switch --- switch --- host 6 | 7 | Adding the 'topos' dict with a key/value pair to generate our newly defined 8 | topology enables one to pass in '--topo=mytopo' from the command line. 9 | """ 10 | 11 | from mininet.topo import Topo 12 | 13 | class MyTopo( Topo ): 14 | "Simple topology example." 15 | 16 | def __init__( self ): 17 | "Create custom topo." 18 | 19 | # Initialize topology 20 | Topo.__init__( self ) 21 | 22 | # Add hosts and switches 23 | client = self.addHost( 'h1' ) 24 | client.setIP('1.0.0.1') 25 | router = self.addHost( 'h2' ) 26 | client.setIP('1.0.1.1',intf='h1-eth0') 27 | client.setIP('2.0.1.2',intf='h1-eth1') 28 | server = self.addHost( 'h3' ) 29 | client.setIP('2.0.0.1') 30 | 31 | #leftSwitch = self.addSwitch( 's3' ) 32 | #rightSwitch = self.addSwitch( 's4' ) 33 | 34 | # Add links 35 | #self.addLink( leftHost, leftSwitch ) 36 | #self.addLink( leftHost, rightSwitch) 37 | #self.addLink( leftSwitch, rightSwitch ) 38 | #self.addLink( rightSwitch, rightHost ) 39 | self.addLink( client, router ) 40 | self.addLink( server, router ) 41 | 42 | 43 | topos = { 'mytopo': ( lambda: MyTopo() ) } 44 | -------------------------------------------------------------------------------- /custom/topo-2sw-2host.py: -------------------------------------------------------------------------------- 1 | """Custom topology example 2 | 3 | Two directly connected switches plus a host for each switch: 4 | 5 | host --- switch --- switch --- host 6 | 7 | Adding the 'topos' dict with a key/value pair to generate our newly defined 8 | topology enables one to pass in '--topo=mytopo' from the command line. 9 | """ 10 | 11 | from mininet.topo import Topo 12 | 13 | class MyTopo( Topo ): 14 | "Simple topology example." 15 | 16 | def __init__( self ): 17 | "Create custom topo." 18 | 19 | # Initialize topology 20 | Topo.__init__( self ) 21 | 22 | # Add hosts and switches 23 | leftHost = self.addHost( 'h1' ) 24 | rightHost = self.addHost( 'h2' ) 25 | leftSwitch = self.addSwitch( 's3' ) 26 | rightSwitch = self.addSwitch( 's4' ) 27 | 28 | # Add links 29 | self.addLink( leftHost, leftSwitch ) 30 | self.addLink( leftSwitch, rightSwitch ) 31 | self.addLink( rightSwitch, rightHost ) 32 | 33 | 34 | topos = { 'mytopo': ( lambda: MyTopo() ) } 35 | -------------------------------------------------------------------------------- /examples/README: -------------------------------------------------------------------------------- 1 | 2 | Mininet Examples 3 | 4 | These examples are intended to help you get started using 5 | Mininet's Python API. 6 | 7 | --- 8 | 9 | baresshd.py: 10 | 11 | This example uses Mininet's medium-level API to create an sshd 12 | process running in a namespace. Doesn't use OpenFlow. 13 | 14 | consoles.py: 15 | 16 | This example creates a grid of console windows, one for each node, 17 | and allows interaction with and monitoring of each console, including 18 | graphical monitoring. 19 | 20 | controllers.py: 21 | 22 | This example creates a network and adds multiple controllers to it. 23 | 24 | cpu.py: 25 | 26 | This example tests iperf bandwidth for varying CPU limits. 27 | 28 | emptynet.py: 29 | 30 | This example demonstrates creating an empty network (i.e. with no 31 | topology object) and adding nodes to it. 32 | 33 | hwintf.py: 34 | 35 | This example shows how to add an interface (for example a real 36 | hardware interface) to a network after the network is created. 37 | 38 | limit.py: 39 | 40 | This example shows how to use link and CPU limits. 41 | 42 | linearbandwidth.py: 43 | 44 | This example shows how to create a custom topology programatically 45 | by subclassing Topo, and how to run a series of tests on it. 46 | 47 | miniedit.py: 48 | 49 | This example demonstrates creating a network via a graphical editor. 50 | 51 | multiping.py: 52 | 53 | This example demonstrates one method for 54 | monitoring output from multiple hosts, using node.monitor(). 55 | 56 | multipoll.py: 57 | 58 | This example demonstrates monitoring output files from multiple hosts. 59 | 60 | multitest.py: 61 | 62 | This example creates a network and runs multiple tests on it. 63 | 64 | popen.py: 65 | 66 | This example monitors a number of hosts using host.popen() and 67 | pmonitor(). 68 | 69 | popenpoll.py: 70 | 71 | This example demonstrates monitoring output from multiple hosts using 72 | the node.popen() interface (which returns Popen objects) and pmonitor(). 73 | 74 | scratchnet.py, scratchnetuser.py: 75 | 76 | These two examples demonstrate how to create a network by using the lowest- 77 | level Mininet functions. Generally the higher-level API is easier to use, 78 | but scratchnet shows what is going on behind the scenes. 79 | 80 | simpleperf.py: 81 | 82 | A simple example of configuring network and CPU bandwidth limits. 83 | 84 | sshd.py: 85 | 86 | This example shows how to run an sshd process in each host, allowing 87 | you to log in via ssh. This requires connecting the Mininet data network 88 | to an interface in the root namespace (generaly the control network 89 | already lives in the root namespace, so it does not need to be explicitly 90 | connected.) 91 | 92 | treeping64.py: 93 | 94 | This example creates a 64-host tree network, and attempts to check full 95 | connectivity using ping, for different switch/datapath types. 96 | 97 | tree1024.py: 98 | 99 | This example attempts to create a 1024-host network, and then runs the 100 | CLI on it. It may run into scalability limits, depending on available 101 | memory and sysctl configuration (see INSTALL.) 102 | 103 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mininet Examples 3 | See README for details 4 | """ 5 | -------------------------------------------------------------------------------- /examples/baresshd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | "This example doesn't use OpenFlow, but attempts to run sshd in a namespace." 4 | 5 | from __future__ import print_function 6 | import sys 7 | 8 | from mininet.node import Host 9 | from mininet.util import ensureRoot, waitListening 10 | 11 | 12 | ensureRoot() 13 | timeout = 5 14 | 15 | print( "*** Creating nodes" ) 16 | h1 = Host( 'h1' ) 17 | 18 | root = Host( 'root', inNamespace=False ) 19 | 20 | print( "*** Creating links" ) 21 | h1.linkTo( root ) 22 | 23 | print( h1 ) 24 | 25 | print( "*** Configuring nodes" ) 26 | h1.setIP( '10.0.0.1', 8 ) 27 | root.setIP( '10.0.0.2', 8 ) 28 | 29 | print( "*** Creating banner file" ) 30 | f = open( '/tmp/%s.banner' % h1.name, 'w' ) 31 | f.write( 'Welcome to %s at %s\n' % ( h1.name, h1.IP() ) ) 32 | f.close() 33 | 34 | print( "*** Running sshd" ) 35 | cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name 36 | # add arguments from the command line 37 | if len( sys.argv ) > 1: 38 | cmd += ' ' + ' '.join( sys.argv[ 1: ] ) 39 | h1.cmd( cmd ) 40 | listening = waitListening( server=h1, port=22, timeout=timeout ) 41 | 42 | if listening: 43 | print( "*** You may now ssh into", h1.name, "at", h1.IP() ) 44 | else: 45 | print( "*** Warning: after %s seconds, %s is not listening on port 22" 46 | % ( timeout, h1.name ) ) 47 | -------------------------------------------------------------------------------- /examples/bind.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | bind.py: Bind mount example 5 | 6 | This creates hosts with private directories that the user specifies. 7 | These hosts may have persistent directories that will be available 8 | across multiple mininet session, or temporary directories that will 9 | only last for one mininet session. To specify a persistent 10 | directory, add a tuple to a list of private directories: 11 | 12 | [ ( 'directory to be mounted on', 'directory to be mounted' ) ] 13 | 14 | String expansion may be used to create a directory template for 15 | each host. To do this, add a %(name)s in place of the host name 16 | when creating your list of directories: 17 | 18 | [ ( '/var/run', '/tmp/%(name)s/var/run' ) ] 19 | 20 | If no persistent directory is specified, the directories will default 21 | to temporary private directories. To do this, simply create a list of 22 | directories to be made private. A tmpfs will then be mounted on them. 23 | 24 | You may use both temporary and persistent directories at the same 25 | time. In the following privateDirs string, each host will have a 26 | persistent directory in the root filesystem at 27 | "/tmp/(hostname)/var/run" mounted on "/var/run". Each host will also 28 | have a temporary private directory mounted on "/var/log". 29 | 30 | [ ( '/var/run', '/tmp/%(name)s/var/run' ), '/var/log' ] 31 | 32 | This example has both persistent directories mounted on '/var/log' 33 | and '/var/run'. It also has a temporary private directory mounted 34 | on '/var/mn' 35 | """ 36 | 37 | from mininet.net import Mininet 38 | from mininet.node import Host 39 | from mininet.cli import CLI 40 | from mininet.topo import SingleSwitchTopo 41 | from mininet.log import setLogLevel, info 42 | 43 | from functools import partial 44 | 45 | 46 | # Sample usage 47 | 48 | def testHostWithPrivateDirs(): 49 | "Test bind mounts" 50 | topo = SingleSwitchTopo( 10 ) 51 | privateDirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ), 52 | ( '/var/run', '/tmp/%(name)s/var/run' ), 53 | '/var/mn' ] 54 | host = partial( Host, 55 | privateDirs=privateDirs ) 56 | net = Mininet( topo=topo, host=host ) 57 | net.start() 58 | directories = [ directory[ 0 ] if isinstance( directory, tuple ) 59 | else directory for directory in privateDirs ] 60 | info( 'Private Directories:', directories, '\n' ) 61 | CLI( net ) 62 | net.stop() 63 | 64 | if __name__ == '__main__': 65 | setLogLevel( 'info' ) 66 | testHostWithPrivateDirs() 67 | info( 'Done.\n') 68 | -------------------------------------------------------------------------------- /examples/clusterSanity.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | A sanity check for cluster edition 5 | ''' 6 | 7 | from mininet.examples.cluster import MininetCluster 8 | from mininet.log import setLogLevel 9 | from mininet.examples.clustercli import ClusterCLI as CLI 10 | from mininet.topo import SingleSwitchTopo 11 | 12 | def clusterSanity(): 13 | "Sanity check for cluster mode" 14 | topo = SingleSwitchTopo() 15 | net = MininetCluster( topo=topo ) 16 | net.start() 17 | CLI( net ) 18 | net.stop() 19 | 20 | if __name__ == '__main__': 21 | setLogLevel( 'info' ) 22 | clusterSanity() 23 | -------------------------------------------------------------------------------- /examples/clustercli.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | "CLI for Mininet Cluster Edition prototype demo" 4 | 5 | from mininet.cli import CLI 6 | from mininet.log import output, error 7 | 8 | # pylint: disable=global-statement 9 | nx, graphviz_layout, plt = None, None, None # Will be imported on demand 10 | 11 | 12 | class ClusterCLI( CLI ): 13 | "CLI with additional commands for Cluster Edition demo" 14 | 15 | @staticmethod 16 | def colorsFor( seq ): 17 | "Return a list of background colors for a sequence" 18 | colors = [ 'red', 'lightgreen', 'cyan', 'yellow', 'orange', 19 | 'magenta', 'pink', 'grey', 'brown', 20 | 'white' ] 21 | slen, clen = len( seq ), len( colors ) 22 | reps = max( 1, slen / clen ) 23 | colors = colors * reps 24 | colors = colors[ 0 : slen ] 25 | return colors 26 | 27 | def do_plot( self, _line ): 28 | "Plot topology colored by node placement" 29 | # Import networkx if needed 30 | global nx, plt 31 | if not nx: 32 | try: 33 | # pylint: disable=import-error 34 | import networkx 35 | nx = networkx # satisfy pylint 36 | from matplotlib import pyplot 37 | plt = pyplot # satisfiy pylint 38 | import pygraphviz 39 | assert pygraphviz # silence pyflakes 40 | # pylint: enable=import-error 41 | except ImportError: 42 | error( 'plot requires networkx, matplotlib and pygraphviz - ' 43 | 'please install them and try again\n' ) 44 | return 45 | # Make a networkx Graph 46 | g = nx.Graph() 47 | mn = self.mn 48 | servers, hosts, switches = mn.servers, mn.hosts, mn.switches 49 | nodes = hosts + switches 50 | g.add_nodes_from( nodes ) 51 | links = [ ( link.intf1.node, link.intf2.node ) 52 | for link in self.mn.links ] 53 | g.add_edges_from( links ) 54 | # Pick some shapes and colors 55 | # shapes = hlen * [ 's' ] + slen * [ 'o' ] 56 | color = dict( zip( servers, self.colorsFor( servers ) ) ) 57 | # Plot it! 58 | pos = nx.graphviz_layout( g ) 59 | opts = { 'ax': None, 'font_weight': 'bold', 60 | 'width': 2, 'edge_color': 'darkblue' } 61 | hcolors = [ color[ getattr( h, 'server', 'localhost' ) ] 62 | for h in hosts ] 63 | scolors = [ color[ getattr( s, 'server', 'localhost' ) ] 64 | for s in switches ] 65 | nx.draw_networkx( g, pos=pos, nodelist=hosts, node_size=800, 66 | label='host', node_color=hcolors, node_shape='s', 67 | **opts ) 68 | nx.draw_networkx( g, pos=pos, nodelist=switches, node_size=1000, 69 | node_color=scolors, node_shape='o', **opts ) 70 | # Get rid of axes, add title, and show 71 | fig = plt.gcf() 72 | ax = plt.gca() 73 | ax.get_xaxis().set_visible( False ) 74 | ax.get_yaxis().set_visible( False ) 75 | fig.canvas.set_window_title( 'Mininet') 76 | plt.title( 'Node Placement', fontweight='bold' ) 77 | plt.show() 78 | 79 | def do_status( self, _line ): 80 | "Report on node shell status" 81 | nodes = self.mn.hosts + self.mn.switches 82 | for node in nodes: 83 | node.shell.poll() 84 | exited = [ node for node in nodes 85 | if node.shell.returncode is not None ] 86 | if exited: 87 | for node in exited: 88 | output( '%s has exited with code %d\n' 89 | % ( node, node.shell.returncode ) ) 90 | else: 91 | output( 'All nodes are still running.\n' ) 92 | 93 | def do_placement( self, _line ): 94 | "Describe node placement" 95 | mn = self.mn 96 | nodes = mn.hosts + mn.switches + mn.controllers 97 | for server in mn.servers: 98 | names = [ n.name for n in nodes if hasattr( n, 'server' ) 99 | and n.server == server ] 100 | output( '%s: %s\n' % ( server, ' '.join( names ) ) ) 101 | -------------------------------------------------------------------------------- /examples/clusterdemo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | "clusterdemo.py: demo of Mininet Cluster Edition prototype" 4 | 5 | from mininet.examples.cluster import MininetCluster, SwitchBinPlacer 6 | from mininet.topolib import TreeTopo 7 | from mininet.log import setLogLevel 8 | from mininet.examples.clustercli import ClusterCLI as CLI 9 | 10 | def demo(): 11 | "Simple Demo of Cluster Mode" 12 | servers = [ 'localhost', 'ubuntu2', 'ubuntu3' ] 13 | topo = TreeTopo( depth=3, fanout=3 ) 14 | net = MininetCluster( topo=topo, servers=servers, 15 | placement=SwitchBinPlacer ) 16 | net.start() 17 | CLI( net ) 18 | net.stop() 19 | 20 | if __name__ == '__main__': 21 | setLogLevel( 'info' ) 22 | demo() 23 | -------------------------------------------------------------------------------- /examples/controllers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Create a network where different switches are connected to 5 | different controllers, by creating a custom Switch() subclass. 6 | """ 7 | 8 | from mininet.net import Mininet 9 | from mininet.node import OVSSwitch, Controller, RemoteController 10 | from mininet.topolib import TreeTopo 11 | from mininet.log import setLogLevel 12 | from mininet.cli import CLI 13 | 14 | setLogLevel( 'info' ) 15 | 16 | # Two local and one "external" controller (which is actually c0) 17 | # Ignore the warning message that the remote isn't (yet) running 18 | c0 = Controller( 'c0', port=6633 ) 19 | c1 = Controller( 'c1', port=6634 ) 20 | c2 = RemoteController( 'c2', ip='127.0.0.1', port=6633 ) 21 | 22 | cmap = { 's1': c0, 's2': c1, 's3': c2 } 23 | 24 | class MultiSwitch( OVSSwitch ): 25 | "Custom Switch() subclass that connects to different controllers" 26 | def start( self, controllers ): 27 | return OVSSwitch.start( self, [ cmap[ self.name ] ] ) 28 | 29 | topo = TreeTopo( depth=2, fanout=2 ) 30 | net = Mininet( topo=topo, switch=MultiSwitch, build=False ) 31 | for c in [ c0, c1 ]: 32 | net.addController(c) 33 | net.build() 34 | net.start() 35 | CLI( net ) 36 | net.stop() 37 | -------------------------------------------------------------------------------- /examples/controllers2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | This example creates a multi-controller network from semi-scratch by 5 | using the net.add*() API and manually starting the switches and controllers. 6 | 7 | This is the "mid-level" API, which is an alternative to the "high-level" 8 | Topo() API which supports parametrized topology classes. 9 | 10 | Note that one could also create a custom switch class and pass it into 11 | the Mininet() constructor. 12 | """ 13 | 14 | from __future__ import print_function 15 | 16 | from mininet.net import Mininet 17 | from mininet.node import Controller, OVSSwitch 18 | from mininet.cli import CLI 19 | from mininet.log import setLogLevel 20 | 21 | def multiControllerNet(): 22 | "Create a network from semi-scratch with multiple controllers." 23 | 24 | net = Mininet( controller=Controller, switch=OVSSwitch ) 25 | 26 | print( "*** Creating (reference) controllers" ) 27 | c1 = net.addController( 'c1', port=6633 ) 28 | c2 = net.addController( 'c2', port=6634 ) 29 | 30 | print( "*** Creating switches" ) 31 | s1 = net.addSwitch( 's1' ) 32 | s2 = net.addSwitch( 's2' ) 33 | 34 | print( "*** Creating hosts" ) 35 | hosts1 = [ net.addHost( 'h%d' % n ) for n in ( 3, 4 ) ] 36 | hosts2 = [ net.addHost( 'h%d' % n ) for n in ( 5, 6 ) ] 37 | 38 | print( "*** Creating links" ) 39 | for h in hosts1: 40 | net.addLink( s1, h ) 41 | for h in hosts2: 42 | net.addLink( s2, h ) 43 | net.addLink( s1, s2 ) 44 | 45 | print( "*** Starting network" ) 46 | net.build() 47 | c1.start() 48 | c2.start() 49 | s1.start( [ c1 ] ) 50 | s2.start( [ c2 ] ) 51 | 52 | print( "*** Testing network" ) 53 | net.pingAll() 54 | 55 | print( "*** Running CLI" ) 56 | CLI( net ) 57 | 58 | print( "*** Stopping network" ) 59 | net.stop() 60 | 61 | if __name__ == '__main__': 62 | setLogLevel( 'info' ) # for CLI output 63 | multiControllerNet() 64 | -------------------------------------------------------------------------------- /examples/cpu.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | cpu.py: test iperf bandwidth for varying cpu limits 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | from mininet.net import Mininet 10 | from mininet.node import CPULimitedHost 11 | from mininet.topolib import TreeTopo 12 | from mininet.util import custom, waitListening 13 | from mininet.log import setLogLevel, info 14 | 15 | 16 | def bwtest( cpuLimits, period_us=100000, seconds=5 ): 17 | """Example/test of link and CPU bandwidth limits 18 | cpu: cpu limit as fraction of overall CPU time""" 19 | 20 | topo = TreeTopo( depth=1, fanout=2 ) 21 | 22 | results = {} 23 | 24 | for sched in 'rt', 'cfs': 25 | print( '*** Testing with', sched, 'bandwidth limiting' ) 26 | for cpu in cpuLimits: 27 | host = custom( CPULimitedHost, sched=sched, 28 | period_us=period_us, 29 | cpu=cpu ) 30 | try: 31 | net = Mininet( topo=topo, host=host ) 32 | # pylint: disable=bare-except 33 | except: 34 | info( '*** Skipping host %s\n' % sched ) 35 | break 36 | net.start() 37 | net.pingAll() 38 | hosts = [ net.getNodeByName( h ) for h in topo.hosts() ] 39 | client, server = hosts[ 0 ], hosts[ -1 ] 40 | server.cmd( 'iperf -s -p 5001 &' ) 41 | waitListening( client, server, 5001 ) 42 | result = client.cmd( 'iperf -yc -t %s -c %s' % ( 43 | seconds, server.IP() ) ).split( ',' ) 44 | bps = float( result[ -1 ] ) 45 | server.cmdPrint( 'kill %iperf' ) 46 | net.stop() 47 | updated = results.get( sched, [] ) 48 | updated += [ ( cpu, bps ) ] 49 | results[ sched ] = updated 50 | 51 | return results 52 | 53 | 54 | def dump( results ): 55 | "Dump results" 56 | 57 | fmt = '%s\t%s\t%s' 58 | 59 | print() 60 | print( fmt % ( 'sched', 'cpu', 'client MB/s' ) ) 61 | print() 62 | 63 | for sched in sorted( results.keys() ): 64 | entries = results[ sched ] 65 | for cpu, bps in entries: 66 | pct = '%.2f%%' % ( cpu * 100 ) 67 | mbps = bps / 1e6 68 | print( fmt % ( sched, pct, mbps ) ) 69 | 70 | 71 | if __name__ == '__main__': 72 | setLogLevel( 'info' ) 73 | limits = [ .45, .4, .3, .2, .1 ] 74 | out = bwtest( limits ) 75 | dump( out ) 76 | -------------------------------------------------------------------------------- /examples/emptynet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | This example shows how to create an empty Mininet object 5 | (without a topology object) and add nodes to it manually. 6 | """ 7 | 8 | from mininet.net import Mininet 9 | from mininet.node import Controller 10 | from mininet.cli import CLI 11 | from mininet.log import setLogLevel, info 12 | 13 | def emptyNet(): 14 | 15 | "Create an empty network and add nodes to it." 16 | 17 | net = Mininet( controller=Controller ) 18 | 19 | info( '*** Adding controller\n' ) 20 | net.addController( 'c0' ) 21 | 22 | info( '*** Adding hosts\n' ) 23 | h1 = net.addHost( 'h1', ip='10.0.0.1' ) 24 | h2 = net.addHost( 'h2', ip='10.0.0.2' ) 25 | 26 | info( '*** Adding switch\n' ) 27 | s3 = net.addSwitch( 's3' ) 28 | 29 | info( '*** Creating links\n' ) 30 | net.addLink( h1, s3 ) 31 | net.addLink( h2, s3 ) 32 | 33 | info( '*** Starting network\n') 34 | net.start() 35 | 36 | info( '*** Running CLI\n' ) 37 | CLI( net ) 38 | 39 | info( '*** Stopping network' ) 40 | net.stop() 41 | 42 | if __name__ == '__main__': 43 | setLogLevel( 'info' ) 44 | emptyNet() 45 | -------------------------------------------------------------------------------- /examples/hwintf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | This example shows how to add an interface (for example a real 5 | hardware interface) to a network after the network is created. 6 | """ 7 | 8 | import re 9 | import sys 10 | 11 | from mininet.cli import CLI 12 | from mininet.log import setLogLevel, info, error 13 | from mininet.net import Mininet 14 | from mininet.link import Intf 15 | from mininet.topolib import TreeTopo 16 | from mininet.util import quietRun 17 | 18 | def checkIntf( intf ): 19 | "Make sure intf exists and is not configured." 20 | config = quietRun( 'ifconfig %s 2>/dev/null' % intf, shell=True ) 21 | if not config: 22 | error( 'Error:', intf, 'does not exist!\n' ) 23 | exit( 1 ) 24 | ips = re.findall( r'\d+\.\d+\.\d+\.\d+', config ) 25 | if ips: 26 | error( 'Error:', intf, 'has an IP address,' 27 | 'and is probably in use!\n' ) 28 | exit( 1 ) 29 | 30 | if __name__ == '__main__': 31 | setLogLevel( 'info' ) 32 | 33 | # try to get hw intf from the command line; by default, use eth1 34 | intfName = sys.argv[ 1 ] if len( sys.argv ) > 1 else 'eth1' 35 | info( '*** Connecting to hw intf: %s' % intfName ) 36 | 37 | info( '*** Checking', intfName, '\n' ) 38 | checkIntf( intfName ) 39 | 40 | info( '*** Creating network\n' ) 41 | net = Mininet( topo=TreeTopo( depth=1, fanout=2 ) ) 42 | 43 | switch = net.switches[ 0 ] 44 | info( '*** Adding hardware interface', intfName, 'to switch', 45 | switch.name, '\n' ) 46 | _intf = Intf( intfName, node=switch ) 47 | 48 | info( '*** Note: you may need to reconfigure the interfaces for ' 49 | 'the Mininet hosts:\n', net.hosts, '\n' ) 50 | 51 | net.start() 52 | CLI( net ) 53 | net.stop() 54 | -------------------------------------------------------------------------------- /examples/intfoptions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | ''' 4 | example of using various TCIntf options. 5 | reconfigures a single interface using intf.config() 6 | to use different traffic control commands to test 7 | bandwidth, loss, and delay 8 | ''' 9 | 10 | from mininet.net import Mininet 11 | from mininet.log import setLogLevel, info 12 | from mininet.link import TCLink 13 | 14 | def intfOptions(): 15 | "run various traffic control commands on a single interface" 16 | net = Mininet( autoStaticArp=True ) 17 | net.addController( 'c0' ) 18 | h1 = net.addHost( 'h1' ) 19 | h2 = net.addHost( 'h2' ) 20 | s1 = net.addSwitch( 's1' ) 21 | link1 = net.addLink( h1, s1, cls=TCLink ) 22 | net.addLink( h2, s1 ) 23 | net.start() 24 | 25 | # flush out latency from reactive forwarding delay 26 | net.pingAll() 27 | 28 | info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' ) 29 | link1.intf1.config( bw=5 ) 30 | info( '\n*** Running iperf to test\n' ) 31 | net.iperf() 32 | 33 | info( '\n*** Configuring one intf with loss of 50%\n' ) 34 | link1.intf1.config( loss=50 ) 35 | info( '\n' ) 36 | net.iperf( ( h1, h2 ), l4Type='UDP' ) 37 | 38 | info( '\n*** Configuring one intf with delay of 15ms\n' ) 39 | link1.intf1.config( delay='15ms' ) 40 | info( '\n*** Run a ping to confirm delay\n' ) 41 | net.pingPairFull() 42 | 43 | info( '\n*** Done testing\n' ) 44 | net.stop() 45 | 46 | if __name__ == '__main__': 47 | setLogLevel( 'info' ) 48 | intfOptions() 49 | -------------------------------------------------------------------------------- /examples/limit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | limit.py: example of using link and CPU limits 5 | """ 6 | 7 | from mininet.net import Mininet 8 | from mininet.link import TCIntf 9 | from mininet.node import CPULimitedHost 10 | from mininet.topolib import TreeTopo 11 | from mininet.util import custom, quietRun 12 | from mininet.log import setLogLevel, info 13 | 14 | 15 | def testLinkLimit( net, bw ): 16 | "Run bandwidth limit test" 17 | info( '*** Testing network %.2f Mbps bandwidth limit\n' % bw ) 18 | net.iperf() 19 | 20 | def limit( bw=10, cpu=.1 ): 21 | """Example/test of link and CPU bandwidth limits 22 | bw: interface bandwidth limit in Mbps 23 | cpu: cpu limit as fraction of overall CPU time""" 24 | intf = custom( TCIntf, bw=bw ) 25 | myTopo = TreeTopo( depth=1, fanout=2 ) 26 | for sched in 'rt', 'cfs': 27 | info( '*** Testing with', sched, 'bandwidth limiting\n' ) 28 | if sched == 'rt': 29 | release = quietRun( 'uname -r' ).strip('\r\n') 30 | output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s' 31 | % release ) 32 | if output == '# CONFIG_RT_GROUP_SCHED is not set\n': 33 | info( '*** RT Scheduler is not enabled in your kernel. ' 34 | 'Skipping this test\n' ) 35 | continue 36 | host = custom( CPULimitedHost, sched=sched, cpu=cpu ) 37 | net = Mininet( topo=myTopo, intf=intf, host=host ) 38 | net.start() 39 | testLinkLimit( net, bw=bw ) 40 | net.runCpuLimitTest( cpu=cpu ) 41 | net.stop() 42 | 43 | def verySimpleLimit( bw=150 ): 44 | "Absurdly simple limiting test" 45 | intf = custom( TCIntf, bw=bw ) 46 | net = Mininet( intf=intf ) 47 | h1, h2 = net.addHost( 'h1' ), net.addHost( 'h2' ) 48 | net.addLink( h1, h2 ) 49 | net.start() 50 | net.pingAll() 51 | net.iperf() 52 | h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() ) 53 | h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() ) 54 | h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() ) 55 | h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() ) 56 | net.stop() 57 | 58 | if __name__ == '__main__': 59 | setLogLevel( 'info' ) 60 | limit() 61 | -------------------------------------------------------------------------------- /examples/linearbandwidth.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Test bandwidth (using iperf) on linear networks of varying size, 5 | using both kernel and user datapaths. 6 | 7 | We construct a network of N hosts and N-1 switches, connected as follows: 8 | 9 | h1 <-> s1 <-> s2 .. sN-1 10 | | | | 11 | h2 h3 hN 12 | 13 | WARNING: by default, the reference controller only supports 16 14 | switches, so this test WILL NOT WORK unless you have recompiled 15 | your controller to support 100 switches (or more.) 16 | 17 | In addition to testing the bandwidth across varying numbers 18 | of switches, this example demonstrates: 19 | 20 | - creating a custom topology, LinearTestTopo 21 | - using the ping() and iperf() tests from Mininet() 22 | - testing both the kernel and user switches 23 | 24 | """ 25 | 26 | from __future__ import print_function 27 | 28 | from mininet.net import Mininet 29 | from mininet.node import UserSwitch, OVSKernelSwitch, Controller 30 | from mininet.topo import Topo 31 | from mininet.log import lg 32 | from mininet.util import irange, quietRun 33 | from mininet.link import TCLink 34 | from functools import partial 35 | 36 | import sys 37 | flush = sys.stdout.flush 38 | 39 | class LinearTestTopo( Topo ): 40 | "Topology for a string of N hosts and N-1 switches." 41 | 42 | def __init__( self, N, **params ): 43 | 44 | # Initialize topology 45 | Topo.__init__( self, **params ) 46 | 47 | # Create switches and hosts 48 | hosts = [ self.addHost( 'h%s' % h ) 49 | for h in irange( 1, N ) ] 50 | switches = [ self.addSwitch( 's%s' % s ) 51 | for s in irange( 1, N - 1 ) ] 52 | 53 | # Wire up switches 54 | last = None 55 | for switch in switches: 56 | if last: 57 | self.addLink( last, switch ) 58 | last = switch 59 | 60 | # Wire up hosts 61 | self.addLink( hosts[ 0 ], switches[ 0 ] ) 62 | for host, switch in zip( hosts[ 1: ], switches ): 63 | self.addLink( host, switch ) 64 | 65 | 66 | def linearBandwidthTest( lengths ): 67 | 68 | "Check bandwidth at various lengths along a switch chain." 69 | 70 | results = {} 71 | switchCount = max( lengths ) 72 | hostCount = switchCount + 1 73 | 74 | switches = { 'reference user': UserSwitch, 75 | 'Open vSwitch kernel': OVSKernelSwitch } 76 | 77 | # UserSwitch is horribly slow with recent kernels. 78 | # We can reinstate it once its performance is fixed 79 | del switches[ 'reference user' ] 80 | 81 | topo = LinearTestTopo( hostCount ) 82 | 83 | # Select TCP Reno 84 | output = quietRun( 'sysctl -w net.ipv4.tcp_congestion_control=reno' ) 85 | assert 'reno' in output 86 | 87 | for datapath in switches.keys(): 88 | print( "*** testing", datapath, "datapath" ) 89 | Switch = switches[ datapath ] 90 | results[ datapath ] = [] 91 | link = partial( TCLink, delay='1ms' ) 92 | net = Mininet( topo=topo, switch=Switch, 93 | controller=Controller, waitConnected=True, 94 | link=link ) 95 | net.start() 96 | print( "*** testing basic connectivity" ) 97 | for n in lengths: 98 | net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] ) 99 | print( "*** testing bandwidth" ) 100 | for n in lengths: 101 | src, dst = net.hosts[ 0 ], net.hosts[ n ] 102 | # Try to prime the pump to reduce PACKET_INs during test 103 | # since the reference controller is reactive 104 | src.cmd( 'telnet', dst.IP(), '5001' ) 105 | print( "testing", src.name, "<->", dst.name ) 106 | bandwidth = net.iperf( [ src, dst ], seconds=10 ) 107 | print( bandwidth ) 108 | flush() 109 | results[ datapath ] += [ ( n, bandwidth ) ] 110 | net.stop() 111 | 112 | for datapath in switches.keys(): 113 | print() 114 | print( "*** Linear network results for", datapath, "datapath:" ) 115 | print() 116 | result = results[ datapath ] 117 | print( "SwitchCount\tiperf Results" ) 118 | for switchCount, bandwidth in result: 119 | print( switchCount, '\t\t' ) 120 | print( bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client' ) 121 | print() 122 | print() 123 | 124 | if __name__ == '__main__': 125 | lg.setLogLevel( 'info' ) 126 | sizes = [ 1, 10, 20, 40, 60, 80 ] 127 | print( "*** Running linearBandwidthTest", sizes ) 128 | linearBandwidthTest( sizes ) 129 | -------------------------------------------------------------------------------- /examples/linuxrouter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | linuxrouter.py: Example network with Linux IP router 5 | 6 | This example converts a Node into a router using IP forwarding 7 | already built into Linux. 8 | 9 | The example topology creates a router and three IP subnets: 10 | 11 | - 192.168.1.0/24 (r0-eth1, IP: 192.168.1.1) 12 | - 172.16.0.0/12 (r0-eth2, IP: 172.16.0.1) 13 | - 10.0.0.0/8 (r0-eth3, IP: 10.0.0.1) 14 | 15 | Each subnet consists of a single host connected to 16 | a single switch: 17 | 18 | r0-eth1 - s1-eth1 - h1-eth0 (IP: 192.168.1.100) 19 | r0-eth2 - s2-eth1 - h2-eth0 (IP: 172.16.0.100) 20 | r0-eth3 - s3-eth1 - h3-eth0 (IP: 10.0.0.100) 21 | 22 | The example relies on default routing entries that are 23 | automatically created for each router interface, as well 24 | as 'defaultRoute' parameters for the host interfaces. 25 | 26 | Additional routes may be added to the router or hosts by 27 | executing 'ip route' or 'route' commands on the router or hosts. 28 | """ 29 | 30 | from __future__ import print_function 31 | 32 | from mininet.topo import Topo 33 | from mininet.net import Mininet 34 | from mininet.node import Node 35 | from mininet.log import setLogLevel, info 36 | from mininet.cli import CLI 37 | 38 | 39 | class LinuxRouter( Node ): 40 | "A Node with IP forwarding enabled." 41 | 42 | def config( self, **params ): 43 | super( LinuxRouter, self).config( **params ) 44 | # Enable forwarding on the router 45 | self.cmd( 'sysctl net.ipv4.ip_forward=1' ) 46 | 47 | def terminate( self ): 48 | self.cmd( 'sysctl net.ipv4.ip_forward=0' ) 49 | super( LinuxRouter, self ).terminate() 50 | 51 | 52 | class NetworkTopo( Topo ): 53 | "A LinuxRouter connecting three IP subnets" 54 | 55 | def build( self, **_opts ): 56 | 57 | defaultIP = '192.168.1.1/24' # IP address for r0-eth1 58 | router = self.addNode( 'r0', cls=LinuxRouter, ip=defaultIP ) 59 | 60 | s1, s2, s3 = [ self.addSwitch( s ) for s in ( 's1', 's2', 's3' ) ] 61 | 62 | self.addLink( s1, router, intfName2='r0-eth1', 63 | params2={ 'ip' : defaultIP } ) # for clarity 64 | self.addLink( s2, router, intfName2='r0-eth2', 65 | params2={ 'ip' : '172.16.0.1/12' } ) 66 | self.addLink( s3, router, intfName2='r0-eth3', 67 | params2={ 'ip' : '10.0.0.1/8' } ) 68 | 69 | h1 = self.addHost( 'h1', ip='192.168.1.100/24', 70 | defaultRoute='via 192.168.1.1' ) 71 | h2 = self.addHost( 'h2', ip='172.16.0.100/12', 72 | defaultRoute='via 172.16.0.1' ) 73 | h3 = self.addHost( 'h3', ip='10.0.0.100/8', 74 | defaultRoute='via 10.0.0.1' ) 75 | 76 | for h, s in [ (h1, s1), (h2, s2), (h3, s3) ]: 77 | self.addLink( h, s ) 78 | 79 | 80 | def run(): 81 | "Test linux router" 82 | topo = NetworkTopo() 83 | net = Mininet( topo=topo ) # controller is used by s1-s3 84 | net.start() 85 | info( '*** Routing Table on Router:\n' ) 86 | print( net[ 'r0' ].cmd( 'route' ) ) 87 | CLI( net ) 88 | net.stop() 89 | 90 | if __name__ == '__main__': 91 | setLogLevel( 'info' ) 92 | run() 93 | -------------------------------------------------------------------------------- /examples/mobility.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Simple example of Mobility with Mininet 5 | (aka enough rope to hang yourself.) 6 | 7 | We move a host from s1 to s2, s2 to s3, and then back to s1. 8 | 9 | Gotchas: 10 | 11 | The reference controller doesn't support mobility, so we need to 12 | manually flush the switch flow tables! 13 | 14 | Good luck! 15 | 16 | to-do: 17 | 18 | - think about wifi/hub behavior 19 | - think about clearing last hop - why doesn't that work? 20 | """ 21 | 22 | from __future__ import print_function 23 | 24 | from mininet.net import Mininet 25 | from mininet.node import OVSSwitch 26 | from mininet.topo import LinearTopo 27 | from mininet.log import output, warn 28 | 29 | from random import randint 30 | 31 | 32 | class MobilitySwitch( OVSSwitch ): 33 | "Switch that can reattach and rename interfaces" 34 | 35 | def delIntf( self, intf ): 36 | "Remove (and detach) an interface" 37 | port = self.ports[ intf ] 38 | del self.ports[ intf ] 39 | del self.intfs[ port ] 40 | del self.nameToIntf[ intf.name ] 41 | 42 | def addIntf( self, intf, rename=False, **kwargs ): 43 | "Add (and reparent) an interface" 44 | OVSSwitch.addIntf( self, intf, **kwargs ) 45 | intf.node = self 46 | if rename: 47 | self.renameIntf( intf ) 48 | 49 | def attach( self, intf ): 50 | "Attach an interface and set its port" 51 | port = self.ports[ intf ] 52 | if port: 53 | if self.isOldOVS(): 54 | self.cmd( 'ovs-vsctl add-port', self, intf ) 55 | else: 56 | self.cmd( 'ovs-vsctl add-port', self, intf, 57 | '-- set Interface', intf, 58 | 'ofport_request=%s' % port ) 59 | self.validatePort( intf ) 60 | 61 | def validatePort( self, intf ): 62 | "Validate intf's OF port number" 63 | ofport = int( self.cmd( 'ovs-vsctl get Interface', intf, 64 | 'ofport' ) ) 65 | if ofport != self.ports[ intf ]: 66 | warn( 'WARNING: ofport for', intf, 'is actually', ofport, 67 | '\n' ) 68 | 69 | def renameIntf( self, intf, newname='' ): 70 | "Rename an interface (to its canonical name)" 71 | intf.ifconfig( 'down' ) 72 | if not newname: 73 | newname = '%s-eth%d' % ( self.name, self.ports[ intf ] ) 74 | intf.cmd( 'ip link set', intf, 'name', newname ) 75 | del self.nameToIntf[ intf.name ] 76 | intf.name = newname 77 | self.nameToIntf[ intf.name ] = intf 78 | intf.ifconfig( 'up' ) 79 | 80 | def moveIntf( self, intf, switch, port=None, rename=True ): 81 | "Move one of our interfaces to another switch" 82 | self.detach( intf ) 83 | self.delIntf( intf ) 84 | switch.addIntf( intf, port=port, rename=rename ) 85 | switch.attach( intf ) 86 | 87 | 88 | def printConnections( switches ): 89 | "Compactly print connected nodes to each switch" 90 | for sw in switches: 91 | output( '%s: ' % sw ) 92 | for intf in sw.intfList(): 93 | link = intf.link 94 | if link: 95 | intf1, intf2 = link.intf1, link.intf2 96 | remote = intf1 if intf1.node != sw else intf2 97 | output( '%s(%s) ' % ( remote.node, sw.ports[ intf ] ) ) 98 | output( '\n' ) 99 | 100 | 101 | def moveHost( host, oldSwitch, newSwitch, newPort=None ): 102 | "Move a host from old switch to new switch" 103 | hintf, sintf = host.connectionsTo( oldSwitch )[ 0 ] 104 | oldSwitch.moveIntf( sintf, newSwitch, port=newPort ) 105 | return hintf, sintf 106 | 107 | 108 | def mobilityTest(): 109 | "A simple test of mobility" 110 | print( '* Simple mobility test' ) 111 | net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch ) 112 | print( '* Starting network:' ) 113 | net.start() 114 | printConnections( net.switches ) 115 | print( '* Testing network' ) 116 | net.pingAll() 117 | print( '* Identifying switch interface for h1' ) 118 | h1, old = net.get( 'h1', 's1' ) 119 | for s in 2, 3, 1: 120 | new = net[ 's%d' % s ] 121 | port = randint( 10, 20 ) 122 | print( '* Moving', h1, 'from', old, 'to', new, 'port', port ) 123 | hintf, sintf = moveHost( h1, old, new, newPort=port ) 124 | print( '*', hintf, 'is now connected to', sintf ) 125 | print( '* Clearing out old flows' ) 126 | for sw in net.switches: 127 | sw.dpctl( 'del-flows' ) 128 | print( '* New network:' ) 129 | printConnections( net.switches ) 130 | print( '* Testing connectivity:' ) 131 | net.pingAll() 132 | old = new 133 | net.stop() 134 | 135 | if __name__ == '__main__': 136 | mobilityTest() 137 | -------------------------------------------------------------------------------- /examples/multilink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | This is a simple example that demonstrates multiple links 5 | between nodes. 6 | """ 7 | 8 | from mininet.cli import CLI 9 | from mininet.log import setLogLevel 10 | from mininet.net import Mininet 11 | from mininet.topo import Topo 12 | 13 | def runMultiLink(): 14 | "Create and run multiple link network" 15 | topo = simpleMultiLinkTopo( n=2 ) 16 | net = Mininet( topo=topo ) 17 | net.start() 18 | CLI( net ) 19 | net.stop() 20 | 21 | class simpleMultiLinkTopo( Topo ): 22 | "Simple topology with multiple links" 23 | 24 | def __init__( self, n, **kwargs ): 25 | Topo.__init__( self, **kwargs ) 26 | 27 | h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' ) 28 | s1 = self.addSwitch( 's1' ) 29 | 30 | for _ in range( n ): 31 | self.addLink( s1, h1 ) 32 | self.addLink( s1, h2 ) 33 | 34 | if __name__ == '__main__': 35 | setLogLevel( 'info' ) 36 | runMultiLink() 37 | -------------------------------------------------------------------------------- /examples/multiping.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | multiping.py: monitor multiple sets of hosts using ping 5 | 6 | This demonstrates how one may send a simple shell script to 7 | multiple hosts and monitor their output interactively for a period= 8 | of time. 9 | """ 10 | 11 | from __future__ import print_function 12 | 13 | from mininet.net import Mininet 14 | from mininet.node import Node 15 | from mininet.topo import SingleSwitchTopo 16 | from mininet.log import setLogLevel 17 | 18 | from select import poll, POLLIN 19 | from time import time 20 | 21 | def chunks( l, n ): 22 | "Divide list l into chunks of size n - thanks Stackoverflow" 23 | return [ l[ i: i + n ] for i in range( 0, len( l ), n ) ] 24 | 25 | def startpings( host, targetips ): 26 | "Tell host to repeatedly ping targets" 27 | 28 | targetips = ' '.join( targetips ) 29 | 30 | # Simple ping loop 31 | cmd = ( 'while true; do ' 32 | ' for ip in %s; do ' % targetips + 33 | ' echo -n %s "->" $ip ' % host.IP() + 34 | ' `ping -c1 -w 1 $ip | grep packets` ;' 35 | ' sleep 1;' 36 | ' done; ' 37 | 'done &' ) 38 | 39 | print( '*** Host %s (%s) will be pinging ips: %s' % 40 | ( host.name, host.IP(), targetips ) ) 41 | 42 | host.cmd( cmd ) 43 | 44 | def multiping( netsize, chunksize, seconds): 45 | "Ping subsets of size chunksize in net of size netsize" 46 | 47 | # Create network and identify subnets 48 | topo = SingleSwitchTopo( netsize ) 49 | net = Mininet( topo=topo ) 50 | net.start() 51 | hosts = net.hosts 52 | subnets = chunks( hosts, chunksize ) 53 | 54 | # Create polling object 55 | fds = [ host.stdout.fileno() for host in hosts ] 56 | poller = poll() 57 | for fd in fds: 58 | poller.register( fd, POLLIN ) 59 | 60 | # Start pings 61 | for subnet in subnets: 62 | ips = [ host.IP() for host in subnet ] 63 | #adding bogus to generate packet loss 64 | ips.append( '10.0.0.200' ) 65 | for host in subnet: 66 | startpings( host, ips ) 67 | 68 | # Monitor output 69 | endTime = time() + seconds 70 | while time() < endTime: 71 | readable = poller.poll(1000) 72 | for fd, _mask in readable: 73 | node = Node.outToNode[ fd ] 74 | print( '%s:' % node.name, node.monitor().strip() ) 75 | 76 | # Stop pings 77 | for host in hosts: 78 | host.cmd( 'kill %while' ) 79 | 80 | net.stop() 81 | 82 | 83 | if __name__ == '__main__': 84 | setLogLevel( 'info' ) 85 | multiping( netsize=20, chunksize=4, seconds=10 ) 86 | -------------------------------------------------------------------------------- /examples/multipoll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Simple example of sending output to multiple files and 5 | monitoring them 6 | """ 7 | 8 | from __future__ import print_function 9 | 10 | from mininet.topo import SingleSwitchTopo 11 | from mininet.net import Mininet 12 | from mininet.log import setLogLevel 13 | 14 | from time import time 15 | from select import poll, POLLIN 16 | from subprocess import Popen, PIPE 17 | 18 | 19 | def monitorFiles( outfiles, seconds, timeoutms ): 20 | "Monitor set of files and return [(host, line)...]" 21 | devnull = open( '/dev/null', 'w' ) 22 | tails, fdToFile, fdToHost = {}, {}, {} 23 | for h, outfile in outfiles.iteritems(): 24 | tail = Popen( [ 'tail', '-f', outfile ], 25 | stdout=PIPE, stderr=devnull ) 26 | fd = tail.stdout.fileno() 27 | tails[ h ] = tail 28 | fdToFile[ fd ] = tail.stdout 29 | fdToHost[ fd ] = h 30 | # Prepare to poll output files 31 | readable = poll() 32 | for t in tails.values(): 33 | readable.register( t.stdout.fileno(), POLLIN ) 34 | # Run until a set number of seconds have elapsed 35 | endTime = time() + seconds 36 | while time() < endTime: 37 | fdlist = readable.poll(timeoutms) 38 | if fdlist: 39 | for fd, _flags in fdlist: 40 | f = fdToFile[ fd ] 41 | host = fdToHost[ fd ] 42 | # Wait for a line of output 43 | line = f.readline().strip() 44 | yield host, line 45 | else: 46 | # If we timed out, return nothing 47 | yield None, '' 48 | for t in tails.values(): 49 | t.terminate() 50 | devnull.close() # Not really necessary 51 | 52 | 53 | def monitorTest( N=3, seconds=3 ): 54 | "Run pings and monitor multiple hosts" 55 | topo = SingleSwitchTopo( N ) 56 | net = Mininet( topo ) 57 | net.start() 58 | hosts = net.hosts 59 | print( "Starting test..." ) 60 | server = hosts[ 0 ] 61 | outfiles, errfiles = {}, {} 62 | for h in hosts: 63 | # Create and/or erase output files 64 | outfiles[ h ] = '/tmp/%s.out' % h.name 65 | errfiles[ h ] = '/tmp/%s.err' % h.name 66 | h.cmd( 'echo >', outfiles[ h ] ) 67 | h.cmd( 'echo >', errfiles[ h ] ) 68 | # Start pings 69 | h.cmdPrint('ping', server.IP(), 70 | '>', outfiles[ h ], 71 | '2>', errfiles[ h ], 72 | '&' ) 73 | print( "Monitoring output for", seconds, "seconds" ) 74 | for h, line in monitorFiles( outfiles, seconds, timeoutms=500 ): 75 | if h: 76 | print( '%s: %s' % ( h.name, line ) ) 77 | for h in hosts: 78 | h.cmd('kill %ping') 79 | net.stop() 80 | 81 | 82 | if __name__ == '__main__': 83 | setLogLevel('info') 84 | monitorTest() 85 | -------------------------------------------------------------------------------- /examples/multitest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | This example shows how to create a network and run multiple tests. 5 | For a more complicated test example, see udpbwtest.py. 6 | """ 7 | 8 | from mininet.cli import CLI 9 | from mininet.log import lg, info 10 | from mininet.net import Mininet 11 | from mininet.node import OVSKernelSwitch 12 | from mininet.topolib import TreeTopo 13 | 14 | def ifconfigTest( net ): 15 | "Run ifconfig on all hosts in net." 16 | hosts = net.hosts 17 | for host in hosts: 18 | info( host.cmd( 'ifconfig' ) ) 19 | 20 | if __name__ == '__main__': 21 | lg.setLogLevel( 'info' ) 22 | info( "*** Initializing Mininet and kernel modules\n" ) 23 | OVSKernelSwitch.setup() 24 | info( "*** Creating network\n" ) 25 | network = Mininet( TreeTopo( depth=2, fanout=2 ), switch=OVSKernelSwitch ) 26 | info( "*** Starting network\n" ) 27 | network.start() 28 | info( "*** Running ping test\n" ) 29 | network.pingAll() 30 | info( "*** Running ifconfig test\n" ) 31 | ifconfigTest( network ) 32 | info( "*** Starting CLI (type 'exit' to exit)\n" ) 33 | CLI( network ) 34 | info( "*** Stopping network\n" ) 35 | network.stop() 36 | -------------------------------------------------------------------------------- /examples/nat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Example to create a Mininet topology and connect it to the internet via NAT 5 | """ 6 | 7 | from __future__ import print_function 8 | 9 | from mininet.cli import CLI 10 | from mininet.log import lg 11 | from mininet.topolib import TreeNet 12 | 13 | 14 | if __name__ == '__main__': 15 | lg.setLogLevel( 'info') 16 | net = TreeNet( depth=1, fanout=4 ) 17 | # Add NAT connectivity 18 | net.addNAT().configDefault() 19 | net.start() 20 | print( "*** Hosts are running and should have internet connectivity" ) 21 | print( "*** Type 'exit' or control-D to shut down network" ) 22 | CLI( net ) 23 | # Shut down NAT 24 | net.stop() 25 | -------------------------------------------------------------------------------- /examples/natnet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | natnet.py: Example network with NATs 5 | 6 | 7 | h0 8 | | 9 | s0 10 | | 11 | ---------------- 12 | | | 13 | nat1 nat2 14 | | | 15 | s1 s2 16 | | | 17 | h1 h2 18 | 19 | """ 20 | 21 | from mininet.topo import Topo 22 | from mininet.net import Mininet 23 | from mininet.nodelib import NAT 24 | from mininet.log import setLogLevel 25 | from mininet.cli import CLI 26 | from mininet.util import irange 27 | 28 | class InternetTopo(Topo): 29 | "Single switch connected to n hosts." 30 | def __init__(self, n=2, **opts): 31 | Topo.__init__(self, **opts) 32 | 33 | # set up inet switch 34 | inetSwitch = self.addSwitch('s0') 35 | # add inet host 36 | inetHost = self.addHost('h0') 37 | self.addLink(inetSwitch, inetHost) 38 | 39 | # add local nets 40 | for i in irange(1, n): 41 | inetIntf = 'nat%d-eth0' % i 42 | localIntf = 'nat%d-eth1' % i 43 | localIP = '192.168.%d.1' % i 44 | localSubnet = '192.168.%d.0/24' % i 45 | natParams = { 'ip' : '%s/24' % localIP } 46 | # add NAT to topology 47 | nat = self.addNode('nat%d' % i, cls=NAT, subnet=localSubnet, 48 | inetIntf=inetIntf, localIntf=localIntf) 49 | switch = self.addSwitch('s%d' % i) 50 | # connect NAT to inet and local switches 51 | self.addLink(nat, inetSwitch, intfName1=inetIntf) 52 | self.addLink(nat, switch, intfName1=localIntf, params1=natParams) 53 | # add host and connect to local switch 54 | host = self.addHost('h%d' % i, 55 | ip='192.168.%d.100/24' % i, 56 | defaultRoute='via %s' % localIP) 57 | self.addLink(host, switch) 58 | 59 | def run(): 60 | "Create network and run the CLI" 61 | topo = InternetTopo() 62 | net = Mininet(topo=topo) 63 | net.start() 64 | CLI(net) 65 | net.stop() 66 | 67 | if __name__ == '__main__': 68 | setLogLevel('info') 69 | run() 70 | -------------------------------------------------------------------------------- /examples/numberedports.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Create a network with 5 hosts, numbered 1-4 and 9. 5 | Validate that the port numbers match to the interface name, 6 | and that the ovs ports match the mininet ports. 7 | """ 8 | 9 | from __future__ import print_function 10 | 11 | from mininet.net import Mininet 12 | from mininet.node import Controller 13 | from mininet.log import setLogLevel, info, warn 14 | 15 | def validatePort( switch, intf ): 16 | "Validate intf's OF port number" 17 | ofport = int( switch.cmd( 'ovs-vsctl get Interface', intf, 18 | 'ofport' ) ) 19 | if ofport != switch.ports[ intf ]: 20 | warn( 'WARNING: ofport for', intf, 'is actually', ofport, '\n' ) 21 | return 0 22 | else: 23 | return 1 24 | 25 | def testPortNumbering(): 26 | 27 | """Test port numbering: 28 | Create a network with 5 hosts (using Mininet's 29 | mid-level API) and check that implicit and 30 | explicit port numbering works as expected.""" 31 | 32 | net = Mininet( controller=Controller ) 33 | 34 | info( '*** Adding controller\n' ) 35 | net.addController( 'c0' ) 36 | 37 | info( '*** Adding hosts\n' ) 38 | h1 = net.addHost( 'h1', ip='10.0.0.1' ) 39 | h2 = net.addHost( 'h2', ip='10.0.0.2' ) 40 | h3 = net.addHost( 'h3', ip='10.0.0.3' ) 41 | h4 = net.addHost( 'h4', ip='10.0.0.4' ) 42 | h5 = net.addHost( 'h5', ip='10.0.0.5' ) 43 | 44 | info( '*** Adding switch\n' ) 45 | s1 = net.addSwitch( 's1' ) 46 | 47 | info( '*** Creating links\n' ) 48 | # host 1-4 connect to ports 1-4 on the switch 49 | net.addLink( h1, s1 ) 50 | net.addLink( h2, s1 ) 51 | net.addLink( h3, s1 ) 52 | net.addLink( h4, s1 ) 53 | # specify a different port to connect host 5 to on the switch. 54 | net.addLink( h5, s1, port1=1, port2= 9) 55 | 56 | info( '*** Starting network\n' ) 57 | net.start() 58 | 59 | # print the interfaces and their port numbers 60 | info( '\n*** printing and validating the ports ' 61 | 'running on each interface\n' ) 62 | for intfs in s1.intfList(): 63 | if not intfs.name == "lo": 64 | info( intfs, ': ', s1.ports[intfs], 65 | '\n' ) 66 | info( 'Validating that', intfs, 67 | 'is actually on port', s1.ports[intfs], '... ' ) 68 | if validatePort( s1, intfs ): 69 | info( 'Validated.\n' ) 70 | print( '\n' ) 71 | 72 | # test the network with pingall 73 | net.pingAll() 74 | print( '\n' ) 75 | 76 | info( '*** Stopping network' ) 77 | net.stop() 78 | 79 | if __name__ == '__main__': 80 | setLogLevel( 'info' ) 81 | testPortNumbering() 82 | -------------------------------------------------------------------------------- /examples/popen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | This example monitors a number of hosts using host.popen() and 5 | pmonitor() 6 | """ 7 | 8 | from __future__ import print_function 9 | 10 | from mininet.net import Mininet 11 | from mininet.node import CPULimitedHost 12 | from mininet.topo import SingleSwitchTopo 13 | from mininet.log import setLogLevel 14 | from mininet.util import custom, pmonitor 15 | 16 | def monitorhosts( hosts=5, sched='cfs' ): 17 | "Start a bunch of pings and monitor them using popen" 18 | mytopo = SingleSwitchTopo( hosts ) 19 | cpu = .5 / hosts 20 | myhost = custom( CPULimitedHost, cpu=cpu, sched=sched ) 21 | net = Mininet( topo=mytopo, host=myhost ) 22 | net.start() 23 | # Start a bunch of pings 24 | popens = {} 25 | last = net.hosts[ -1 ] 26 | for host in net.hosts: 27 | popens[ host ] = host.popen( "ping -c5 %s" % last.IP() ) 28 | last = host 29 | # Monitor them and print output 30 | for host, line in pmonitor( popens ): 31 | if host: 32 | print( "<%s>: %s" % ( host.name, line.strip() ) ) 33 | # Done 34 | net.stop() 35 | 36 | if __name__ == '__main__': 37 | setLogLevel( 'info' ) 38 | monitorhosts( hosts=5 ) 39 | -------------------------------------------------------------------------------- /examples/popenpoll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | "Monitor multiple hosts using popen()/pmonitor()" 4 | 5 | from __future__ import print_function 6 | 7 | from mininet.net import Mininet 8 | from mininet.topo import SingleSwitchTopo 9 | from mininet.util import pmonitor 10 | from time import time 11 | from signal import SIGINT 12 | 13 | 14 | def pmonitorTest( N=3, seconds=10 ): 15 | "Run pings and monitor multiple hosts using pmonitor" 16 | topo = SingleSwitchTopo( N ) 17 | net = Mininet( topo ) 18 | net.start() 19 | hosts = net.hosts 20 | print( "Starting test..." ) 21 | server = hosts[ 0 ] 22 | popens = {} 23 | for h in hosts: 24 | popens[ h ] = h.popen('ping', server.IP() ) 25 | print( "Monitoring output for", seconds, "seconds" ) 26 | endTime = time() + seconds 27 | for h, line in pmonitor( popens, timeoutms=500 ): 28 | if h: 29 | print( '<%s>: %s' % ( h.name, line ) ) 30 | if time() >= endTime: 31 | for p in popens.values(): 32 | p.send_signal( SIGINT ) 33 | net.stop() 34 | 35 | if __name__ == '__main__': 36 | pmonitorTest() 37 | -------------------------------------------------------------------------------- /examples/scratchnet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Build a simple network from scratch, using mininet primitives. 5 | This is more complicated than using the higher-level classes, 6 | but it exposes the configuration details and allows customization. 7 | 8 | For most tasks, the higher-level API will be preferable. 9 | """ 10 | 11 | from __future__ import print_function 12 | 13 | from mininet.net import Mininet 14 | from mininet.node import Node 15 | from mininet.link import Link 16 | from mininet.log import setLogLevel, info 17 | from mininet.util import quietRun 18 | 19 | from time import sleep 20 | 21 | def scratchNet( cname='controller', cargs='-v ptcp:' ): 22 | "Create network from scratch using Open vSwitch." 23 | 24 | info( "*** Creating nodes\n" ) 25 | controller = Node( 'c0', inNamespace=False ) 26 | switch = Node( 's0', inNamespace=False ) 27 | h0 = Node( 'h0' ) 28 | h1 = Node( 'h1' ) 29 | 30 | info( "*** Creating links\n" ) 31 | Link( h0, switch ) 32 | Link( h1, switch ) 33 | 34 | info( "*** Configuring hosts\n" ) 35 | h0.setIP( '192.168.123.1/24' ) 36 | h1.setIP( '192.168.123.2/24' ) 37 | info( str( h0 ) + '\n' ) 38 | info( str( h1 ) + '\n' ) 39 | 40 | info( "*** Starting network using Open vSwitch\n" ) 41 | controller.cmd( cname + ' ' + cargs + '&' ) 42 | switch.cmd( 'ovs-vsctl del-br dp0' ) 43 | switch.cmd( 'ovs-vsctl add-br dp0' ) 44 | for intf in switch.intfs.values(): 45 | print( switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf ) ) 46 | 47 | # Note: controller and switch are in root namespace, and we 48 | # can connect via loopback interface 49 | switch.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' ) 50 | 51 | info( '*** Waiting for switch to connect to controller' ) 52 | while 'is_connected' not in quietRun( 'ovs-vsctl show' ): 53 | sleep( 1 ) 54 | info( '.' ) 55 | info( '\n' ) 56 | 57 | info( "*** Running test\n" ) 58 | h0.cmdPrint( 'ping -c1 ' + h1.IP() ) 59 | 60 | info( "*** Stopping network\n" ) 61 | controller.cmd( 'kill %' + cname ) 62 | switch.cmd( 'ovs-vsctl del-br dp0' ) 63 | switch.deleteIntfs() 64 | info( '\n' ) 65 | 66 | if __name__ == '__main__': 67 | setLogLevel( 'info' ) 68 | info( '*** Scratch network demo (kernel datapath)\n' ) 69 | Mininet.init() 70 | scratchNet() 71 | -------------------------------------------------------------------------------- /examples/scratchnetuser.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Build a simple network from scratch, using mininet primitives. 5 | This is more complicated than using the higher-level classes, 6 | but it exposes the configuration details and allows customization. 7 | 8 | For most tasks, the higher-level API will be preferable. 9 | 10 | This version uses the user datapath and an explicit control network. 11 | """ 12 | 13 | from mininet.net import Mininet 14 | from mininet.node import Node 15 | from mininet.link import Link 16 | from mininet.log import setLogLevel, info 17 | 18 | def linkIntfs( node1, node2 ): 19 | "Create link from node1 to node2 and return intfs" 20 | link = Link( node1, node2 ) 21 | return link.intf1, link.intf2 22 | 23 | def scratchNetUser( cname='controller', cargs='ptcp:' ): 24 | "Create network from scratch using user switch." 25 | 26 | # It's not strictly necessary for the controller and switches 27 | # to be in separate namespaces. For performance, they probably 28 | # should be in the root namespace. However, it's interesting to 29 | # see how they could work even if they are in separate namespaces. 30 | 31 | info( '*** Creating Network\n' ) 32 | controller = Node( 'c0' ) 33 | switch = Node( 's0') 34 | h0 = Node( 'h0' ) 35 | h1 = Node( 'h1' ) 36 | cintf, sintf = linkIntfs( controller, switch ) 37 | h0intf, sintf1 = linkIntfs( h0, switch ) 38 | h1intf, sintf2 = linkIntfs( h1, switch ) 39 | 40 | info( '*** Configuring control network\n' ) 41 | controller.setIP( '10.0.123.1/24', intf=cintf ) 42 | switch.setIP( '10.0.123.2/24', intf=sintf) 43 | 44 | info( '*** Configuring hosts\n' ) 45 | h0.setIP( '192.168.123.1/24', intf=h0intf ) 46 | h1.setIP( '192.168.123.2/24', intf=h1intf ) 47 | 48 | info( '*** Network state:\n' ) 49 | for node in controller, switch, h0, h1: 50 | info( str( node ) + '\n' ) 51 | 52 | info( '*** Starting controller and user datapath\n' ) 53 | controller.cmd( cname + ' ' + cargs + '&' ) 54 | switch.cmd( 'ifconfig lo 127.0.0.1' ) 55 | intfs = str( sintf1 ), str( sintf2 ) 56 | switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' ) 57 | switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' ) 58 | 59 | info( '*** Running test\n' ) 60 | h0.cmdPrint( 'ping -c1 ' + h1.IP() ) 61 | 62 | info( '*** Stopping network\n' ) 63 | controller.cmd( 'kill %' + cname ) 64 | switch.cmd( 'kill %ofdatapath' ) 65 | switch.cmd( 'kill %ofprotocol' ) 66 | switch.deleteIntfs() 67 | info( '\n' ) 68 | 69 | if __name__ == '__main__': 70 | setLogLevel( 'info' ) 71 | info( '*** Scratch network demo (user datapath)\n' ) 72 | Mininet.init() 73 | scratchNetUser() 74 | -------------------------------------------------------------------------------- /examples/simpleperf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Simple example of setting network and CPU parameters 5 | 6 | NOTE: link params limit BW, add latency, and loss. 7 | There is a high chance that pings WILL fail and that 8 | iperf will hang indefinitely if the TCP handshake fails 9 | to complete. 10 | """ 11 | 12 | from __future__ import print_function 13 | 14 | from mininet.topo import Topo 15 | from mininet.net import Mininet 16 | from mininet.node import CPULimitedHost 17 | from mininet.link import TCLink 18 | from mininet.util import dumpNodeConnections 19 | from mininet.log import setLogLevel 20 | 21 | from sys import argv 22 | 23 | class SingleSwitchTopo(Topo): 24 | "Single switch connected to n hosts." 25 | def __init__(self, n=2, lossy=True, **opts): 26 | Topo.__init__(self, **opts) 27 | switch = self.addSwitch('s1') 28 | for h in range(n): 29 | # Each host gets 50%/n of system CPU 30 | host = self.addHost('h%s' % (h + 1), 31 | cpu=.5 / n) 32 | if lossy: 33 | # 10 Mbps, 5ms delay, 10% packet loss 34 | self.addLink(host, switch, 35 | bw=10, delay='5ms', loss=10, use_htb=True) 36 | else: 37 | # 10 Mbps, 5ms delay, no packet loss 38 | self.addLink(host, switch, 39 | bw=10, delay='5ms', loss=0, use_htb=True) 40 | 41 | 42 | def perfTest( lossy=True ): 43 | "Create network and run simple performance test" 44 | topo = SingleSwitchTopo( n=4, lossy=lossy ) 45 | net = Mininet( topo=topo, 46 | host=CPULimitedHost, link=TCLink, 47 | autoStaticArp=True ) 48 | net.start() 49 | print( "Dumping host connections" ) 50 | dumpNodeConnections(net.hosts) 51 | print( "Testing bandwidth between h1 and h4" ) 52 | h1, h4 = net.getNodeByName('h1', 'h4') 53 | net.iperf( ( h1, h4 ), l4Type='UDP' ) 54 | net.stop() 55 | 56 | if __name__ == '__main__': 57 | setLogLevel( 'info' ) 58 | # Prevent test_simpleperf from failing due to packet loss 59 | perfTest( lossy=( 'testmode' not in argv ) ) 60 | -------------------------------------------------------------------------------- /examples/sshd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Create a network and start sshd(8) on each host. 5 | 6 | While something like rshd(8) would be lighter and faster, 7 | (and perfectly adequate on an in-machine network) 8 | the advantage of running sshd is that scripts can work 9 | unchanged on mininet and hardware. 10 | 11 | In addition to providing ssh access to hosts, this example 12 | demonstrates: 13 | 14 | - creating a convenience function to construct networks 15 | - connecting the host network to the root namespace 16 | - running server processes (sshd in this case) on hosts 17 | """ 18 | 19 | from __future__ import print_function 20 | import sys 21 | 22 | from mininet.net import Mininet 23 | from mininet.cli import CLI 24 | from mininet.log import lg 25 | from mininet.node import Node 26 | from mininet.topolib import TreeTopo 27 | from mininet.util import waitListening 28 | 29 | 30 | def TreeNet( depth=1, fanout=2, **kwargs ): 31 | "Convenience function for creating tree networks." 32 | topo = TreeTopo( depth, fanout ) 33 | return Mininet( topo, **kwargs ) 34 | 35 | def connectToRootNS( network, switch, ip, routes ): 36 | """Connect hosts to root namespace via switch. Starts network. 37 | network: Mininet() network object 38 | switch: switch to connect to root namespace 39 | ip: IP address for root namespace node 40 | routes: host networks to route to""" 41 | # Create a node in root namespace and link to switch 0 42 | root = Node( 'root', inNamespace=False ) 43 | intf = network.addLink( root, switch ).intf1 44 | root.setIP( ip, intf=intf ) 45 | # Start network that now includes link to root namespace 46 | network.start() 47 | # Add routes from root ns to hosts 48 | for route in routes: 49 | root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) ) 50 | 51 | def sshd( network, cmd='/usr/sbin/sshd', opts='-D', 52 | ip='10.123.123.1/32', routes=None, switch=None ): 53 | """Start a network, connect it to root ns, and run sshd on all hosts. 54 | ip: root-eth0 IP address in root namespace (10.123.123.1/32) 55 | routes: Mininet host networks to route to (10.0/24) 56 | switch: Mininet switch to connect to root namespace (s1)""" 57 | if not switch: 58 | switch = network[ 's1' ] # switch to use 59 | if not routes: 60 | routes = [ '10.0.0.0/24' ] 61 | connectToRootNS( network, switch, ip, routes ) 62 | for host in network.hosts: 63 | host.cmd( cmd + ' ' + opts + '&' ) 64 | print( "*** Waiting for ssh daemons to start" ) 65 | for server in network.hosts: 66 | waitListening( server=server, port=22, timeout=5 ) 67 | 68 | print() 69 | print( "*** Hosts are running sshd at the following addresses:" ) 70 | print() 71 | for host in network.hosts: 72 | print( host.name, host.IP() ) 73 | print() 74 | print( "*** Type 'exit' or control-D to shut down network" ) 75 | CLI( network ) 76 | for host in network.hosts: 77 | host.cmd( 'kill %' + cmd ) 78 | network.stop() 79 | 80 | if __name__ == '__main__': 81 | lg.setLogLevel( 'info') 82 | net = TreeNet( depth=1, fanout=4 ) 83 | # get sshd args from the command line or use default args 84 | # useDNS=no -u0 to avoid reverse DNS lookup timeout 85 | argvopts = ' '.join( sys.argv[ 1: ] ) if len( sys.argv ) > 1 else ( 86 | '-D -o UseDNS=no -u0' ) 87 | sshd( net, opts=argvopts ) 88 | -------------------------------------------------------------------------------- /examples/test/runner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Run all mininet.examples tests 5 | -v : verbose output 6 | -quick : skip tests that take more than ~30 seconds 7 | """ 8 | 9 | import unittest 10 | import os 11 | import sys 12 | from mininet.util import ensureRoot 13 | from mininet.clean import cleanup 14 | 15 | class MininetTestResult( unittest.TextTestResult ): 16 | def addFailure( self, test, err ): 17 | super( MininetTestResult, self ).addFailure( test, err ) 18 | cleanup() 19 | def addError( self,test, err ): 20 | super( MininetTestResult, self ).addError( test, err ) 21 | cleanup() 22 | 23 | class MininetTestRunner( unittest.TextTestRunner ): 24 | def _makeResult( self ): 25 | return MininetTestResult( self.stream, self.descriptions, self.verbosity ) 26 | 27 | def runTests( testDir, verbosity=1 ): 28 | "discover and run all tests in testDir" 29 | # ensure root and cleanup before starting tests 30 | ensureRoot() 31 | cleanup() 32 | # discover all tests in testDir 33 | testSuite = unittest.defaultTestLoader.discover( testDir ) 34 | # run tests 35 | MininetTestRunner( verbosity=verbosity ).run( testSuite ) 36 | 37 | if __name__ == '__main__': 38 | # get the directory containing example tests 39 | testDir = os.path.dirname( os.path.realpath( __file__ ) ) 40 | verbosity = 2 if '-v' in sys.argv else 1 41 | runTests( testDir, verbosity ) 42 | -------------------------------------------------------------------------------- /examples/test/test_baresshd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Tests for baresshd.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | from mininet.clean import cleanup, sh 10 | 11 | class testBareSSHD( unittest.TestCase ): 12 | 13 | opts = [ 'Welcome to h1', pexpect.EOF, pexpect.TIMEOUT ] 14 | 15 | def connected( self ): 16 | "Log into ssh server, check banner, then exit" 17 | p = pexpect.spawn( 'ssh 10.0.0.1 -o StrictHostKeyChecking=no -i /tmp/ssh/test_rsa exit' ) 18 | while True: 19 | index = p.expect( self.opts ) 20 | if index == 0: 21 | return True 22 | else: 23 | return False 24 | 25 | def setUp( self ): 26 | # verify that sshd is not running 27 | self.assertFalse( self.connected() ) 28 | # create public key pair for testing 29 | sh( 'rm -rf /tmp/ssh' ) 30 | sh( 'mkdir /tmp/ssh' ) 31 | sh( "ssh-keygen -t rsa -P '' -f /tmp/ssh/test_rsa" ) 32 | sh( 'cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys' ) 33 | # run example with custom sshd args 34 | cmd = ( 'python -m mininet.examples.baresshd ' 35 | '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys ' 36 | '-o StrictModes=no' ) 37 | p = pexpect.spawn( cmd ) 38 | runOpts = [ 'You may now ssh into h1 at 10.0.0.1', 39 | 'after 5 seconds, h1 is not listening on port 22', 40 | pexpect.EOF, pexpect.TIMEOUT ] 41 | while True: 42 | index = p.expect( runOpts ) 43 | if index == 0: 44 | break 45 | else: 46 | self.tearDown() 47 | self.fail( 'sshd failed to start in host h1' ) 48 | 49 | def testSSH( self ): 50 | "Simple test to verify that we can ssh into h1" 51 | result = False 52 | # try to connect up to 3 times; sshd can take a while to start 53 | result = self.connected() 54 | self.assertTrue( result ) 55 | 56 | def tearDown( self ): 57 | # kill the ssh process 58 | sh( "ps aux | grep 'ssh.*Banner' | awk '{ print $2 }' | xargs kill" ) 59 | cleanup() 60 | # remove public key pair 61 | sh( 'rm -rf /tmp/ssh' ) 62 | 63 | if __name__ == '__main__': 64 | unittest.main() 65 | -------------------------------------------------------------------------------- /examples/test/test_bind.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Tests for bind.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testBind( unittest.TestCase ): 11 | 12 | prompt = 'mininet>' 13 | 14 | def setUp( self ): 15 | self.net = pexpect.spawn( 'python -m mininet.examples.bind' ) 16 | self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" ) 17 | self.directories = [] 18 | # parse directories from mn output 19 | for d in self.net.match.group(1).split(', '): 20 | self.directories.append( d.strip("'") ) 21 | self.net.expect( self.prompt ) 22 | self.assertTrue( len( self.directories ) > 0 ) 23 | 24 | def testCreateFile( self ): 25 | "Create a file, a.txt, in the first private directory and verify" 26 | fileName = 'a.txt' 27 | directory = self.directories[ 0 ] 28 | path = directory + '/' + fileName 29 | self.net.sendline( 'h1 touch %s; ls %s' % ( path, directory ) ) 30 | index = self.net.expect( [ fileName, self.prompt ] ) 31 | self.assertTrue( index == 0 ) 32 | self.net.expect( self.prompt ) 33 | self.net.sendline( 'h1 rm %s' % path ) 34 | self.net.expect( self.prompt ) 35 | 36 | def testIsolation( self ): 37 | "Create a file in two hosts and verify that contents are different" 38 | fileName = 'b.txt' 39 | directory = self.directories[ 0 ] 40 | path = directory + '/' + fileName 41 | contents = { 'h1' : '1', 'h2' : '2' } 42 | # Verify file doesn't exist, then write private copy of file 43 | for host in contents: 44 | value = contents[ host ] 45 | self.net.sendline( '%s cat %s' % ( host, path ) ) 46 | self.net.expect( 'No such file' ) 47 | self.net.expect( self.prompt ) 48 | self.net.sendline( '%s echo %s > %s' % ( host, value, path ) ) 49 | self.net.expect( self.prompt ) 50 | # Verify file contents 51 | for host in contents: 52 | value = contents[ host ] 53 | self.net.sendline( '%s cat %s' % ( host, path ) ) 54 | self.net.expect( value ) 55 | self.net.expect( self.prompt ) 56 | self.net.sendline( '%s rm %s' % ( host, path ) ) 57 | self.net.expect( self.prompt ) 58 | 59 | # TODO: need more tests 60 | 61 | def tearDown( self ): 62 | self.net.sendline( 'exit' ) 63 | self.net.wait() 64 | 65 | if __name__ == '__main__': 66 | unittest.main() 67 | -------------------------------------------------------------------------------- /examples/test/test_clusterSanity.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | A simple sanity check test for cluster edition 5 | ''' 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class clusterSanityCheck( unittest.TestCase ): 11 | 12 | prompt = 'mininet>' 13 | 14 | def testClusterPingAll( self ): 15 | p = pexpect.spawn( 'python -m mininet.examples.clusterSanity' ) 16 | p.expect( self.prompt ) 17 | p.sendline( 'pingall' ) 18 | p.expect ( '(\d+)% dropped' ) 19 | percent = int( p.match.group( 1 ) ) if p.match else -1 20 | self.assertEqual( percent, 0 ) 21 | p.expect( self.prompt ) 22 | p.sendline( 'exit' ) 23 | p.wait() 24 | 25 | 26 | if __name__ == '__main__': 27 | unittest.main() 28 | -------------------------------------------------------------------------------- /examples/test/test_controllers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Tests for controllers.py and controllers2.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testControllers( unittest.TestCase ): 11 | 12 | prompt = 'mininet>' 13 | 14 | def connectedTest( self, name, cmap ): 15 | "Verify that switches are connected to the controller specified by cmap" 16 | p = pexpect.spawn( 'python -m %s' % name ) 17 | p.expect( self.prompt ) 18 | # but first a simple ping test 19 | p.sendline( 'pingall' ) 20 | p.expect ( '(\d+)% dropped' ) 21 | percent = int( p.match.group( 1 ) ) if p.match else -1 22 | self.assertEqual( percent, 0 ) 23 | p.expect( self.prompt ) 24 | # verify connected controller 25 | for switch in cmap: 26 | p.sendline( 'sh ovs-vsctl get-controller %s' % switch ) 27 | p.expect( 'tcp:([\d.:]+)') 28 | actual = p.match.group(1) 29 | expected = cmap[ switch ] 30 | self.assertEqual( actual, expected ) 31 | p.expect( self.prompt ) 32 | p.sendline( 'exit' ) 33 | p.wait() 34 | 35 | def testControllers( self ): 36 | c0 = '127.0.0.1:6633' 37 | c1 = '127.0.0.1:6634' 38 | cmap = { 's1': c0, 's2': c1, 's3': c0 } 39 | self.connectedTest( 'mininet.examples.controllers', cmap ) 40 | 41 | def testControllers2( self ): 42 | c0 = '127.0.0.1:6633' 43 | c1 = '127.0.0.1:6634' 44 | cmap = { 's1': c0, 's2': c1 } 45 | self.connectedTest( 'mininet.examples.controllers2', cmap ) 46 | 47 | if __name__ == '__main__': 48 | unittest.main() 49 | -------------------------------------------------------------------------------- /examples/test/test_controlnet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for controlnet.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testControlNet( unittest.TestCase ): 11 | 12 | prompt = 'mininet>' 13 | 14 | def testPingall( self ): 15 | "Simple pingall test that verifies 0% packet drop in data network" 16 | p = pexpect.spawn( 'python -m mininet.examples.controlnet' ) 17 | p.expect( self.prompt ) 18 | p.sendline( 'pingall' ) 19 | p.expect ( '(\d+)% dropped' ) 20 | percent = int( p.match.group( 1 ) ) if p.match else -1 21 | self.assertEqual( percent, 0 ) 22 | p.expect( self.prompt ) 23 | p.sendline( 'exit' ) 24 | p.wait() 25 | 26 | def testFailover( self ): 27 | "Kill controllers and verify that switch, s1, fails over properly" 28 | count = 1 29 | p = pexpect.spawn( 'python -m mininet.examples.controlnet' ) 30 | p.expect( self.prompt ) 31 | lp = pexpect.spawn( 'tail -f /tmp/s1-ofp.log' ) 32 | lp.expect( 'tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected' ) 33 | ip = int( lp.match.group( 1 ) ) 34 | self.assertEqual( count, ip ) 35 | count += 1 36 | for c in [ 'c0', 'c1' ]: 37 | p.sendline( '%s ifconfig %s-eth0 down' % ( c, c) ) 38 | p.expect( self.prompt ) 39 | lp.expect( 'tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected' ) 40 | ip = int( lp.match.group( 1 ) ) 41 | self.assertEqual( count, ip ) 42 | count += 1 43 | p.sendline( 'exit' ) 44 | p.wait() 45 | 46 | if __name__ == '__main__': 47 | unittest.main() 48 | -------------------------------------------------------------------------------- /examples/test/test_cpu.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for cpu.py 5 | 6 | results format: 7 | 8 | sched cpu client MB/s 9 | 10 | cfs 45.00% 13254.669841 11 | cfs 40.00% 11822.441399 12 | cfs 30.00% 5112.963009 13 | cfs 20.00% 3449.090009 14 | cfs 10.00% 2271.741564 15 | 16 | """ 17 | 18 | import unittest 19 | import pexpect 20 | import sys 21 | 22 | class testCPU( unittest.TestCase ): 23 | 24 | prompt = 'mininet>' 25 | 26 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 27 | def testCPU( self ): 28 | "Verify that CPU utilization is monotonically decreasing for each scheduler" 29 | p = pexpect.spawn( 'python -m mininet.examples.cpu' ) 30 | # matches each line from results( shown above ) 31 | opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)', 32 | pexpect.EOF ] 33 | scheds = [] 34 | while True: 35 | index = p.expect( opts, timeout=600 ) 36 | if index == 0: 37 | sched = p.match.group( 1 ) 38 | cpu = float( p.match.group( 2 ) ) 39 | bw = float( p.match.group( 3 ) ) 40 | if sched not in scheds: 41 | scheds.append( sched ) 42 | else: 43 | self.assertTrue( bw < previous_bw, 44 | "%f should be less than %f\n" % 45 | ( bw, previous_bw ) ) 46 | previous_bw = bw 47 | else: 48 | break 49 | 50 | self.assertTrue( len( scheds ) > 0 ) 51 | 52 | if __name__ == '__main__': 53 | unittest.main() 54 | -------------------------------------------------------------------------------- /examples/test/test_emptynet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for emptynet.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testEmptyNet( unittest.TestCase ): 11 | 12 | prompt = 'mininet>' 13 | 14 | def testEmptyNet( self ): 15 | "Run simple CLI tests: pingall (verify 0% drop) and iperf (sanity)" 16 | p = pexpect.spawn( 'python -m mininet.examples.emptynet' ) 17 | p.expect( self.prompt ) 18 | # pingall test 19 | p.sendline( 'pingall' ) 20 | p.expect ( '(\d+)% dropped' ) 21 | percent = int( p.match.group( 1 ) ) if p.match else -1 22 | self.assertEqual( percent, 0 ) 23 | p.expect( self.prompt ) 24 | # iperf test 25 | p.sendline( 'iperf' ) 26 | p.expect( "Results: \['[\d.]+ .bits/sec', '[\d.]+ .bits/sec'\]" ) 27 | p.expect( self.prompt ) 28 | p.sendline( 'exit' ) 29 | p.wait() 30 | 31 | if __name__ == '__main__': 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /examples/test/test_hwintf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for hwintf.py 5 | """ 6 | 7 | import unittest 8 | import re 9 | 10 | import pexpect 11 | 12 | from mininet.log import setLogLevel 13 | from mininet.node import Node 14 | from mininet.link import Link 15 | 16 | 17 | class testHwintf( unittest.TestCase ): 18 | 19 | prompt = 'mininet>' 20 | 21 | def setUp( self ): 22 | self.h3 = Node( 't0', ip='10.0.0.3/8' ) 23 | self.n0 = Node( 't1', inNamespace=False ) 24 | Link( self.h3, self.n0 ) 25 | self.h3.configDefault() 26 | 27 | def testLocalPing( self ): 28 | "Verify connectivity between virtual hosts using pingall" 29 | p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() ) 30 | p.expect( self.prompt ) 31 | p.sendline( 'pingall' ) 32 | p.expect ( '(\d+)% dropped' ) 33 | percent = int( p.match.group( 1 ) ) if p.match else -1 34 | self.assertEqual( percent, 0 ) 35 | p.expect( self.prompt ) 36 | p.sendline( 'exit' ) 37 | p.wait() 38 | 39 | def testExternalPing( self ): 40 | "Verify connnectivity between virtual host and virtual-physical 'external' host " 41 | p = pexpect.spawn( 'python -m mininet.examples.hwintf %s' % self.n0.intf() ) 42 | p.expect( self.prompt ) 43 | # test ping external to internal 44 | expectStr = '(\d+) packets transmitted, (\d+) received' 45 | m = re.search( expectStr, self.h3.cmd( 'ping -v -c 1 10.0.0.1' ) ) 46 | tx = m.group( 1 ) 47 | rx = m.group( 2 ) 48 | self.assertEqual( tx, rx ) 49 | # test ping internal to external 50 | p.sendline( 'h1 ping -c 1 10.0.0.3') 51 | p.expect( expectStr ) 52 | tx = p.match.group( 1 ) 53 | rx = p.match.group( 2 ) 54 | self.assertEqual( tx, rx ) 55 | p.expect( self.prompt ) 56 | p.sendline( 'exit' ) 57 | p.wait() 58 | 59 | def tearDown( self ): 60 | self.h3.terminate() 61 | self.n0.terminate() 62 | 63 | if __name__ == '__main__': 64 | setLogLevel( 'warning' ) 65 | unittest.main() 66 | -------------------------------------------------------------------------------- /examples/test/test_intfoptions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for intfOptions.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | 11 | class testIntfOptions( unittest.TestCase ): 12 | 13 | def testIntfOptions( self ): 14 | "verify that intf.config is correctly limiting traffic" 15 | p = pexpect.spawn( 'python -m mininet.examples.intfoptions ' ) 16 | tolerance = .2 # plus or minus 20% 17 | opts = [ "Results: \['([\d\.]+) .bits/sec", 18 | "Results: \['10M', '([\d\.]+) .bits/sec", 19 | "h(\d+)->h(\d+): (\d)/(\d)," 20 | "rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms", 21 | pexpect.EOF ] 22 | while True: 23 | index = p.expect( opts, timeout=600 ) 24 | if index == 0: 25 | BW = 5 26 | bw = float( p.match.group( 1 ) ) 27 | self.assertGreaterEqual( bw, BW * ( 1 - tolerance ) ) 28 | self.assertLessEqual( bw, BW * ( 1 + tolerance ) ) 29 | elif index == 1: 30 | BW = 10 31 | measuredBw = float( p.match.group( 1 ) ) 32 | loss = ( measuredBw / BW ) * 100 33 | self.assertGreaterEqual( loss, 50 * ( 1 - tolerance ) ) 34 | self.assertLessEqual( loss, 50 * ( 1 + tolerance ) ) 35 | elif index == 2: 36 | delay = float( p.match.group( 6 ) ) 37 | self.assertGreaterEqual( delay, 15 * ( 1 - tolerance ) ) 38 | self.assertLessEqual( delay, 15 * ( 1 + tolerance ) ) 39 | else: 40 | break 41 | 42 | 43 | if __name__ == '__main__': 44 | unittest.main() 45 | -------------------------------------------------------------------------------- /examples/test/test_limit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for limit.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | 11 | class testLimit( unittest.TestCase ): 12 | 13 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 14 | def testLimit( self ): 15 | "Verify that CPU limits are within a 2% tolerance of limit for each scheduler" 16 | p = pexpect.spawn( 'python -m mininet.examples.limit' ) 17 | opts = [ '\*\*\* Testing network ([\d\.]+) Mbps', 18 | '\*\*\* Results: \[([\d\., ]+)\]', 19 | pexpect.EOF ] 20 | count = 0 21 | bw = 0 22 | tolerance = 2 23 | while True: 24 | index = p.expect( opts ) 25 | if index == 0: 26 | bw = float( p.match.group( 1 ) ) 27 | count += 1 28 | elif index == 1: 29 | results = p.match.group( 1 ) 30 | for x in results.split( ',' ): 31 | result = float( x ) 32 | self.assertTrue( result < bw + tolerance ) 33 | self.assertTrue( result > bw - tolerance ) 34 | else: 35 | break 36 | 37 | self.assertTrue( count > 0 ) 38 | 39 | if __name__ == '__main__': 40 | unittest.main() 41 | -------------------------------------------------------------------------------- /examples/test/test_linearbandwidth.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for linearbandwidth.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | 11 | class testLinearBandwidth( unittest.TestCase ): 12 | 13 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 14 | def testLinearBandwidth( self ): 15 | "Verify that bandwidth is monotonically decreasing as # of hops increases" 16 | p = pexpect.spawn( 'python -m mininet.examples.linearbandwidth' ) 17 | count = 0 18 | opts = [ '\*\*\* Linear network results', 19 | '(\d+)\s+([\d\.]+) (.bits)', 20 | pexpect.EOF ] 21 | while True: 22 | index = p.expect( opts, timeout=600 ) 23 | if index == 0: 24 | count += 1 25 | elif index == 1: 26 | n = int( p.match.group( 1 ) ) 27 | bw = float( p.match.group( 2 ) ) 28 | unit = p.match.group( 3 ) 29 | if unit[ 0 ] == 'K': 30 | bw *= 10 ** 3 31 | elif unit[ 0 ] == 'M': 32 | bw *= 10 ** 6 33 | elif unit[ 0 ] == 'G': 34 | bw *= 10 ** 9 35 | # check that we have a previous result to compare to 36 | if n != 1: 37 | info = ( 'bw: %d bits/s across %d switches, ' 38 | 'previous: %d bits/s across %d switches' % 39 | ( bw, n, previous_bw, previous_n ) ) 40 | self.assertTrue( bw < previous_bw, info ) 41 | previous_bw, previous_n = bw, n 42 | else: 43 | break 44 | 45 | # verify that we received results from at least one switch 46 | self.assertTrue( count > 0 ) 47 | 48 | if __name__ == '__main__': 49 | unittest.main() 50 | -------------------------------------------------------------------------------- /examples/test/test_linuxrouter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for linuxrouter.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | from mininet.util import quietRun 10 | 11 | class testLinuxRouter( unittest.TestCase ): 12 | 13 | prompt = 'mininet>' 14 | 15 | def testPingall( self ): 16 | "Test connectivity between hosts" 17 | p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' ) 18 | p.expect( self.prompt ) 19 | p.sendline( 'pingall' ) 20 | p.expect ( '(\d+)% dropped' ) 21 | percent = int( p.match.group( 1 ) ) if p.match else -1 22 | p.expect( self.prompt ) 23 | p.sendline( 'exit' ) 24 | p.wait() 25 | self.assertEqual( percent, 0 ) 26 | 27 | def testRouterPing( self ): 28 | "Test connectivity from h1 to router" 29 | p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' ) 30 | p.expect( self.prompt ) 31 | p.sendline( 'h1 ping -c 1 r0' ) 32 | p.expect ( '(\d+)% packet loss' ) 33 | percent = int( p.match.group( 1 ) ) if p.match else -1 34 | p.expect( self.prompt ) 35 | p.sendline( 'exit' ) 36 | p.wait() 37 | self.assertEqual( percent, 0 ) 38 | 39 | def testTTL( self ): 40 | "Verify that the TTL is decremented" 41 | p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' ) 42 | p.expect( self.prompt ) 43 | p.sendline( 'h1 ping -c 1 h2' ) 44 | p.expect ( 'ttl=(\d+)' ) 45 | ttl = int( p.match.group( 1 ) ) if p.match else -1 46 | p.expect( self.prompt ) 47 | p.sendline( 'exit' ) 48 | p.wait() 49 | self.assertEqual( ttl, 63 ) # 64 - 1 50 | 51 | if __name__ == '__main__': 52 | unittest.main() 53 | -------------------------------------------------------------------------------- /examples/test/test_mobility.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for mobility.py 5 | """ 6 | 7 | import unittest 8 | from subprocess import check_output 9 | 10 | class testMobility( unittest.TestCase ): 11 | 12 | def testMobility( self ): 13 | "Run the example and verify its 4 ping results" 14 | cmd = 'python -m mininet.examples.mobility 2>&1' 15 | grep = ' | grep -c " 0% dropped" ' 16 | result = check_output( cmd + grep, shell=True ) 17 | assert int( result ) == 4 18 | 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /examples/test/test_multilink.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | ''' 4 | Test for multiple links between nodes 5 | validates mininet interfaces against systems interfaces 6 | ''' 7 | 8 | import unittest 9 | import pexpect 10 | 11 | class testMultiLink( unittest.TestCase ): 12 | 13 | prompt = 'mininet>' 14 | 15 | def testMultiLink(self): 16 | p = pexpect.spawn( 'python -m mininet.examples.multilink' ) 17 | p.expect( self.prompt ) 18 | p.sendline( 'intfs' ) 19 | p.expect( 's(\d): lo' ) 20 | intfsOutput = p.before 21 | # parse interfaces from mininet intfs, and store them in a list 22 | hostToIntfs = intfsOutput.split( '\r\n' )[ 1:3 ] 23 | intfList = [] 24 | for hostToIntf in hostToIntfs: 25 | intfList += [ intf for intf in 26 | hostToIntf.split()[1].split(',') ] 27 | 28 | # get interfaces from system by running ifconfig on every host 29 | sysIntfList = [] 30 | opts = [ 'h(\d)-eth(\d)', self.prompt ] 31 | p.expect( self.prompt ) 32 | 33 | p.sendline( 'h1 ifconfig' ) 34 | while True: 35 | p.expect( opts ) 36 | if p.after == self.prompt: 37 | break 38 | sysIntfList.append( p.after ) 39 | 40 | p.sendline( 'h2 ifconfig' ) 41 | while True: 42 | p.expect( opts ) 43 | if p.after == self.prompt: 44 | break 45 | sysIntfList.append( p.after ) 46 | 47 | failMsg = ( 'The systems interfaces and mininet interfaces\n' 48 | 'are not the same' ) 49 | 50 | self.assertEqual( sysIntfList, intfList, msg=failMsg ) 51 | p.sendline( 'exit' ) 52 | p.wait() 53 | 54 | if __name__ == '__main__': 55 | unittest.main() 56 | -------------------------------------------------------------------------------- /examples/test/test_multiping.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for multiping.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | from collections import defaultdict 10 | 11 | class testMultiPing( unittest.TestCase ): 12 | 13 | def testMultiPing( self ): 14 | """Verify that each target is pinged at least once, and 15 | that pings to 'real' targets are successful and unknown targets fail""" 16 | p = pexpect.spawn( 'python -m mininet.examples.multiping' ) 17 | opts = [ "Host (h\d+) \(([\d.]+)\) will be pinging ips: ([\d\. ]+)", 18 | "(h\d+): ([\d.]+) -> ([\d.]+) \d packets transmitted, (\d) received", 19 | pexpect.EOF ] 20 | pings = defaultdict( list ) 21 | while True: 22 | index = p.expect( opts ) 23 | if index == 0: 24 | name = p.match.group(1) 25 | ip = p.match.group(2) 26 | targets = p.match.group(3).split() 27 | pings[ name ] += targets 28 | elif index == 1: 29 | name = p.match.group(1) 30 | ip = p.match.group(2) 31 | target = p.match.group(3) 32 | received = int( p.match.group(4) ) 33 | if target == '10.0.0.200': 34 | self.assertEqual( received, 0 ) 35 | else: 36 | self.assertEqual( received, 1 ) 37 | try: 38 | pings[ name ].remove( target ) 39 | except: 40 | pass 41 | else: 42 | break 43 | self.assertTrue( len( pings ) > 0 ) 44 | for t in pings.values(): 45 | self.assertEqual( len( t ), 0 ) 46 | 47 | if __name__ == '__main__': 48 | unittest.main() 49 | -------------------------------------------------------------------------------- /examples/test/test_multipoll.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for multipoll.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testMultiPoll( unittest.TestCase ): 11 | 12 | def testMultiPoll( self ): 13 | "Verify that we receive one ping per second per host" 14 | p = pexpect.spawn( 'python -m mininet.examples.multipoll' ) 15 | opts = [ "\*\*\* (h\d) :" , 16 | "(h\d+): \d+ bytes from", 17 | "Monitoring output for (\d+) seconds", 18 | pexpect.EOF ] 19 | pings = {} 20 | while True: 21 | index = p.expect( opts ) 22 | if index == 0: 23 | name = p.match.group( 1 ) 24 | pings[ name ] = 0 25 | elif index == 1: 26 | name = p.match.group( 1 ) 27 | pings[ name ] += 1 28 | elif index == 2: 29 | seconds = int( p.match.group( 1 ) ) 30 | else: 31 | break 32 | self.assertTrue( len( pings ) > 0 ) 33 | # make sure we have received at least one ping per second 34 | for count in pings.values(): 35 | self.assertTrue( count >= seconds ) 36 | 37 | if __name__ == '__main__': 38 | unittest.main() 39 | -------------------------------------------------------------------------------- /examples/test/test_multitest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for multitest.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testMultiTest( unittest.TestCase ): 11 | 12 | prompt = 'mininet>' 13 | 14 | def testMultiTest( self ): 15 | "Verify pingall (0% dropped) and hX-eth0 interface for each host (ifconfig)" 16 | p = pexpect.spawn( 'python -m mininet.examples.multitest' ) 17 | p.expect( '(\d+)% dropped' ) 18 | dropped = int( p.match.group( 1 ) ) 19 | self.assertEqual( dropped, 0 ) 20 | ifCount = 0 21 | while True: 22 | index = p.expect( [ 'h\d-eth0', self.prompt ] ) 23 | if index == 0: 24 | ifCount += 1 25 | elif index == 1: 26 | p.sendline( 'exit' ) 27 | break 28 | p.wait() 29 | self.assertEqual( ifCount, 4 ) 30 | 31 | if __name__ == '__main__': 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /examples/test/test_nat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for nat.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | from mininet.util import quietRun 10 | 11 | destIP = '8.8.8.8' # Google DNS 12 | 13 | class testNAT( unittest.TestCase ): 14 | 15 | prompt = 'mininet>' 16 | 17 | @unittest.skipIf( '0 received' in quietRun( 'ping -c 1 %s' % destIP ), 18 | 'Destination IP is not reachable' ) 19 | def testNAT( self ): 20 | "Attempt to ping an IP on the Internet and verify 0% packet loss" 21 | p = pexpect.spawn( 'python -m mininet.examples.nat' ) 22 | p.expect( self.prompt ) 23 | p.sendline( 'h1 ping -c 1 %s' % destIP ) 24 | p.expect ( '(\d+)% packet loss' ) 25 | percent = int( p.match.group( 1 ) ) if p.match else -1 26 | p.expect( self.prompt ) 27 | p.sendline( 'exit' ) 28 | p.wait() 29 | self.assertEqual( percent, 0 ) 30 | 31 | if __name__ == '__main__': 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /examples/test/test_natnet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for natnet.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | from mininet.util import quietRun 10 | 11 | class testNATNet( unittest.TestCase ): 12 | 13 | prompt = 'mininet>' 14 | 15 | def setUp( self ): 16 | self.net = pexpect.spawn( 'python -m mininet.examples.natnet' ) 17 | self.net.expect( self.prompt ) 18 | 19 | def testPublicPing( self ): 20 | "Attempt to ping the public server (h0) from h1 and h2" 21 | self.net.sendline( 'h1 ping -c 1 h0' ) 22 | self.net.expect ( '(\d+)% packet loss' ) 23 | percent = int( self.net.match.group( 1 ) ) if self.net.match else -1 24 | self.assertEqual( percent, 0 ) 25 | self.net.expect( self.prompt ) 26 | 27 | self.net.sendline( 'h2 ping -c 1 h0' ) 28 | self.net.expect ( '(\d+)% packet loss' ) 29 | percent = int( self.net.match.group( 1 ) ) if self.net.match else -1 30 | self.assertEqual( percent, 0 ) 31 | self.net.expect( self.prompt ) 32 | 33 | def testPrivatePing( self ): 34 | "Attempt to ping h1 and h2 from public server" 35 | self.net.sendline( 'h0 ping -c 1 -t 1 h1' ) 36 | result = self.net.expect ( [ 'unreachable', 'loss' ] ) 37 | self.assertEqual( result, 0 ) 38 | self.net.expect( self.prompt ) 39 | 40 | self.net.sendline( 'h0 ping -c 1 -t 1 h2' ) 41 | result = self.net.expect ( [ 'unreachable', 'loss' ] ) 42 | self.assertEqual( result, 0 ) 43 | self.net.expect( self.prompt ) 44 | 45 | def testPrivateToPrivatePing( self ): 46 | "Attempt to ping from NAT'ed host h1 to NAT'ed host h2" 47 | self.net.sendline( 'h1 ping -c 1 -t 1 h2' ) 48 | result = self.net.expect ( [ '[Uu]nreachable', 'loss' ] ) 49 | self.assertEqual( result, 0 ) 50 | self.net.expect( self.prompt ) 51 | 52 | def tearDown( self ): 53 | self.net.sendline( 'exit' ) 54 | self.net.wait() 55 | 56 | if __name__ == '__main__': 57 | unittest.main() 58 | -------------------------------------------------------------------------------- /examples/test/test_numberedports.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for numberedports.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | from collections import defaultdict 10 | from mininet.node import OVSSwitch 11 | 12 | class testNumberedports( unittest.TestCase ): 13 | 14 | @unittest.skipIf( OVSSwitch.setup() or OVSSwitch.isOldOVS(), "old version of OVS" ) 15 | def testConsistency( self ): 16 | """verify consistency between mininet and ovs ports""" 17 | p = pexpect.spawn( 'python -m mininet.examples.numberedports' ) 18 | opts = [ 'Validating that s1-eth\d is actually on port \d ... Validated.', 19 | 'Validating that s1-eth\d is actually on port \d ... WARNING', 20 | pexpect.EOF ] 21 | correct_ports = True 22 | count = 0 23 | while True: 24 | index = p.expect( opts ) 25 | if index == 0: 26 | count += 1 27 | elif index == 1: 28 | correct_ports = False 29 | elif index == 2: 30 | self.assertNotEqual( 0, count ) 31 | break 32 | self.assertTrue( correct_ports ) 33 | 34 | def testNumbering( self ): 35 | """verify that all of the port numbers are printed correctly and consistent with their interface""" 36 | p = pexpect.spawn( 'python -m mininet.examples.numberedports' ) 37 | opts = [ 's1-eth(\d+) : (\d+)', 38 | pexpect.EOF ] 39 | count_intfs = 0 40 | while True: 41 | index = p.expect( opts ) 42 | if index == 0: 43 | count_intfs += 1 44 | intfport = p.match.group( 1 ) 45 | ofport = p.match.group( 2 ) 46 | self.assertEqual( intfport, ofport ) 47 | elif index == 1: 48 | break 49 | self.assertNotEqual( 0, count_intfs ) 50 | 51 | if __name__ == '__main__': 52 | unittest.main() 53 | -------------------------------------------------------------------------------- /examples/test/test_popen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for popen.py and popenpoll.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testPopen( unittest.TestCase ): 11 | 12 | def pingTest( self, name ): 13 | "Verify that there are no dropped packets for each host" 14 | p = pexpect.spawn( 'python -m %s' % name ) 15 | opts = [ "<(h\d+)>: PING ", 16 | "<(h\d+)>: (\d+) packets transmitted, (\d+) received", 17 | pexpect.EOF ] 18 | pings = {} 19 | while True: 20 | index = p.expect( opts ) 21 | if index == 0: 22 | name = p.match.group(1) 23 | pings[ name ] = 0 24 | elif index == 1: 25 | name = p.match.group(1) 26 | transmitted = p.match.group(2) 27 | received = p.match.group(3) 28 | # verify no dropped packets 29 | self.assertEqual( received, transmitted ) 30 | pings[ name ] += 1 31 | else: 32 | break 33 | self.assertTrue( len(pings) > 0 ) 34 | # verify that each host has gotten results 35 | for count in pings.values(): 36 | self.assertEqual( count, 1 ) 37 | 38 | def testPopen( self ): 39 | self.pingTest( 'mininet.examples.popen' ) 40 | 41 | def testPopenPoll( self ): 42 | self.pingTest( 'mininet.examples.popenpoll' ) 43 | 44 | if __name__ == '__main__': 45 | unittest.main() 46 | -------------------------------------------------------------------------------- /examples/test/test_scratchnet.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for scratchnet.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | 10 | class testScratchNet( unittest.TestCase ): 11 | 12 | opts = [ "1 packets transmitted, 1 received, 0% packet loss", pexpect.EOF ] 13 | 14 | def pingTest( self, name ): 15 | "Verify that no ping packets were dropped" 16 | p = pexpect.spawn( 'python -m %s' % name ) 17 | index = p.expect( self.opts ) 18 | self.assertEqual( index, 0 ) 19 | 20 | def testPingKernel( self ): 21 | self.pingTest( 'mininet.examples.scratchnet' ) 22 | 23 | def testPingUser( self ): 24 | self.pingTest( 'mininet.examples.scratchnetuser' ) 25 | 26 | if __name__ == '__main__': 27 | unittest.main() 28 | -------------------------------------------------------------------------------- /examples/test/test_simpleperf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for simpleperf.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | from mininet.log import setLogLevel 11 | 12 | from mininet.examples.simpleperf import SingleSwitchTopo 13 | 14 | class testSimplePerf( unittest.TestCase ): 15 | 16 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 17 | def testE2E( self ): 18 | "Run the example and verify iperf results" 19 | # 10 Mb/s, plus or minus 20% tolerance 20 | BW = 10 21 | TOLERANCE = .2 22 | p = pexpect.spawn( 'python -m mininet.examples.simpleperf testmode' ) 23 | # check iperf results 24 | p.expect( "Results: \['10M', '([\d\.]+) .bits/sec", timeout=480 ) 25 | measuredBw = float( p.match.group( 1 ) ) 26 | lowerBound = BW * ( 1 - TOLERANCE ) 27 | upperBound = BW + ( 1 + TOLERANCE ) 28 | self.assertGreaterEqual( measuredBw, lowerBound ) 29 | self.assertLessEqual( measuredBw, upperBound ) 30 | p.wait() 31 | 32 | if __name__ == '__main__': 33 | setLogLevel( 'warning' ) 34 | unittest.main() 35 | -------------------------------------------------------------------------------- /examples/test/test_sshd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for sshd.py 5 | """ 6 | 7 | from __future__ import print_function 8 | import unittest 9 | import pexpect 10 | from mininet.clean import sh 11 | 12 | class testSSHD( unittest.TestCase ): 13 | 14 | opts = [ '\(yes/no\)\?', 'refused', 'Welcome|\$|#', pexpect.EOF, pexpect.TIMEOUT ] 15 | 16 | def connected( self, ip ): 17 | "Log into ssh server, check banner, then exit" 18 | # Note: this test will fail if "Welcome" is not in the sshd banner 19 | # and '#'' or '$'' are not in the prompt 20 | p = pexpect.spawn( 'ssh -i /tmp/ssh/test_rsa %s' % ip, timeout=10 ) 21 | while True: 22 | index = p.expect( self.opts ) 23 | if index == 0: 24 | print( p.match.group(0) ) 25 | p.sendline( 'yes' ) 26 | elif index == 1: 27 | return False 28 | elif index == 2: 29 | p.sendline( 'exit' ) 30 | p.wait() 31 | return True 32 | else: 33 | return False 34 | 35 | def setUp( self ): 36 | # create public key pair for testing 37 | sh( 'rm -rf /tmp/ssh' ) 38 | sh( 'mkdir /tmp/ssh' ) 39 | sh( "ssh-keygen -t rsa -P '' -f /tmp/ssh/test_rsa" ) 40 | sh( 'cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys' ) 41 | cmd = ( 'python -m mininet.examples.sshd -D ' 42 | '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys ' 43 | '-o StrictModes=no -o UseDNS=no -u0' ) 44 | # run example with custom sshd args 45 | self.net = pexpect.spawn( cmd ) 46 | self.net.expect( 'mininet>' ) 47 | 48 | def testSSH( self ): 49 | "Verify that we can ssh into all hosts (h1 to h4)" 50 | for h in range( 1, 5 ): 51 | self.assertTrue( self.connected( '10.0.0.%d' % h ) ) 52 | 53 | def tearDown( self ): 54 | self.net.sendline( 'exit' ) 55 | self.net.wait() 56 | # remove public key pair 57 | sh( 'rm -rf /tmp/ssh' ) 58 | 59 | if __name__ == '__main__': 60 | unittest.main() 61 | 62 | -------------------------------------------------------------------------------- /examples/test/test_tree1024.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for tree1024.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | 11 | class testTree1024( unittest.TestCase ): 12 | 13 | prompt = 'mininet>' 14 | 15 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 16 | def testTree1024( self ): 17 | "Run the example and do a simple ping test from h1 to h1024" 18 | p = pexpect.spawn( 'python -m mininet.examples.tree1024' ) 19 | p.expect( self.prompt, timeout=6000 ) # it takes awhile to set up 20 | p.sendline( 'h1 ping -c 20 h1024' ) 21 | p.expect ( '(\d+)% packet loss' ) 22 | packetLossPercent = int( p.match.group( 1 ) ) if p.match else -1 23 | p.expect( self.prompt ) 24 | p.sendline( 'exit' ) 25 | p.wait() 26 | # Tolerate slow startup on some systems - we should revisit this 27 | # and determine the root cause. 28 | self.assertLess( packetLossPercent, 60 ) 29 | 30 | if __name__ == '__main__': 31 | unittest.main() 32 | -------------------------------------------------------------------------------- /examples/test/test_treeping64.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for treeping64.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | 11 | class testTreePing64( unittest.TestCase ): 12 | 13 | prompt = 'mininet>' 14 | 15 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 16 | def testTreePing64( self ): 17 | "Run the example and verify ping results" 18 | p = pexpect.spawn( 'python -m mininet.examples.treeping64' ) 19 | p.expect( 'Tree network ping results:', timeout=6000 ) 20 | count = 0 21 | while True: 22 | index = p.expect( [ '(\d+)% packet loss', pexpect.EOF ] ) 23 | if index == 0: 24 | percent = int( p.match.group( 1 ) ) if p.match else -1 25 | self.assertEqual( percent, 0 ) 26 | count += 1 27 | else: 28 | break 29 | self.assertTrue( count > 0 ) 30 | 31 | if __name__ == '__main__': 32 | unittest.main() 33 | -------------------------------------------------------------------------------- /examples/test/test_vlanhost.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Test for vlanhost.py 5 | """ 6 | 7 | import unittest 8 | import pexpect 9 | import sys 10 | from mininet.util import quietRun 11 | 12 | class testVLANHost( unittest.TestCase ): 13 | 14 | prompt = 'mininet>' 15 | 16 | @unittest.skipIf( '-quick' in sys.argv, 'long test' ) 17 | def testVLANTopo( self ): 18 | "Test connectivity (or lack thereof) between hosts in VLANTopo" 19 | p = pexpect.spawn( 'python -m mininet.examples.vlanhost' ) 20 | p.expect( self.prompt ) 21 | p.sendline( 'pingall 1' ) #ping timeout=1 22 | p.expect( '(\d+)% dropped', timeout=30 ) # there should be 24 failed pings 23 | percent = int( p.match.group( 1 ) ) if p.match else -1 24 | p.expect( self.prompt ) 25 | p.sendline( 'exit' ) 26 | p.wait() 27 | self.assertEqual( percent, 80 ) 28 | 29 | def testSpecificVLAN( self ): 30 | "Test connectivity between hosts on a specific VLAN" 31 | vlan = 1001 32 | p = pexpect.spawn( 'python -m mininet.examples.vlanhost %d' % vlan ) 33 | p.expect( self.prompt ) 34 | 35 | p.sendline( 'h1 ping -c 1 h2' ) 36 | p.expect ( '(\d+)% packet loss' ) 37 | percent = int( p.match.group( 1 ) ) if p.match else -1 38 | p.expect( self.prompt ) 39 | 40 | p.sendline( 'h1 ifconfig' ) 41 | i = p.expect( ['h1-eth0.%d' % vlan, pexpect.TIMEOUT ], timeout=2 ) 42 | p.expect( self.prompt ) 43 | 44 | p.sendline( 'exit' ) 45 | p.wait() 46 | self.assertEqual( percent, 0 ) # no packet loss on ping 47 | self.assertEqual( i, 0 ) # check vlan intf is present 48 | 49 | if __name__ == '__main__': 50 | unittest.main() 51 | -------------------------------------------------------------------------------- /examples/tree1024.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Create a 1024-host network, and run the CLI on it. 5 | If this fails because of kernel limits, you may have 6 | to adjust them, e.g. by adding entries to /etc/sysctl.conf 7 | and running sysctl -p. Check util/sysctl_addon. 8 | """ 9 | 10 | from mininet.cli import CLI 11 | from mininet.log import setLogLevel 12 | from mininet.node import OVSSwitch 13 | from mininet.topolib import TreeNet 14 | 15 | if __name__ == '__main__': 16 | setLogLevel( 'info' ) 17 | network = TreeNet( depth=2, fanout=32, switch=OVSSwitch ) 18 | network.run( CLI, network ) 19 | -------------------------------------------------------------------------------- /examples/treeping64.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | "Create a 64-node tree network, and test connectivity using ping." 4 | 5 | from __future__ import print_function 6 | 7 | from mininet.log import setLogLevel 8 | from mininet.node import UserSwitch, OVSKernelSwitch # , KernelSwitch 9 | from mininet.topolib import TreeNet 10 | 11 | def treePing64(): 12 | "Run ping test on 64-node tree networks." 13 | 14 | results = {} 15 | switches = { # 'reference kernel': KernelSwitch, 16 | 'reference user': UserSwitch, 17 | 'Open vSwitch kernel': OVSKernelSwitch } 18 | 19 | for name in switches: 20 | print( "*** Testing", name, "datapath" ) 21 | switch = switches[ name ] 22 | network = TreeNet( depth=2, fanout=8, switch=switch ) 23 | result = network.run( network.pingAll ) 24 | results[ name ] = result 25 | 26 | print() 27 | print( "*** Tree network ping results:" ) 28 | for name in switches: 29 | print( "%s: %d%% packet loss" % ( name, results[ name ] ) ) 30 | print() 31 | 32 | if __name__ == '__main__': 33 | setLogLevel( 'info' ) 34 | treePing64() 35 | -------------------------------------------------------------------------------- /examples/vlanhost.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | vlanhost.py: Host subclass that uses a VLAN tag for the default interface. 4 | 5 | Dependencies: 6 | This class depends on the "vlan" package 7 | $ sudo apt-get install vlan 8 | 9 | Usage (example uses VLAN ID=1000): 10 | From the command line: 11 | sudo mn --custom vlanhost.py --host vlan,vlan=1000 12 | 13 | From a script (see exampleUsage function below): 14 | from functools import partial 15 | from vlanhost import VLANHost 16 | 17 | .... 18 | 19 | host = partial( VLANHost, vlan=1000 ) 20 | net = Mininet( host=host, ... ) 21 | 22 | Directly running this script: 23 | sudo python vlanhost.py 1000 24 | 25 | """ 26 | 27 | from mininet.node import Host 28 | from mininet.topo import Topo 29 | from mininet.util import quietRun 30 | from mininet.log import error 31 | 32 | class VLANHost( Host ): 33 | "Host connected to VLAN interface" 34 | 35 | def config( self, vlan=100, **params ): 36 | """Configure VLANHost according to (optional) parameters: 37 | vlan: VLAN ID for default interface""" 38 | 39 | r = super( VLANHost, self ).config( **params ) 40 | 41 | intf = self.defaultIntf() 42 | # remove IP from default, "physical" interface 43 | self.cmd( 'ifconfig %s inet 0' % intf ) 44 | # create VLAN interface 45 | self.cmd( 'vconfig add %s %d' % ( intf, vlan ) ) 46 | # assign the host's IP to the VLAN interface 47 | self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) ) 48 | # update the intf name and host's intf map 49 | newName = '%s.%d' % ( intf, vlan ) 50 | # update the (Mininet) interface to refer to VLAN interface name 51 | intf.name = newName 52 | # add VLAN interface to host's name to intf map 53 | self.nameToIntf[ newName ] = intf 54 | 55 | return r 56 | 57 | hosts = { 'vlan': VLANHost } 58 | 59 | 60 | def exampleAllHosts( vlan ): 61 | """Simple example of how VLANHost can be used in a script""" 62 | # This is where the magic happens... 63 | host = partial( VLANHost, vlan=vlan ) 64 | # vlan (type: int): VLAN ID to be used by all hosts 65 | 66 | # Start a basic network using our VLANHost 67 | topo = SingleSwitchTopo( k=2 ) 68 | net = Mininet( host=host, topo=topo ) 69 | net.start() 70 | CLI( net ) 71 | net.stop() 72 | 73 | # pylint: disable=arguments-differ 74 | 75 | class VLANStarTopo( Topo ): 76 | """Example topology that uses host in multiple VLANs 77 | 78 | The topology has a single switch. There are k VLANs with 79 | n hosts in each, all connected to the single switch. There 80 | are also n hosts that are not in any VLAN, also connected to 81 | the switch.""" 82 | 83 | def build( self, k=2, n=2, vlanBase=100 ): 84 | s1 = self.addSwitch( 's1' ) 85 | for i in range( k ): 86 | vlan = vlanBase + i 87 | for j in range(n): 88 | name = 'h%d-%d' % ( j+1, vlan ) 89 | h = self.addHost( name, cls=VLANHost, vlan=vlan ) 90 | self.addLink( h, s1 ) 91 | for j in range( n ): 92 | h = self.addHost( 'h%d' % (j+1) ) 93 | self.addLink( h, s1 ) 94 | 95 | 96 | def exampleCustomTags(): 97 | """Simple example that exercises VLANStarTopo""" 98 | 99 | net = Mininet( topo=VLANStarTopo() ) 100 | net.start() 101 | CLI( net ) 102 | net.stop() 103 | 104 | if __name__ == '__main__': 105 | import sys 106 | from functools import partial 107 | 108 | from mininet.net import Mininet 109 | from mininet.cli import CLI 110 | from mininet.topo import SingleSwitchTopo 111 | from mininet.log import setLogLevel 112 | 113 | setLogLevel( 'info' ) 114 | 115 | if not quietRun( 'which vconfig' ): 116 | error( "Cannot find command 'vconfig'\nThe package", 117 | "'vlan' is required in Ubuntu or Debian,", 118 | "or 'vconfig' in Fedora\n" ) 119 | exit() 120 | 121 | if len( sys.argv ) >= 2: 122 | exampleAllHosts( vlan=int( sys.argv[ 1 ] ) ) 123 | else: 124 | exampleCustomTags() 125 | -------------------------------------------------------------------------------- /mininet/__init__.py: -------------------------------------------------------------------------------- 1 | "Docstring to silence pylint; ignores --ignore option for __init__.py" 2 | -------------------------------------------------------------------------------- /mininet/clean.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mininet Cleanup 3 | author: Bob Lantz (rlantz@cs.stanford.edu) 4 | 5 | Unfortunately, Mininet and OpenFlow (and the Linux kernel) 6 | don't always clean up properly after themselves. Until they do 7 | (or until cleanup functionality is integrated into the Python 8 | code), this script may be used to get rid of unwanted garbage. 9 | It may also get rid of 'false positives', but hopefully 10 | nothing irreplaceable! 11 | """ 12 | 13 | from subprocess import ( Popen, PIPE, check_output as co, 14 | CalledProcessError ) 15 | import time 16 | 17 | from mininet.log import info 18 | from mininet.term import cleanUpScreens 19 | 20 | 21 | def sh( cmd ): 22 | "Print a command and send it to the shell" 23 | info( cmd + '\n' ) 24 | return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ] 25 | 26 | def killprocs( pattern ): 27 | "Reliably terminate processes matching a pattern (including args)" 28 | sh( 'pkill -9 -f %s' % pattern ) 29 | # Make sure they are gone 30 | while True: 31 | try: 32 | pids = co( [ 'pgrep', '-f', pattern ] ) 33 | except CalledProcessError: 34 | pids = '' 35 | if pids: 36 | sh( 'pkill -9 -f %s' % pattern ) 37 | time.sleep( .5 ) 38 | else: 39 | break 40 | 41 | class Cleanup( object ): 42 | "Wrapper for cleanup()" 43 | 44 | callbacks = [] 45 | 46 | @classmethod 47 | def cleanup( cls): 48 | """Clean up junk which might be left over from old runs; 49 | do fast stuff before slow dp and link removal!""" 50 | 51 | info( "*** Removing excess controllers/ofprotocols/ofdatapaths/" 52 | "pings/noxes\n" ) 53 | zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core ' 54 | zombies += 'ovs-openflowd ovs-controller udpbwtest mnexec ivs' 55 | # Note: real zombie processes can't actually be killed, since they 56 | # are already (un)dead. Then again, 57 | # you can't connect to them either, so they're mostly harmless. 58 | # Send SIGTERM first to give processes a chance to shutdown cleanly. 59 | sh( 'killall ' + zombies + ' 2> /dev/null' ) 60 | time.sleep( 1 ) 61 | sh( 'killall -9 ' + zombies + ' 2> /dev/null' ) 62 | 63 | # And kill off sudo mnexec 64 | sh( 'pkill -9 -f "sudo mnexec"') 65 | 66 | info( "*** Removing junk from /tmp\n" ) 67 | sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' ) 68 | 69 | info( "*** Removing old X11 tunnels\n" ) 70 | cleanUpScreens() 71 | 72 | info( "*** Removing excess kernel datapaths\n" ) 73 | dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" 74 | ).splitlines() 75 | for dp in dps: 76 | if dp: 77 | sh( 'dpctl deldp ' + dp ) 78 | 79 | info( "*** Removing OVS datapaths\n" ) 80 | dps = sh("ovs-vsctl --timeout=1 list-br").strip().splitlines() 81 | if dps: 82 | sh( "ovs-vsctl " + " -- ".join( "--if-exists del-br " + dp 83 | for dp in dps if dp ) ) 84 | # And in case the above didn't work... 85 | dps = sh( "ovs-vsctl --timeout=1 list-br" ).strip().splitlines() 86 | for dp in dps: 87 | sh( 'ovs-vsctl del-br ' + dp ) 88 | 89 | info( "*** Removing all links of the pattern foo-ethX\n" ) 90 | links = sh( "ip link show | " 91 | "egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'" 92 | ).splitlines() 93 | # Delete blocks of links 94 | n = 1000 # chunk size 95 | for i in range( 0, len( links ), n ): 96 | cmd = ';'.join( 'ip link del %s' % link 97 | for link in links[ i : i + n ] ) 98 | sh( '( %s ) 2> /dev/null' % cmd ) 99 | 100 | if 'tap9' in sh( 'ip link show' ): 101 | info( "*** Removing tap9 - assuming it's from cluster edition\n" ) 102 | sh( 'ip link del tap9' ) 103 | 104 | info( "*** Killing stale mininet node processes\n" ) 105 | killprocs( 'mininet:' ) 106 | 107 | info( "*** Shutting down stale tunnels\n" ) 108 | killprocs( 'Tunnel=Ethernet' ) 109 | killprocs( '.ssh/mn') 110 | sh( 'rm -f ~/.ssh/mn/*' ) 111 | 112 | # Call any additional cleanup code if necessary 113 | for callback in cls.callbacks: 114 | callback() 115 | 116 | info( "*** Cleanup complete.\n" ) 117 | 118 | @classmethod 119 | def addCleanupCallback( cls, callback ): 120 | "Add cleanup callback" 121 | if callback not in cls.callbacks: 122 | cls.callbacks.append( callback ) 123 | 124 | 125 | cleanup = Cleanup.cleanup 126 | addCleanupCallback = Cleanup.addCleanupCallback 127 | -------------------------------------------------------------------------------- /mininet/examples: -------------------------------------------------------------------------------- 1 | ../examples -------------------------------------------------------------------------------- /mininet/moduledeps.py: -------------------------------------------------------------------------------- 1 | "Module dependency utility functions for Mininet." 2 | 3 | from mininet.util import quietRun 4 | from mininet.log import info, error, debug 5 | from os import environ 6 | 7 | def lsmod(): 8 | "Return output of lsmod." 9 | return quietRun( 'lsmod' ) 10 | 11 | def rmmod( mod ): 12 | """Return output of lsmod. 13 | mod: module string""" 14 | return quietRun( [ 'rmmod', mod ] ) 15 | 16 | def modprobe( mod ): 17 | """Return output of modprobe 18 | mod: module string""" 19 | return quietRun( [ 'modprobe', mod ] ) 20 | 21 | OF_KMOD = 'ofdatapath' 22 | OVS_KMOD = 'openvswitch_mod' # Renamed 'openvswitch' in OVS 1.7+/Linux 3.5+ 23 | TUN = 'tun' 24 | 25 | def moduleDeps( subtract=None, add=None ): 26 | """Handle module dependencies. 27 | subtract: string or list of module names to remove, if already loaded 28 | add: string or list of module names to add, if not already loaded""" 29 | subtract = subtract if subtract is not None else [] 30 | add = add if add is not None else [] 31 | if type( subtract ) is str: 32 | subtract = [ subtract ] 33 | if type( add ) is str: 34 | add = [ add ] 35 | for mod in subtract: 36 | if mod in lsmod(): 37 | info( '*** Removing ' + mod + '\n' ) 38 | rmmodOutput = rmmod( mod ) 39 | if rmmodOutput: 40 | error( 'Error removing ' + mod + ': "%s">\n' % rmmodOutput ) 41 | exit( 1 ) 42 | if mod in lsmod(): 43 | error( 'Failed to remove ' + mod + '; still there!\n' ) 44 | exit( 1 ) 45 | for mod in add: 46 | if mod not in lsmod(): 47 | info( '*** Loading ' + mod + '\n' ) 48 | modprobeOutput = modprobe( mod ) 49 | if modprobeOutput: 50 | error( 'Error inserting ' + mod + 51 | ' - is it installed and available via modprobe?\n' + 52 | 'Error was: "%s"\n' % modprobeOutput ) 53 | if mod not in lsmod(): 54 | error( 'Failed to insert ' + mod + ' - quitting.\n' ) 55 | exit( 1 ) 56 | else: 57 | debug( '*** ' + mod + ' already loaded\n' ) 58 | 59 | 60 | def pathCheck( *args, **kwargs ): 61 | "Make sure each program in *args can be found in $PATH." 62 | moduleName = kwargs.get( 'moduleName', 'it' ) 63 | for arg in args: 64 | if not quietRun( 'which ' + arg ): 65 | error( 'Cannot find required executable %s.\n' % arg + 66 | 'Please make sure that %s is installed ' % moduleName + 67 | 'and available in your $PATH:\n(%s)\n' % environ[ 'PATH' ] ) 68 | exit( 1 ) 69 | -------------------------------------------------------------------------------- /mininet/term.py: -------------------------------------------------------------------------------- 1 | """ 2 | Terminal creation and cleanup. 3 | Utility functions to run a term (connected via screen(1)) on each host. 4 | 5 | Requires GNU screen(1) and xterm(1). 6 | Optionally uses gnome-terminal. 7 | """ 8 | 9 | import re 10 | from subprocess import Popen 11 | 12 | from mininet.log import error 13 | from mininet.util import quietRun 14 | 15 | def quoteArg( arg ): 16 | "Quote an argument if it contains spaces." 17 | return repr( arg ) if ' ' in arg else arg 18 | 19 | def makeTerm( node, title='Node', term='xterm' ): 20 | """Run screen on a node, and hook up a terminal. 21 | node: Node object 22 | title: base title 23 | term: 'xterm' or 'gterm' 24 | returns: process created""" 25 | title += ': ' + node.name 26 | if not node.inNamespace: 27 | title += ' (root)' 28 | cmds = { 29 | 'xterm': [ 'xterm', '-title', title, '-e' ], 30 | 'gterm': [ 'gnome-terminal', '--title', title, '-e' ] 31 | } 32 | if term not in cmds: 33 | error( 'invalid terminal type: %s' % term ) 34 | return 35 | if not node.execed: 36 | node.cmd( 'screen -dmS ' + 'mininet.' + node.name) 37 | args = [ 'screen', '-D', '-RR', '-S', 'mininet.' + node.name ] 38 | else: 39 | args = [ 'sh', '-c', 'exec tail -f /tmp/' + node.name + '*.log' ] 40 | if term == 'gterm': 41 | # Compress these for gnome-terminal, which expects one token 42 | # to follow the -e option 43 | args = [ ' '.join( [ quoteArg( arg ) for arg in args ] ) ] 44 | return Popen( cmds[ term ] + args ) 45 | 46 | def cleanUpScreens(): 47 | "Remove moldy old screen sessions." 48 | r = r'(\d+\.mininet\.[hsc]\d+)' 49 | output = quietRun( 'screen -ls' ).split( '\n' ) 50 | for line in output: 51 | m = re.search( r, line ) 52 | if m: 53 | quietRun( 'screen -S ' + m.group( 1 ) + ' -X quit' ) 54 | 55 | def makeTerms( nodes, title='Node', term='xterm' ): 56 | """Create terminals. 57 | nodes: list of Node objects 58 | title: base title for each 59 | returns: list of created terminal processes""" 60 | return [ makeTerm( node, title, term ) for node in nodes ] 61 | -------------------------------------------------------------------------------- /mininet/test/runner.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Run all mininet core tests 5 | -v : verbose output 6 | -quick : skip tests that take more than ~30 seconds 7 | """ 8 | 9 | from unittest import defaultTestLoader, TextTestRunner 10 | import os 11 | import sys 12 | from mininet.util import ensureRoot 13 | from mininet.clean import cleanup 14 | from mininet.log import setLogLevel 15 | 16 | def runTests( testDir, verbosity=1 ): 17 | "discover and run all tests in testDir" 18 | # ensure root and cleanup before starting tests 19 | ensureRoot() 20 | cleanup() 21 | # discover all tests in testDir 22 | testSuite = defaultTestLoader.discover( testDir ) 23 | # run tests 24 | TextTestRunner( verbosity=verbosity ).run( testSuite ) 25 | 26 | if __name__ == '__main__': 27 | setLogLevel( 'warning' ) 28 | # get the directory containing example tests 29 | thisdir = os.path.dirname( os.path.realpath( __file__ ) ) 30 | vlevel = 2 if '-v' in sys.argv else 1 31 | runTests( testDir=thisdir, verbosity=vlevel ) 32 | -------------------------------------------------------------------------------- /mininet/test/test_nets.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Package: mininet 4 | Test creation and all-pairs ping for each included mininet topo type.""" 5 | 6 | import unittest 7 | import sys 8 | from functools import partial 9 | 10 | from mininet.net import Mininet 11 | from mininet.node import Host, Controller 12 | from mininet.node import UserSwitch, OVSSwitch, IVSSwitch 13 | from mininet.topo import SingleSwitchTopo, LinearTopo 14 | from mininet.log import setLogLevel 15 | from mininet.util import quietRun 16 | from mininet.clean import cleanup 17 | 18 | # Tell pylint not to complain about calls to other class 19 | # pylint: disable=E1101 20 | 21 | class testSingleSwitchCommon( object ): 22 | "Test ping with single switch topology (common code)." 23 | 24 | switchClass = None # overridden in subclasses 25 | 26 | @staticmethod 27 | def tearDown(): 28 | "Clean up if necessary" 29 | if sys.exc_info != ( None, None, None ): 30 | cleanup() 31 | 32 | def testMinimal( self ): 33 | "Ping test on minimal topology" 34 | mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller, 35 | waitConnected=True ) 36 | dropped = mn.run( mn.ping ) 37 | self.assertEqual( dropped, 0 ) 38 | 39 | def testSingle5( self ): 40 | "Ping test on 5-host single-switch topology" 41 | mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host, 42 | Controller, waitConnected=True ) 43 | dropped = mn.run( mn.ping ) 44 | self.assertEqual( dropped, 0 ) 45 | 46 | # pylint: enable=E1101 47 | 48 | class testSingleSwitchOVSKernel( testSingleSwitchCommon, unittest.TestCase ): 49 | "Test ping with single switch topology (OVS kernel switch)." 50 | switchClass = OVSSwitch 51 | 52 | class testSingleSwitchOVSUser( testSingleSwitchCommon, unittest.TestCase ): 53 | "Test ping with single switch topology (OVS user switch)." 54 | switchClass = partial( OVSSwitch, datapath='user' ) 55 | 56 | @unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' ) 57 | class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ): 58 | "Test ping with single switch topology (IVS switch)." 59 | switchClass = IVSSwitch 60 | 61 | @unittest.skipUnless( quietRun( 'which ofprotocol' ), 62 | 'Reference user switch is not installed' ) 63 | class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ): 64 | "Test ping with single switch topology (Userspace switch)." 65 | switchClass = UserSwitch 66 | 67 | 68 | # Tell pylint not to complain about calls to other class 69 | # pylint: disable=E1101 70 | 71 | class testLinearCommon( object ): 72 | "Test all-pairs ping with LinearNet (common code)." 73 | 74 | switchClass = None # overridden in subclasses 75 | 76 | def testLinear5( self ): 77 | "Ping test on a 5-switch topology" 78 | mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host, 79 | Controller, waitConnected=True ) 80 | dropped = mn.run( mn.ping ) 81 | self.assertEqual( dropped, 0 ) 82 | 83 | # pylint: enable=E1101 84 | 85 | 86 | class testLinearOVSKernel( testLinearCommon, unittest.TestCase ): 87 | "Test all-pairs ping with LinearNet (OVS kernel switch)." 88 | switchClass = OVSSwitch 89 | 90 | class testLinearOVSUser( testLinearCommon, unittest.TestCase ): 91 | "Test all-pairs ping with LinearNet (OVS user switch)." 92 | switchClass = partial( OVSSwitch, datapath='user' ) 93 | 94 | @unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' ) 95 | class testLinearIVS( testLinearCommon, unittest.TestCase ): 96 | "Test all-pairs ping with LinearNet (IVS switch)." 97 | switchClass = IVSSwitch 98 | 99 | @unittest.skipUnless( quietRun( 'which ofprotocol' ), 100 | 'Reference user switch is not installed' ) 101 | class testLinearUserspace( testLinearCommon, unittest.TestCase ): 102 | "Test all-pairs ping with LinearNet (Userspace switch)." 103 | switchClass = UserSwitch 104 | 105 | 106 | if __name__ == '__main__': 107 | setLogLevel( 'warning' ) 108 | unittest.main() 109 | -------------------------------------------------------------------------------- /mininet/test/test_switchdpidassignment.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """Package: mininet 4 | Regression tests for switch dpid assignment.""" 5 | 6 | import unittest 7 | import sys 8 | 9 | from mininet.net import Mininet 10 | from mininet.node import Host, Controller 11 | from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch ) 12 | from mininet.topo import Topo 13 | from mininet.log import setLogLevel 14 | from mininet.util import quietRun 15 | from mininet.clean import cleanup 16 | 17 | 18 | class TestSwitchDpidAssignmentOVS( unittest.TestCase ): 19 | "Verify Switch dpid assignment." 20 | 21 | switchClass = OVSSwitch # overridden in subclasses 22 | 23 | def tearDown( self ): 24 | "Clean up if necessary" 25 | # satisfy pylint 26 | assert self 27 | if sys.exc_info != ( None, None, None ): 28 | cleanup() 29 | 30 | def testDefaultDpid( self ): 31 | """Verify that the default dpid is assigned using a valid provided 32 | canonical switchname if no dpid is passed in switch creation.""" 33 | switch = Mininet( Topo(), 34 | self.switchClass, 35 | Host, Controller ).addSwitch( 's1' ) 36 | self.assertEqual( switch.defaultDpid(), switch.dpid ) 37 | 38 | def dpidFrom( self, num ): 39 | "Compute default dpid from number" 40 | fmt = ( '%0' + str( self.switchClass.dpidLen ) + 'x' ) 41 | return fmt % num 42 | 43 | def testActualDpidAssignment( self ): 44 | """Verify that Switch dpid is the actual dpid assigned if dpid is 45 | passed in switch creation.""" 46 | dpid = self.dpidFrom( 0xABCD ) 47 | switch = Mininet( Topo(), self.switchClass, 48 | Host, Controller ).addSwitch( 49 | 's1', dpid=dpid ) 50 | self.assertEqual( switch.dpid, dpid ) 51 | 52 | def testDefaultDpidAssignmentFailure( self ): 53 | """Verify that Default dpid assignment raises an Exception if the 54 | name of the switch does not contin a digit. Also verify the 55 | exception message.""" 56 | with self.assertRaises( Exception ) as raises_cm: 57 | Mininet( Topo(), self.switchClass, 58 | Host, Controller ).addSwitch( 'A' ) 59 | self.assertEqual(raises_cm.exception.message, 'Unable to derive ' 60 | 'default datapath ID - please either specify a dpid ' 61 | 'or use a canonical switch name such as s23.') 62 | 63 | def testDefaultDpidLen( self ): 64 | """Verify that Default dpid length is 16 characters consisting of 65 | 16 - len(hex of first string of contiguous digits passed in switch 66 | name) 0's followed by hex of first string of contiguous digits passed 67 | in switch name.""" 68 | switch = Mininet( Topo(), self.switchClass, 69 | Host, Controller ).addSwitch( 's123' ) 70 | 71 | self.assertEqual( switch.dpid, self.dpidFrom( 123 ) ) 72 | 73 | class OVSUser( OVSSwitch): 74 | "OVS User Switch convenience class" 75 | def __init__( self, *args, **kwargs ): 76 | kwargs.update( datapath='user' ) 77 | OVSSwitch.__init__( self, *args, **kwargs ) 78 | 79 | class testSwitchOVSUser( TestSwitchDpidAssignmentOVS ): 80 | "Test dpid assignnment of OVS User Switch." 81 | switchClass = OVSUser 82 | 83 | @unittest.skipUnless( quietRun( 'which ivs-ctl' ), 84 | 'IVS switch is not installed' ) 85 | class testSwitchIVS( TestSwitchDpidAssignmentOVS ): 86 | "Test dpid assignment of IVS switch." 87 | switchClass = IVSSwitch 88 | 89 | @unittest.skipUnless( quietRun( 'which ofprotocol' ), 90 | 'Reference user switch is not installed' ) 91 | class testSwitchUserspace( TestSwitchDpidAssignmentOVS ): 92 | "Test dpid assignment of Userspace switch." 93 | switchClass = UserSwitch 94 | 95 | if __name__ == '__main__': 96 | setLogLevel( 'warning' ) 97 | unittest.main() 98 | -------------------------------------------------------------------------------- /mininet/topolib.py: -------------------------------------------------------------------------------- 1 | "Library of potentially useful topologies for Mininet" 2 | 3 | from mininet.topo import Topo 4 | from mininet.net import Mininet 5 | 6 | class TreeTopo( Topo ): 7 | "Topology for a tree network with a given depth and fanout." 8 | 9 | def __init__( self, depth=1, fanout=2 ): 10 | super( TreeTopo, self ).__init__() 11 | # Numbering: h1..N, s1..M 12 | self.hostNum = 1 13 | self.switchNum = 1 14 | # Build topology 15 | self.addTree( depth, fanout ) 16 | 17 | def addTree( self, depth, fanout ): 18 | """Add a subtree starting with node n. 19 | returns: last node added""" 20 | isSwitch = depth > 0 21 | if isSwitch: 22 | node = self.addSwitch( 's%s' % self.switchNum ) 23 | self.switchNum += 1 24 | for _ in range( fanout ): 25 | child = self.addTree( depth - 1, fanout ) 26 | self.addLink( node, child ) 27 | else: 28 | node = self.addHost( 'h%s' % self.hostNum ) 29 | self.hostNum += 1 30 | return node 31 | 32 | 33 | def TreeNet( depth=1, fanout=2, **kwargs ): 34 | "Convenience function for creating tree networks." 35 | topo = TreeTopo( depth, fanout ) 36 | return Mininet( topo, **kwargs ) 37 | 38 | class TorusTopo( Topo ): 39 | """2-D Torus topology 40 | WARNING: this topology has LOOPS and WILL NOT WORK 41 | with the default controller or any Ethernet bridge 42 | without STP turned on! It can be used with STP, e.g.: 43 | # mn --topo torus,3,3 --switch lxbr,stp=1 --test pingall""" 44 | 45 | def build( self, x, y, n=1 ): 46 | """x: dimension of torus in x-direction 47 | y: dimension of torus in y-direction 48 | n: number of hosts per switch""" 49 | if x < 3 or y < 3: 50 | raise Exception( 'Please use 3x3 or greater for compatibility ' 51 | 'with 2.1' ) 52 | if n == 1: 53 | genHostName = lambda loc, k: 'h%s' % ( loc ) 54 | else: 55 | genHostName = lambda loc, k: 'h%sx%d' % ( loc, k ) 56 | 57 | hosts, switches, dpid = {}, {}, 0 58 | # Create and wire interior 59 | for i in range( 0, x ): 60 | for j in range( 0, y ): 61 | loc = '%dx%d' % ( i + 1, j + 1 ) 62 | # dpid cannot be zero for OVS 63 | dpid = ( i + 1 ) * 256 + ( j + 1 ) 64 | switch = switches[ i, j ] = self.addSwitch( 65 | 's' + loc, dpid='%x' % dpid ) 66 | for k in range( 0, n ): 67 | host = hosts[ i, j, k ] = self.addHost( 68 | genHostName( loc, k + 1 ) ) 69 | self.addLink( host, switch ) 70 | # Connect switches 71 | for i in range( 0, x ): 72 | for j in range( 0, y ): 73 | sw1 = switches[ i, j ] 74 | sw2 = switches[ i, ( j + 1 ) % y ] 75 | sw3 = switches[ ( i + 1 ) % x, j ] 76 | self.addLink( sw1, sw2 ) 77 | self.addLink( sw1, sw3 ) 78 | 79 | # pylint: enable=arguments-differ 80 | -------------------------------------------------------------------------------- /ospfn/caida-ucsd/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname caida-ucsd 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface caida-ucsd-eth0 11 | interface caida-ucsd-eth1 12 | interface caida-ucsd-eth2 13 | ! 14 | ! 15 | !access-list ospfn permit 10.0.0.0/8 16 | !access-list ospfn deny any 17 | ! 18 | router ospf 19 | ospf router-id 0.0.0.1 20 | redistribute connected 21 | distribute-list ospfn out connected 22 | network 1.0.0.8/30 area 0 23 | network 1.0.0.4/30 area 0 24 | network 1.0.0.0/30 area 0 25 | capability opaque 26 | ! 27 | line vty 28 | ! 29 | !end of configuration file here 30 | -------------------------------------------------------------------------------- /ospfn/caida-ucsd/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/caida-ucsd/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/caida.org/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/caida-ucsd/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/caida-ucsd/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname caida-ucsd 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/clean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | killall -r ccnd ospf zebra 3 | rm log* 4 | rm */*log 5 | rm -rf /var/run/quagga-state/* 6 | -------------------------------------------------------------------------------- /ospfn/csu/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname caida-ucsd 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface csu-eth0 11 | interface csu-eth1 12 | interface csu-eth2 13 | interface csu-eth3 14 | interface csu-eth4 15 | interface csu-eth5 16 | ! 17 | ! 18 | !access-list ospfn permit 10.0.0.0/8 19 | !access-list ospfn deny any 20 | ! 21 | router ospf 22 | ospf router-id 0.0.0.2 23 | redistribute connected 24 | distribute-list ospfn out connected 25 | network 1.0.0.12/30 area 0 26 | network 1.0.0.24/30 area 0 27 | network 1.0.0.16/30 area 0 28 | network 1.0.0.20/30 area 0 29 | network 1.0.0.28/30 area 0 30 | network 1.0.0.32/30 area 0 31 | capability opaque 32 | ! 33 | line vty 34 | ! 35 | !end of configuration file here 36 | -------------------------------------------------------------------------------- /ospfn/csu/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/csu/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/colostate.edu/netsec/ 1 2 | ccnname /ndn/opschat/ 2 3 | logdir . 4 | -------------------------------------------------------------------------------- /ospfn/csu/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/csu/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname csu 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/delay: -------------------------------------------------------------------------------- 1 | pku:ucla 10070 0.05035 2 | parc:ucla 499 0.002495 3 | parc:remap 499 0.002495 4 | parc:csu 1518 0.00759 5 | parc:uiuc 2946 0.01473 6 | ucla:remap 1 5e-06 7 | ucla:caida-ucsd 186 0.00093 8 | ucla:uci 72 0.00036 9 | ucla:ua 728 0.00364 10 | ucla:csu 1385 0.006925 11 | ucla:spp-salt 941 0.004705 12 | remap:uci 72 0.00036 13 | uci:caida-ucsd 115 0.000575 14 | caida-ucsd:ua 588 0.00294 15 | spp-salt:spp-hous 1931 0.009655 16 | spp-salt:spp-kans 1489 0.007445 17 | spp-salt:csu 577 0.002885 18 | ua:csu 1065 0.005325 19 | ua:um 1972 0.00986 20 | ua:spp-hous 1512 0.00756 21 | csu:um 1461 0.007305 22 | csu:washu 1285 0.006425 23 | spp-kans:spp-hous 1039 0.005195 24 | spp-kans:spp-atla 1089 0.005445 25 | spp-kans:washu 374 0.00187 26 | spp-kans:spp-wash 1517 0.007585 27 | spp-kans:uiuc 556 0.00278 28 | spp-hous:spp-atla 1130 0.00565 29 | washu:um 393 0.001965 30 | washu:uiuc 239 0.001195 31 | um:neu 1818 0.00909 32 | um:spp-atla 530 0.00265 33 | uiuc:neu 1454 0.00727 34 | spp-atla:spp-wash 872 0.00436 35 | spp-wash:neu 632 0.00316 36 | -------------------------------------------------------------------------------- /ospfn/distance: -------------------------------------------------------------------------------- 1 | pku:ucla 10070 2 | parc:ucla 499 3 | parc:remap 499 4 | parc:csu 1518 5 | parc:uiuc 2946 6 | ucla:remap 1 7 | ucla:caida-ucsd 186 8 | ucla:uci 72 9 | ucla:ua 728 10 | ucla:csu 1385 11 | ucla:spp-salt 941 12 | remap:uci 72 13 | uci:caida-ucsd 115 14 | caida-ucsd:ua 588 15 | spp-salt:spp-hous 1931 16 | spp-salt:spp-kans 1489 17 | spp-salt:csu 577 18 | ua:csu 1065 19 | ua:um 1972 20 | ua:spp-hous 1512 21 | csu:um 1461 22 | csu:washu 1285 23 | spp-kans:spp-hous 1039 24 | spp-kans:spp-atla 1089 25 | spp-kans:washu 374 26 | spp-kans:spp-wash 1517 27 | spp-kans:uiuc 556 28 | spp-hous:spp-atla 1130 29 | washu:um 393 30 | washu:uiuc 239 31 | um:neu 1818 32 | um:spp-atla 530 33 | uiuc:neu 1454 34 | spp-atla:spp-wash 872 35 | spp-wash:neu 632 36 | -------------------------------------------------------------------------------- /ospfn/dump.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ospfn/miniccnx.conf: -------------------------------------------------------------------------------- 1 | [nodes] 2 | pku: _ ccnx:/,ucla 3 | parc: _ 4 | ucla: _ 5 | remap: _ 6 | uci: _ 7 | caida-ucsd: _ 8 | spp-salt: _ 9 | ua: _ 10 | csu: _ 11 | spp-kans: _ 12 | spp-hous: _ 13 | washu: _ 14 | um: _ 15 | uiuc: _ 16 | spp-atla: _ 17 | spp-wash: _ 18 | neu: _ 19 | [links] 20 | pku:ucla bw=200 delay=50ms 21 | parc:ucla bw=200 delay=2ms 22 | parc:remap bw=200 delay=2ms 23 | parc:csu bw=200 delay=8ms 24 | parc:uiuc bw=200 delay=14ms 25 | ucla:remap bw=200 26 | ucla:caida-ucsd bw=200 27 | ucla:uci bw=200 28 | ucla:ua bw=200 delay=4ms 29 | ucla:csu bw=200 delay=7ms 30 | ucla:spp-salt bw=200 delay=5ms 31 | remap:uci bw=200 32 | uci:caida-ucsd bw=200 33 | caida-ucsd:ua bw=200 delay=3ms 34 | spp-salt:spp-hous bw=200 delay=10ms 35 | spp-salt:spp-kans bw=200 delay=7ms 36 | spp-salt:csu bw=200 delay=3ms 37 | ua:csu bw=200 delay=5ms 38 | ua:um bw=200 delay=10ms 39 | ua:spp-hous bw=200 delay=7ms 40 | csu:um bw=200 delay=7ms 41 | csu:washu bw=200 delay=6ms 42 | spp-kans:spp-hous bw=200 delay=5ms 43 | spp-kans:spp-atla bw=200 delay=5ms 44 | spp-kans:washu bw=200 delay=2ms 45 | spp-kans:spp-wash bw=200 delay=7ms 46 | spp-kans:uiuc bw=200 delay=3ms 47 | spp-hous:spp-atla bw=200 delay=6ms 48 | washu:um bw=200 delay=2ms 49 | washu:uiuc bw=200 delay=1ms 50 | um:neu bw=200 delay=9ms 51 | um:spp-atla bw=200 delay=3ms 52 | uiuc:neu bw=200 delay=7ms 53 | spp-atla:spp-wash bw=200 delay=4ms 54 | spp-wash:neu bw=200 delay=3ms 55 | -------------------------------------------------------------------------------- /ospfn/neu/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname caida-ucsd 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface neu-eth0 11 | interface neu-eth1 12 | interface neu-eth2 13 | ! 14 | ! 15 | !access-list ospfn permit 10.0.0.0/8 16 | !access-list ospfn deny any 17 | ! 18 | router ospf 19 | ospf router-id 0.0.0.3 20 | redistribute connected 21 | distribute-list ospfn out connected 22 | network 1.0.0.36/30 area 0 23 | network 1.0.0.40/30 area 0 24 | network 1.0.0.44/30 area 0 25 | capability opaque 26 | ! 27 | line vty 28 | ! 29 | !end of configuration file here 30 | -------------------------------------------------------------------------------- /ospfn/neu/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/neu/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/neu.edu/northpole/ 1 2 | ccnname /ndn/opschat/ 2 3 | logdir . 4 | -------------------------------------------------------------------------------- /ospfn/neu/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/neu/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname neu 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ospfn -f ospfn.conf -d 3 | sleep 1 4 | -------------------------------------------------------------------------------- /ospfn/parc/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname parc 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface parc-eth0 11 | interface parc-eth1 12 | interface parc-eth2 13 | interface parc-eth3 14 | ! 15 | ! 16 | !access-list ospfn permit 10.0.0.0/8 17 | !access-list ospfn deny any 18 | ! 19 | router ospf 20 | ospf router-id 0.0.0.4 21 | redistribute connected 22 | distribute-list ospfn out connected 23 | network 1.0.0.52/30 area 0 24 | network 1.0.0.48/30 area 0 25 | network 1.0.0.12/30 area 0 26 | network 1.0.0.56/30 area 0 27 | capability opaque 28 | ! 29 | line vty 30 | ! 31 | !end of configuration file here 32 | -------------------------------------------------------------------------------- /ospfn/parc/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/parc/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/parc.com/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/parc/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/parc/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname parc 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/pku/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname pku 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface pku-eth0 11 | ! 12 | ! 13 | !access-list ospfn permit 10.0.0.0/8 14 | !access-list ospfn deny any 15 | ! 16 | router ospf 17 | ospf router-id 0.0.0.5 18 | redistribute connected 19 | distribute-list ospfn out connected 20 | network 1.0.0.60/30 area 0 21 | capability opaque 22 | ! 23 | line vty 24 | ! 25 | !end of configuration file here 26 | -------------------------------------------------------------------------------- /ospfn/pku/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/pku/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/pku.edu.cn/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/pku/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/pku/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname pku 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/remap/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname remap 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface remap-eth0 11 | interface remap-eth1 12 | interface remap-eth2 13 | ! 14 | ! 15 | !access-list ospfn permit 10.0.0.0/8 16 | !access-list ospfn deny any 17 | ! 18 | router ospf 19 | ospf router-id 0.0.0.6 20 | redistribute connected 21 | distribute-list ospfn out connected 22 | network 1.0.0.48/30 area 0 23 | network 1.0.0.68/30 area 0 24 | network 1.0.0.64/30 area 0 25 | capability opaque 26 | ! 27 | line vty 28 | ! 29 | !end of configuration file here 30 | -------------------------------------------------------------------------------- /ospfn/remap/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/remap/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ucla.edu/apps/ 1 2 | ccnname /ndn/remap.ucla.edu/ 2 3 | ccnname /ndn/ucla.edu/apps/ 3 4 | logdir . 5 | -------------------------------------------------------------------------------- /ospfn/remap/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/remap/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname remap 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/routing.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #sleep 1 3 | zebra -d -f zebra.conf -i /var/run/quagga-state/zebra.$1.pid 4 | #sleep 1 5 | ospfd -f ospfd.conf -i /var/run/quagga-state/ospfd.$1.pid -d -a 6 | #sleep 5 7 | #ospfn -d -f ospfn.conf 8 | 9 | -------------------------------------------------------------------------------- /ospfn/spp-atla/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname spp-atla 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface spp-atla-eth0 11 | interface spp-atla-eth1 12 | interface spp-atla-eth2 13 | interface spp-atla-eth3 14 | ! 15 | ! 16 | !access-list ospfn permit 10.0.0.0/8 17 | !access-list ospfn deny any 18 | ! 19 | router ospf 20 | ospf router-id 0.0.0.7 21 | redistribute connected 22 | distribute-list ospfn out connected 23 | network 1.0.0.72/30 area 0 24 | network 1.0.0.76/30 area 0 25 | network 1.0.0.80/30 area 0 26 | network 1.0.0.84/30 area 0 27 | capability opaque 28 | ! 29 | line vty 30 | ! 31 | !end of configuration file here 32 | -------------------------------------------------------------------------------- /ospfn/spp-atla/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/spp-atla/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/sppatla1/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/spp-atla/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/spp-atla/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname spp-atla 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/spp-hous/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname spp-hous 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface spp-hous-eth0 11 | interface spp-hous-eth1 12 | interface spp-hous-eth2 13 | interface spp-hous-eth3 14 | ! 15 | ! 16 | !access-list ospfn permit 10.0.0.0/8 17 | !access-list ospfn deny any 18 | ! 19 | router ospf 20 | ospf router-id 0.0.0.8 21 | redistribute connected 22 | distribute-list ospfn out connected 23 | network 1.0.0.92/30 area 0 24 | network 1.0.0.96/30 area 0 25 | network 1.0.0.88/30 area 0 26 | network 1.0.0.72/30 area 0 27 | capability opaque 28 | ! 29 | line vty 30 | ! 31 | !end of configuration file here 32 | -------------------------------------------------------------------------------- /ospfn/spp-hous/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/spp-hous/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/spphous1/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/spp-hous/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/spp-hous/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname spp-hous 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/spp-kans/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname spp-kans 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface spp-kans-eth0 11 | interface spp-kans-eth1 12 | interface spp-kans-eth2 13 | interface spp-kans-eth3 14 | interface spp-kans-eth4 15 | interface spp-kans-eth5 16 | ! 17 | ! 18 | !access-list ospfn permit 10.0.0.0/8 19 | !access-list ospfn deny any 20 | ! 21 | router ospf 22 | ospf router-id 0.0.0.9 23 | redistribute connected 24 | distribute-list ospfn out connected 25 | network 1.0.0.100/30 area 0 26 | network 1.0.0.88/30 area 0 27 | network 1.0.0.76/30 area 0 28 | network 1.0.0.112/30 area 0 29 | network 1.0.0.104/30 area 0 30 | network 1.0.0.108/30 area 0 31 | capability opaque 32 | ! 33 | line vty 34 | ! 35 | !end of configuration file here 36 | -------------------------------------------------------------------------------- /ospfn/spp-kans/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/spp-kans/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/sppkans1/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/spp-kans/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/spp-kans/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname spp-kans 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/spp-salt/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname spp-salt 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface spp-salt-eth0 11 | interface spp-salt-eth1 12 | interface spp-salt-eth2 13 | interface spp-salt-eth3 14 | ! 15 | ! 16 | !access-list ospfn permit 10.0.0.0/8 17 | !access-list ospfn deny any 18 | ! 19 | router ospf 20 | ospf router-id 0.0.0.10 21 | redistribute connected 22 | distribute-list ospfn out connected 23 | network 1.0.0.116/30 area 0 24 | network 1.0.0.92/30 area 0 25 | network 1.0.0.100/30 area 0 26 | network 1.0.0.16/30 area 0 27 | capability opaque 28 | ! 29 | line vty 30 | ! 31 | !end of configuration file here 32 | -------------------------------------------------------------------------------- /ospfn/spp-salt/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/spp-salt/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/sppsalt1/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/spp-salt/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/spp-salt/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname spp-salt 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/spp-wash/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname spp-wash 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface spp-wash-eth0 11 | interface spp-wash-eth1 12 | interface spp-wash-eth2 13 | ! 14 | ! 15 | !access-list ospfn permit 10.0.0.0/8 16 | !access-list ospfn deny any 17 | ! 18 | router ospf 19 | ospf router-id 0.0.0.11 20 | redistribute connected 21 | distribute-list ospfn out connected 22 | network 1.0.0.104/30 area 0 23 | network 1.0.0.80/30 area 0 24 | network 1.0.0.36/30 area 0 25 | capability opaque 26 | ! 27 | line vty 28 | ! 29 | !end of configuration file here 30 | -------------------------------------------------------------------------------- /ospfn/spp-wash/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/spp-wash/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/sppwash1/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/spp-wash/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/spp-wash/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname spp-wash 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/ua/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname ua 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface ua-eth0 11 | interface ua-eth1 12 | interface ua-eth2 13 | interface ua-eth3 14 | interface ua-eth4 15 | ! 16 | ! 17 | !access-list ospfn permit 10.0.0.0/8 18 | !access-list ospfn deny any 19 | ! 20 | router ospf 21 | ospf router-id 0.0.0.12 22 | redistribute connected 23 | distribute-list ospfn out connected 24 | network 1.0.0.120/30 area 0 25 | network 1.0.0.0/30 area 0 26 | network 1.0.0.20/30 area 0 27 | network 1.0.0.124/30 area 0 28 | network 1.0.0.96/30 area 0 29 | capability opaque 30 | ! 31 | line vty 32 | ! 33 | !end of configuration file here 34 | -------------------------------------------------------------------------------- /ospfn/ua/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/ua/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/arizona.edu/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/ua/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/ua/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname ua 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/uci/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname caida-ucsd 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface uci-eth0 11 | interface uci-eth1 12 | interface uci-eth2 13 | ! 14 | ! 15 | !access-list ospfn permit 10.0.0.0/8 16 | !access-list ospfn deny any 17 | ! 18 | router ospf 19 | ospf router-id 0.0.0.13 20 | redistribute connected 21 | distribute-list ospfn out connected 22 | network 1.0.0.128/30 area 0 23 | network 1.0.0.64/30 area 0 24 | network 1.0.0.4/30 area 0 25 | capability opaque 26 | ! 27 | line vty 28 | ! 29 | !end of configuration file here 30 | -------------------------------------------------------------------------------- /ospfn/uci/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/uci/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /uci.edu/ 1 2 | ccnname /ndn/uci.edu/ 2 3 | logdir . 4 | -------------------------------------------------------------------------------- /ospfn/uci/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/uci/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname uci 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/ucla/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname ucla 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface ucla-eth0 11 | interface ucla-eth1 12 | interface ucla-eth2 13 | interface ucla-eth3 14 | interface ucla-eth4 15 | interface ucla-eth5 16 | interface ucla-eth6 17 | interface ucla-eth7 18 | ! 19 | ! 20 | !access-list ospfn permit 10.0.0.0/8 21 | !access-list ospfn deny any 22 | ! 23 | router ospf 24 | ospf router-id 0.0.0.14 25 | redistribute connected 26 | distribute-list ospfn out connected 27 | network 1.0.0.60/30 area 0 28 | network 1.0.0.52/30 area 0 29 | network 1.0.0.68/30 area 0 30 | network 1.0.0.8/30 area 0 31 | network 1.0.0.128/30 area 0 32 | network 1.0.0.120/30 area 0 33 | network 1.0.0.24/30 area 0 34 | network 1.0.0.116/30 area 0 35 | capability opaque 36 | ! 37 | line vty 38 | ! 39 | !end of configuration file here 40 | -------------------------------------------------------------------------------- /ospfn/ucla/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/ucla/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/ucla.edu/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/ucla/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/ucla/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname ucla 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/uiuc/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname uiuc 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface uiuc-eth0 11 | interface uiuc-eth1 12 | interface uiuc-eth2 13 | interface uiuc-eth3 14 | ! 15 | ! 16 | !access-list ospfn permit 10.0.0.0/8 17 | !access-list ospfn deny any 18 | ! 19 | router ospf 20 | ospf router-id 0.0.0.15 21 | redistribute connected 22 | distribute-list ospfn out connected 23 | network 1.0.0.56/30 area 0 24 | network 1.0.0.108/30 area 0 25 | network 1.0.0.132/30 area 0 26 | network 1.0.0.40/30 area 0 27 | capability opaque 28 | ! 29 | line vty 30 | ! 31 | !end of configuration file here 32 | -------------------------------------------------------------------------------- /ospfn/uiuc/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/uiuc/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/uiuc.edu/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/uiuc/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/uiuc/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname uiuc 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/um/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname um 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface um-eth0 11 | interface um-eth1 12 | interface um-eth2 13 | interface um-eth3 14 | interface um-eth4 15 | ! 16 | ! 17 | !access-list ospfn permit 10.0.0.0/8 18 | !access-list ospfn deny any 19 | ! 20 | router ospf 21 | ospf router-id 0.0.0.16 22 | redistribute connected 23 | distribute-list ospfn out connected 24 | network 1.0.0.124/30 area 0 25 | network 1.0.0.28/30 area 0 26 | network 1.0.0.136/30 area 0 27 | network 1.0.0.44/30 area 0 28 | network 1.0.0.84/30 area 0 29 | capability opaque 30 | ! 31 | line vty 32 | ! 33 | !end of configuration file here 34 | -------------------------------------------------------------------------------- /ospfn/um/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/um/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/memphis.edu/ 1 2 | ccnname /ndn/memphis.edu/netlab/ 2 3 | logdir . 4 | -------------------------------------------------------------------------------- /ospfn/um/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/um/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname um 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /ospfn/washu/ospfd.conf: -------------------------------------------------------------------------------- 1 | 2 | hostname washu 3 | password pwd 4 | enable password pwd 5 | !log file /var/log/quagga/ospfd-s1.log 6 | log file ospfd.log 7 | ! 8 | ! 9 | ! 10 | interface washu-eth0 11 | interface washu-eth1 12 | interface washu-eth2 13 | interface washu-eth3 14 | ! 15 | ! 16 | !access-list ospfn permit 10.0.0.0/8 17 | !access-list ospfn deny any 18 | ! 19 | router ospf 20 | ospf router-id 0.0.0.17 21 | redistribute connected 22 | distribute-list ospfn out connected 23 | network 1.0.0.32/30 area 0 24 | network 1.0.0.112/30 area 0 25 | network 1.0.0.136/30 area 0 26 | network 1.0.0.132/30 area 0 27 | capability opaque 28 | ! 29 | line vty 30 | ! 31 | !end of configuration file here 32 | -------------------------------------------------------------------------------- /ospfn/washu/ospfn-start.sh: -------------------------------------------------------------------------------- 1 | ../ospfn-start.sh -------------------------------------------------------------------------------- /ospfn/washu/ospfn.conf: -------------------------------------------------------------------------------- 1 | ccnname /ndn/uiuc.edu/ 1 2 | logdir . 3 | -------------------------------------------------------------------------------- /ospfn/washu/routing.sh: -------------------------------------------------------------------------------- 1 | ../routing.sh -------------------------------------------------------------------------------- /ospfn/washu/zebra.conf: -------------------------------------------------------------------------------- 1 | ! -*- zebra -*- 2 | ! 3 | ! zebra sample configuration file 4 | ! 5 | ! $Id: zebra.conf.sample,v 1.1 2002/12/13 20:15:30 paul Exp $ 6 | ! 7 | hostname washu 8 | password zebra 9 | enable password zebra 10 | ! 11 | ! Interface's description. 12 | ! 13 | !interface lo 14 | ! description test of desc. 15 | ! 16 | !interface sit0 17 | ! multicast 18 | 19 | ! 20 | ! Static default route sample. 21 | ! 22 | !ip route 0.0.0.0/0 203.181.89.241 23 | ! 24 | 25 | log file zebra.log 26 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | "Setuptools params" 4 | 5 | from setuptools import setup, find_packages 6 | from os.path import join 7 | 8 | # Get version number from source tree 9 | import sys 10 | sys.path.append( '.' ) 11 | from mininet.net import VERSION 12 | 13 | scripts = [ join( 'bin', filename ) for filename in [ 'mn', 'miniccnx', 'miniccnxedit'] ] 14 | 15 | modname = distname = 'mininet' 16 | 17 | setup( 18 | name=distname, 19 | version=VERSION, 20 | description='Process-based OpenFlow emulator with CCNx extension', 21 | author='Bob Lantz, Carlos Cabral', 22 | author_email='rlantz@cs.stanford.edu, cabral@dca.fee.unicamp.br', 23 | packages=find_packages(exclude='test'), 24 | long_description=""" 25 | Mininet is a network emulator which uses lightweight 26 | virtualization to create virtual networks for rapid 27 | prototyping of Software-Defined Network (SDN) designs 28 | using OpenFlow. http://openflow.org/mininet. 29 | This also includes an extension for using Content Centric 30 | Networks based on the NDN model (project CCNx). 31 | """, 32 | classifiers=[ 33 | "License :: OSI Approved :: BSD License", 34 | "Programming Language :: Python", 35 | "Development Status :: 2 - Pre-Alpha", 36 | "Intended Audience :: Developers", 37 | "Topic :: Internet", 38 | ], 39 | keywords='networking emulator protocol Internet OpenFlow SDN CCNx CCN', 40 | license='BSD', 41 | install_requires=[ 42 | 'setuptools', 43 | 'networkx' 44 | ], 45 | scripts=scripts, 46 | ) 47 | -------------------------------------------------------------------------------- /sources/__init__.py: -------------------------------------------------------------------------------- 1 | "Docstring to silence pylint; ignores --ignore option for __init__.py" 2 | -------------------------------------------------------------------------------- /sources/ccndparser.py: -------------------------------------------------------------------------------- 1 | """ 2 | A simple parser for the ccndstatus info 3 | """ 4 | 5 | import re, datetime 6 | import pdb 7 | from influxdb import InfluxDBClient 8 | 9 | contentItems ={} 10 | interests = {} 11 | iTotals = {} 12 | facesStats = [] 13 | facesRates = [] 14 | forwarding=[] 15 | 16 | contentList=[] 17 | dataList=[] 18 | 19 | datapoints=[] 20 | 21 | ccndout = open('ccndout').read().splitlines() 22 | lineCount = len(ccndout) 23 | 24 | for line in xrange(1, 4): 25 | pdb.set_trace() 26 | splitLine=re.split(': ',ccndout[line]) 27 | rest=re.split(', ', splitLine[1]) 28 | 29 | for item in rest: 30 | itemSplit=re.split(' ', item) 31 | if(line == 1): 32 | contentItems[itemSplit[1]] = itemSplit[0] 33 | elif(line == 2): 34 | interests[itemSplit[1]] = itemSplit[0] 35 | elif(line == 3): 36 | iTotals[itemSplit[1]] = itemSplit[0] 37 | 38 | contentList.append({"name": 'content_items', "data": contentItems}) 39 | contentList.append({"name": 'interests', "data": interests}) 40 | contentList.append({"name": 'interest_totals', "data": iTotals}) 41 | 42 | line = 5 43 | 44 | while (ccndout[line] != 'Face Activity Rates'): 45 | splitLine=re.split(' ', ccndout[line]) 46 | try: 47 | rest=splitLine[8] 48 | except IndexError: 49 | rest = '' 50 | 51 | faceInfo={ 52 | "face": splitLine[2], 53 | "flags": splitLine[4], 54 | "pending": splitLine[6], 55 | "local": rest, 56 | } 57 | 58 | facesStats.append({"name": 'faces', "data": faceInfo}) 59 | line += 1 60 | 61 | line += 2 62 | 63 | while (ccndout[line] != 'Forwarding'): 64 | face = re.split(': ', re.search('face: [0-9]+', ccndout[13]).group(0)) 65 | faceStat = re.findall('[0-9]+ / [0-9]+', ccndout[line]) 66 | 67 | Bytes=re.split(' / ', faceStat[0]) 68 | rData=re.split(' / ', faceStat[1]) 69 | sData=re.split(' / ', faceStat[2]) 70 | 71 | faceInfo={ 72 | "face": face[1], 73 | "BIn": Bytes[0], 74 | "BOut": Bytes[1], 75 | "rData": rData[0], 76 | "sInt": rData[1], 77 | "sData": sData[0], 78 | "rInt": sData[1], 79 | } 80 | 81 | facesRates.append({"name": 'face_activity_rates', "data": faceInfo}) 82 | 83 | line += 1 84 | 85 | line += 1 86 | 87 | while (line < (lineCount-1)): 88 | 89 | splitLine=re.split(' ', ccndout[line]) 90 | 91 | faceInfo={ 92 | "path": splitLine[1], 93 | "face": splitLine[3], 94 | "flags": splitLine[5], 95 | "expires": splitLine[7], 96 | } 97 | 98 | forwarding.append({"name": 'forwarding', "data": faceInfo}) 99 | 100 | line += 1 101 | 102 | dataList.append(contentList) 103 | dataList.append(facesStats) 104 | dataList.append(facesRates) 105 | dataList.append(forwarding) 106 | 107 | pdb.set_trace() 108 | 109 | for data in dataList: 110 | for series in data: 111 | newEntry={ 112 | "name": series['name'], 113 | #"tags": None, 114 | "time": datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%fZ'), 115 | "fields": series['data'] 116 | } 117 | 118 | datapoints.append(newEntry) 119 | 120 | host='localhost' 121 | port=8086 122 | user='root' 123 | passwd='root' 124 | dbname='mn_ccnx_data' 125 | 126 | client = InfluxDBClient(host, port, user, passwd, dbname) 127 | client.drop_database(dbname) 128 | client.create_database(dbname) 129 | client.write_points(datapoints) 130 | 131 | pdb.set_trace() 132 | -------------------------------------------------------------------------------- /util/build-ovs-packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Attempt to build debian packages for OVS 4 | 5 | set -e # exit on error 6 | set -u # exit on undefined variable 7 | 8 | kvers=`uname -r` 9 | ksrc=/lib/modules/$kvers/build 10 | dist=`lsb_release -is | tr [A-Z] [a-z]` 11 | release=`lsb_release -rs` 12 | arch=`uname -m` 13 | buildsuffix=-2 14 | if [ "$arch" = "i686" ]; then arch=i386; fi 15 | if [ "$arch" = "x86_64" ]; then arch=amd64; fi 16 | 17 | overs=1.4.0 18 | ovs=openvswitch-$overs 19 | ovstgz=$ovs.tar.gz 20 | ovsurl=http://openvswitch.org/releases/$ovstgz 21 | 22 | install='sudo apt-get install -y' 23 | 24 | echo "*** Installing debian/ubuntu build system" 25 | $install build-essential devscripts ubuntu-dev-tools debhelper dh-make 26 | $install diff patch cdbs quilt gnupg fakeroot lintian pbuilder piuparts 27 | $install module-assistant 28 | 29 | echo "*** Installing OVS dependencies" 30 | $install pkg-config gcc make python-dev libssl-dev libtool 31 | $install dkms ipsec-tools 32 | 33 | echo "*** Installing headers for $kvers" 34 | $install linux-headers-$kvers 35 | 36 | echo "*** Retrieving OVS source" 37 | wget -c $ovsurl 38 | tar xzf $ovstgz 39 | cd $ovs 40 | 41 | echo "*** Patching OVS source" 42 | # Not sure why this fails, but off it goes! 43 | sed -i -e 's/dh_strip/# dh_strip/' debian/rules 44 | if [ "$release" = "10.04" ]; then 45 | # Lucid doesn't seem to have all the packages for ovsdbmonitor 46 | echo "*** Patching debian/rules to remove dh_python2" 47 | sed -i -e 's/dh_python2/dh_pysupport/' debian/rules 48 | echo "*** Not building ovsdbmonitor since it's too hard on 10.04" 49 | mv debian/ovsdbmonitor.install debian/ovsdbmonitor.install.backup 50 | sed -i -e 's/ovsdbmonitor.install/ovsdbmonitor.install.backup/' Makefile.in 51 | else 52 | # Install a bag of hurt for ovsdbmonitor 53 | $install python-pyside.qtcore pyqt4-dev-tools python-twisted python-twisted-bin \ 54 | python-twisted-core python-twisted-conch python-anyjson python-zope.interface 55 | fi 56 | # init script was written to assume that commands complete 57 | sed -i -e 's/^set -e/#set -e/' debian/openvswitch-controller.init 58 | 59 | echo "*** Building OVS user packages" 60 | opts=--with-linux=/lib/modules/`uname -r`/build 61 | fakeroot make -f debian/rules DATAPATH_CONFIGURE_OPTS=$opts binary 62 | 63 | echo "*** Building OVS datapath kernel module package" 64 | # Still looking for the "right" way to do this... 65 | sudo mkdir -p /usr/src/linux 66 | ln -sf _debian/openvswitch.tar.gz . 67 | sudo make -f debian/rules.modules KSRC=$ksrc KVERS=$kvers binary-modules 68 | 69 | echo "*** Built the following packages:" 70 | cd ~ 71 | ls -l *deb 72 | 73 | archive=ovs-$overs-core-$dist-$release-$arch$buildsuffix.tar 74 | ovsbase='common pki switch brcompat controller datapath-dkms' 75 | echo "*** Packing up $ovsbase .debs into:" 76 | echo " $archive" 77 | pkgs="" 78 | for component in $ovsbase; do 79 | if echo $component | egrep 'dkms|pki'; then 80 | # Architecture-independent packages 81 | deb=(openvswitch-${component}_$overs*all.deb) 82 | else 83 | deb=(openvswitch-${component}_$overs*$arch.deb) 84 | fi 85 | pkgs="$pkgs $deb" 86 | done 87 | rm -rf $archive 88 | tar cf $archive $pkgs 89 | 90 | echo "*** Contents of archive $archive:" 91 | tar tf $archive 92 | 93 | echo "*** Done (hopefully)" 94 | 95 | -------------------------------------------------------------------------------- /util/colorfilters: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT THIS FILE! It was created by Wireshark 2 | @Bad TCP@tcp.analysis.flags@[0,0,0][65535,24383,24383] 3 | @HSRP State Change@hsrp.state != 8 && hsrp.state != 16@[0,0,0][65535,63222,0] 4 | @Spanning Tree Topology Change@stp.type == 0x80@[0,0,0][65535,63222,0] 5 | @OSPF State Change@ospf.msg != 1@[0,0,0][65535,63222,0] 6 | @ICMP errors@icmp.type eq 3 || icmp.type eq 4 || icmp.type eq 5 || icmp.type eq 11@[0,0,0][0,65535,3616] 7 | @ARP@arp@[55011,59486,65534][0,0,0] 8 | @ICMP@icmp@[49680,49737,65535][0,0,0] 9 | @TCP RST@tcp.flags.reset eq 1@[37008,0,0][65535,63121,32911] 10 | @TTL low or unexpected@( ! ip.dst == 224.0.0.0/4 && ip.ttl < 5) || (ip.dst == 224.0.0.0/24 && ip.ttl != 1)@[37008,0,0][65535,65535,65535] 11 | @of@of@[0,5,65535][65535,65535,65535] 12 | @Checksum Errors@cdp.checksum_bad==1 || edp.checksum_bad==1 || ip.checksum_bad==1 || tcp.checksum_bad==1 || udp.checksum_bad==1@[0,0,0][65535,24383,24383] 13 | @SMB@smb || nbss || nbns || nbipx || ipxsap || netbios@[65534,64008,39339][0,0,0] 14 | @HTTP@http || tcp.port == 80@[36107,65535,32590][0,0,0] 15 | @IPX@ipx || spx@[65534,58325,58808][0,0,0] 16 | @DCERPC@dcerpc@[51199,38706,65533][0,0,0] 17 | @Routing@hsrp || eigrp || ospf || bgp || cdp || vrrp || gvrp || igmp || ismp@[65534,62325,54808][0,0,0] 18 | @TCP SYN/FIN@tcp.flags & 0x02 || tcp.flags.fin == 1@[41026,41026,41026][0,0,0] 19 | @TCP@tcp@[59345,58980,65534][0,0,0] 20 | @UDP@udp@[28834,57427,65533][0,0,0] 21 | @Broadcast@eth[0] & 1@[65535,65535,65535][32768,32768,32768] 22 | -------------------------------------------------------------------------------- /util/doxify.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | Convert simple documentation to epydoc/pydoctor-compatible markup 5 | """ 6 | 7 | from sys import stdin, stdout, argv 8 | import os 9 | from tempfile import mkstemp 10 | from subprocess import call 11 | 12 | import re 13 | 14 | spaces = re.compile( r'\s+' ) 15 | singleLineExp = re.compile( r'\s+"([^"]+)"' ) 16 | commentStartExp = re.compile( r'\s+"""' ) 17 | commentEndExp = re.compile( r'"""$' ) 18 | returnExp = re.compile( r'\s+(returns:.*)' ) 19 | lastindent = '' 20 | 21 | 22 | comment = False 23 | 24 | def fixParam( line ): 25 | "Change foo: bar to @foo bar" 26 | result = re.sub( r'(\w+):', r'@param \1', line ) 27 | result = re.sub( r' @', r'@', result) 28 | return result 29 | 30 | def fixReturns( line ): 31 | "Change returns: foo to @return foo" 32 | return re.sub( 'returns:', r'@returns', line ) 33 | 34 | def fixLine( line ): 35 | global comment 36 | match = spaces.match( line ) 37 | if not match: 38 | return line 39 | else: 40 | indent = match.group(0) 41 | if singleLineExp.match( line ): 42 | return re.sub( '"', '"""', line ) 43 | if commentStartExp.match( line ): 44 | comment = True 45 | if comment: 46 | line = fixReturns( line ) 47 | line = fixParam( line ) 48 | if commentEndExp.search( line ): 49 | comment = False 50 | return line 51 | 52 | 53 | def test(): 54 | "Test transformations" 55 | assert fixLine(' "foo"') == ' """foo"""' 56 | assert fixParam( 'foo: bar' ) == '@param foo bar' 57 | assert commentStartExp.match( ' """foo"""') 58 | 59 | def funTest(): 60 | testFun = ( 61 | 'def foo():\n' 62 | ' "Single line comment"\n' 63 | ' """This is a test"""\n' 64 | ' bar: int\n' 65 | ' baz: string\n' 66 | ' returns: junk"""\n' 67 | ' if True:\n' 68 | ' print "OK"\n' 69 | ).splitlines( True ) 70 | 71 | fixLines( testFun ) 72 | 73 | def fixLines( lines, fid ): 74 | for line in lines: 75 | os.write( fid, fixLine( line ) ) 76 | 77 | if __name__ == '__main__': 78 | if False: 79 | funTest() 80 | infile = open( argv[1] ) 81 | outfid, outname = mkstemp() 82 | fixLines( infile.readlines(), outfid ) 83 | infile.close() 84 | os.close( outfid ) 85 | call( [ 'doxypy', outname ] ) 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /util/kbuild/kbuild: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script to build new Debian kernel packages for 2.6.33.1 4 | # 5 | # Caveats: 6 | # 7 | # Since kernel-package in debian-stable doesn't work with 8 | # 2.6.33.1, we attempt to patch it in place. This may not be the 9 | # right thing to do. A possibly better alternative is to install 10 | # a later version of kernel-package, although that could potentially 11 | # cause problems with upgrades, etc.. 12 | # 13 | # The patch to tun.c is a workaround rather than a real fix. 14 | # 15 | # Building a full Debian kernel package with all drivers takes a long 16 | # time, 60-80 minutes on my laptop. 17 | # 18 | # Re-running a make-kpkg may not work without running 'make-kpkg clean' 19 | 20 | # Season to taste 21 | # export PATH=/usr/lib/ccache:$PATH 22 | export CONCURRENCY_LEVEL=3 23 | 24 | debversion=2.6.26-2-686-bigmem 25 | 26 | image=linux-image-$debversion 27 | 28 | echo "*** Installing $image" 29 | sudo aptitude install $image 30 | 31 | newversion=2.6.33.1 32 | archive=linux-$newversion.tar.bz2 33 | location=http://www.kernel.org/pub/linux/kernel/v2.6 34 | 35 | echo "*** Fetching $location/$archive" 36 | wget -c $location/$archive 37 | 38 | tree=linux-$newversion 39 | if [ -e $tree ]; then 40 | echo "*** $tree already exists" 41 | else 42 | echo "*** Extracting $archive" 43 | tar xjf $archive 44 | fi 45 | 46 | echo "*** Patching tun driver" 47 | patch $tree/drivers/net/tun.c < tun.patch 48 | 49 | echo "*** Patching debian build script" 50 | sudo patch /usr/share/kernel-package/ruleset/misc/version_vars.mk < version_vars.patch 51 | 52 | config=/boot/config-$debversion 53 | echo "*** Copying $config to $tree/.config" 54 | cp $config $tree/.config 55 | 56 | echo "*** Updating config" 57 | cd $tree 58 | yes '' | make oldconfig 1> /dev/null 59 | sed 's/# CONFIG_NET_NS is not set/CONFIG_NET_NS=y/' .config > .config-new 60 | mv .config-new .config 61 | echo "*** Result: " `grep CONFIG_NET_NS .config` 62 | 63 | echo "*** Building kernel" 64 | time fakeroot make-kpkg --initrd --append-to-version=-mininet kernel_image kernel_headers 65 | 66 | cd .. 67 | echo "*** Done - package should be in current directory" 68 | ls *$newversion*.deb 69 | 70 | echo "To install:" 71 | echo "# dpkg -i " *$newversion*.deb 72 | -------------------------------------------------------------------------------- /util/kbuild/tun.patch: -------------------------------------------------------------------------------- 1 | --- linux-2.6.33.1/drivers/net/tun.c 2010-03-24 22:47:32.000000000 -0700 2 | +++ tun-new.c 2010-03-24 22:45:00.000000000 -0700 3 | @@ -1006,7 +1006,9 @@ 4 | if (err < 0) 5 | goto err_free_sk; 6 | 7 | - if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) || 8 | + /* BL hack: check for null parent kobj */ 9 | + if (!tun->dev->dev.kobj.sd || 10 | + device_create_file(&tun->dev->dev, &dev_attr_tun_flags) || 11 | device_create_file(&tun->dev->dev, &dev_attr_owner) || 12 | device_create_file(&tun->dev->dev, &dev_attr_group)) 13 | printk(KERN_ERR "Failed to create tun sysfs files\n"); 14 | -------------------------------------------------------------------------------- /util/kbuild/version_vars.patch: -------------------------------------------------------------------------------- 1 | --- /usr/share/kernel-package/ruleset/misc/version_vars.mk 2010-03-25 18:14:41.000000000 -0700 2 | +++ version_vars.mk 2010-03-03 06:46:59.000000000 -0800 3 | @@ -138,11 +138,13 @@ 4 | EXTRAV_ARG := 5 | endif 6 | 7 | -UTS_RELEASE_HEADER=$(call doit,if [ -f include/linux/utsrelease.h ]; then \ 8 | +UTS_RELEASE_HEADER=$(call doit, if [ -f include/generated/utsrelease.h ]; then \ 9 | + echo include/generated/utsrelease.h; \ 10 | + else if [ -f include/linux/utsrelease.h ]; then \ 11 | echo include/linux/utsrelease.h; \ 12 | else \ 13 | echo include/linux/version.h ; \ 14 | - fi) 15 | + fi fi) 16 | UTS_RELEASE_VERSION=$(call doit,if [ -f $(UTS_RELEASE_HEADER) ]; then \ 17 | grep 'define UTS_RELEASE' $(UTS_RELEASE_HEADER) | \ 18 | perl -nle 'm/^\s*\#define\s+UTS_RELEASE\s+("?)(\S+)\1/g && print $$2;';\ 19 | -------------------------------------------------------------------------------- /util/m: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Attach to a Mininet host and run a command 4 | 5 | if [ -z $1 ]; then 6 | echo "usage: $0 host cmd [args...]" 7 | exit 1 8 | else 9 | host=$1 10 | fi 11 | 12 | pid=`ps ax | grep "mininet:$host$" | grep bash | grep -v mnexec | awk '{print $1};'` 13 | 14 | if echo $pid | grep -q ' '; then 15 | echo "Error: found multiple mininet:$host processes" 16 | exit 2 17 | fi 18 | 19 | if [ "$pid" == "" ]; then 20 | echo "Could not find Mininet host $host" 21 | exit 3 22 | fi 23 | 24 | if [ -z $2 ]; then 25 | cmd='bash' 26 | else 27 | shift 28 | cmd=$* 29 | fi 30 | 31 | cgroup=/sys/fs/cgroup/cpu/$host 32 | if [ -d "$cgroup" ]; then 33 | cg="-g $host" 34 | fi 35 | 36 | # Check whether host should be running in a chroot dir 37 | rootdir="/var/run/mn/$host/root" 38 | if [ -d $rootdir -a -x $rootdir/bin/bash ]; then 39 | cmd="'cd `pwd`; exec $cmd'" 40 | cmd="chroot $rootdir /bin/bash -c $cmd" 41 | fi 42 | 43 | cmd="exec sudo mnexec $cg -a $pid $cmd" 44 | eval $cmd 45 | -------------------------------------------------------------------------------- /util/nox-patches/README: -------------------------------------------------------------------------------- 1 | 0001: This patch adds the OpenFlow tutorial module source code to nox-destiny. 2 | 0002: This patch hacks nox-destiny to compile on Ubuntu 12.04. 3 | -------------------------------------------------------------------------------- /util/openflow-patches/README: -------------------------------------------------------------------------------- 1 | Patches for OpenFlow Reference Implementation 2 | 3 | controller.patch: patch controller to support up to 4096 switches (up from 16!) 4 | 5 | datapath.patch: patch to kernel datapath to compile with CONFIG_NET_NS=y 6 | -------------------------------------------------------------------------------- /util/openflow-patches/controller.patch: -------------------------------------------------------------------------------- 1 | diff --git a/controller/controller.c b/controller/controller.c 2 | index 41f2547..6eec590 100644 3 | --- a/controller/controller.c 4 | +++ b/controller/controller.c 5 | @@ -58,8 +58,8 @@ 6 | #include "vlog.h" 7 | #define THIS_MODULE VLM_controller 8 | 9 | -#define MAX_SWITCHES 16 10 | -#define MAX_LISTENERS 16 11 | +#define MAX_SWITCHES 4096 12 | +#define MAX_LISTENERS 4096 13 | 14 | struct switch_ { 15 | struct lswitch *lswitch; 16 | -------------------------------------------------------------------------------- /util/openflow-patches/datapath.patch: -------------------------------------------------------------------------------- 1 | diff --git a/datapath/datapath.c b/datapath/datapath.c 2 | index 4a4d3a2..365aa25 100644 3 | --- a/datapath/datapath.c 4 | +++ b/datapath/datapath.c 5 | @@ -47,6 +47,9 @@ 6 | 7 | #include "compat.h" 8 | 9 | +#ifdef CONFIG_NET_NS 10 | +#include 11 | +#endif 12 | 13 | /* Strings to describe the manufacturer, hardware, and software. This data 14 | * is queriable through the switch description stats message. */ 15 | @@ -259,6 +262,10 @@ send_openflow_skb(const struct datapath *dp, 16 | struct sk_buff *skb, const struct sender *sender) 17 | { 18 | return (sender 19 | - ? genlmsg_unicast(skb, sender->pid) 20 | +#ifdef CONFIG_NET_NS 21 | + ? genlmsg_unicast(&init_net, skb, sender->pid) 22 | +#else 23 | + ? genlmsg_unicast(skb, sender->pid) 24 | +#endif 25 | : genlmsg_multicast(skb, 0, dp_mc_group(dp), GFP_ATOMIC)); 26 | } 27 | -------------------------------------------------------------------------------- /util/sch_htb-ofbuf/Makefile: -------------------------------------------------------------------------------- 1 | obj-m = sch_htb.o 2 | KVERSION = $(shell uname -r) 3 | all: 4 | make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules 5 | install: 6 | test -e /lib/modules/$(KVERSION)/kernel/net/sched/sch_htb.ko.bak || mv /lib/modules/$(KVERSION)/kernel/net/sched/sch_htb.ko /lib/modules/$(KVERSION)/kernel/net/sched/sch_htb.ko.bak 7 | cp sch_htb.ko /lib/modules/$(KVERSION)/kernel/net/sched/sch_htb.ko 8 | rmmod sch_htb 9 | modprobe sch_htb 10 | clean: 11 | make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean 12 | -------------------------------------------------------------------------------- /util/sch_htb-ofbuf/README: -------------------------------------------------------------------------------- 1 | Modified sch_htb implementation with ofbuf support. 2 | 3 | To compile, just type make. To use this module instead 4 | of regular sch_htb, do: 5 | 6 | 0. make 7 | 1. rmmod sch_htb 8 | 2. insmod ./sch_htb.ko 9 | 10 | To revert, just rmmod sch_htb. 11 | -------------------------------------------------------------------------------- /util/sysctl_addon: -------------------------------------------------------------------------------- 1 | # Mininet: Increase open file limit 2 | fs.file-max = 100000 3 | 4 | # Mininet: increase network buffer space 5 | net.core.wmem_max = 16777216 6 | net.core.rmem_max = 16777216 7 | net.ipv4.tcp_rmem = 10240 87380 16777216 8 | net.ipv4.tcp_rmem = 10240 87380 16777216 9 | net.core.netdev_max_backlog = 5000 10 | 11 | # Mininet: increase arp cache size 12 | net.ipv4.neigh.default.gc_thresh1 = 4096 13 | net.ipv4.neigh.default.gc_thresh2 = 8192 14 | net.ipv4.neigh.default.gc_thresh3 = 16384 15 | 16 | # Mininet: increase routing table size 17 | net.ipv4.route.max_size=32768 18 | 19 | -------------------------------------------------------------------------------- /util/versioncheck.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | from __future__ import print_function 4 | from subprocess import check_output as co 5 | from sys import exit 6 | 7 | # Actually run bin/mn rather than importing via python path 8 | version = 'Mininet ' + co( 'PYTHONPATH=. bin/mn --version', shell=True ) 9 | version = version.strip() 10 | 11 | # Find all Mininet path references 12 | lines = co( "egrep -or 'Mininet [0-9\.\+]+\w*' *", shell=True ) 13 | 14 | error = False 15 | 16 | for line in lines.split( '\n' ): 17 | if line and 'Binary' not in line: 18 | fname, fversion = line.split( ':' ) 19 | if version != fversion: 20 | print( "%s: incorrect version '%s' (should be '%s')" % ( 21 | fname, fversion, version ) ) 22 | error = True 23 | 24 | if error: 25 | exit( 1 ) 26 | -------------------------------------------------------------------------------- /util/vm/.bash_profile: -------------------------------------------------------------------------------- 1 | SSH_ENV="$HOME/.ssh/environment" 2 | 3 | function start_agent { 4 | echo "Initialising new SSH agent..." 5 | /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" 6 | echo succeeded 7 | chmod 600 "${SSH_ENV}" 8 | . "${SSH_ENV}" > /dev/null 9 | /usr/bin/ssh-add; 10 | } 11 | 12 | # Source SSH settings, if applicable 13 | 14 | if [ -f "${SSH_ENV}" ]; then 15 | . "${SSH_ENV}" > /dev/null 16 | #ps ${SSH_AGENT_PID} doesn't work under cywgin 17 | ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { 18 | start_agent; 19 | } 20 | else 21 | start_agent; 22 | fi 23 | 24 | source ~/.bashrc 25 | -------------------------------------------------------------------------------- /util/vm/install-mininet-vm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script is intended to install Mininet into 4 | # a brand-new Ubuntu virtual machine, 5 | # to create a fully usable "tutorial" VM. 6 | # 7 | # optional argument: Mininet branch to install 8 | set -e 9 | echo "$(whoami) ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers > /dev/null 10 | sudo sed -i -e 's/Default/#Default/' /etc/sudoers 11 | echo mininet-vm | sudo tee /etc/hostname > /dev/null 12 | sudo sed -i -e 's/ubuntu/mininet-vm/g' /etc/hosts 13 | sudo hostname `cat /etc/hostname` 14 | sudo sed -i -e 's/splash//' /etc/default/grub 15 | sudo sed -i -e 's/quiet/text/' /etc/default/grub 16 | sudo update-grub 17 | # Update from official archive 18 | sudo apt-get update 19 | # 12.10 and earlier 20 | #sudo sed -i -e 's/us.archive.ubuntu.com/mirrors.kernel.org/' \ 21 | # /etc/apt/sources.list 22 | # 13.04 and later 23 | #sudo sed -i -e 's/\/archive.ubuntu.com/\/mirrors.kernel.org/' \ 24 | # /etc/apt/sources.list 25 | # Clean up vmware easy install junk if present 26 | if [ -e /etc/issue.backup ]; then 27 | sudo mv /etc/issue.backup /etc/issue 28 | fi 29 | if [ -e /etc/rc.local.backup ]; then 30 | sudo mv /etc/rc.local.backup /etc/rc.local 31 | fi 32 | # Fetch Mininet 33 | sudo apt-get -y install git-core openssh-server 34 | git clone git://github.com/mininet/mininet 35 | # Optionally check out branch 36 | if [ "$1" != "" ]; then 37 | pushd mininet 38 | #git checkout -b $1 $1 39 | # TODO branch will in detached HEAD state if it is not master 40 | git checkout $1 41 | popd 42 | fi 43 | # Install Mininet 44 | time mininet/util/install.sh 45 | # Finalize VM 46 | time mininet/util/install.sh -tcd 47 | # Ignoring this since NOX classic is deprecated 48 | #if ! grep NOX_CORE_DIR .bashrc; then 49 | # echo "export NOX_CORE_DIR=~/noxcore/build/src/" >> .bashrc 50 | #fi 51 | echo "Done preparing Mininet VM." 52 | --------------------------------------------------------------------------------