Compare commits
89 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d7f399d7a1 | |||
| 1c42632978 | |||
| 5ef6e1dedc | |||
| f8e54cad47 | |||
| fc3152d724 | |||
| 9a3a3edf75 | |||
| 377a4b5af5 | |||
| 4a1dbac09b | |||
| 92fe3cc120 | |||
| 39ed456de2 | |||
| 5d4ec1ab9e | |||
| 6b90434b9c | |||
| c2fb4d2e8c | |||
| 7b240ce5b8 | |||
| c7de350a4e | |||
| 06dae1adc1 | |||
| f0c726a42f | |||
| a882d68a5f | |||
| 9b69c99f4e | |||
| 904796436d | |||
| ec2d93d482 | |||
| dffddc338f | |||
| b6ad3a1619 | |||
| 96ac94a985 | |||
| 715db45b9d | |||
| e07a29b4e6 | |||
| 2255bc7da3 | |||
| 12f4d5b8ae | |||
| f9d5ef3461 | |||
| dad451bf8f | |||
| 77938e0a85 | |||
| e4003290e0 | |||
| 9517f6c197 | |||
| d8c30910cb | |||
| 53975940de | |||
| 77c473687e | |||
| 0847991030 | |||
| 462929b3af | |||
| 26c7c70024 | |||
| 942745e91f | |||
| dcc39a7b25 | |||
| ebdb3a5107 | |||
| 6def304585 | |||
| e02e338e3c | |||
| b7c412073a | |||
| afdf9fd571 | |||
| 336b01ae34 | |||
| 537e8242fc | |||
| cab8970b0a | |||
| 3625149356 | |||
| fd9e011277 | |||
| 591a961762 | |||
| bfc42f6d02 | |||
| 458d20e3fd | |||
| 73b2ecc5fe | |||
| 6a5adb48d2 | |||
| 5f69bf0ade | |||
| d5b4aa829b | |||
| 1704541cc9 | |||
| f56a12a1ab | |||
| 70c643f8de | |||
| fa9fd770ca | |||
| dd41ecaae4 | |||
| 287c1fb154 | |||
| 1c268e7667 | |||
| 2b8d254cc0 | |||
| 8fc867b1f4 | |||
| 6af291c968 | |||
| c0582b9c5e | |||
| 023c53aec6 | |||
| bd1a442a17 | |||
| 6c17e1ade7 | |||
| e56f6839f1 | |||
| e0436642ae | |||
| c5f626ce27 | |||
| 10e758e80a | |||
| de28f67a97 | |||
| 46242acdd4 | |||
| e203808a20 | |||
| 3b3a11b6dd | |||
| 7c0d1506e7 | |||
| c5f23b9f82 | |||
| cfb0a6d3f0 | |||
| 664ba39383 | |||
| 598d694058 | |||
| f92e3d3432 | |||
| ce4f1e0c92 | |||
| 31f44e1856 | |||
| a73e776695 |
@@ -1,7 +1,7 @@
|
||||
Mininet uses GitHub issues for bug reports and feature requests only.
|
||||
**Mininet uses GitHub issues for bug reports and feature requests only.**
|
||||
These issues can be viewed at bugs.mininet.org
|
||||
|
||||
If you have a question that is not a bug report or a feature request,
|
||||
If you have a question that is not a **bug report** or a **feature request**,
|
||||
please use the documentation at docs.mininet.org, the FAQ
|
||||
at faq.mininet.org, and the mininet-discuss mailing list.
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
name: code-check
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
code-check:
|
||||
name: Mininet Code Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.x
|
||||
- name: Check out Mininet source
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Mininet code check dependencies
|
||||
run: |
|
||||
PYTHON=`which python` util/install.sh -n
|
||||
python -m pip install pylint==2.4.4
|
||||
- name: Run code check
|
||||
run: make codecheck
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
name: mininet-tests
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Mininet Tests
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04]
|
||||
python-version: [3.x, 2.x]
|
||||
steps:
|
||||
- name: Check out Mininet source
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install Mininet and base dependencies
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
# This seems too slow unfortunately:
|
||||
# sudo apt-get upgrade -y -qq
|
||||
PYTHON=`which python` util/install.sh -nv
|
||||
- name: Sanity test
|
||||
run: |
|
||||
export sudo="sudo env PATH=$PATH"
|
||||
# Verify major python-version number matches python and mininet
|
||||
export PYVER=`echo ${{ matrix.python-version }} | cut -d . -f 1`
|
||||
export CHKVER='px import platform; print(platform.python_version())'
|
||||
python --version |& grep " $PYVER\."
|
||||
echo $CHKVER | $sudo mn -v output | grep " $PYVER\."
|
||||
# Newer OvS tries OpenFlow15 which crashes ovsc on ubuntu-20.04
|
||||
$sudo mn --switch ovs,protocols=OpenFlow13 --test pingall
|
||||
- name: Install test dependencies
|
||||
run: |
|
||||
sudo apt-get install -qq vlan
|
||||
pip install pexpect
|
||||
util/install.sh -fw
|
||||
- name: Run core tests
|
||||
run: |
|
||||
export sudo="sudo env PATH=$PATH"
|
||||
export PYTHON=`which python`
|
||||
$sudo $PYTHON mininet/test/runner.py -v
|
||||
- name: Run examples tests (quick)
|
||||
run: |
|
||||
export sudo="sudo env PATH=$PATH"
|
||||
export PYTHON=`which python`
|
||||
$sudo $PYTHON examples/test/runner.py -v -quick
|
||||
@@ -41,10 +41,16 @@ load-plugins=
|
||||
# can either give multiple identifier separated by comma (,) or put this option
|
||||
# multiple time (only on the command line, not in the configuration file where
|
||||
# it should appear only once).
|
||||
#
|
||||
# Note: we may want to re-enable some of these at some point, but many of them
|
||||
# are just style issues rather than errors.
|
||||
#
|
||||
disable=pointless-except, invalid-name, super-init-not-called, fixme, star-args,
|
||||
too-many-instance-attributes, too-few-public-methods, too-many-arguments,
|
||||
too-many-instance-attributes, too-few-public-methods,
|
||||
too-many-locals, too-many-public-methods, duplicate-code, bad-whitespace,
|
||||
locally-disabled, locally-enabled
|
||||
locally-disabled, locally-enabled, bad-continuation,
|
||||
useless-object-inheritance, unnecessary-pass, no-else-return,
|
||||
no-else-raise, no-else-continue, super-with-arguments
|
||||
|
||||
# bad-continuation, wrong-import-order
|
||||
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
language: python
|
||||
sudo: required
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- dist: trusty
|
||||
python: 2.7
|
||||
env: dist="14.04 LTS trusty"
|
||||
- dist: trusty
|
||||
python: 3.6
|
||||
env: dist="14.04 LTS trusty"
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq vlan
|
||||
- PYTHON=`which python` util/install.sh -n
|
||||
|
||||
install:
|
||||
- bash -c "if [ `lsb_release -rs` == '14.04' ]; then make codecheck; fi"
|
||||
- pip install pexpect || pip3 install pexpect
|
||||
- util/install.sh -nfvw
|
||||
|
||||
script:
|
||||
- alias sudo="sudo env PATH=$PATH"
|
||||
- export PYTHON=`which python`
|
||||
- echo 'px import sys; print(sys.version_info)' | sudo $PYTHON bin/mn -v output
|
||||
- sudo $PYTHON bin/mn --test pingall
|
||||
- sudo $PYTHON mininet/test/runner.py -v -quick
|
||||
- sudo $PYTHON examples/test/runner.py -v -quick
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
||||
|
||||
# More details: https://docs.travis-ci.com/user/notifications
|
||||
+30
-1
@@ -18,34 +18,63 @@ Cody Burkard
|
||||
|
||||
Additional Mininet Contributors
|
||||
|
||||
Joseph Beshay
|
||||
M S Vishwanath Bhat
|
||||
Muhammad Umair Bhatti
|
||||
Arie Bregman
|
||||
Tomasz Buchert
|
||||
Gustavo Pantuza Coelho Pinto
|
||||
Fernando Cappi
|
||||
HW Chiu
|
||||
Ryan Cox
|
||||
Shaun Crampton
|
||||
Jason Croft
|
||||
Hantao Cui
|
||||
Nirmoy Das
|
||||
Lenoardo D'avila
|
||||
Giuseppe Di Lena
|
||||
David Erickson
|
||||
Juan Gascon
|
||||
Glen Gibb
|
||||
Andrew Ferguson
|
||||
Eder Leao Fernandes
|
||||
Julian Filter
|
||||
Ben Frankel
|
||||
Tim Gates
|
||||
Gregory Gee
|
||||
Jon Hall
|
||||
Roan Huang
|
||||
Vitaly Ivanov
|
||||
Theo Jepsen
|
||||
Mathieu Jadin
|
||||
Babis Kaidos
|
||||
Rich Lane
|
||||
Rémy Léone
|
||||
Xiaozhou Li
|
||||
Zi Shen Lim
|
||||
David Mahler
|
||||
Felix Maurer
|
||||
Murphy McCauley
|
||||
Alex Moijes
|
||||
Felician Nemeth
|
||||
José Pedro Oliveira
|
||||
James Page
|
||||
Gustavo Pantuza Coelho Pinto
|
||||
Ramon Pujianto
|
||||
Stempha Reiter
|
||||
Damien Saucez
|
||||
Shan Sikdar
|
||||
Angad Singh
|
||||
Piyush Srivastava
|
||||
Ed Swierk
|
||||
Darshan Thaker
|
||||
Olivier Tl]ilmans
|
||||
Niels van Adrichem
|
||||
Brad Walker
|
||||
Andreas Wundsam
|
||||
Vikas Yadav
|
||||
Isaku Yamahata
|
||||
Baohua Yang
|
||||
Zhuo
|
||||
|
||||
Thanks also to everyone who has submitted issues and pull
|
||||
requests on github, and to our friendly mininet-discuss
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Mininet Installation/Configuration Notes
|
||||
----------------------------------------
|
||||
|
||||
Mininet 2.3.0d4
|
||||
Mininet 2.3.0
|
||||
---
|
||||
|
||||
The supported installation methods for Mininet are 1) using a
|
||||
@@ -32,19 +32,21 @@ like to contribute an installation script, we would welcome it!)
|
||||
2. Next-easiest option: use our Ubuntu package!
|
||||
|
||||
To install Mininet itself (i.e. `mn` and the Python API) on Ubuntu
|
||||
12.10+:
|
||||
16.04+:
|
||||
|
||||
sudo apt-get install mininet
|
||||
|
||||
Note: if you are upgrading from an older version of Mininet, make
|
||||
sure you remove the old OVS from `/usr/local`:
|
||||
|
||||
sudo rm /usr/local/bin/ovs*
|
||||
sudo rm /usr/local/sbin/ovs*
|
||||
Note: this may install an older version of Mininet which may not
|
||||
support Python 3. If you would like the latest version of Mininet,
|
||||
consider installing from source as described in the next section.
|
||||
|
||||
3. Native installation from source
|
||||
|
||||
3.1. Native installation from source on Ubuntu 12.04+
|
||||
If you are running Ubuntu, Debian, or Fedora, you may be able to use
|
||||
our handy `install.sh` script, which is in `util/`. Please read the
|
||||
following sections first.
|
||||
|
||||
3.1. Obtaining the Mininet source code
|
||||
|
||||
If you're reading this, you've probably already done so, but the
|
||||
command to download the Mininet source code is:
|
||||
@@ -52,8 +54,9 @@ like to contribute an installation script, we would welcome it!)
|
||||
git clone git://github.com/mininet/mininet.git
|
||||
|
||||
Note that the above git command will check out the latest and greatest
|
||||
Mininet (which we recommend!) If you want to run the last tagged/released
|
||||
version of Mininet, you can look at the release tags using
|
||||
Mininet (which we recommend!) If you want to run the last
|
||||
tagged/released version of Mininet, you can look at the release tags
|
||||
using
|
||||
|
||||
cd mininet
|
||||
git tag
|
||||
@@ -64,21 +67,38 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
where <release tag> is the release you want to check out.
|
||||
|
||||
If you are running Ubuntu, Debian, or Fedora, you may be able to use
|
||||
our handy `install.sh` script, which is in `util/`.
|
||||
3.1.1 *CAUTION: USE AT YOUR OWN RISK!*
|
||||
|
||||
*WARNING: USE AT YOUR OWN RISK!*
|
||||
|
||||
`install.sh` is a bit intrusive and may possibly damage your OS
|
||||
`install.sh` can be a bit intrusive and may possibly damage your OS
|
||||
and/or home directory, by creating/modifying several directories
|
||||
such as `mininet`, `openflow`, `oftest`, `pox`, etc.. We recommend
|
||||
trying it in a VM before trying it on a system you use from day to day.
|
||||
trying it in a VM before trying it on a system you use from day to
|
||||
day.
|
||||
|
||||
Although we hope it won't do anything completely terrible, you may
|
||||
want to look at the script before you run it, and you should make
|
||||
sure your system and home directory are backed up just in case!
|
||||
|
||||
To install Mininet itself, the OpenFlow reference implementation, and
|
||||
You can change the directory where the dependencies are installed
|
||||
using the -s <directory> flag.
|
||||
|
||||
util/install.sh -s <directory> ...
|
||||
|
||||
3.1.2 Running `install.sh`
|
||||
|
||||
Installing a "minimal" version of Mininet with Open vSwitch should
|
||||
be reasonably non-perturbing since it should not create directories
|
||||
for other tools:
|
||||
|
||||
util/install.sh -nv
|
||||
|
||||
Note this will not install a controller, so you will have to either
|
||||
install your own controller, or use a switch such OVSBridge that does
|
||||
not require a controller:
|
||||
|
||||
sudo mn --switch ovsbr --test pingall
|
||||
|
||||
To install Mininet itself, the OpenFlow reference controller, and
|
||||
Open vSwitch, you may use:
|
||||
|
||||
util/install.sh -fnv
|
||||
@@ -88,6 +108,27 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
sudo mn --test pingall
|
||||
|
||||
3.1.3 Python 3 and Python 2 support
|
||||
|
||||
Mininet supports Python 3 and Python 2. By default, `install.sh`
|
||||
will use whatever `python` is on your system. To specify a
|
||||
specific version of Pythonm, you can set the PYTHON environment
|
||||
variable:
|
||||
|
||||
PYTHON=python3 util/install.sh -fnv
|
||||
|
||||
You can install Mininet for both Python 3 and Python 2:
|
||||
|
||||
PYTHON=python2 util/install.sh -fnv
|
||||
PYTHON=python3 util/install.sh -n
|
||||
|
||||
Whichever version was installed last will be the default for `mn`.
|
||||
As long as Mininet is installed for the appropriate version of
|
||||
Python, you can run it using that versinon of Python:
|
||||
|
||||
python3 `which mn`
|
||||
python2 `which mn`
|
||||
|
||||
To install ALL of the software which we use for OpenFlow tutorials,
|
||||
including POX, the OpenFlow WireShark dissector, the `oftest`
|
||||
framework, and other potentially useful software, you may use:
|
||||
@@ -96,12 +137,7 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
This takes about 4 minutes on our test system.
|
||||
|
||||
You can change the directory where the dependencies are installed using
|
||||
the -s <directory> flag.
|
||||
|
||||
util/install.sh -s <directory> -a
|
||||
|
||||
3.2. Native installation from source on Fedora 18+.
|
||||
3.2. (Experimental) Native installation from source on Fedora:
|
||||
|
||||
As root execute the following operations:
|
||||
|
||||
@@ -109,18 +145,6 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
yum install git
|
||||
|
||||
* create an user account (e.g. mininet) and add it to the wheel group
|
||||
|
||||
useradd [...] mininet
|
||||
usermod -a -G wheel mininet
|
||||
|
||||
* change the SElinux setting to permissive. It can be done
|
||||
temporarily with:
|
||||
|
||||
setenforce 0
|
||||
|
||||
then login with the new account (e.g. mininet) and do the following:
|
||||
|
||||
* clone the Mininet repository
|
||||
|
||||
git clone git://github.com/mininet/mininet.git
|
||||
@@ -139,7 +163,10 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
sudo mn --test pingall
|
||||
|
||||
4. Creating your own Mininet/OpenFlow tutorial VM
|
||||
Note that `install.sh -fnv `may not install all dependencies on Fedora,
|
||||
and many tests may still fail.
|
||||
|
||||
4. Creating your own Mininet/OpenFlow tutorial VM on Ubuntu/Debian
|
||||
|
||||
Creating your own Ubuntu Mininet VM for use with the OpenFlow tutorial
|
||||
is easy! First, create a new Ubuntu VM. Next, run two commands in it:
|
||||
@@ -155,7 +182,8 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
Although we don't support other Linux distributions directly, it
|
||||
should be possible to install and run Mininet with some degree of
|
||||
manual effort.
|
||||
manual effort. People have even gotten `mn --switch user` to run
|
||||
in a ChromeOS container.
|
||||
|
||||
In general, you must have:
|
||||
|
||||
@@ -172,8 +200,11 @@ like to contribute an installation script, we would welcome it!)
|
||||
support other Linux distributions.
|
||||
|
||||
|
||||
Good luck!
|
||||
As always, please feel free to submit issues or pull requests for
|
||||
installation-related features.
|
||||
|
||||
Mininet Team
|
||||
Good luck, and have fun!
|
||||
|
||||
Mininet Developers
|
||||
|
||||
---
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Mininet 2.3.0d4 License
|
||||
Mininet 2.3.0 License
|
||||
|
||||
Copyright (c) 2013-2018 Open Networking Laboratory
|
||||
Copyright (c) 2013-2021 Open Networking Foundation
|
||||
Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of
|
||||
The Leland Stanford Junior University
|
||||
|
||||
|
||||
@@ -8,12 +8,13 @@ BIN = $(MN)
|
||||
PYSRC = $(MININET) $(TEST) $(EXAMPLES) $(BIN)
|
||||
MNEXEC = mnexec
|
||||
MANPAGES = mn.1 mnexec.1
|
||||
P8IGN = E251,E201,E302,E202,E126,E127,E203,E226
|
||||
P8IGN = E251,E201,E302,E202,E126,E127,E203,E226,E402,W504,W503,E731
|
||||
PREFIX ?= /usr
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
MANDIR ?= $(PREFIX)/share/man/man1
|
||||
DOCDIRS = doc/html doc/latex
|
||||
PDF = doc/latex/refman.pdf
|
||||
CC ?= cc
|
||||
|
||||
CFLAGS += -Wall -Wextra
|
||||
|
||||
@@ -46,7 +47,7 @@ slowtest: $(MININET)
|
||||
mininet/examples/test/runner.py -v
|
||||
|
||||
mnexec: mnexec.c $(MN) mininet/net.py
|
||||
cc $(CFLAGS) $(LDFLAGS) -DVERSION=\"`PYTHONPATH=. $(PYMN) --version`\" $< -o $@
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -DVERSION=\"`PYTHONPATH=. $(PYMN) --version`\" $< -o $@
|
||||
|
||||
install-mnexec: $(MNEXEC)
|
||||
install -D $(MNEXEC) $(BINDIR)/$(MNEXEC)
|
||||
@@ -55,13 +56,16 @@ install-manpages: $(MANPAGES)
|
||||
install -D -t $(MANDIR) $(MANPAGES)
|
||||
|
||||
install: install-mnexec install-manpages
|
||||
$(PYTHON) setup.py install
|
||||
# This seems to work on all pip versions
|
||||
$(PYTHON) -m pip uninstall -y mininet || true
|
||||
$(PYTHON) -m pip install .
|
||||
|
||||
develop: $(MNEXEC) $(MANPAGES)
|
||||
# Perhaps we should link these as well
|
||||
install $(MNEXEC) $(BINDIR)
|
||||
install $(MANPAGES) $(MANDIR)
|
||||
$(PYTHON) setup.py develop
|
||||
$(PYTHON) -m pip uninstall -y mininet || true
|
||||
$(PYTHON) -m pip install -e . --no-binary :all:
|
||||
|
||||
man: $(MANPAGES)
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ Mininet: Rapid Prototyping for Software Defined Networks
|
||||
========================================================
|
||||
*The best way to emulate almost any network on your laptop!*
|
||||
|
||||
Mininet 2.3.0d4
|
||||
Mininet 2.3.0
|
||||
|
||||
[![Build Status][1]](https://github.com/mininet/mininet/actions)
|
||||
|
||||
[![Build Status][1]](https://travis-ci.org/mininet/mininet)
|
||||
|
||||
### What is Mininet?
|
||||
|
||||
@@ -67,27 +68,31 @@ Mininet includes:
|
||||
|
||||
`mn -c`
|
||||
|
||||
### New features in this release
|
||||
### Python 3 Support
|
||||
|
||||
This is primarily a performance improvement and bug fix release.
|
||||
- Mininet 2.3.0 supports Python 3 and Python 2!
|
||||
|
||||
- Batch startup has been implemented for Open vSwitch, improving
|
||||
startup performance.
|
||||
- You can install both the Python 3 and Python 2 versions of
|
||||
Mininet side by side, but the most recent installation will
|
||||
determine which Python version is used by default by `mn`.
|
||||
|
||||
- OVS patch links have been implemented via OVSLink and --link ovs
|
||||
- You can run `mn` directly with Python 2 or Python 3,
|
||||
as long as the appropriate version of Mininet is installed,
|
||||
e.g.
|
||||
|
||||
Warning! These links have *serious limitations* compared to
|
||||
virtual Ethernet pairs: they are not attached to real Linux
|
||||
interfaces so you cannot use tcpdump or wireshark with them;
|
||||
they also cannot be used in long chains - we don't recommend more
|
||||
than 64 OVSLinks, for example --linear,64. However, they can offer
|
||||
significantly better performance than veth pairs, for certain
|
||||
configurations.
|
||||
$ sudo python2 `which mn`
|
||||
|
||||
- You can now easily install Mininet on a Raspberry Pi ;-)
|
||||
- More information regarding Python 3 and Python 2 support
|
||||
may be found in the release notes on http://docs.mininet.org.
|
||||
|
||||
- Additional information for this release and previous releases
|
||||
may be found in the release notes on docs.mininet.org
|
||||
### Other Enhancements and Information
|
||||
|
||||
- Support for Ubuntu 20.04 LTS (and 18.04 and 16.04)
|
||||
|
||||
- More reliable testing and CI via github actions
|
||||
|
||||
- Additional information about this release and previous releases
|
||||
may be found in the release notes on http://docs.mininet.org.
|
||||
|
||||
### Installation
|
||||
|
||||
@@ -100,7 +105,8 @@ information, including a Mininet walkthrough and an introduction
|
||||
to the Python API, is available on the
|
||||
[Mininet Web Site](http://mininet.org).
|
||||
There is also a wiki which you are encouraged to read and to
|
||||
contribute to, particularly the Frequently Asked Questions (FAQ.)
|
||||
contribute to, particularly the Frequently Asked Questions
|
||||
(FAQ) at http://faq.mininet.org.
|
||||
|
||||
### Support
|
||||
|
||||
@@ -111,7 +117,7 @@ Mininet mailing list, `mininet-discuss` at:
|
||||
|
||||
### Join Us
|
||||
|
||||
Thanks again to all of the Mininet contributors!
|
||||
Thanks again to all of the Mininet contributors and users!
|
||||
|
||||
Mininet is an open source project and is currently hosted
|
||||
at <https://github.com/mininet>. You are encouraged to download
|
||||
@@ -123,10 +129,10 @@ hard work that Mininet continues to grow and improve.
|
||||
|
||||
### Enjoy Mininet
|
||||
|
||||
Best wishes, and we look forward to seeing what you can do with
|
||||
Mininet to change the networking world!
|
||||
Have fun! We look forward to seeing what you will do with Mininet
|
||||
to change the networking world.
|
||||
|
||||
Bob Lantz
|
||||
Mininet Core Team
|
||||
Bob Lantz,
|
||||
on behalf of the Mininet Contributors
|
||||
|
||||
[1]: https://travis-ci.org/mininet/mininet.svg?branch=master
|
||||
[1]: https://github.com/mininet/mininet/workflows/mininet-tests/badge.svg
|
||||
|
||||
@@ -11,15 +11,20 @@ Example to pull custom params (topo, switch, etc.) from a file:
|
||||
sudo mn --custom ~/mininet/custom/custom_example.py
|
||||
"""
|
||||
|
||||
from optparse import OptionParser
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from functools import partial
|
||||
from optparse import OptionParser # pylint: disable=deprecated-module
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
|
||||
# Fix setuptools' evil madness, and open up (more?) security holes
|
||||
if 'PYTHONPATH' in os.environ:
|
||||
sys.path = os.environ[ 'PYTHONPATH' ].split( ':' ) + sys.path
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
|
||||
from mininet.clean import cleanup
|
||||
import mininet.cli
|
||||
from mininet.log import lg, LEVELS, info, debug, warn, error, output
|
||||
@@ -34,10 +39,7 @@ from mininet.link import Link, TCLink, TCULink, OVSLink
|
||||
from mininet.topo import ( SingleSwitchTopo, LinearTopo,
|
||||
SingleSwitchReversedTopo, MinimalTopo )
|
||||
from mininet.topolib import TreeTopo, TorusTopo
|
||||
from mininet.util import customClass, specialClass, splitArgs
|
||||
from mininet.util import buildTopo
|
||||
|
||||
from functools import partial
|
||||
from mininet.util import customClass, specialClass, splitArgs, buildTopo
|
||||
|
||||
# Experimental! cluster edition prototype
|
||||
from mininet.examples.cluster import ( MininetCluster, RemoteHost,
|
||||
@@ -46,6 +48,7 @@ from mininet.examples.cluster import ( MininetCluster, RemoteHost,
|
||||
ClusterCleanup )
|
||||
from mininet.examples.clustercli import ClusterCLI
|
||||
|
||||
|
||||
PLACEMENT = { 'block': SwitchBinPlacer, 'random': RandomPlacer }
|
||||
|
||||
# built in topologies, created only when run
|
||||
@@ -98,7 +101,6 @@ CLI = None # Set below if needed
|
||||
# Locally defined tests
|
||||
def allTest( net ):
|
||||
"Run ping and iperf tests"
|
||||
net.waitConnected()
|
||||
net.start()
|
||||
net.ping()
|
||||
net.iperf()
|
||||
@@ -107,6 +109,7 @@ def nullTest( _net ):
|
||||
"Null 'test' (does nothing)"
|
||||
pass
|
||||
|
||||
|
||||
TESTS.update( all=allTest, none=nullTest, build=nullTest )
|
||||
|
||||
# Map to alternate spellings of Mininet() methods
|
||||
@@ -127,7 +130,6 @@ def runTests( mn, options ):
|
||||
if callable( testfn ):
|
||||
testfn( mn, *args, **kwargs )
|
||||
elif hasattr( mn, test ):
|
||||
mn.waitConnected()
|
||||
getattr( mn, test )( *args, **kwargs )
|
||||
else:
|
||||
raise Exception( 'Test %s is unknown - please specify one of '
|
||||
@@ -284,6 +286,11 @@ class MininetRunner( object ):
|
||||
" Mininet's IP subnet, see the --ipbase option." )
|
||||
opts.add_option( '--version', action='callback', callback=version,
|
||||
help='prints the version and exits' )
|
||||
opts.add_option( '--wait', '-w', action='store_true',
|
||||
default=False, help='wait for switches to connect' )
|
||||
opts.add_option( '--twait', '-t', action='store', type='int',
|
||||
dest='wait',
|
||||
help='timed wait (s) for switches to connect' )
|
||||
opts.add_option( '--cluster', type='string', default=None,
|
||||
metavar='server1,server2...',
|
||||
help=( 'run on multiple servers (experimental!)' ) )
|
||||
@@ -380,14 +387,24 @@ class MininetRunner( object ):
|
||||
placement=PLACEMENT[ opts.placement ] )
|
||||
mininet.cli.CLI = ClusterCLI
|
||||
|
||||
# Wait for controllers to connect unless we're running null test
|
||||
if ( opts.test and opts.test != [ 'none' ] and
|
||||
isinstance( opts.wait, bool ) ):
|
||||
opts.wait = True
|
||||
|
||||
mn = Net( topo=topo,
|
||||
switch=switch, host=host, controller=controller, link=link,
|
||||
ipBase=opts.ipbase, inNamespace=opts.innamespace,
|
||||
xterms=opts.xterms, autoSetMacs=opts.mac,
|
||||
autoStaticArp=opts.arp, autoPinCpus=opts.pin,
|
||||
waitConnected=opts.wait,
|
||||
listenPort=opts.listenport )
|
||||
|
||||
if opts.ensure_value( 'nat', False ):
|
||||
with open( '/etc/resolv.conf' ) as f:
|
||||
if 'nameserver 127.' in f.read():
|
||||
warn( '*** Warning: loopback address in /etc/resolv.conf '
|
||||
'may break host DNS over NAT\n')
|
||||
mn.addNAT( *opts.nat_args, **opts.nat_kwargs ).configDefault()
|
||||
|
||||
# --custom files can set CLI or change mininet.cli.CLI
|
||||
@@ -418,7 +435,7 @@ if __name__ == "__main__":
|
||||
except KeyboardInterrupt:
|
||||
info( "\n\nKeyboard Interrupt. Shutting down and cleaning up...\n\n")
|
||||
cleanup()
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# Print exception
|
||||
type_, val_, trace_ = sys.exc_info()
|
||||
errorMsg = ( "-"*80 + "\n" +
|
||||
|
||||
+1927
-821
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"This example doesn't use OpenFlow, but attempts to run sshd in a namespace."
|
||||
|
||||
|
||||
+5
-4
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
bind.py: Bind mount example
|
||||
@@ -34,14 +34,14 @@ and '/var/run'. It also has a temporary private directory mounted
|
||||
on '/var/mn'
|
||||
"""
|
||||
|
||||
from functools import partial
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Host
|
||||
from mininet.cli import CLI
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
from functools import partial
|
||||
|
||||
|
||||
# Sample usage
|
||||
|
||||
@@ -53,7 +53,7 @@ def testHostWithPrivateDirs():
|
||||
'/var/mn' ]
|
||||
host = partial( Host,
|
||||
privateDirs=privateDirs )
|
||||
net = Mininet( topo=topo, host=host )
|
||||
net = Mininet( topo=topo, host=host, waitConnected=True )
|
||||
net.start()
|
||||
directories = [ directory[ 0 ] if isinstance( directory, tuple )
|
||||
else directory for directory in privateDirs ]
|
||||
@@ -61,6 +61,7 @@ def testHostWithPrivateDirs():
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
testHostWithPrivateDirs()
|
||||
|
||||
+98
-61
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
cluster.py: prototyping/experimentation for distributed Mininet,
|
||||
@@ -74,17 +74,6 @@ Things to do:
|
||||
- hifi support (e.g. delay compensation)
|
||||
"""
|
||||
|
||||
|
||||
from mininet.node import Node, Host, OVSSwitch, Controller
|
||||
from mininet.link import Link, Intf
|
||||
from mininet.net import Mininet
|
||||
from mininet.topo import LinearTopo
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import quietRun, errRun
|
||||
from mininet.examples.clustercli import CLI
|
||||
from mininet.log import setLogLevel, debug, info, error
|
||||
from mininet.clean import addCleanupCallback
|
||||
|
||||
from signal import signal, SIGINT, SIG_IGN
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
import os
|
||||
@@ -95,6 +84,18 @@ from itertools import groupby
|
||||
from operator import attrgetter
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
from mininet.node import Node, Host, OVSSwitch, Controller
|
||||
from mininet.link import Link, Intf
|
||||
from mininet.net import Mininet
|
||||
from mininet.topo import LinearTopo
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import quietRun, errRun, decode
|
||||
from mininet.examples.clustercli import CLI
|
||||
from mininet.log import setLogLevel, debug, info, error
|
||||
from mininet.clean import addCleanupCallback
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
def findUser():
|
||||
"Try to return logged-in (usually non-root) user"
|
||||
@@ -246,7 +247,7 @@ class RemoteMixin( object ):
|
||||
result = ''
|
||||
while True:
|
||||
poll = popen.poll()
|
||||
result += popen.stdout.read()
|
||||
result += decode( popen.stdout.read() )
|
||||
if poll is not None:
|
||||
break
|
||||
return result
|
||||
@@ -261,7 +262,7 @@ class RemoteMixin( object ):
|
||||
cmd: remote command to run (list)
|
||||
**params: parameters to Popen()
|
||||
returns: Popen() object"""
|
||||
if type( cmd ) is str:
|
||||
if isinstance( cmd, str):
|
||||
cmd = cmd.split()
|
||||
if self.isRemote:
|
||||
if sudo:
|
||||
@@ -289,6 +290,7 @@ class RemoteMixin( object ):
|
||||
def addIntf( self, *args, **kwargs ):
|
||||
"Override: use RemoteLink.moveIntf"
|
||||
# kwargs.update( moveIntfFn=RemoteLink.moveIntf )
|
||||
# pylint: disable=useless-super-delegation
|
||||
return super( RemoteMixin, self).addIntf( *args, **kwargs )
|
||||
|
||||
|
||||
@@ -325,6 +327,7 @@ class RemoteOVSSwitch( RemoteMixin, OVSSwitch ):
|
||||
StrictVersion( '1.10' ) )
|
||||
|
||||
@classmethod
|
||||
# pylint: disable=arguments-differ
|
||||
def batchStartup( cls, switches, **_kwargs ):
|
||||
"Start up switches in per-server batches"
|
||||
key = attrgetter( 'server' )
|
||||
@@ -336,6 +339,7 @@ class RemoteOVSSwitch( RemoteMixin, OVSSwitch ):
|
||||
return switches
|
||||
|
||||
@classmethod
|
||||
# pylint: disable=arguments-differ
|
||||
def batchShutdown( cls, switches, **_kwargs ):
|
||||
"Stop switches in per-server batches"
|
||||
key = attrgetter( 'server' )
|
||||
@@ -413,8 +417,9 @@ class RemoteLink( Link ):
|
||||
# And we can't ssh into this server remotely as 'localhost',
|
||||
# so try again swappping node1 and node2
|
||||
if node2.server == 'localhost':
|
||||
return self.makeTunnel( node2, node1, intfname2, intfname1,
|
||||
addr2, addr1 )
|
||||
return self.makeTunnel( node1=node2, node2=node1,
|
||||
intfname1=intfname2, intfname2=intfname1,
|
||||
addr1=addr2, addr2=addr1 )
|
||||
debug( '\n*** Make SSH tunnel ' + node1.server + ':' + intfname1 +
|
||||
' == ' + node2.server + ':' + intfname2 )
|
||||
# 1. Create tap interfaces
|
||||
@@ -435,13 +440,16 @@ class RemoteLink( Link ):
|
||||
# When we receive the character '@', it means that our
|
||||
# tunnel should be set up
|
||||
debug( 'Waiting for tunnel to come up...\n' )
|
||||
ch = tunnel.stdout.read( 1 )
|
||||
ch = decode( tunnel.stdout.read( 1 ) )
|
||||
if ch != '@':
|
||||
raise Exception( 'makeTunnel:\n',
|
||||
'Tunnel setup failed for',
|
||||
'%s:%s' % ( node1, node1.dest ), 'to',
|
||||
'%s:%s\n' % ( node2, node2.dest ),
|
||||
'command was:', cmd, '\n' )
|
||||
ch += decode( tunnel.stdout.read() )
|
||||
cmd = ' '.join( cmd )
|
||||
raise Exception( 'makeTunnel:\n'
|
||||
'Tunnel setup failed for '
|
||||
'%s:%s' % ( node1, node1.dest ) + ' to '
|
||||
'%s:%s\n' % ( node2, node2.dest ) +
|
||||
'command was: %s' % cmd + '\n' +
|
||||
'result was: ' + ch )
|
||||
# 3. Move interfaces if necessary
|
||||
for node in node1, node2:
|
||||
if not self.moveIntf( 'tap9', node ):
|
||||
@@ -526,8 +534,9 @@ class RemoteGRELink( RemoteLink ):
|
||||
# We should never try to create a tunnel to ourselves!
|
||||
assert node1.server != node2.server
|
||||
if node2.server == 'localhost':
|
||||
return self.makeTunnel( node2, node1, intfname2, intfname1,
|
||||
addr2, addr1 )
|
||||
return self.makeTunnel( node1=node2, node2=node1,
|
||||
intfname1=intfname2, intfname2=intfname1,
|
||||
addr1=addr2, addr2=addr1 )
|
||||
IP1, IP2 = node1.serverIP, node2.serverIP
|
||||
# GRE tunnel needs to be set up with the IP of the local interface
|
||||
# that connects the remote node, NOT '127.0.0.1' of localhost
|
||||
@@ -555,6 +564,7 @@ class RemoteGRELink( RemoteLink ):
|
||||
node.rcmd('ip link set dev %s mtu 1450' % intfname)
|
||||
if not self.moveIntf(intfname, node):
|
||||
raise Exception('interface move failed on node %s' % node)
|
||||
return None # May want to return something useful here
|
||||
|
||||
|
||||
# Some simple placement algorithms for MininetCluster
|
||||
@@ -589,10 +599,10 @@ class Placer( object ):
|
||||
|
||||
class RandomPlacer( Placer ):
|
||||
"Random placement"
|
||||
def place( self, nodename ):
|
||||
def place( self, node ):
|
||||
"""Random placement function
|
||||
nodename: node name"""
|
||||
assert nodename # please pylint
|
||||
node: node"""
|
||||
assert node # please pylint
|
||||
# This may be slow with lots of servers
|
||||
return self.servers[ randrange( 0, len( self.servers ) ) ]
|
||||
|
||||
@@ -606,10 +616,10 @@ class RoundRobinPlacer( Placer ):
|
||||
Placer.__init__( self, *args, **kwargs )
|
||||
self.next = 0
|
||||
|
||||
def place( self, nodename ):
|
||||
def place( self, node ):
|
||||
"""Round-robin placement function
|
||||
nodename: node name"""
|
||||
assert nodename # please pylint
|
||||
node: node"""
|
||||
assert node # please pylint
|
||||
# This may be slow with lots of servers
|
||||
server = self.servers[ self.next ]
|
||||
self.next = ( self.next + 1 ) % len( self.servers )
|
||||
@@ -647,7 +657,7 @@ class SwitchBinPlacer( Placer ):
|
||||
tickets = sum( [ binsizes[ server ] * [ server ]
|
||||
for server in servers ], [] )
|
||||
# And assign one ticket to each node
|
||||
return { node: ticket for node, ticket in zip( nodes, tickets ) }
|
||||
return dict( zip( nodes, tickets ) )
|
||||
|
||||
def calculatePlacement( self ):
|
||||
"Pre-calculate node placement"
|
||||
@@ -704,21 +714,21 @@ class HostSwitchBinPlacer( Placer ):
|
||||
self.cset = frozenset( self.controllers )
|
||||
self.hind, self.sind, self.cind = 0, 0, 0
|
||||
|
||||
def place( self, nodename ):
|
||||
def place( self, node ):
|
||||
"""Simple placement algorithm:
|
||||
place nodes into evenly sized bins"""
|
||||
# Place nodes into bins
|
||||
if nodename in self.hset:
|
||||
if node in self.hset:
|
||||
server = self.servdict[ self.hind / self.hbin ]
|
||||
self.hind += 1
|
||||
elif nodename in self.sset:
|
||||
elif node in self.sset:
|
||||
server = self.servdict[ self.sind / self.sbin ]
|
||||
self.sind += 1
|
||||
elif nodename in self.cset:
|
||||
elif node in self.cset:
|
||||
server = self.servdict[ self.cind / self.cbin ]
|
||||
self.cind += 1
|
||||
else:
|
||||
info( 'warning: unknown node', nodename )
|
||||
info( 'warning: unknown node', node )
|
||||
server = self.servdict[ 0 ]
|
||||
return server
|
||||
|
||||
@@ -764,6 +774,7 @@ class MininetCluster( Mininet ):
|
||||
# Make sure control directory exists
|
||||
self.cdir = os.environ[ 'HOME' ] + '/.ssh/mn'
|
||||
errRun( [ 'mkdir', '-p', self.cdir ] )
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
Mininet.__init__( self, *args, **params )
|
||||
|
||||
def popen( self, cmd ):
|
||||
@@ -840,31 +851,43 @@ class MininetCluster( Mininet ):
|
||||
if cfile:
|
||||
config.setdefault( 'controlPath', cfile )
|
||||
|
||||
@staticmethod
|
||||
def isLoopback( ipaddr ):
|
||||
"Is ipaddr an IPv4 loopback address?"
|
||||
return ipaddr.startswith( '127.' )
|
||||
|
||||
# pylint: disable=arguments-differ,signature-differs
|
||||
def addController( self, *args, **kwargs ):
|
||||
"Patch to update IP address to global IP address"
|
||||
controller = Mininet.addController( self, *args, **kwargs )
|
||||
loopback = '127.0.0.1'
|
||||
controllerIP = controller.IP()
|
||||
if ( not isinstance( controller, Controller ) or
|
||||
controller.IP() != loopback ):
|
||||
return
|
||||
not self.isLoopback( controller.IP() ) ):
|
||||
return controller
|
||||
# Find route to a different server IP address
|
||||
serverIPs = [ ip for ip in self.serverIP.values()
|
||||
if ip is not controller.IP() ]
|
||||
if ip != controllerIP ]
|
||||
if not serverIPs:
|
||||
return # no remote servers - loopback is fine
|
||||
remoteIP = serverIPs[ 0 ]
|
||||
# Route should contain 'dev <intfname>'
|
||||
route = controller.cmd( 'ip route get', remoteIP,
|
||||
r'| egrep -o "dev\s[^[:space:]]+"' )
|
||||
if not route:
|
||||
raise Exception('addController: no route from', controller,
|
||||
'to', remoteIP )
|
||||
intf = route.split()[ 1 ].strip()
|
||||
return None # no remote servers - loopback is fine
|
||||
for remoteIP in serverIPs:
|
||||
# Route should contain 'dev <intfname>'
|
||||
route = controller.cmd( 'ip route get', remoteIP,
|
||||
r'| egrep -o "dev\s[^[:space:]]+"' )
|
||||
if not route:
|
||||
raise Exception('addController: no route from', controller,
|
||||
'to', remoteIP )
|
||||
intf = route.split()[ 1 ].strip()
|
||||
if intf != 'lo':
|
||||
break
|
||||
if intf == 'lo':
|
||||
raise Exception( 'addController: could not find external '
|
||||
'interface/IP for %s' % controller )
|
||||
debug( 'adding', intf, 'to', controller )
|
||||
Intf( intf, node=controller ).updateIP()
|
||||
debug( controller, 'IP address updated to', controller.IP() )
|
||||
return controller
|
||||
|
||||
# pylint: disable=arguments-differ,signature-differs
|
||||
def buildFromTopo( self, *args, **kwargs ):
|
||||
"Start network"
|
||||
info( '*** Placing nodes\n' )
|
||||
@@ -873,9 +896,12 @@ class MininetCluster( Mininet ):
|
||||
Mininet.buildFromTopo( self, *args, **kwargs )
|
||||
|
||||
|
||||
def testNsTunnels( remote='ubuntu2', link=RemoteGRELink ):
|
||||
# Default remote server for tests
|
||||
remoteServer = 'ubuntu2'
|
||||
|
||||
def testNsTunnels( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test tunnels between nodes in namespaces"
|
||||
net = Mininet( host=RemoteHost, link=link )
|
||||
net = Mininet( host=RemoteHost, link=link, waitConnected=True )
|
||||
h1 = net.addHost( 'h1')
|
||||
h2 = net.addHost( 'h2', server=remote )
|
||||
net.addLink( h1, h2 )
|
||||
@@ -888,13 +914,14 @@ def testNsTunnels( remote='ubuntu2', link=RemoteGRELink ):
|
||||
# This shows how node options may be used to manage
|
||||
# cluster placement using the net.add*() API
|
||||
|
||||
def testRemoteNet( remote='ubuntu2', link=RemoteGRELink ):
|
||||
def testRemoteNet( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test remote Node classes"
|
||||
info( '*** Remote Node Test\n' )
|
||||
net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch, link=link )
|
||||
net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch,
|
||||
link=link, controller=ClusterController,
|
||||
waitConnected=True )
|
||||
c0 = net.addController( 'c0' )
|
||||
# Make sure controller knows its non-loopback address
|
||||
Intf( 'eth0', node=c0 ).updateIP()
|
||||
info( "*** Creating local h1\n" )
|
||||
h1 = net.addHost( 'h1' )
|
||||
info( "*** Creating remote h2\n" )
|
||||
@@ -926,7 +953,7 @@ def testRemoteNet( remote='ubuntu2', link=RemoteGRELink ):
|
||||
|
||||
remoteHosts = [ 'h2' ]
|
||||
remoteSwitches = [ 's2' ]
|
||||
remoteServer = 'ubuntu2'
|
||||
|
||||
|
||||
def HostPlacer( name, *args, **params ):
|
||||
"Custom Host() constructor which places hosts on servers"
|
||||
@@ -943,10 +970,21 @@ def SwitchPlacer( name, *args, **params ):
|
||||
return RemoteOVSSwitch( name, *args, **params )
|
||||
|
||||
def ClusterController( *args, **kwargs):
|
||||
"Custom Controller() constructor which updates its eth0 IP address"
|
||||
"Custom Controller() constructor which updates its intf IP address"
|
||||
intf = kwargs.pop( 'intf', '' )
|
||||
controller = Controller( *args, **kwargs )
|
||||
# Find out its IP address so that cluster switches can connect
|
||||
Intf( 'eth0', node=controller ).updateIP()
|
||||
if not intf:
|
||||
output = controller.cmd(
|
||||
r"ip a | egrep -o '\w+:\s\w+'" ).split( '\n' )
|
||||
for line in output:
|
||||
intf = line.split()[ -1 ]
|
||||
if intf != 'lo':
|
||||
break
|
||||
if intf == 'lo':
|
||||
raise Exception( 'Could not find non-loopback interface'
|
||||
'for %s' % controller )
|
||||
Intf( intf, node=controller ).updateIP()
|
||||
return controller
|
||||
|
||||
def testRemoteTopo( link=RemoteGRELink ):
|
||||
@@ -963,7 +1001,7 @@ def testRemoteTopo( link=RemoteGRELink ):
|
||||
# do random switch placement rather than completely random
|
||||
# host placement.
|
||||
|
||||
def testRemoteSwitches( remote='ubuntu2', link=RemoteGRELink ):
|
||||
def testRemoteSwitches( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test with local hosts and remote switches"
|
||||
servers = [ 'localhost', remote]
|
||||
topo = TreeTopo( depth=4, fanout=2 )
|
||||
@@ -981,7 +1019,7 @@ def testRemoteSwitches( remote='ubuntu2', link=RemoteGRELink ):
|
||||
# functions, for maximum ease of use. MininetCluster() also
|
||||
# pre-flights and multiplexes server connections.
|
||||
|
||||
def testMininetCluster( remote='ubuntu2', link=RemoteGRELink ):
|
||||
def testMininetCluster( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test MininetCluster()"
|
||||
servers = [ 'localhost', remote ]
|
||||
topo = TreeTopo( depth=3, fanout=3 )
|
||||
@@ -991,7 +1029,7 @@ def testMininetCluster( remote='ubuntu2', link=RemoteGRELink ):
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
|
||||
def signalTest( remote='ubuntu2'):
|
||||
def signalTest( remote=remoteServer):
|
||||
"Make sure hosts are robust to signals"
|
||||
h = RemoteHost( 'h0', server=remote )
|
||||
h.shell.send_signal( SIGINT )
|
||||
@@ -1006,7 +1044,6 @@ def signalTest( remote='ubuntu2'):
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
remoteServer = 'ubuntu2'
|
||||
remoteLink = RemoteSSHLink
|
||||
testRemoteTopo(link=remoteLink)
|
||||
testNsTunnels( remote=remoteServer, link=remoteLink )
|
||||
|
||||
@@ -17,6 +17,7 @@ def clusterSanity():
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
clusterSanity()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"CLI for Mininet Cluster Edition prototype demo"
|
||||
|
||||
@@ -31,6 +31,7 @@ class ClusterCLI( CLI ):
|
||||
if not nx:
|
||||
try:
|
||||
# pylint: disable=import-error,no-member
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import networkx
|
||||
nx = networkx # satisfy pylint
|
||||
from matplotlib import pyplot
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"clusterdemo.py: demo of Mininet Cluster Edition prototype"
|
||||
|
||||
@@ -13,12 +13,13 @@ def demo():
|
||||
"Simple Demo of Cluster Mode"
|
||||
servers = [ 'localhost', 'ubuntu2', 'ubuntu3' ]
|
||||
topo = TreeTopo( depth=3, fanout=3 )
|
||||
net = MininetCluster( topo=topo, servers=servers, Link=RemoteLink,
|
||||
net = MininetCluster( topo=topo, servers=servers, link=RemoteLink,
|
||||
placement=SwitchBinPlacer )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
demo()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"clusterperf.py compare the maximum throughput between SSH and GRE tunnels"
|
||||
|
||||
@@ -8,7 +8,7 @@ from mininet.log import setLogLevel
|
||||
|
||||
def perf(Link):
|
||||
"Test connectivity nand performance over Link"
|
||||
net = Mininet( host=RemoteHost, link=Link )
|
||||
net = Mininet( host=RemoteHost, link=Link, waitConnected=True )
|
||||
h1 = net.addHost( 'h1')
|
||||
h2 = net.addHost( 'h2', server='ubuntu2' )
|
||||
net.addLink( h1, h2 )
|
||||
@@ -17,6 +17,7 @@ def perf(Link):
|
||||
net.iperf()
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel('info')
|
||||
perf( RemoteSSHLink )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
consoles.py: bring up a bunch of miniature consoles on a virtual network
|
||||
@@ -27,6 +27,7 @@ Bob Lantz, April 2010
|
||||
|
||||
import re
|
||||
|
||||
# pylint: disable=import-error
|
||||
from Tkinter import Frame, Button, Label, Text, Scrollbar, Canvas, Wm, READABLE
|
||||
|
||||
from mininet.log import setLogLevel
|
||||
@@ -34,6 +35,9 @@ from mininet.topolib import TreeNet
|
||||
from mininet.term import makeTerms, cleanUpScreens
|
||||
from mininet.util import quietRun
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
class Console( Frame ):
|
||||
"A simple console on a host."
|
||||
|
||||
@@ -319,7 +323,7 @@ class ConsoleApp( Frame ):
|
||||
if not m:
|
||||
return
|
||||
val, units = float( m.group( 1 ) ), m.group( 2 )
|
||||
#convert to Gbps
|
||||
# convert to Gbps
|
||||
if units[0] == 'M':
|
||||
val *= 10 ** -3
|
||||
elif units[0] == 'K':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Create a network where different switches are connected to
|
||||
@@ -26,8 +26,9 @@ class MultiSwitch( OVSSwitch ):
|
||||
def start( self, controllers ):
|
||||
return OVSSwitch.start( self, [ cmap[ self.name ] ] )
|
||||
|
||||
|
||||
topo = TreeTopo( depth=2, fanout=2 )
|
||||
net = Mininet( topo=topo, switch=MultiSwitch, build=False )
|
||||
net = Mininet( topo=topo, switch=MultiSwitch, build=False, waitConnected=True )
|
||||
for c in [ c0, c1 ]:
|
||||
net.addController(c)
|
||||
net.build()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example creates a multi-controller network from semi-scratch by
|
||||
@@ -20,7 +20,8 @@ from mininet.log import setLogLevel, info
|
||||
def multiControllerNet():
|
||||
"Create a network from semi-scratch with multiple controllers."
|
||||
|
||||
net = Mininet( controller=Controller, switch=OVSSwitch )
|
||||
net = Mininet( controller=Controller, switch=OVSSwitch,
|
||||
waitConnected=True )
|
||||
|
||||
info( "*** Creating (reference) controllers\n" )
|
||||
c1 = net.addController( 'c1', port=6633 )
|
||||
@@ -57,6 +58,7 @@ def multiControllerNet():
|
||||
info( "*** Stopping network\n" )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' ) # for CLI output
|
||||
multiControllerNet()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
controlnet.py: Mininet with a custom control network
|
||||
@@ -59,13 +59,14 @@ class MininetFacade( object ):
|
||||
|
||||
def __getitem__( self, key ):
|
||||
"returns primary/named networks or node from any net"
|
||||
#search kwargs for net named key
|
||||
# search kwargs for net named key
|
||||
if key in self.nameToNet:
|
||||
return self.nameToNet[ key ]
|
||||
#search each net for node named key
|
||||
# search each net for node named key
|
||||
for net in self.nets:
|
||||
if key in net:
|
||||
return net[ key ]
|
||||
return None
|
||||
|
||||
def __iter__( self ):
|
||||
"Iterate through all nodes in all Mininet objects"
|
||||
@@ -100,6 +101,7 @@ class MininetFacade( object ):
|
||||
|
||||
class ControlNetwork( Topo ):
|
||||
"Control Network Topology"
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, n, dataController=DataController, **_kwargs ):
|
||||
"""n: number of data network controller nodes
|
||||
dataController: class for data network controllers"""
|
||||
@@ -123,7 +125,8 @@ def run():
|
||||
|
||||
info( '* Creating Control Network\n' )
|
||||
ctopo = ControlNetwork( n=4, dataController=DataController )
|
||||
cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None )
|
||||
cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24',
|
||||
controller=None, waitConnected=True )
|
||||
info( '* Adding Control Network Controller\n')
|
||||
cnet.addController( 'cc0', controller=Controller )
|
||||
info( '* Starting Control Network\n')
|
||||
@@ -133,7 +136,8 @@ def run():
|
||||
topo = TreeTopo( depth=2, fanout=2 )
|
||||
# UserSwitch so we can easily test failover
|
||||
sw = partial( UserSwitch, opts='--inactivity-probe=1 --max-backoff=1' )
|
||||
net = Mininet( topo=topo, switch=sw, controller=None )
|
||||
net = Mininet( topo=topo, switch=sw, controller=None,
|
||||
waitConnected=True )
|
||||
info( '* Adding Controllers to Data Network\n' )
|
||||
for host in cnet.hosts:
|
||||
if isinstance(host, Controller):
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
cpu.py: test iperf bandwidth for varying cpu limits
|
||||
@@ -52,9 +52,9 @@ def bwtest( cpuLimits, period_us=100000, seconds=10 ):
|
||||
period_us=period_us,
|
||||
cpu=.5*cpu )
|
||||
try:
|
||||
net = Mininet( topo=topo, host=host )
|
||||
net = Mininet( topo=topo, host=host, waitConnected=True )
|
||||
# pylint: disable=bare-except
|
||||
except:
|
||||
except: # noqa
|
||||
info( '*** Skipping scheduler %s and cleaning up\n' % sched )
|
||||
cleanup()
|
||||
break
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example shows how to create an empty Mininet object
|
||||
@@ -14,7 +14,7 @@ def emptyNet():
|
||||
|
||||
"Create an empty network and add nodes to it."
|
||||
|
||||
net = Mininet( controller=Controller )
|
||||
net = Mininet( controller=Controller, waitConnected=True )
|
||||
|
||||
info( '*** Adding controller\n' )
|
||||
net.addController( 'c0' )
|
||||
@@ -39,6 +39,7 @@ def emptyNet():
|
||||
info( '*** Stopping network' )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
emptyNet()
|
||||
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example shows how to add an interface (for example a real
|
||||
@@ -8,6 +8,8 @@ hardware interface) to a network after the network is created.
|
||||
import re
|
||||
import sys
|
||||
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import setLogLevel, info, error
|
||||
from mininet.net import Mininet
|
||||
@@ -15,6 +17,7 @@ from mininet.link import Intf
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import quietRun
|
||||
|
||||
|
||||
def checkIntf( intf ):
|
||||
"Make sure intf exists and is not configured."
|
||||
config = quietRun( 'ifconfig %s 2>/dev/null' % intf, shell=True )
|
||||
@@ -27,6 +30,7 @@ def checkIntf( intf ):
|
||||
'and is probably in use!\n' )
|
||||
exit( 1 )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
|
||||
@@ -38,7 +42,7 @@ if __name__ == '__main__':
|
||||
checkIntf( intfName )
|
||||
|
||||
info( '*** Creating network\n' )
|
||||
net = Mininet( topo=TreeTopo( depth=1, fanout=2 ) )
|
||||
net = Mininet( topo=TreeTopo( depth=1, fanout=2 ), waitConnected=True )
|
||||
|
||||
switch = net.switches[ 0 ]
|
||||
info( '*** Adding hardware interface', intfName, 'to switch',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
'''
|
||||
example of using various TCIntf options.
|
||||
@@ -13,7 +13,7 @@ from mininet.link import TCLink
|
||||
|
||||
def intfOptions():
|
||||
"run various traffic control commands on a single interface"
|
||||
net = Mininet( autoStaticArp=True )
|
||||
net = Mininet( autoStaticArp=True, waitConnected=True )
|
||||
net.addController( 'c0' )
|
||||
h1 = net.addHost( 'h1' )
|
||||
h2 = net.addHost( 'h2' )
|
||||
@@ -25,10 +25,10 @@ def intfOptions():
|
||||
# flush out latency from reactive forwarding delay
|
||||
net.pingAll()
|
||||
|
||||
info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' )
|
||||
link1.intf1.config( bw=5 )
|
||||
info( '\n*** Configuring one intf with bandwidth of 10 Mb\n' )
|
||||
link1.intf1.config( bw=10 )
|
||||
info( '\n*** Running iperf to test\n' )
|
||||
net.iperf()
|
||||
net.iperf( seconds=10 )
|
||||
|
||||
info( '\n*** Configuring one intf with loss of 50%\n' )
|
||||
link1.intf1.config( loss=50 )
|
||||
@@ -43,6 +43,7 @@ def intfOptions():
|
||||
info( '\n*** Done testing\n' )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
intfOptions()
|
||||
|
||||
+4
-3
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
limit.py: example of using link and CPU limits
|
||||
@@ -34,7 +34,7 @@ def limit( bw=10, cpu=.1 ):
|
||||
'Skipping this test\n' )
|
||||
continue
|
||||
host = custom( CPULimitedHost, sched=sched, cpu=cpu )
|
||||
net = Mininet( topo=myTopo, intf=intf, host=host )
|
||||
net = Mininet( topo=myTopo, intf=intf, host=host, waitConnected=True )
|
||||
net.start()
|
||||
testLinkLimit( net, bw=bw )
|
||||
net.runCpuLimitTest( cpu=cpu )
|
||||
@@ -43,7 +43,7 @@ def limit( bw=10, cpu=.1 ):
|
||||
def verySimpleLimit( bw=150 ):
|
||||
"Absurdly simple limiting test"
|
||||
intf = custom( TCIntf, bw=bw )
|
||||
net = Mininet( intf=intf )
|
||||
net = Mininet( intf=intf, waitConnected=True )
|
||||
h1, h2 = net.addHost( 'h1' ), net.addHost( 'h2' )
|
||||
net.addLink( h1, h2 )
|
||||
net.start()
|
||||
@@ -55,6 +55,7 @@ def verySimpleLimit( bw=150 ):
|
||||
h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
limit()
|
||||
|
||||
+15
-10
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test bandwidth (using iperf) on linear networks of varying size,
|
||||
@@ -24,20 +24,24 @@ of switches, this example demonstrates:
|
||||
"""
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
from functools import partial
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch, Controller
|
||||
from mininet.topo import Topo
|
||||
from mininet.log import lg, info
|
||||
from mininet.util import irange, quietRun
|
||||
from mininet.link import TCLink
|
||||
from functools import partial
|
||||
|
||||
import sys
|
||||
flush = sys.stdout.flush
|
||||
|
||||
|
||||
class LinearTestTopo( Topo ):
|
||||
"Topology for a string of N hosts and N-1 switches."
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, N, **params ):
|
||||
# Create switches and hosts
|
||||
hosts = [ self.addHost( 'h%s' % h )
|
||||
@@ -79,14 +83,14 @@ def linearBandwidthTest( lengths ):
|
||||
output = quietRun( 'sysctl -w net.ipv4.tcp_congestion_control=reno' )
|
||||
assert 'reno' in output
|
||||
|
||||
for datapath in switches.keys():
|
||||
for datapath in switches:
|
||||
info( "*** testing", datapath, "datapath\n" )
|
||||
Switch = switches[ datapath ]
|
||||
results[ datapath ] = []
|
||||
link = partial( TCLink, delay='2ms', bw=10 )
|
||||
link = partial( TCLink, delay='30ms', bw=100 )
|
||||
net = Mininet( topo=topo, switch=Switch,
|
||||
controller=Controller, waitConnected=True,
|
||||
link=link )
|
||||
controller=Controller, link=link,
|
||||
waitConnected=True )
|
||||
net.start()
|
||||
info( "*** testing basic connectivity\n" )
|
||||
for n in lengths:
|
||||
@@ -99,13 +103,13 @@ def linearBandwidthTest( lengths ):
|
||||
src.cmd( 'telnet', dst.IP(), '5001' )
|
||||
info( "testing", src.name, "<->", dst.name, '\n' )
|
||||
# serverbw = received; _clientbw = buffered
|
||||
serverbw, _clientbw = net.iperf( [ src, dst ], seconds=10 )
|
||||
serverbw, _clientbw = net.iperf( [ src, dst ], seconds=5 )
|
||||
info( serverbw, '\n' )
|
||||
flush()
|
||||
results[ datapath ] += [ ( n, serverbw ) ]
|
||||
net.stop()
|
||||
|
||||
for datapath in switches.keys():
|
||||
for datapath in switches:
|
||||
info( "\n*** Linear network results for", datapath, "datapath:\n" )
|
||||
result = results[ datapath ]
|
||||
info( "SwitchCount\tiperf Results\n" )
|
||||
@@ -115,8 +119,9 @@ def linearBandwidthTest( lengths ):
|
||||
info( '\n')
|
||||
info( '\n' )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info' )
|
||||
sizes = [ 1, 10, 20, 40, 60, 80 ]
|
||||
sizes = [ 1, 2, 3, 4 ]
|
||||
info( "*** Running linearBandwidthTest", sizes, '\n' )
|
||||
linearBandwidthTest( sizes )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
linuxrouter.py: Example network with Linux IP router
|
||||
@@ -38,6 +38,7 @@ from mininet.cli import CLI
|
||||
class LinuxRouter( Node ):
|
||||
"A Node with IP forwarding enabled."
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def config( self, **params ):
|
||||
super( LinuxRouter, self).config( **params )
|
||||
# Enable forwarding on the router
|
||||
@@ -51,6 +52,7 @@ class LinuxRouter( Node ):
|
||||
class NetworkTopo( Topo ):
|
||||
"A LinuxRouter connecting three IP subnets"
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, **_opts ):
|
||||
|
||||
defaultIP = '192.168.1.1/24' # IP address for r0-eth1
|
||||
@@ -79,13 +81,15 @@ class NetworkTopo( Topo ):
|
||||
def run():
|
||||
"Test linux router"
|
||||
topo = NetworkTopo()
|
||||
net = Mininet( topo=topo ) # controller is used by s1-s3
|
||||
net = Mininet( topo=topo,
|
||||
waitConnected=True ) # controller is used by s1-s3
|
||||
net.start()
|
||||
info( '*** Routing Table on Router:\n' )
|
||||
info( net[ 'r0' ].cmd( 'route' ) )
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
run()
|
||||
|
||||
+75
-71
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
MiniEdit: a simple network editor for Mininet
|
||||
@@ -13,16 +13,30 @@ Controller icon from http://semlabs.co.uk/
|
||||
OpenFlow icon from https://www.opennetworking.org/
|
||||
"""
|
||||
|
||||
# Miniedit needs some work in order to pass pylint...
|
||||
# pylint: disable=line-too-long,too-many-branches
|
||||
# pylint: disable=too-many-statements,attribute-defined-outside-init
|
||||
# pylint: disable=missing-docstring
|
||||
|
||||
MINIEDIT_VERSION = '2.2.0.1'
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from distutils.version import StrictVersion
|
||||
from functools import partial
|
||||
from optparse import OptionParser
|
||||
from subprocess import call
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
|
||||
from mininet.log import info, debug, warn, setLogLevel
|
||||
from mininet.net import Mininet, VERSION
|
||||
from mininet.util import (netParse, ipAdd, quietRun,
|
||||
buildTopo, custom, customClass )
|
||||
from mininet.term import makeTerm, cleanUpScreens
|
||||
from mininet.node import (Controller, RemoteController, NOX, OVSController,
|
||||
CPULimitedHost, Host, Node,
|
||||
OVSSwitch, UserSwitch, IVSSwitch )
|
||||
from mininet.link import TCLink, Intf, Link
|
||||
from mininet.cli import CLI
|
||||
from mininet.moduledeps import moduleDeps
|
||||
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||
from mininet.topolib import TreeTopo
|
||||
|
||||
# pylint: disable=import-error
|
||||
if sys.version_info[0] == 2:
|
||||
@@ -47,38 +61,24 @@ else:
|
||||
from tkinter import font as tkFont
|
||||
from tkinter import simpledialog as tkSimpleDialog
|
||||
from tkinter import filedialog as tkFileDialog
|
||||
# someday: from ttk import *
|
||||
# pylint: enable=import-error
|
||||
|
||||
import re
|
||||
import json
|
||||
from distutils.version import StrictVersion
|
||||
import os
|
||||
from functools import partial
|
||||
|
||||
# Miniedit still needs work in order to pass pylint...
|
||||
# pylint: disable=line-too-long,too-many-branches
|
||||
# pylint: disable=too-many-statements,attribute-defined-outside-init
|
||||
# pylint: disable=missing-docstring,too-many-ancestors
|
||||
# pylint: disable=too-many-nested-blocks,too-many-arguments
|
||||
|
||||
|
||||
MINIEDIT_VERSION = '2.2.0.1'
|
||||
|
||||
if 'PYTHONPATH' in os.environ:
|
||||
sys.path = os.environ[ 'PYTHONPATH' ].split( ':' ) + sys.path
|
||||
|
||||
# someday: from ttk import *
|
||||
|
||||
from mininet.log import info, debug, warn, setLogLevel
|
||||
from mininet.net import Mininet, VERSION
|
||||
from mininet.util import netParse, ipAdd, quietRun
|
||||
from mininet.util import buildTopo
|
||||
from mininet.util import custom, customClass
|
||||
from mininet.term import makeTerm, cleanUpScreens
|
||||
from mininet.node import Controller, RemoteController, NOX, OVSController
|
||||
from mininet.node import CPULimitedHost, Host, Node
|
||||
from mininet.node import OVSSwitch, UserSwitch
|
||||
from mininet.link import TCLink, Intf, Link
|
||||
from mininet.cli import CLI
|
||||
from mininet.moduledeps import moduleDeps
|
||||
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||
from mininet.topolib import TreeTopo
|
||||
|
||||
info( 'MiniEdit running against Mininet '+VERSION, '\n' )
|
||||
MININET_VERSION = re.sub(r'[^\d\.]', '', VERSION)
|
||||
if StrictVersion(MININET_VERSION) > StrictVersion('2.0'):
|
||||
from mininet.node import IVSSwitch
|
||||
|
||||
TOPODEF = 'none'
|
||||
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
|
||||
@@ -138,6 +138,7 @@ class LegacyRouter( Node ):
|
||||
def __init__( self, name, inNamespace=True, **params ):
|
||||
Node.__init__( self, name, inNamespace, **params )
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def config( self, **_params ):
|
||||
if self.intfs:
|
||||
self.setParam( _params, 'setIP', ip='0.0.0.0' )
|
||||
@@ -818,8 +819,8 @@ class VerticalScrolledTable(LabelFrame):
|
||||
* This frame only allows vertical scrolling
|
||||
|
||||
"""
|
||||
def __init__(self, parent, rows=2, columns=2, title=None, *args, **kw):
|
||||
LabelFrame.__init__(self, parent, text=title, padx=5, pady=5, *args, **kw)
|
||||
def __init__(self, parent, rows=2, columns=2, title=None, **kw):
|
||||
LabelFrame.__init__(self, parent, text=title, padx=5, pady=5, **kw)
|
||||
|
||||
# create a canvas object and a vertical scrollbar for scrolling it
|
||||
vscrollbar = Scrollbar(self, orient=VERTICAL)
|
||||
@@ -855,8 +856,6 @@ class VerticalScrolledTable(LabelFrame):
|
||||
canvas.itemconfigure(interior_id, width=canvas.winfo_width())
|
||||
canvas.bind('<Configure>', _configure_canvas)
|
||||
|
||||
return
|
||||
|
||||
class TableFrame(Frame):
|
||||
def __init__(self, parent, rows=2, columns=2):
|
||||
|
||||
@@ -888,7 +887,7 @@ class TableFrame(Frame):
|
||||
label.grid(row=self.rows, column=column, sticky="wens", padx=1, pady=1)
|
||||
if value is not None:
|
||||
label.insert(0, value[column])
|
||||
if readonly == True:
|
||||
if readonly:
|
||||
label.configure(state='readonly')
|
||||
current_row.append(label)
|
||||
self._widgets.append(current_row)
|
||||
@@ -1401,11 +1400,11 @@ class MiniEdit( Frame ):
|
||||
|
||||
def addNode( self, node, nodeNum, x, y, name=None):
|
||||
"Add a new node to our canvas."
|
||||
if 'Switch' == node:
|
||||
if node == 'Switch':
|
||||
self.switchCount += 1
|
||||
if 'Host' == node:
|
||||
if node == 'Host':
|
||||
self.hostCount += 1
|
||||
if 'Controller' == node:
|
||||
if node == 'Controller':
|
||||
self.controllerCount += 1
|
||||
if name is None:
|
||||
name = self.nodePrefixes[ node ] + nodeNum
|
||||
@@ -1422,14 +1421,17 @@ class MiniEdit( Frame ):
|
||||
|
||||
def convertJsonUnicode(self, text):
|
||||
"Some part of Mininet don't like Unicode"
|
||||
try:
|
||||
unicode
|
||||
except NameError:
|
||||
return text
|
||||
if isinstance(text, dict):
|
||||
return {self.convertJsonUnicode(key): self.convertJsonUnicode(value) for key, value in text.items()}
|
||||
elif isinstance(text, list):
|
||||
if isinstance(text, list):
|
||||
return [self.convertJsonUnicode(element) for element in text]
|
||||
elif isinstance(text, unicode):
|
||||
if isinstance(text, unicode): # pylint: disable=undefined-variable
|
||||
return text.encode('utf-8')
|
||||
else:
|
||||
return text
|
||||
return text
|
||||
|
||||
def loadTopology( self ):
|
||||
"Load command."
|
||||
@@ -1440,7 +1442,7 @@ class MiniEdit( Frame ):
|
||||
('All Files','*'),
|
||||
]
|
||||
f = tkFileDialog.askopenfile(filetypes=myFormats, mode='rb')
|
||||
if f == None:
|
||||
if f is None:
|
||||
return
|
||||
self.newTopology()
|
||||
loadedTopology = self.convertJsonUnicode(json.load(f))
|
||||
@@ -1601,10 +1603,11 @@ class MiniEdit( Frame ):
|
||||
for widget in self.widgetToItem:
|
||||
if name == widget[ 'text' ]:
|
||||
return widget
|
||||
return None
|
||||
|
||||
def newTopology( self ):
|
||||
"New command."
|
||||
for widget in self.widgetToItem.keys():
|
||||
for widget in self.widgetToItem:
|
||||
self.deleteItem( self.widgetToItem[ widget ] )
|
||||
self.hostCount = 0
|
||||
self.switchCount = 0
|
||||
@@ -1701,7 +1704,7 @@ class MiniEdit( Frame ):
|
||||
# debug( "Now saving under %s\n" % fileName )
|
||||
f = open(fileName, 'wb')
|
||||
|
||||
f.write("#!/usr/bin/python\n")
|
||||
f.write("#!/usr/bin/env python\n")
|
||||
f.write("\n")
|
||||
f.write("from mininet.net import Mininet\n")
|
||||
f.write("from mininet.node import Controller, RemoteController, OVSController\n")
|
||||
@@ -1725,7 +1728,7 @@ class MiniEdit( Frame ):
|
||||
if controllerType == 'inband':
|
||||
inBandCtrl = True
|
||||
|
||||
if inBandCtrl == True:
|
||||
if inBandCtrl:
|
||||
f.write("\n")
|
||||
f.write("class InbandController( RemoteController ):\n")
|
||||
f.write("\n")
|
||||
@@ -2122,7 +2125,7 @@ class MiniEdit( Frame ):
|
||||
c = self.canvas
|
||||
x, y = c.canvasx( event.x ), c.canvasy( event.y )
|
||||
name = self.nodePrefixes[ node ]
|
||||
if 'Switch' == node:
|
||||
if node == 'Switch':
|
||||
self.switchCount += 1
|
||||
name = self.nodePrefixes[ node ] + str( self.switchCount )
|
||||
self.switchOpts[name] = {}
|
||||
@@ -2130,14 +2133,14 @@ class MiniEdit( Frame ):
|
||||
self.switchOpts[name]['hostname']=name
|
||||
self.switchOpts[name]['switchType']='default'
|
||||
self.switchOpts[name]['controllers']=[]
|
||||
if 'LegacyRouter' == node:
|
||||
if node == 'LegacyRouter':
|
||||
self.switchCount += 1
|
||||
name = self.nodePrefixes[ node ] + str( self.switchCount )
|
||||
self.switchOpts[name] = {}
|
||||
self.switchOpts[name]['nodeNum']=self.switchCount
|
||||
self.switchOpts[name]['hostname']=name
|
||||
self.switchOpts[name]['switchType']='legacyRouter'
|
||||
if 'LegacySwitch' == node:
|
||||
if node == 'LegacySwitch':
|
||||
self.switchCount += 1
|
||||
name = self.nodePrefixes[ node ] + str( self.switchCount )
|
||||
self.switchOpts[name] = {}
|
||||
@@ -2145,13 +2148,13 @@ class MiniEdit( Frame ):
|
||||
self.switchOpts[name]['hostname']=name
|
||||
self.switchOpts[name]['switchType']='legacySwitch'
|
||||
self.switchOpts[name]['controllers']=[]
|
||||
if 'Host' == node:
|
||||
if node == 'Host':
|
||||
self.hostCount += 1
|
||||
name = self.nodePrefixes[ node ] + str( self.hostCount )
|
||||
self.hostOpts[name] = {'sched':'host'}
|
||||
self.hostOpts[name]['nodeNum']=self.hostCount
|
||||
self.hostOpts[name]['hostname']=name
|
||||
if 'Controller' == node:
|
||||
if node == 'Controller':
|
||||
name = self.nodePrefixes[ node ] + str( self.controllerCount )
|
||||
ctrlr = { 'controllerType': 'ref',
|
||||
'hostname': name,
|
||||
@@ -2169,15 +2172,15 @@ class MiniEdit( Frame ):
|
||||
self.itemToWidget[ item ] = icon
|
||||
self.selectItem( item )
|
||||
icon.links = {}
|
||||
if 'Switch' == node:
|
||||
if node == 'Switch':
|
||||
icon.bind('<Button-3>', self.do_switchPopup )
|
||||
if 'LegacyRouter' == node:
|
||||
if node == 'LegacyRouter':
|
||||
icon.bind('<Button-3>', self.do_legacyRouterPopup )
|
||||
if 'LegacySwitch' == node:
|
||||
if node == 'LegacySwitch':
|
||||
icon.bind('<Button-3>', self.do_legacySwitchPopup )
|
||||
if 'Host' == node:
|
||||
if node == 'Host':
|
||||
icon.bind('<Button-3>', self.do_hostPopup )
|
||||
if 'Controller' == node:
|
||||
if node == 'Controller':
|
||||
icon.bind('<Button-3>', self.do_controllerPopup )
|
||||
|
||||
def clickController( self, event ):
|
||||
@@ -2247,7 +2250,7 @@ class MiniEdit( Frame ):
|
||||
|
||||
def clickNode( self, event ):
|
||||
"Node click handler."
|
||||
if self.active is 'NetLink':
|
||||
if self.active == 'NetLink':
|
||||
self.startLink( event )
|
||||
else:
|
||||
self.selectNode( event )
|
||||
@@ -2255,14 +2258,14 @@ class MiniEdit( Frame ):
|
||||
|
||||
def dragNode( self, event ):
|
||||
"Node drag handler."
|
||||
if self.active is 'NetLink':
|
||||
if self.active == 'NetLink':
|
||||
self.dragNetLink( event )
|
||||
else:
|
||||
self.dragNodeAround( event )
|
||||
|
||||
def releaseNode( self, event ):
|
||||
"Node release handler."
|
||||
if self.active is 'NetLink':
|
||||
if self.active == 'NetLink':
|
||||
self.finishLink( event )
|
||||
|
||||
# Specific node handlers
|
||||
@@ -2374,6 +2377,8 @@ class MiniEdit( Frame ):
|
||||
# For now, don't allow hosts to be directly linked
|
||||
stags = self.canvas.gettags( self.widgetToItem[ source ] )
|
||||
dtags = self.canvas.gettags( target )
|
||||
# TODO: Make this less confusing
|
||||
# pylint: disable=too-many-boolean-expressions
|
||||
if (('Host' in stags and 'Host' in dtags) or
|
||||
('Controller' in dtags and 'LegacyRouter' in stags) or
|
||||
('Controller' in stags and 'LegacyRouter' in dtags) or
|
||||
@@ -2657,7 +2662,7 @@ class MiniEdit( Frame ):
|
||||
linkopts = {}
|
||||
source.links[ dest ] = self.link
|
||||
dest.links[ source ] = self.link
|
||||
self.links[ self.link ] = {'type' :linktype,
|
||||
self.links[ self.link ] = {'type':linktype,
|
||||
'src':source,
|
||||
'dest':dest,
|
||||
'linkOpts':linkopts}
|
||||
@@ -2698,14 +2703,13 @@ class MiniEdit( Frame ):
|
||||
tags = self.canvas.gettags(item)
|
||||
if 'Controller' in tags:
|
||||
# remove from switch controller lists
|
||||
for serachwidget in self.widgetToItem:
|
||||
name = serachwidget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ serachwidget ] )
|
||||
for searchwidget in self.widgetToItem:
|
||||
name = searchwidget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ searchwidget ] )
|
||||
if 'Switch' in tags:
|
||||
if widget['text'] in self.switchOpts[name]['controllers']:
|
||||
self.switchOpts[name]['controllers'].remove(widget['text'])
|
||||
|
||||
for link in widget.links.values():
|
||||
for link in tuple( widget.links.values() ):
|
||||
# Delete from view and model
|
||||
self.deleteItem( link )
|
||||
del self.itemToWidget[ item ]
|
||||
@@ -3011,7 +3015,7 @@ class MiniEdit( Frame ):
|
||||
## NOTE: MAKE SURE THIS IS LAST THING CALLED
|
||||
# Start the CLI if enabled
|
||||
if self.appPrefs['startCLI'] == '1':
|
||||
info( "\n\n NOTE: PLEASE REMEMBER TO EXIT THE CLI BEFORE YOU PRESS THE STOP BUTTON. Not exiting will prevent MiniEdit from quitting and will prevent you from starting the network again during this sessoin.\n\n")
|
||||
info( "\n\n NOTE: PLEASE REMEMBER TO EXIT THE CLI BEFORE YOU PRESS THE STOP BUTTON. Not exiting will prevent MiniEdit from quitting and will prevent you from starting the network again during this session.\n\n")
|
||||
CLI(self.net)
|
||||
|
||||
def start( self ):
|
||||
@@ -3225,7 +3229,8 @@ class MiniEdit( Frame ):
|
||||
"Parse custom file and add params before parsing cmd-line options."
|
||||
customs = {}
|
||||
if os.path.isfile( fileName ):
|
||||
execfile( fileName, customs, customs )
|
||||
with open( fileName, 'r' ) as f:
|
||||
exec( f.read() ) # pylint: disable=exec-used
|
||||
for name, val in customs.items():
|
||||
self.setCustom( name, val )
|
||||
else:
|
||||
@@ -3592,8 +3597,7 @@ def addDictOption( opts, choicesDict, default, name, helpStr=None ):
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
app = MiniEdit()
|
||||
### import topology if specified ###
|
||||
app.parseArgs()
|
||||
### import topology if specified ###
|
||||
app.importTopo()
|
||||
|
||||
app.mainloop()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Simple example of Mobility with Mininet
|
||||
@@ -19,14 +19,13 @@ to-do:
|
||||
- think about clearing last hop - why doesn't that work?
|
||||
"""
|
||||
|
||||
from random import randint
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import OVSSwitch
|
||||
from mininet.topo import LinearTopo
|
||||
from mininet.log import info, output, warn, setLogLevel
|
||||
|
||||
from random import randint
|
||||
|
||||
|
||||
class MobilitySwitch( OVSSwitch ):
|
||||
"Switch that can reattach and rename interfaces"
|
||||
@@ -38,6 +37,7 @@ class MobilitySwitch( OVSSwitch ):
|
||||
del self.intfs[ port ]
|
||||
del self.nameToIntf[ intf.name ]
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def addIntf( self, intf, rename=False, **kwargs ):
|
||||
"Add (and reparent) an interface"
|
||||
OVSSwitch.addIntf( self, intf, **kwargs )
|
||||
@@ -107,7 +107,8 @@ def moveHost( host, oldSwitch, newSwitch, newPort=None ):
|
||||
def mobilityTest():
|
||||
"A simple test of mobility"
|
||||
info( '* Simple mobility test\n' )
|
||||
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch )
|
||||
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch,
|
||||
waitConnected=True )
|
||||
info( '* Starting network:\n' )
|
||||
net.start()
|
||||
printConnections( net.switches )
|
||||
@@ -131,6 +132,7 @@ def mobilityTest():
|
||||
old = new
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
mobilityTest()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This is a simple example that demonstrates multiple links
|
||||
@@ -13,7 +13,7 @@ from mininet.topo import Topo
|
||||
def runMultiLink():
|
||||
"Create and run multiple link network"
|
||||
topo = simpleMultiLinkTopo( n=2 )
|
||||
net = Mininet( topo=topo )
|
||||
net = Mininet( topo=topo, waitConnected=True )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
@@ -21,6 +21,7 @@ def runMultiLink():
|
||||
class simpleMultiLinkTopo( Topo ):
|
||||
"Simple topology with multiple links"
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, n, **_kwargs ):
|
||||
h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' )
|
||||
s1 = self.addSwitch( 's1' )
|
||||
@@ -29,6 +30,7 @@ class simpleMultiLinkTopo( Topo ):
|
||||
self.addLink( s1, h1 )
|
||||
self.addLink( s1, h2 )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
runMultiLink()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
multiping.py: monitor multiple sets of hosts using ping
|
||||
@@ -8,14 +8,14 @@ multiple hosts and monitor their output interactively for a period=
|
||||
of time.
|
||||
"""
|
||||
|
||||
from select import poll, POLLIN
|
||||
from time import time
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Node
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import info, setLogLevel
|
||||
|
||||
from select import poll, POLLIN
|
||||
from time import time
|
||||
|
||||
def chunks( l, n ):
|
||||
"Divide list l into chunks of size n - thanks Stackoverflow"
|
||||
@@ -59,7 +59,7 @@ def multiping( netsize, chunksize, seconds):
|
||||
# Start pings
|
||||
for subnet in subnets:
|
||||
ips = [ host.IP() for host in subnet ]
|
||||
#adding bogus to generate packet loss
|
||||
# adding bogus to generate packet loss
|
||||
ips.append( '10.0.0.200' )
|
||||
for host in subnet:
|
||||
startpings( host, ips )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Simple example of sending output to multiple files and
|
||||
@@ -6,15 +6,15 @@ monitoring them
|
||||
"""
|
||||
|
||||
|
||||
from time import time
|
||||
from select import poll, POLLIN
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.net import Mininet
|
||||
from mininet.log import info, setLogLevel
|
||||
from mininet.util import decode
|
||||
|
||||
from time import time
|
||||
from select import poll, POLLIN
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
|
||||
def monitorFiles( outfiles, seconds, timeoutms ):
|
||||
"Monitor set of files and return [(host, line)...]"
|
||||
@@ -53,7 +53,7 @@ def monitorFiles( outfiles, seconds, timeoutms ):
|
||||
def monitorTest( N=3, seconds=3 ):
|
||||
"Run pings and monitor multiple hosts"
|
||||
topo = SingleSwitchTopo( N )
|
||||
net = Mininet( topo )
|
||||
net = Mininet( topo, waitConnected=True )
|
||||
net.start()
|
||||
hosts = net.hosts
|
||||
info( "Starting test...\n" )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example shows how to create a network and run multiple tests.
|
||||
@@ -17,12 +17,14 @@ def ifconfigTest( net ):
|
||||
for host in hosts:
|
||||
info( host.cmd( 'ifconfig' ) )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info' )
|
||||
info( "*** Initializing Mininet and kernel modules\n" )
|
||||
OVSKernelSwitch.setup()
|
||||
info( "*** Creating network\n" )
|
||||
network = Mininet( TreeTopo( depth=2, fanout=2 ), switch=OVSKernelSwitch )
|
||||
network = Mininet( TreeTopo( depth=2, fanout=2), switch=OVSKernelSwitch,
|
||||
waitConnected=True )
|
||||
info( "*** Starting network\n" )
|
||||
network.start()
|
||||
info( "*** Running ping test\n" )
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Example to create a Mininet topology and connect it to the internet via NAT
|
||||
@@ -12,7 +12,7 @@ from mininet.topolib import TreeNet
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info')
|
||||
net = TreeNet( depth=1, fanout=4 )
|
||||
net = TreeNet( depth=1, fanout=4, waitConnected=True )
|
||||
# Add NAT connectivity
|
||||
net.addNAT().configDefault()
|
||||
net.start()
|
||||
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
natnet.py: Example network with NATs
|
||||
@@ -27,6 +27,7 @@ from mininet.util import irange
|
||||
|
||||
class InternetTopo(Topo):
|
||||
"Single switch connected to n hosts."
|
||||
# pylint: disable=arguments-differ
|
||||
def build(self, n=2, **_kwargs ):
|
||||
# set up inet switch
|
||||
inetSwitch = self.addSwitch('s0')
|
||||
@@ -57,11 +58,12 @@ class InternetTopo(Topo):
|
||||
def run():
|
||||
"Create network and run the CLI"
|
||||
topo = InternetTopo()
|
||||
net = Mininet(topo=topo)
|
||||
net = Mininet(topo=topo, waitConnected=True )
|
||||
net.start()
|
||||
CLI(net)
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel('info')
|
||||
run()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Create a network with 5 hosts, numbered 1-4 and 9.
|
||||
@@ -28,7 +28,7 @@ def testPortNumbering():
|
||||
mid-level API) and check that implicit and
|
||||
explicit port numbering works as expected."""
|
||||
|
||||
net = Mininet( controller=Controller )
|
||||
net = Mininet( controller=Controller, waitConnected=True )
|
||||
|
||||
info( '*** Adding controller\n' )
|
||||
net.addController( 'c0' )
|
||||
@@ -75,6 +75,7 @@ def testPortNumbering():
|
||||
info( '*** Stopping network\n' )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
testPortNumbering()
|
||||
|
||||
+5
-8
@@ -1,23 +1,19 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example monitors a number of hosts using host.popen() and
|
||||
pmonitor()
|
||||
"""
|
||||
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import setLogLevel, info
|
||||
from mininet.util import custom, pmonitor
|
||||
from mininet.util import pmonitor
|
||||
|
||||
def monitorhosts( hosts=5, sched='cfs' ):
|
||||
def monitorhosts( hosts=5 ):
|
||||
"Start a bunch of pings and monitor them using popen"
|
||||
mytopo = SingleSwitchTopo( hosts )
|
||||
cpu = .5 / hosts
|
||||
myhost = custom( CPULimitedHost, cpu=cpu, sched=sched )
|
||||
net = Mininet( topo=mytopo, host=myhost )
|
||||
net = Mininet( topo=mytopo, waitConnected=True )
|
||||
net.start()
|
||||
# Start a bunch of pings
|
||||
popens = {}
|
||||
@@ -32,6 +28,7 @@ def monitorhosts( hosts=5, sched='cfs' ):
|
||||
# Done
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
monitorhosts( hosts=5 )
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"Monitor multiple hosts using popen()/pmonitor()"
|
||||
|
||||
from time import time
|
||||
from signal import SIGINT
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.util import pmonitor
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
from time import time
|
||||
from signal import SIGINT
|
||||
|
||||
def pmonitorTest( N=3, seconds=10 ):
|
||||
"Run pings and monitor multiple hosts using pmonitor"
|
||||
topo = SingleSwitchTopo( N )
|
||||
net = Mininet( topo )
|
||||
net = Mininet( topo, waitConnected=True )
|
||||
net.start()
|
||||
hosts = net.hosts
|
||||
info( "Starting test...\n" )
|
||||
@@ -31,6 +32,7 @@ def pmonitorTest( N=3, seconds=10 ):
|
||||
p.send_signal( SIGINT )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
pmonitorTest()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Build a simple network from scratch, using mininet primitives.
|
||||
@@ -8,6 +8,7 @@ but it exposes the configuration details and allows customization.
|
||||
For most tasks, the higher-level API will be preferable.
|
||||
"""
|
||||
|
||||
from time import sleep
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Node
|
||||
@@ -15,7 +16,6 @@ from mininet.link import Link
|
||||
from mininet.log import setLogLevel, info
|
||||
from mininet.util import quietRun
|
||||
|
||||
from time import sleep
|
||||
|
||||
def scratchNet( cname='controller', cargs='-v ptcp:' ):
|
||||
"Create network from scratch using Open vSwitch."
|
||||
@@ -62,6 +62,7 @@ def scratchNet( cname='controller', cargs='-v ptcp:' ):
|
||||
switch.deleteIntfs()
|
||||
info( '\n' )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
info( '*** Scratch network demo (kernel datapath)\n' )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Build a simple network from scratch, using mininet primitives.
|
||||
@@ -66,6 +66,7 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):
|
||||
switch.deleteIntfs()
|
||||
info( '\n' )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
info( '*** Scratch network demo (user datapath)\n' )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Simple example of setting network and CPU parameters
|
||||
@@ -9,6 +9,7 @@ iperf will hang indefinitely if the TCP handshake fails
|
||||
to complete.
|
||||
"""
|
||||
|
||||
from sys import argv
|
||||
|
||||
from mininet.topo import Topo
|
||||
from mininet.net import Mininet
|
||||
@@ -17,7 +18,6 @@ from mininet.link import TCLink
|
||||
from mininet.util import dumpNodeConnections
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
from sys import argv
|
||||
|
||||
# It would be nice if we didn't have to do this:
|
||||
# pylint: disable=arguments-differ
|
||||
@@ -54,6 +54,7 @@ def perfTest( lossy=True ):
|
||||
net.iperf( ( h1, h4 ), l4Type='UDP' )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
# Prevent test_simpleperf from failing due to packet loss
|
||||
|
||||
+4
-2
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Create a network and start sshd(8) on each host.
|
||||
@@ -29,7 +29,7 @@ from mininet.util import waitListening
|
||||
def TreeNet( depth=1, fanout=2, **kwargs ):
|
||||
"Convenience function for creating tree networks."
|
||||
topo = TreeTopo( depth, fanout )
|
||||
return Mininet( topo, **kwargs )
|
||||
return Mininet( topo, waitConnected=True, **kwargs )
|
||||
|
||||
def connectToRootNS( network, switch, ip, routes ):
|
||||
"""Connect hosts to root namespace via switch. Starts network.
|
||||
@@ -47,6 +47,7 @@ def connectToRootNS( network, switch, ip, routes ):
|
||||
for route in routes:
|
||||
root.cmd( 'route add -net ' + route + ' dev ' + str( intf ) )
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
|
||||
ip='10.123.123.1/32', routes=None, switch=None ):
|
||||
"""Start a network, connect it to root ns, and run sshd on all hosts.
|
||||
@@ -73,6 +74,7 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
|
||||
host.cmd( 'kill %' + cmd )
|
||||
network.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info')
|
||||
net = TreeNet( depth=1, fanout=4 )
|
||||
|
||||
@@ -14,6 +14,8 @@ class clusterSanityCheck( unittest.TestCase ):
|
||||
def testClusterPingAll( self ):
|
||||
p = pexpect.spawn( 'python -m mininet.examples.clusterSanity' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'py net.waitConnected()' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'pingall' )
|
||||
p.expect ( '(\d+)% dropped' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
|
||||
@@ -7,13 +7,15 @@ Test for controlnet.py
|
||||
import unittest
|
||||
from mininet.util import pexpect
|
||||
|
||||
from sys import stdout
|
||||
|
||||
class testControlNet( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
def testPingall( self ):
|
||||
"Simple pingall test that verifies 0% packet drop in data network"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.controlnet' )
|
||||
p = pexpect.spawn( 'python -m mininet.examples.controlnet', logfile=stdout)
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'pingall' )
|
||||
p.expect ( '(\d+)% dropped' )
|
||||
@@ -26,9 +28,9 @@ class testControlNet( unittest.TestCase ):
|
||||
def testFailover( self ):
|
||||
"Kill controllers and verify that switch, s1, fails over properly"
|
||||
count = 1
|
||||
p = pexpect.spawn( 'python -m mininet.examples.controlnet' )
|
||||
p = pexpect.spawn( 'python -m mininet.examples.controlnet', logfile=stdout )
|
||||
p.expect( self.prompt )
|
||||
lp = pexpect.spawn( 'tail -f /tmp/s1-ofp.log' )
|
||||
lp = pexpect.spawn( 'tail -f /tmp/s1-ofp.log', logfile=stdout )
|
||||
lp.expect( 'tcp:\d+\.\d+\.\d+\.(\d+):\d+: connected' )
|
||||
ip = int( lp.match.group( 1 ) )
|
||||
self.assertEqual( count, ip )
|
||||
|
||||
@@ -13,7 +13,7 @@ class testIntfOptions( unittest.TestCase ):
|
||||
def testIntfOptions( self ):
|
||||
"verify that intf.config is correctly limiting traffic"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.intfoptions ' )
|
||||
tolerance = .2 # plus or minus 20%
|
||||
tolerance = .25 # plus or minus 25% for cloud CI tests
|
||||
opts = [ "Results: \['([\d\.]+) .bits/sec",
|
||||
"Results: \['10M', '([\d\.]+) .bits/sec",
|
||||
"h(\d+)->h(\d+): (\d)/(\d),"
|
||||
@@ -22,7 +22,7 @@ class testIntfOptions( unittest.TestCase ):
|
||||
while True:
|
||||
index = p.expect( opts, timeout=600 )
|
||||
if index == 0:
|
||||
BW = 5
|
||||
BW = 10
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertGreaterEqual( bw, BW * ( 1 - tolerance ) )
|
||||
self.assertLessEqual( bw, BW * ( 1 + tolerance ) )
|
||||
@@ -30,8 +30,10 @@ class testIntfOptions( unittest.TestCase ):
|
||||
BW = 10
|
||||
measuredBw = float( p.match.group( 1 ) )
|
||||
loss = ( measuredBw / BW ) * 100
|
||||
self.assertGreaterEqual( loss, 50 * ( 1 - tolerance ) )
|
||||
self.assertLessEqual( loss, 50 * ( 1 + tolerance ) )
|
||||
self.assertGreaterEqual( loss, 50 * ( 1 - tolerance ),
|
||||
'loss of %d%% << 50%%' % loss )
|
||||
self.assertLessEqual( loss, 50 * ( 1 + tolerance ),
|
||||
'loss of %d%% >> 50%%' % loss )
|
||||
elif index == 2:
|
||||
delay = float( p.match.group( 6 ) )
|
||||
self.assertGreaterEqual( delay, 15 * ( 1 - tolerance ) )
|
||||
|
||||
Regular → Executable
Regular → Executable
@@ -16,6 +16,7 @@ class testScratchNet( unittest.TestCase ):
|
||||
p = pexpect.spawn( 'python -m %s' % name )
|
||||
index = p.expect( self.opts, timeout=120 )
|
||||
self.assertEqual( index, 0 )
|
||||
p.wait()
|
||||
|
||||
def testPingKernel( self ):
|
||||
self.pingTest( 'mininet.examples.scratchnet' )
|
||||
|
||||
@@ -16,7 +16,8 @@ class testSSHD( unittest.TestCase ):
|
||||
"Log into ssh server, check banner, then exit"
|
||||
# Note: this test will fail if "Welcome" is not in the sshd banner
|
||||
# and '#'' or '$'' are not in the prompt
|
||||
p = pexpect.spawn( 'ssh -i /tmp/ssh/test_rsa %s' % ip, timeout=10 )
|
||||
ssh = 'ssh -o StrictHostKeyChecking=no -i /tmp/ssh/test_rsa ' + ip
|
||||
p = pexpect.spawn( ssh, timeout=5 )
|
||||
while True:
|
||||
index = p.expect( self.opts )
|
||||
if index == 0:
|
||||
@@ -57,4 +58,3 @@ class testSSHD( unittest.TestCase ):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
Regular → Executable
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Create a 1024-host network, and run the CLI on it.
|
||||
@@ -11,8 +11,10 @@ from mininet.cli import CLI
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.node import OVSSwitch
|
||||
from mininet.topolib import TreeNet
|
||||
from mininet.examples.treeping64 import HostV4
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
network = TreeNet( depth=2, fanout=32, switch=OVSSwitch )
|
||||
network = TreeNet( depth=2, fanout=32, host=HostV4,
|
||||
switch=OVSSwitch, waitConnected=True)
|
||||
network.run( CLI, network )
|
||||
|
||||
+18
-6
@@ -1,24 +1,35 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"Create a 64-node tree network, and test connectivity using ping."
|
||||
|
||||
|
||||
from mininet.log import setLogLevel, info
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch # , KernelSwitch
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch, Host
|
||||
from mininet.topolib import TreeNet
|
||||
|
||||
|
||||
class HostV4( Host ):
|
||||
"Try to IPv6 and its awful neighbor discovery"
|
||||
def __init__( self, *args, **kwargs ):
|
||||
super( HostV4, self ).__init__( *args, **kwargs )
|
||||
cfgs = [ 'all.disable_ipv6=1', 'default.disable_ipv6=1',
|
||||
'default.autoconf=0', 'lo.autoconf=0' ]
|
||||
for cfg in cfgs:
|
||||
self.cmd( 'sysctl -w net.ipv6.conf.' + cfg )
|
||||
|
||||
|
||||
def treePing64():
|
||||
"Run ping test on 64-node tree networks."
|
||||
|
||||
results = {}
|
||||
switches = { # 'reference kernel': KernelSwitch,
|
||||
'reference user': UserSwitch,
|
||||
'Open vSwitch kernel': OVSKernelSwitch }
|
||||
switches = { 'reference user': UserSwitch,
|
||||
'Open vSwitch kernel': OVSKernelSwitch }
|
||||
|
||||
for name in switches:
|
||||
info( "*** Testing", name, "datapath\n" )
|
||||
switch = switches[ name ]
|
||||
network = TreeNet( depth=2, fanout=8, switch=switch )
|
||||
network = TreeNet( depth=2, fanout=8, switch=switch,
|
||||
waitConnected=True )
|
||||
result = network.run( network.pingAll )
|
||||
results[ name ] = result
|
||||
|
||||
@@ -27,6 +38,7 @@ def treePing64():
|
||||
info( "%s: %d%% packet loss\n" % ( name, results[ name ] ) )
|
||||
info( '\n' )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
treePing64()
|
||||
|
||||
@@ -24,14 +24,18 @@ Usage (example uses VLAN ID=1000):
|
||||
|
||||
"""
|
||||
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
|
||||
from mininet.node import Host
|
||||
from mininet.topo import Topo
|
||||
from mininet.util import quietRun
|
||||
from mininet.log import error
|
||||
|
||||
|
||||
class VLANHost( Host ):
|
||||
"Host connected to VLAN interface"
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def config( self, vlan=100, **params ):
|
||||
"""Configure VLANHost according to (optional) parameters:
|
||||
vlan: VLAN ID for default interface"""
|
||||
@@ -54,6 +58,7 @@ class VLANHost( Host ):
|
||||
|
||||
return r
|
||||
|
||||
|
||||
hosts = { 'vlan': VLANHost }
|
||||
|
||||
|
||||
@@ -65,7 +70,7 @@ def exampleAllHosts( vlan ):
|
||||
|
||||
# Start a basic network using our VLANHost
|
||||
topo = SingleSwitchTopo( k=2 )
|
||||
net = Mininet( host=host, topo=topo )
|
||||
net = Mininet( host=host, topo=topo, waitConnected=True )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
@@ -96,11 +101,12 @@ class VLANStarTopo( Topo ):
|
||||
def exampleCustomTags():
|
||||
"""Simple example that exercises VLANStarTopo"""
|
||||
|
||||
net = Mininet( topo=VLANStarTopo() )
|
||||
net = Mininet( topo=VLANStarTopo(), waitConnected=True )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
+24
-9
@@ -46,7 +46,8 @@ class CLI( Cmd ):
|
||||
|
||||
prompt = 'mininet> '
|
||||
|
||||
def __init__( self, mininet, stdin=sys.stdin, script=None ):
|
||||
def __init__( self, mininet, stdin=sys.stdin, script=None,
|
||||
**kwargs ):
|
||||
"""Start and run interactive or batch mode CLI
|
||||
mininet: Mininet network object
|
||||
stdin: standard input for CLI
|
||||
@@ -55,11 +56,10 @@ class CLI( Cmd ):
|
||||
# Local variable bindings for py command
|
||||
self.locals = { 'net': mininet }
|
||||
# Attempt to handle input
|
||||
self.stdin = stdin
|
||||
self.inPoller = poll()
|
||||
self.inPoller.register( stdin )
|
||||
self.inputFile = script
|
||||
Cmd.__init__( self )
|
||||
Cmd.__init__( self, stdin=stdin, **kwargs )
|
||||
info( '*** Starting CLI:\n' )
|
||||
|
||||
if self.inputFile:
|
||||
@@ -79,6 +79,7 @@ class CLI( Cmd ):
|
||||
return
|
||||
cls.readlineInited = True
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from readline import ( read_history_file, write_history_file,
|
||||
set_history_length )
|
||||
except ImportError:
|
||||
@@ -88,7 +89,15 @@ class CLI( Cmd ):
|
||||
if os.path.isfile( history_path ):
|
||||
read_history_file( history_path )
|
||||
set_history_length( 1000 )
|
||||
atexit.register( lambda: write_history_file( history_path ) )
|
||||
|
||||
def writeHistory():
|
||||
"Write out history file"
|
||||
try:
|
||||
write_history_file( history_path )
|
||||
except IOError:
|
||||
# Ignore probably spurious IOError
|
||||
pass
|
||||
atexit.register( writeHistory )
|
||||
|
||||
def run( self ):
|
||||
"Run our cmdloop(), catching KeyboardInterrupt"
|
||||
@@ -141,10 +150,10 @@ class CLI( Cmd ):
|
||||
' mininet> xterm h2\n\n'
|
||||
)
|
||||
|
||||
def do_help( self, line ):
|
||||
def do_help( self, line ): # pylint: disable=arguments-differ
|
||||
"Describe available CLI commands."
|
||||
Cmd.do_help( self, line )
|
||||
if line is '':
|
||||
if line == '':
|
||||
output( self.helpStr )
|
||||
|
||||
def do_nodes( self, _line ):
|
||||
@@ -173,6 +182,7 @@ class CLI( Cmd ):
|
||||
"""Evaluate a Python expression.
|
||||
Node names may be used, e.g.: py h1.cmd('ls')"""
|
||||
try:
|
||||
# pylint: disable=eval-used
|
||||
result = eval( line, globals(), self.getLocals() )
|
||||
if not result:
|
||||
return
|
||||
@@ -399,6 +409,10 @@ class CLI( Cmd ):
|
||||
error( 'invalid command: '
|
||||
'switch <switch name> {start, stop}\n' )
|
||||
|
||||
def do_wait( self, _line ):
|
||||
"Wait until all switches have connected to a controller"
|
||||
self.mn.waitConnected()
|
||||
|
||||
def default( self, line ):
|
||||
"""Called on an input line when the command prefix is not recognized.
|
||||
Overridden to run shell commands when a node is the first
|
||||
@@ -444,7 +458,7 @@ class CLI( Cmd ):
|
||||
# XXX BL: this doesn't quite do what we want.
|
||||
if False and self.inputFile:
|
||||
key = self.inputFile.read( 1 )
|
||||
if key is not '':
|
||||
if key != '':
|
||||
node.write( key )
|
||||
else:
|
||||
self.inputFile = None
|
||||
@@ -463,10 +477,10 @@ class CLI( Cmd ):
|
||||
node.sendInt()
|
||||
except select.error as e:
|
||||
# pylint: disable=unpacking-non-sequence
|
||||
# pylint: disable=unbalanced-tuple-unpacking
|
||||
errno_, errmsg = e.args
|
||||
# pylint: enable=unpacking-non-sequence
|
||||
if errno_ != errno.EINTR:
|
||||
error( "select.error: %d, %s" % (errno_, errmsg) )
|
||||
error( "select.error: %s, %s" % (errno_, errmsg) )
|
||||
node.sendInt()
|
||||
|
||||
def precmd( self, line ):
|
||||
@@ -484,3 +498,4 @@ def isReadable( poller ):
|
||||
mask = fdmask[ 1 ]
|
||||
if mask & POLLIN:
|
||||
return True
|
||||
return False
|
||||
|
||||
+33
-26
@@ -24,9 +24,14 @@ TCIntf: interface with bandwidth limiting and delay via tc
|
||||
Link: basic link class for creating veth pairs
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from mininet.log import info, error, debug
|
||||
from mininet.util import makeIntfPair
|
||||
import re
|
||||
|
||||
# Make pylint happy:
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
class Intf( object ):
|
||||
|
||||
@@ -170,7 +175,7 @@ class Intf( object ):
|
||||
name, value = list( param.items() )[ 0 ]
|
||||
f = getattr( self, method, None )
|
||||
if not f or value is None:
|
||||
return
|
||||
return None
|
||||
if isinstance( value, list ):
|
||||
result = f( *value )
|
||||
elif isinstance( value, dict ):
|
||||
@@ -295,7 +300,7 @@ class TCIntf( Intf ):
|
||||
netemargs = '%s%s%s%s' % (
|
||||
'delay %s ' % delay if delay is not None else '',
|
||||
'%s ' % jitter if jitter is not None else '',
|
||||
'loss %.5f ' % loss if loss is not None else '',
|
||||
'loss %.5f ' % loss if (loss is not None and loss > 0) else '',
|
||||
'limit %d' % max_queue_size if max_queue_size is not None
|
||||
else '' )
|
||||
if netemargs:
|
||||
@@ -311,6 +316,7 @@ class TCIntf( Intf ):
|
||||
debug(" *** executing command: %s\n" % c)
|
||||
return self.cmd( c )
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def config( self, bw=None, delay=None, jitter=None, loss=None,
|
||||
gro=False, txo=True, rxo=True,
|
||||
speedup=0, use_hfsc=False, use_tbf=False,
|
||||
@@ -351,7 +357,7 @@ class TCIntf( Intf ):
|
||||
# Question: what happens if we want to reset things?
|
||||
if ( bw is None and not delay and not loss
|
||||
and max_queue_size is None ):
|
||||
return
|
||||
return None
|
||||
|
||||
# Clear existing configuration
|
||||
tcoutput = self.tc( '%s qdisc show dev %s' )
|
||||
@@ -407,7 +413,7 @@ class Link( object ):
|
||||
def __init__( self, node1, node2, port1=None, port2=None,
|
||||
intfName1=None, intfName2=None, addr1=None, addr2=None,
|
||||
intf=Intf, cls1=None, cls2=None, params1=None,
|
||||
params2=None, fast=True ):
|
||||
params2=None, fast=True, **params ):
|
||||
"""Create veth link to another node, making two new interfaces.
|
||||
node1: first node
|
||||
node2: second node
|
||||
@@ -417,18 +423,15 @@ class Link( object ):
|
||||
cls1, cls2: optional interface-specific constructors
|
||||
intfName1: node1 interface name (optional)
|
||||
intfName2: node2 interface name (optional)
|
||||
params1: parameters for interface 1
|
||||
params2: parameters for interface 2"""
|
||||
params1: parameters for interface 1 (optional)
|
||||
params2: parameters for interface 2 (optional)
|
||||
**params: additional parameters for both interfaces"""
|
||||
|
||||
# This is a bit awkward; it seems that having everything in
|
||||
# params is more orthogonal, but being able to specify
|
||||
# in-line arguments is more convenient! So we support both.
|
||||
if params1 is None:
|
||||
params1 = {}
|
||||
if params2 is None:
|
||||
params2 = {}
|
||||
# Allow passing in params1=params2
|
||||
if params2 is params1:
|
||||
params2 = dict( params1 )
|
||||
params1 = dict( params1 ) if params1 else {}
|
||||
params2 = dict( params2 ) if params2 else {}
|
||||
if port1 is not None:
|
||||
params1[ 'port' ] = port1
|
||||
if port2 is not None:
|
||||
@@ -442,6 +445,10 @@ class Link( object ):
|
||||
if not intfName2:
|
||||
intfName2 = self.intfName( node2, params2[ 'port' ] )
|
||||
|
||||
# Update with remaining parameter list
|
||||
params1.update( params )
|
||||
params2.update( params )
|
||||
|
||||
self.fast = fast
|
||||
if fast:
|
||||
params1.setdefault( 'moveIntfFn', self._ignore )
|
||||
@@ -463,6 +470,7 @@ class Link( object ):
|
||||
|
||||
# All we are is dust in the wind, and our two interfaces
|
||||
self.intf1, self.intf2 = intf1, intf2
|
||||
|
||||
# pylint: enable=too-many-branches
|
||||
|
||||
@staticmethod
|
||||
@@ -531,7 +539,11 @@ class OVSLink( Link ):
|
||||
|
||||
def __init__( self, node1, node2, **kwargs ):
|
||||
"See Link.__init__() for options"
|
||||
from mininet.node import OVSSwitch
|
||||
try:
|
||||
OVSSwitch
|
||||
except NameError:
|
||||
# pylint: disable=import-outside-toplevel,cyclic-import
|
||||
from mininet.node import OVSSwitch
|
||||
self.isPatchLink = False
|
||||
if ( isinstance( node1, OVSSwitch ) and
|
||||
isinstance( node2, OVSSwitch ) ):
|
||||
@@ -539,6 +551,7 @@ class OVSLink( Link ):
|
||||
kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
|
||||
Link.__init__( self, node1, node2, **kwargs )
|
||||
|
||||
# pylint: disable=arguments-differ, signature-differs
|
||||
def makeIntfPair( self, *args, **kwargs ):
|
||||
"Usually delegated to OVSSwitch"
|
||||
if self.isPatchLink:
|
||||
@@ -548,17 +561,11 @@ class OVSLink( Link ):
|
||||
|
||||
|
||||
class TCLink( Link ):
|
||||
"Link with symmetric TC interfaces configured via opts"
|
||||
def __init__( self, node1, node2, port1=None, port2=None,
|
||||
intfName1=None, intfName2=None,
|
||||
addr1=None, addr2=None, **params ):
|
||||
Link.__init__( self, node1, node2, port1=port1, port2=port2,
|
||||
intfName1=intfName1, intfName2=intfName2,
|
||||
cls1=TCIntf,
|
||||
cls2=TCIntf,
|
||||
addr1=addr1, addr2=addr2,
|
||||
params1=params,
|
||||
params2=params )
|
||||
"Link with TC interfaces"
|
||||
def __init__( self, *args, **kwargs):
|
||||
kwargs.setdefault( 'cls1', TCIntf )
|
||||
kwargs.setdefault( 'cls2', TCIntf )
|
||||
Link.__init__( self, *args, **kwargs)
|
||||
|
||||
|
||||
class TCULink( TCLink ):
|
||||
|
||||
+23
-28
@@ -4,6 +4,7 @@ import logging
|
||||
from logging import Logger
|
||||
import types
|
||||
|
||||
|
||||
# Create a new loglevel, 'CLI info', which enables a Mininet user to see only
|
||||
# the output of the commands they execute, plus any errors or warnings. This
|
||||
# level is in between info and warning. CLI info-level commands should not be
|
||||
@@ -14,13 +15,14 @@ LEVELS = { 'debug': logging.DEBUG,
|
||||
'info': logging.INFO,
|
||||
'output': OUTPUT,
|
||||
'warning': logging.WARNING,
|
||||
'warn': logging.WARNING,
|
||||
'error': logging.ERROR,
|
||||
'critical': logging.CRITICAL }
|
||||
|
||||
# change this to logging.INFO to get printouts when running unit tests
|
||||
LOGLEVELDEFAULT = OUTPUT
|
||||
|
||||
#default: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
# default: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||
LOGMSGFORMAT = '%(message)s'
|
||||
|
||||
|
||||
@@ -51,7 +53,7 @@ class StreamHandlerNoNewline( logging.StreamHandler ):
|
||||
self.flush()
|
||||
except ( KeyboardInterrupt, SystemExit ):
|
||||
raise
|
||||
except:
|
||||
except: # noqa pylint: disable=bare-except
|
||||
self.handleError( record )
|
||||
|
||||
|
||||
@@ -95,9 +97,9 @@ class MininetLogger( Logger, object ):
|
||||
|
||||
__metaclass__ = Singleton
|
||||
|
||||
def __init__( self ):
|
||||
def __init__( self, name="mininet" ):
|
||||
|
||||
Logger.__init__( self, "mininet" )
|
||||
Logger.__init__( self, name )
|
||||
|
||||
# create console handler
|
||||
ch = StreamHandlerNoNewline()
|
||||
@@ -105,30 +107,22 @@ class MininetLogger( Logger, object ):
|
||||
formatter = logging.Formatter( LOGMSGFORMAT )
|
||||
# add formatter to ch
|
||||
ch.setFormatter( formatter )
|
||||
# add ch to lg
|
||||
# add ch to lg and initialize log level
|
||||
self.addHandler( ch )
|
||||
|
||||
self.ch = ch
|
||||
self.setLogLevel()
|
||||
|
||||
def setLogLevel( self, levelname=None ):
|
||||
"""Setup loglevel.
|
||||
Convenience function to support lowercase names.
|
||||
levelName: level name from LEVELS"""
|
||||
level = LOGLEVELDEFAULT
|
||||
if levelname is not None:
|
||||
if levelname not in LEVELS:
|
||||
raise Exception( 'unknown levelname seen in setLogLevel' )
|
||||
else:
|
||||
level = LEVELS.get( levelname, level )
|
||||
|
||||
if levelname and levelname not in LEVELS:
|
||||
print(LEVELS)
|
||||
raise Exception( 'setLogLevel: unknown levelname %s' % levelname )
|
||||
level = LEVELS.get( levelname, LOGLEVELDEFAULT )
|
||||
self.setLevel( level )
|
||||
self.handlers[ 0 ].setLevel( level )
|
||||
self.ch.setLevel( level )
|
||||
|
||||
# pylint: disable=method-hidden
|
||||
# "An attribute inherited from mininet.log hide this method" (sic)
|
||||
# Not sure why this is occurring - this function definitely gets called.
|
||||
|
||||
# See /usr/lib/python2.5/logging/__init__.py; modified from warning()
|
||||
def output( self, msg, *args, **kwargs ):
|
||||
"""Log 'msg % args' with severity 'OUTPUT'.
|
||||
|
||||
@@ -137,14 +131,11 @@ class MininetLogger( Logger, object ):
|
||||
|
||||
logger.warning("Houston, we have a %s", "cli output", exc_info=1)
|
||||
"""
|
||||
if self.manager.disable >= OUTPUT:
|
||||
if getattr( self.manager, 'disabled', 0 ) >= OUTPUT:
|
||||
return
|
||||
if self.isEnabledFor( OUTPUT ):
|
||||
self._log( OUTPUT, msg, args, kwargs )
|
||||
|
||||
# pylint: enable=method-hidden
|
||||
|
||||
lg = MininetLogger()
|
||||
|
||||
# Make things a bit more convenient by adding aliases
|
||||
# (info, warn, error, debug) and allowing info( 'this', 'is', 'OK' )
|
||||
@@ -168,10 +159,14 @@ def makeListCompatible( fn ):
|
||||
setattr( newfn, '__doc__', fn.__doc__ )
|
||||
return newfn
|
||||
|
||||
_loggers = lg.info, lg.output, lg.warn, lg.error, lg.debug
|
||||
_loggers = tuple( makeListCompatible( logger )
|
||||
for logger in _loggers )
|
||||
lg.info, lg.output, lg.warn, lg.error, lg.debug = _loggers
|
||||
info, output, warn, error, debug = _loggers
|
||||
|
||||
# Initialize logger and logging functions
|
||||
|
||||
logging.setLoggerClass( MininetLogger )
|
||||
lg = logging.getLogger( "mininet" )
|
||||
_loggers = lg.info, lg.output, lg.warning, lg.error, lg.debug
|
||||
_loggers = tuple( makeListCompatible( logger ) for logger in _loggers )
|
||||
lg.info, lg.output, lg.warning, lg.error, lg.debug = _loggers
|
||||
info, output, warning, error, debug = _loggers
|
||||
warn = warning # alternate/old name
|
||||
setLogLevel = lg.setLogLevel
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
"Module dependency utility functions for Mininet."
|
||||
|
||||
from os import environ
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
|
||||
from mininet.util import quietRun, BaseString
|
||||
from mininet.log import info, error, debug
|
||||
from os import environ
|
||||
|
||||
|
||||
def lsmod():
|
||||
"Return output of lsmod."
|
||||
@@ -18,6 +21,7 @@ def modprobe( mod ):
|
||||
mod: module string"""
|
||||
return quietRun( [ 'modprobe', mod ] )
|
||||
|
||||
|
||||
OF_KMOD = 'ofdatapath'
|
||||
OVS_KMOD = 'openvswitch_mod' # Renamed 'openvswitch' in OVS 1.7+/Linux 3.5+
|
||||
TUN = 'tun'
|
||||
|
||||
+14
-8
@@ -92,6 +92,7 @@ import select
|
||||
import signal
|
||||
import random
|
||||
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
from time import sleep
|
||||
from itertools import chain, groupby
|
||||
from math import ceil
|
||||
@@ -108,11 +109,12 @@ from mininet.util import ( quietRun, fixLimits, numCores, ensureRoot,
|
||||
from mininet.term import cleanUpScreens, makeTerms
|
||||
|
||||
# Mininet version: should be consistent with README and LICENSE
|
||||
VERSION = "2.3.0d4"
|
||||
VERSION = "2.3.0"
|
||||
|
||||
class Mininet( object ):
|
||||
"Network emulation with hosts spawned in network namespaces."
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host,
|
||||
controller=DefaultController, link=Link, intf=Intf,
|
||||
build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8',
|
||||
@@ -135,7 +137,9 @@ class Mininet( object ):
|
||||
autoStaticArp: set all-pairs static MAC addrs?
|
||||
autoPinCpus: pin hosts to (real) cores (requires CPULimitedHost)?
|
||||
listenPort: base listening port to open; will be incremented for
|
||||
each additional switch in the net if inNamespace=False"""
|
||||
each additional switch in the net if inNamespace=False
|
||||
waitConnected: wait for switches to Connect?
|
||||
(False; True/None=wait indefinitely; time(s)=timed wait)"""
|
||||
self.topo = topo
|
||||
self.switch = switch
|
||||
self.host = host
|
||||
@@ -174,14 +178,16 @@ class Mininet( object ):
|
||||
self.build()
|
||||
|
||||
def waitConnected( self, timeout=None, delay=.5 ):
|
||||
"""wait for each switch to connect to a controller,
|
||||
up to 5 seconds
|
||||
timeout: time to wait, or None to wait indefinitely
|
||||
"""wait for each switch to connect to a controller
|
||||
timeout: time to wait, or None or True to wait indefinitely
|
||||
delay: seconds to sleep per iteration
|
||||
returns: True if all switches are connected"""
|
||||
info( '*** Waiting for switches to connect\n' )
|
||||
time = 0
|
||||
time = 0.0
|
||||
remaining = list( self.switches )
|
||||
# False: 0s timeout; None: wait forever (preserve 2.2 behavior)
|
||||
if isinstance( timeout, bool ):
|
||||
timeout = None if timeout else 0
|
||||
while True:
|
||||
for switch in tuple( remaining ):
|
||||
if switch.connected():
|
||||
@@ -190,7 +196,7 @@ class Mininet( object ):
|
||||
if not remaining:
|
||||
info( '\n' )
|
||||
return True
|
||||
if timeout is not None and time > timeout:
|
||||
if timeout is not None and time >= timeout:
|
||||
break
|
||||
sleep( delay )
|
||||
time += delay
|
||||
@@ -557,7 +563,7 @@ class Mininet( object ):
|
||||
started.update( { s: s for s in success } )
|
||||
info( '\n' )
|
||||
if self.waitConn:
|
||||
self.waitConnected()
|
||||
self.waitConnected( self.waitConn )
|
||||
|
||||
def stop( self ):
|
||||
"Stop the controller(s), switches and hosts"
|
||||
|
||||
+67
-48
@@ -57,17 +57,22 @@ import pty
|
||||
import re
|
||||
import signal
|
||||
import select
|
||||
from distutils.version import StrictVersion
|
||||
from re import findall
|
||||
from subprocess import Popen, PIPE
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
from time import sleep
|
||||
|
||||
from mininet.log import info, error, warn, debug
|
||||
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
|
||||
numCores, retry, mountCgroups, BaseString, decode,
|
||||
encode, Python3 )
|
||||
encode, getincrementaldecoder, Python3, which )
|
||||
from mininet.moduledeps import moduleDeps, pathCheck, TUN
|
||||
from mininet.link import Link, Intf, TCIntf, OVSIntf
|
||||
from re import findall
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
class Node( object ):
|
||||
"""A virtual network node is simply a shell in a network namespace.
|
||||
@@ -94,9 +99,13 @@ class Node( object ):
|
||||
# Stash configuration parameters for future reference
|
||||
self.params = params
|
||||
|
||||
self.intfs = {} # dict of port numbers to interfaces
|
||||
self.ports = {} # dict of interfaces to port numbers
|
||||
# replace with Port objects, eventually ?
|
||||
# dict of port numbers to interfacse
|
||||
self.intfs = {}
|
||||
|
||||
# dict of interfaces to port numbers
|
||||
# todo: replace with Port objects, eventually ?
|
||||
self.ports = {}
|
||||
|
||||
self.nameToIntf = {} # dict of interface names to Intfs
|
||||
|
||||
# Make pylint happy
|
||||
@@ -106,6 +115,9 @@ class Node( object ):
|
||||
self.waiting = False
|
||||
self.readbuf = ''
|
||||
|
||||
# Incremental decoder for buffered reading
|
||||
self.decoder = getincrementaldecoder()
|
||||
|
||||
# Start command interpreter shell
|
||||
self.master, self.slave = None, None # pylint
|
||||
self.startShell()
|
||||
@@ -229,19 +241,19 @@ class Node( object ):
|
||||
|
||||
# Subshell I/O, commands and control
|
||||
|
||||
def read( self, maxbytes=1024 ):
|
||||
def read( self, size=1024 ):
|
||||
"""Buffered read from node, potentially blocking.
|
||||
maxbytes: maximum number of bytes to return"""
|
||||
size: maximum number of characters to return"""
|
||||
count = len( self.readbuf )
|
||||
if count < maxbytes:
|
||||
data = decode( os.read( self.stdout.fileno(), maxbytes - count ) )
|
||||
self.readbuf += data
|
||||
if maxbytes >= len( self.readbuf ):
|
||||
if count < size:
|
||||
data = os.read( self.stdout.fileno(), size - count )
|
||||
self.readbuf += self.decoder.decode( data )
|
||||
if size >= len( self.readbuf ):
|
||||
result = self.readbuf
|
||||
self.readbuf = ''
|
||||
else:
|
||||
result = self.readbuf[ :maxbytes ]
|
||||
self.readbuf = self.readbuf[ maxbytes: ]
|
||||
result = self.readbuf[ :size ]
|
||||
self.readbuf = self.readbuf[ size: ]
|
||||
return result
|
||||
|
||||
def readline( self ):
|
||||
@@ -281,6 +293,7 @@ class Node( object ):
|
||||
returns: result of poll()"""
|
||||
if len( self.readbuf ) == 0:
|
||||
return self.pollOut.poll( timeoutms )
|
||||
return None
|
||||
|
||||
def sendCmd( self, *args, **kwargs ):
|
||||
"""Send a command, followed by a command to echo a sentinel,
|
||||
@@ -374,6 +387,7 @@ class Node( object ):
|
||||
return self.waitOutput( verbose )
|
||||
else:
|
||||
warn( '(%s exited - ignoring cmd%s)\n' % ( self, args ) )
|
||||
return None
|
||||
|
||||
def cmdPrint( self, *args):
|
||||
"""Call cmd and printing its output
|
||||
@@ -466,6 +480,7 @@ class Node( object ):
|
||||
else:
|
||||
warn( '*** defaultIntf: warning:', self.name,
|
||||
'has no interfaces\n' )
|
||||
return None
|
||||
|
||||
def intf( self, intf=None ):
|
||||
"""Return our interface object with given string name,
|
||||
@@ -579,10 +594,10 @@ class Node( object ):
|
||||
value may also be list or dict"""
|
||||
name, value = list( param.items() )[ 0 ]
|
||||
if value is None:
|
||||
return
|
||||
return None
|
||||
f = getattr( self, method, None )
|
||||
if not f:
|
||||
return
|
||||
return None
|
||||
if isinstance( value, list ):
|
||||
result = f( *value )
|
||||
elif isinstance( value, dict ):
|
||||
@@ -650,11 +665,12 @@ class Node( object ):
|
||||
@classmethod
|
||||
def checkSetup( cls ):
|
||||
"Make sure our class and superclasses are set up"
|
||||
while cls and not getattr( cls, 'isSetup', True ):
|
||||
cls.setup()
|
||||
cls.isSetup = True
|
||||
clas = cls
|
||||
while clas and not getattr( clas, 'isSetup', True ):
|
||||
clas.setup()
|
||||
clas.isSetup = True
|
||||
# Make pylint happy
|
||||
cls = getattr( type( cls ), '__base__', None )
|
||||
clas = getattr( type( clas ), '__base__', None )
|
||||
|
||||
@classmethod
|
||||
def setup( cls ):
|
||||
@@ -835,6 +851,7 @@ class CPULimitedHost( Host ):
|
||||
errFail( 'cgclassify -g cpuset:/%s %s' % (
|
||||
self.name, self.pid ) )
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def config( self, cpu=-1, cores=None, **params ):
|
||||
"""cpu: desired overall system CPU fraction
|
||||
cores: (real) core(s) this host can run on
|
||||
@@ -927,6 +944,7 @@ class Switch( Node ):
|
||||
else:
|
||||
error( '*** Error: %s has execed and cannot accept commands' %
|
||||
self.name )
|
||||
return None
|
||||
|
||||
def connected( self ):
|
||||
"Is the switch connected to a controller? (override this method)"
|
||||
@@ -1112,6 +1130,7 @@ class OVSSwitch( Switch ):
|
||||
if self.batch:
|
||||
cmd = ' '.join( str( arg ).strip() for arg in args )
|
||||
self.commands.append( cmd )
|
||||
return None
|
||||
else:
|
||||
return self.cmd( 'ovs-vsctl', *args, **kwargs )
|
||||
|
||||
@@ -1299,7 +1318,7 @@ class OVSBridge( OVSSwitch ):
|
||||
"Are we forwarding yet?"
|
||||
if self.stp:
|
||||
status = self.dpctl( 'show' )
|
||||
return 'STP_FORWARD' in status and not 'STP_LEARN' in status
|
||||
return 'STP_FORWARD' in status and 'STP_LEARN' not in status
|
||||
else:
|
||||
return True
|
||||
|
||||
@@ -1379,10 +1398,12 @@ class Controller( Node ):
|
||||
OpenFlow controller."""
|
||||
|
||||
def __init__( self, name, inNamespace=False, command='controller',
|
||||
cargs='-v ptcp:%d', cdir=None, ip="127.0.0.1",
|
||||
port=6653, protocol='tcp', **params ):
|
||||
cargs='ptcp:%d', cdir=None, ip="127.0.0.1",
|
||||
port=6653, protocol='tcp', verbose=False, **params ):
|
||||
self.command = command
|
||||
self.cargs = cargs
|
||||
if verbose:
|
||||
cargs = '-v ' + cargs
|
||||
self.cdir = cdir
|
||||
# Accept 'ip:port' syntax as shorthand
|
||||
if ':' in ip:
|
||||
@@ -1424,6 +1445,7 @@ class Controller( Node ):
|
||||
' 1>' + cout + ' 2>' + cout + ' &' )
|
||||
self.execed = False
|
||||
|
||||
# pylint: disable=arguments-differ,signature-differs
|
||||
def stop( self, *args, **kwargs ):
|
||||
"Stop controller."
|
||||
self.cmd( 'kill %' + self.command )
|
||||
@@ -1447,7 +1469,7 @@ class Controller( Node ):
|
||||
@classmethod
|
||||
def isAvailable( cls ):
|
||||
"Is controller available?"
|
||||
return quietRun( 'which controller' )
|
||||
return which( 'controller' )
|
||||
|
||||
|
||||
class OVSController( Controller ):
|
||||
@@ -1459,9 +1481,9 @@ class OVSController( Controller ):
|
||||
|
||||
@classmethod
|
||||
def isAvailable( cls ):
|
||||
return ( quietRun( 'which ovs-controller' ) or
|
||||
quietRun( 'which test-controller' ) or
|
||||
quietRun( 'which ovs-testcontroller' ) ).strip()
|
||||
return (which( 'ovs-controller' ) or
|
||||
which( 'test-controller' ) or
|
||||
which( 'ovs-testcontroller' ))
|
||||
|
||||
class NOX( Controller ):
|
||||
"Controller to run a NOX application."
|
||||
@@ -1474,7 +1496,7 @@ class NOX( Controller ):
|
||||
warn( 'warning: no NOX modules specified; '
|
||||
'running packetdump only\n' )
|
||||
noxArgs = [ 'packetdump' ]
|
||||
elif type( noxArgs ) not in ( list, tuple ):
|
||||
elif not isinstance( noxArgs, ( list, tuple ) ):
|
||||
noxArgs = [ noxArgs ]
|
||||
|
||||
if 'NOX_CORE_DIR' not in os.environ:
|
||||
@@ -1483,32 +1505,26 @@ class NOX( Controller ):
|
||||
|
||||
Controller.__init__( self, name,
|
||||
command=noxCoreDir + '/nox_core',
|
||||
cargs='--libdir=/usr/local/lib -v -i ptcp:%s ' +
|
||||
cargs='--libdir=/usr/local/lib -v '
|
||||
'-i ptcp:%s ' +
|
||||
' '.join( noxArgs ),
|
||||
cdir=noxCoreDir,
|
||||
**kwargs )
|
||||
|
||||
class Ryu( Controller ):
|
||||
"Controller to run Ryu application"
|
||||
def __init__( self, name, *ryuArgs, **kwargs ):
|
||||
"Ryu OpenFlow Controller"
|
||||
def __init__( self, name, ryuArgs='ryu.app.simple_switch',
|
||||
command='ryu run', **kwargs ):
|
||||
"""Init.
|
||||
name: name to give controller.
|
||||
ryuArgs: arguments and modules to pass to Ryu"""
|
||||
homeDir = quietRun( 'printenv HOME' ).strip( '\r\n' )
|
||||
ryuCoreDir = '%s/ryu/ryu/app/' % homeDir
|
||||
if not ryuArgs:
|
||||
warn( 'warning: no Ryu modules specified; '
|
||||
'running simple_switch only\n' )
|
||||
ryuArgs = [ ryuCoreDir + 'simple_switch.py' ]
|
||||
elif type( ryuArgs ) not in ( list, tuple ):
|
||||
ryuArgs = [ ryuArgs ]
|
||||
|
||||
Controller.__init__( self, name,
|
||||
command='ryu-manager',
|
||||
cargs='--ofp-tcp-listen-port %s ' +
|
||||
' '.join( ryuArgs ),
|
||||
cdir=ryuCoreDir,
|
||||
**kwargs )
|
||||
name: name to give controller.
|
||||
ryuArgs: modules to pass to Ryu (ryu.app.simple_switch)
|
||||
command: comand to run Ryu ('ryu run')"""
|
||||
if isinstance( ryuArgs, ( list, tuple ) ):
|
||||
ryuArgs = ' '.join( ryuArgs )
|
||||
cargs = kwargs.pop(
|
||||
'cargs', ryuArgs + ' --ofp-tcp-listen-port %s' )
|
||||
Controller.__init__( self, name, command=command,
|
||||
cargs=cargs, **kwargs )
|
||||
|
||||
|
||||
class RemoteController( Controller ):
|
||||
@@ -1527,6 +1543,7 @@ class RemoteController( Controller ):
|
||||
"Overridden to do nothing."
|
||||
return
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def stop( self ):
|
||||
"Overridden to do nothing."
|
||||
return
|
||||
@@ -1558,6 +1575,7 @@ class RemoteController( Controller ):
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
DefaultControllers = ( Controller, OVSController )
|
||||
|
||||
def findController( controllers=DefaultControllers ):
|
||||
@@ -1565,6 +1583,7 @@ def findController( controllers=DefaultControllers ):
|
||||
for controller in controllers:
|
||||
if controller.isAvailable():
|
||||
return controller
|
||||
return None
|
||||
|
||||
def DefaultController( name, controllers=DefaultControllers, **kwargs ):
|
||||
"Find a controller that is available and instantiate it"
|
||||
|
||||
+24
-15
@@ -84,13 +84,36 @@ class NAT( Node ):
|
||||
self.flush = flush
|
||||
self.forwardState = self.cmd( 'sysctl -n net.ipv4.ip_forward' ).strip()
|
||||
|
||||
def setManualConfig( self, intf ):
|
||||
"""Prevent network-manager/networkd from messing with our interface
|
||||
by specifying manual configuration in /etc/network/interfaces"""
|
||||
cfile = '/etc/network/interfaces'
|
||||
line = '\niface %s inet manual\n' % intf
|
||||
try:
|
||||
with open( cfile ) as f:
|
||||
config = f.read()
|
||||
except IOError:
|
||||
config = ''
|
||||
if ( line ) not in config:
|
||||
info( '*** Adding "' + line.strip() + '" to ' + cfile + '\n' )
|
||||
with open( cfile, 'a' ) as f:
|
||||
f.write( line )
|
||||
# Probably need to restart network manager to be safe -
|
||||
# hopefully this won't disconnect you
|
||||
self.cmd( 'service network-manager restart || netplan apply' )
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def config( self, **params ):
|
||||
"""Configure the NAT and iptables"""
|
||||
super( NAT, self).config( **params )
|
||||
|
||||
if not self.localIntf:
|
||||
self.localIntf = self.defaultIntf()
|
||||
|
||||
self.setManualConfig( self.localIntf )
|
||||
|
||||
# Now we can configure manually without interference
|
||||
super( NAT, self).config( **params )
|
||||
|
||||
if self.flush:
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
self.cmd( 'iptables -F' )
|
||||
@@ -114,20 +137,6 @@ class NAT( Node ):
|
||||
# Instruct the kernel to perform forwarding
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=1' )
|
||||
|
||||
# Prevent network-manager from messing with our interface
|
||||
# by specifying manual configuration in /etc/network/interfaces
|
||||
intf = self.localIntf
|
||||
cfile = '/etc/network/interfaces'
|
||||
line = '\niface %s inet manual\n' % intf
|
||||
config = open( cfile ).read()
|
||||
if ( line ) not in config:
|
||||
info( '*** Adding "' + line.strip() + '" to ' + cfile + '\n' )
|
||||
with open( cfile, 'a' ) as f:
|
||||
f.write( line )
|
||||
# Probably need to restart network-manager to be safe -
|
||||
# hopefully this won't disconnect you
|
||||
self.cmd( 'service network-manager restart' )
|
||||
|
||||
def terminate( self ):
|
||||
"Stop NAT/forwarding between Mininet and external network"
|
||||
# Remote NAT rules
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ def makeTerm( node, title='Node', term='xterm', display=None, cmd='bash'):
|
||||
}
|
||||
if term not in cmds:
|
||||
error( 'invalid terminal type: %s' % term )
|
||||
return
|
||||
return None
|
||||
display, tunnel = tunnelX11( node, display )
|
||||
if display is None:
|
||||
return []
|
||||
|
||||
@@ -25,6 +25,7 @@ def runTests( testDir, verbosity=1 ):
|
||||
.run( testSuite ).wasSuccessful() )
|
||||
sys.exit( 0 if success else 1 )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
# get the directory containing example tests
|
||||
|
||||
@@ -45,7 +45,7 @@ class testOptionsTopoCommon( object ):
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
"Clean up if necessary"
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
if sys.exc_info() != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
def runOptionsTopoTest( self, n, msg, hopts=None, lopts=None ):
|
||||
@@ -95,7 +95,7 @@ class testOptionsTopoCommon( object ):
|
||||
CPU_FRACTION = 0.1
|
||||
CPU_TOLERANCE = 0.8 # CPU fraction below which test should fail
|
||||
hopts = { 'cpu': CPU_FRACTION }
|
||||
#self.runOptionsTopoTest( N, hopts=hopts )
|
||||
# self.runOptionsTopoTest( N, hopts=hopts )
|
||||
|
||||
mn = Mininet( SingleSwitchOptionsTopo( n=N, hopts=hopts ),
|
||||
host=CPULimitedHost, switch=self.switchClass,
|
||||
@@ -118,7 +118,7 @@ class testOptionsTopoCommon( object ):
|
||||
% ( CPU_FRACTION * 100, hostUsage, N, hoptsStr,
|
||||
self.switchClass ) )
|
||||
for pct in results:
|
||||
#divide cpu by 100 to convert from percentage to fraction
|
||||
# divide cpu by 100 to convert from percentage to fraction
|
||||
self.assertWithinTolerance( pct/100, CPU_FRACTION,
|
||||
CPU_TOLERANCE, msg )
|
||||
|
||||
@@ -263,6 +263,7 @@ class testOptionsTopoUserspace( testOptionsTopoCommon, unittest.TestCase ):
|
||||
longMessage = True
|
||||
switchClass = UserSwitch
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
|
||||
@@ -26,7 +26,7 @@ class testSingleSwitchCommon( object ):
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
"Clean up if necessary"
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
if sys.exc_info() != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
def testMinimal( self ):
|
||||
|
||||
@@ -26,6 +26,7 @@ class TestPtyLeak( unittest.TestCase ):
|
||||
assert ( host.slave, host.master ) == oldptys
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
cleanup()
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
"Clean up if necessary"
|
||||
# satisfy pylint
|
||||
assert self
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
if sys.exc_info() != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
def testDefaultDpid( self ):
|
||||
@@ -95,6 +95,7 @@ class testSwitchUserspace( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignment of Userspace switch."
|
||||
switchClass = UserSwitch
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Package: mininet
|
||||
Test functions defined in mininet.util."""
|
||||
|
||||
import unittest
|
||||
|
||||
from mininet.util import quietRun
|
||||
|
||||
class testQuietRun( unittest.TestCase ):
|
||||
"""Test quietRun that runs a command and returns its merged output from
|
||||
STDOUT and STDIN"""
|
||||
|
||||
@staticmethod
|
||||
def getEchoCmd( n ):
|
||||
"Return a command that will print n characters"
|
||||
return "echo -n " + "x" * n
|
||||
|
||||
def testEmpty( self ):
|
||||
"Run a command that prints nothing"
|
||||
output = quietRun(testQuietRun.getEchoCmd( 0 ) )
|
||||
self.assertEqual( 0, len( output ) )
|
||||
|
||||
def testOneRead( self ):
|
||||
"""Run a command whose output is entirely read on the first call if
|
||||
each call reads at most 1024 characters
|
||||
"""
|
||||
for n in [ 42, 1024 ]:
|
||||
output = quietRun( testQuietRun.getEchoCmd( n ) )
|
||||
self.assertEqual( n, len( output ) )
|
||||
|
||||
def testMultipleReads( self ):
|
||||
"Run a command whose output is not entirely read on the first read"
|
||||
for n in [ 1025, 4242 ]:
|
||||
output = quietRun(testQuietRun.getEchoCmd( n ) )
|
||||
self.assertEqual( n, len( output ) )
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -6,12 +6,15 @@ Tests for the Mininet Walkthrough
|
||||
TODO: missing xterm test
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import re
|
||||
from mininet.util import quietRun, pexpect
|
||||
import unittest
|
||||
|
||||
from distutils.version import StrictVersion
|
||||
from time import sleep
|
||||
from sys import stdout
|
||||
|
||||
from mininet.util import quietRun, pexpect
|
||||
from mininet.clean import cleanup
|
||||
|
||||
|
||||
def tsharkVersion():
|
||||
@@ -28,6 +31,11 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
@staticmethod
|
||||
def setup():
|
||||
"Be paranoid and run cleanup() before each test"
|
||||
cleanup()
|
||||
|
||||
# PART 1
|
||||
def testHelp( self ):
|
||||
"Check the usage message"
|
||||
@@ -43,17 +51,18 @@ class testWalkthrough( unittest.TestCase ):
|
||||
tshark = pexpect.spawn( 'tshark -i lo -R of' )
|
||||
else:
|
||||
tshark = pexpect.spawn( 'tshark -i lo -Y openflow_v1' )
|
||||
tshark.expect( [ 'Capturing on lo', "Capturing on 'Loopback'" ] )
|
||||
tshark.expect( [ 'Capturing on lo', "Capturing on 'Loopback" ] )
|
||||
mn = pexpect.spawn( 'mn --test pingall' )
|
||||
mn.expect( '0% dropped' )
|
||||
tshark.expect( [ '74 Hello', '74 of_hello', '74 Type: OFPT_HELLO' ] )
|
||||
tshark.sendintr()
|
||||
mn.expect( pexpect.EOF )
|
||||
tshark.expect( 'aptured' ) # 'xx packets captured'
|
||||
tshark.expect( pexpect.EOF )
|
||||
|
||||
def testBasic( self ):
|
||||
"Test basic CLI commands (help, nodes, net, dump)"
|
||||
p = pexpect.spawn( 'mn' )
|
||||
p = pexpect.spawn( 'mn -w' )
|
||||
p.expect( self.prompt )
|
||||
# help command
|
||||
p.sendline( 'help' )
|
||||
@@ -67,7 +76,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p.expect( self.prompt )
|
||||
# net command
|
||||
p.sendline( 'net' )
|
||||
expected = [ x for x in nodes ]
|
||||
expected = list( nodes )
|
||||
while len( expected ) > 0:
|
||||
index = p.expect( expected )
|
||||
node = p.match.group( 0 )
|
||||
@@ -92,7 +101,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
def testHostCommands( self ):
|
||||
"Test ifconfig and ps on h1 and s1"
|
||||
p = pexpect.spawn( 'mn' )
|
||||
p = pexpect.spawn( 'mn -w' )
|
||||
p.expect( self.prompt )
|
||||
# Third pattern is a local interface beginning with 'eth' or 'en'
|
||||
interfaces = [ r'h1-eth0[:\s]', r's1-eth1[:\s]',
|
||||
@@ -103,7 +112,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
ifcount = 0
|
||||
while True:
|
||||
index = p.expect( interfaces )
|
||||
if index == 0 or index == 3:
|
||||
if index in (0, 3):
|
||||
ifcount += 1
|
||||
elif index == 1:
|
||||
self.fail( 's1 interface displayed in "h1 ifconfig"' )
|
||||
@@ -119,7 +128,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
index = p.expect( interfaces )
|
||||
if index == 0:
|
||||
self.fail( 'h1 interface displayed in "s1 ifconfig"' )
|
||||
elif index == 1 or index == 2 or index == 3:
|
||||
elif index in (1, 2, 3):
|
||||
ifcount += 1
|
||||
else:
|
||||
break
|
||||
@@ -144,7 +153,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
def testConnectivity( self ):
|
||||
"Test ping and pingall"
|
||||
p = pexpect.spawn( 'mn' )
|
||||
p = pexpect.spawn( 'mn -w' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 ping -c 1 h2' )
|
||||
p.expect( '1 packets transmitted, 1 received' )
|
||||
@@ -161,14 +170,16 @@ class testWalkthrough( unittest.TestCase ):
|
||||
httpserver = 'SimpleHTTPServer'
|
||||
else:
|
||||
httpserver = 'http.server'
|
||||
p = pexpect.spawn( 'mn' )
|
||||
p = pexpect.spawn( 'mn -w', logfile=stdout )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 python -m %s 80 >& /dev/null &' % httpserver )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 python -m %s 80 &' % httpserver )
|
||||
# The walkthrough doesn't specify a delay here, and
|
||||
# we also don't read the output (also a possible problem),
|
||||
# but for now let's wait a couple of seconds to make
|
||||
# but for now let's wait a number of seconds to make
|
||||
# it less likely to fail due to the race condition.
|
||||
sleep( 2 )
|
||||
p.sendline( 'px from mininet.util import waitListening;'
|
||||
'waitListening(h1, port=80, timeout=30)' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( ' h2 wget -O - h1' )
|
||||
p.expect( '200 OK' )
|
||||
@@ -213,7 +224,9 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
def testLinkChange( self ):
|
||||
"Test TCLink bw and delay"
|
||||
p = pexpect.spawn( 'mn --link tc,bw=10,delay=10ms' )
|
||||
p = pexpect.spawn( 'mn -w --link tc,bw=10,delay=10ms' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 route && ping -c1 h2' )
|
||||
# test bw
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'iperf' )
|
||||
@@ -298,7 +311,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
ifcount = 0
|
||||
while True:
|
||||
index = p.expect( interfaces )
|
||||
if index == 1 or index == 3:
|
||||
if index in (1, 3):
|
||||
ifcount += 1
|
||||
elif index == 0:
|
||||
self.fail( 'h1 interface displayed in "s1 ifconfig"' )
|
||||
@@ -319,7 +332,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
# PART 3
|
||||
def testPythonInterpreter( self ):
|
||||
"Test py and px by checking IP for h1 and adding h3"
|
||||
p = pexpect.spawn( 'mn' )
|
||||
p = pexpect.spawn( 'mn -w' )
|
||||
p.expect( self.prompt )
|
||||
# test host IP
|
||||
p.sendline( 'py h1.IP()' )
|
||||
@@ -341,7 +354,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
def testLink( self ):
|
||||
"Test link CLI command using ping"
|
||||
p = pexpect.spawn( 'mn' )
|
||||
p = pexpect.spawn( 'mn -w' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'link s1 h1 down' )
|
||||
p.expect( self.prompt )
|
||||
|
||||
+5
-3
@@ -13,6 +13,9 @@ setup for testing, and can even be emulated with the Mininet package.
|
||||
|
||||
from mininet.util import irange, natural, naturalSeq
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
class MultiGraph( object ):
|
||||
"Utility class to track nodes and edges - replaces networkx.MultiGraph"
|
||||
|
||||
@@ -34,7 +37,7 @@ class MultiGraph( object ):
|
||||
key: optional key
|
||||
attr_dict: optional attribute dict
|
||||
attrs: more attributes
|
||||
warning: udpates attr_dict with attrs"""
|
||||
warning: updates attr_dict with attrs"""
|
||||
attr_dict = {} if attr_dict is None else attr_dict
|
||||
attr_dict.update( attrs )
|
||||
self.node.setdefault( src, {} )
|
||||
@@ -156,8 +159,7 @@ class Topo( object ):
|
||||
port1, port2 = self.addPort( node1, node2, port1, port2 )
|
||||
opts = dict( opts )
|
||||
opts.update( node1=node1, node2=node2, port1=port1, port2=port2 )
|
||||
self.g.add_edge(node1, node2, key, opts )
|
||||
return key
|
||||
return self.g.add_edge(node1, node2, key, opts )
|
||||
|
||||
def nodes( self, sort=True ):
|
||||
"Return nodes in graph"
|
||||
|
||||
+80
-40
@@ -1,35 +1,64 @@
|
||||
"Utility functions for Mininet."
|
||||
|
||||
import codecs
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from mininet.log import output, info, error, warn, debug
|
||||
|
||||
from time import sleep
|
||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||
from functools import partial
|
||||
from os import O_NONBLOCK
|
||||
from resource import getrlimit, setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
||||
from select import poll, POLLIN, POLLHUP
|
||||
from subprocess import call, check_call, Popen, PIPE, STDOUT
|
||||
import re
|
||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||
from os import O_NONBLOCK
|
||||
import os
|
||||
from functools import partial
|
||||
import sys
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
from time import sleep
|
||||
|
||||
from mininet.log import output, info, error, warn, debug
|
||||
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
# Python 2/3 compatibility
|
||||
|
||||
Python3 = sys.version_info[0] == 3
|
||||
BaseString = str if Python3 else getattr( str, '__base__' )
|
||||
Encoding = 'utf-8' if Python3 else None
|
||||
def decode( s ):
|
||||
"Decode a byte string if needed for Python 3"
|
||||
return s.decode( Encoding ) if Python3 else s
|
||||
def encode( s ):
|
||||
"Encode a byte string if needed for Python 3"
|
||||
return s.encode( Encoding ) if Python3 else s
|
||||
class NullCodec( object ):
|
||||
"Null codec for Python 2"
|
||||
@staticmethod
|
||||
def decode( buf ):
|
||||
"Null decode"
|
||||
return buf
|
||||
|
||||
@staticmethod
|
||||
def encode( buf ):
|
||||
"Null encode"
|
||||
return buf
|
||||
|
||||
|
||||
if Python3:
|
||||
def decode( buf ):
|
||||
"Decode buffer for Python 3"
|
||||
return buf.decode( Encoding )
|
||||
|
||||
def encode( buf ):
|
||||
"Encode buffer for Python 3"
|
||||
return buf.encode( Encoding )
|
||||
getincrementaldecoder = codecs.getincrementaldecoder( Encoding )
|
||||
else:
|
||||
decode, encode = NullCodec.decode, NullCodec.encode
|
||||
|
||||
def getincrementaldecoder():
|
||||
"Return null codec for Python 2"
|
||||
return NullCodec
|
||||
|
||||
try:
|
||||
# pylint: disable=import-error
|
||||
oldpexpect = None
|
||||
import pexpect as oldpexpect
|
||||
# pylint: enable=import-error
|
||||
|
||||
# pylint: enable=import-error
|
||||
class Pexpect( object ):
|
||||
"Custom pexpect that is compatible with str"
|
||||
@staticmethod
|
||||
@@ -119,20 +148,21 @@ def errRun( *cmd, **kwargs ):
|
||||
out, err = '', ''
|
||||
poller = poll()
|
||||
poller.register( popen.stdout, POLLIN )
|
||||
fdtofile = { popen.stdout.fileno(): popen.stdout }
|
||||
fdToFile = { popen.stdout.fileno(): popen.stdout }
|
||||
fdToDecoder = { popen.stdout.fileno(): getincrementaldecoder() }
|
||||
outDone, errDone = False, True
|
||||
if popen.stderr:
|
||||
fdtofile[ popen.stderr.fileno() ] = popen.stderr
|
||||
fdToFile[ popen.stderr.fileno() ] = popen.stderr
|
||||
fdToDecoder[ popen.stderr.fileno() ] = getincrementaldecoder()
|
||||
poller.register( popen.stderr, POLLIN )
|
||||
errDone = False
|
||||
while not outDone or not errDone:
|
||||
readable = poller.poll()
|
||||
for fd, event in readable:
|
||||
f = fdtofile[ fd ]
|
||||
if event & POLLIN:
|
||||
data = f.read( 1024 )
|
||||
if Python3:
|
||||
data = data.decode( Encoding )
|
||||
f = fdToFile[ fd ]
|
||||
decoder = fdToDecoder[ fd ]
|
||||
if event & ( POLLIN | POLLHUP ):
|
||||
data = decoder.decode( f.read( 1024 ) )
|
||||
if echo:
|
||||
output( data )
|
||||
if f == popen.stdout:
|
||||
@@ -143,7 +173,7 @@ def errRun( *cmd, **kwargs ):
|
||||
err += data
|
||||
if data == '':
|
||||
errDone = True
|
||||
else: # POLLHUP or something unexpected
|
||||
else: # something unexpected
|
||||
if f == popen.stdout:
|
||||
outDone = True
|
||||
elif f == popen.stderr:
|
||||
@@ -171,19 +201,26 @@ def quietRun( cmd, **kwargs ):
|
||||
"Run a command and return merged stdout and stderr"
|
||||
return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ]
|
||||
|
||||
def which(cmd, **kwargs ):
|
||||
"Run a command and return merged stdout and stderr"
|
||||
out, _, ret = errRun( ["which", cmd], stderr=STDOUT, **kwargs )
|
||||
return out.rstrip() if ret == 0 else None
|
||||
|
||||
# pylint: enable=maybe-no-member
|
||||
|
||||
def isShellBuiltin( cmd ):
|
||||
"Return True if cmd is a bash builtin."
|
||||
if isShellBuiltin.builtIns is None:
|
||||
isShellBuiltin.builtIns = quietRun( 'bash -c enable' )
|
||||
isShellBuiltin.builtIns = set(quietRun( 'bash -c enable' ).split())
|
||||
space = cmd.find( ' ' )
|
||||
if space > 0:
|
||||
cmd = cmd[ :space]
|
||||
return cmd in isShellBuiltin.builtIns
|
||||
|
||||
|
||||
isShellBuiltin.builtIns = None
|
||||
|
||||
|
||||
# Interface management
|
||||
#
|
||||
# Interfaces are managed as strings which are simply the
|
||||
@@ -370,7 +407,7 @@ def netParse( ipstr ):
|
||||
if '/' in ipstr:
|
||||
ip, pf = ipstr.split( '/' )
|
||||
prefixLen = int( pf )
|
||||
#if no prefix is specified, set the prefix to 24
|
||||
# if no prefix is specified, set the prefix to 24
|
||||
else:
|
||||
ip = ipstr
|
||||
prefixLen = 24
|
||||
@@ -413,24 +450,28 @@ def pmonitor(popens, timeoutms=500, readline=True,
|
||||
terminates: when all EOFs received"""
|
||||
poller = poll()
|
||||
fdToHost = {}
|
||||
fdToDecoder = {}
|
||||
for host, popen in popens.items():
|
||||
fd = popen.stdout.fileno()
|
||||
fdToHost[ fd ] = host
|
||||
poller.register( fd, POLLIN | POLLHUP )
|
||||
fdToDecoder[ fd ] = getincrementaldecoder()
|
||||
poller.register( fd, POLLIN )
|
||||
flags = fcntl( fd, F_GETFL )
|
||||
fcntl( fd, F_SETFL, flags | O_NONBLOCK )
|
||||
# pylint: disable=too-many-nested-blocks
|
||||
while popens:
|
||||
fds = poller.poll( timeoutms )
|
||||
if fds:
|
||||
for fd, event in fds:
|
||||
host = fdToHost[ fd ]
|
||||
decoder = fdToDecoder[ fd ]
|
||||
popen = popens[ host ]
|
||||
if event & POLLIN or event & POLLHUP:
|
||||
if event & ( POLLIN | POLLHUP ):
|
||||
while True:
|
||||
try:
|
||||
f = popen.stdout
|
||||
line = decode( f.readline() if readline
|
||||
else f.read( readmax ) )
|
||||
line = decoder.decode( f.readline() if readline
|
||||
else f.read( readmax ) )
|
||||
except IOError:
|
||||
line = ''
|
||||
if line == '':
|
||||
@@ -445,19 +486,19 @@ def pmonitor(popens, timeoutms=500, readline=True,
|
||||
# Other stuff we use
|
||||
def sysctlTestAndSet( name, limit ):
|
||||
"Helper function to set sysctl limits"
|
||||
#convert non-directory names into directory names
|
||||
# convert non-directory names into directory names
|
||||
if '/' not in name:
|
||||
name = '/proc/sys/' + name.replace( '.', '/' )
|
||||
#read limit
|
||||
# read limit
|
||||
with open( name, 'r' ) as readFile:
|
||||
oldLimit = readFile.readline()
|
||||
if isinstance( limit, int ):
|
||||
#compare integer limits before overriding
|
||||
# compare integer limits before overriding
|
||||
if int( oldLimit ) < limit:
|
||||
with open( name, 'w' ) as writeFile:
|
||||
writeFile.write( "%d" % limit )
|
||||
else:
|
||||
#overwrite non-integer limits
|
||||
# overwrite non-integer limits
|
||||
with open( name, 'w' ) as writeFile:
|
||||
writeFile.write( limit )
|
||||
|
||||
@@ -474,21 +515,21 @@ def fixLimits():
|
||||
try:
|
||||
rlimitTestAndSet( RLIMIT_NPROC, 8192 )
|
||||
rlimitTestAndSet( RLIMIT_NOFILE, 16384 )
|
||||
#Increase open file limit
|
||||
# Increase open file limit
|
||||
sysctlTestAndSet( 'fs.file-max', 10000 )
|
||||
#Increase network buffer space
|
||||
# Increase network buffer space
|
||||
sysctlTestAndSet( 'net.core.wmem_max', 16777216 )
|
||||
sysctlTestAndSet( 'net.core.rmem_max', 16777216 )
|
||||
sysctlTestAndSet( 'net.ipv4.tcp_rmem', '10240 87380 16777216' )
|
||||
sysctlTestAndSet( 'net.ipv4.tcp_wmem', '10240 87380 16777216' )
|
||||
sysctlTestAndSet( 'net.core.netdev_max_backlog', 5000 )
|
||||
#Increase arp cache size
|
||||
# Increase arp cache size
|
||||
sysctlTestAndSet( 'net.ipv4.neigh.default.gc_thresh1', 4096 )
|
||||
sysctlTestAndSet( 'net.ipv4.neigh.default.gc_thresh2', 8192 )
|
||||
sysctlTestAndSet( 'net.ipv4.neigh.default.gc_thresh3', 16384 )
|
||||
#Increase routing table size
|
||||
# Increase routing table size
|
||||
sysctlTestAndSet( 'net.ipv4.route.max_size', 32768 )
|
||||
#Increase number of PTYs for nodes
|
||||
# Increase number of PTYs for nodes
|
||||
sysctlTestAndSet( 'kernel.pty.max', 20000 )
|
||||
# pylint: disable=broad-except
|
||||
except Exception:
|
||||
@@ -629,7 +670,6 @@ def ensureRoot():
|
||||
if os.getuid() != 0:
|
||||
error( '*** Mininet must run as root.\n' )
|
||||
exit( 1 )
|
||||
return
|
||||
|
||||
def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
|
||||
"""Wait until server is listening on port.
|
||||
|
||||
+1
-5
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python2
|
||||
|
||||
"""
|
||||
Convert simple documentation to epydoc/pydoctor-compatible markup
|
||||
@@ -83,7 +83,3 @@ if __name__ == '__main__':
|
||||
infile.close()
|
||||
os.close( outfid )
|
||||
call( [ 'doxypy', outname ] )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+90
-45
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
# Mininet install script for Ubuntu (and Debian Wheezy+)
|
||||
# Brandon Heller (brandonh@stanford.edu)
|
||||
# Mininet install script for Ubuntu and Debian
|
||||
# Original author: Brandon Heller
|
||||
|
||||
# Fail on error
|
||||
set -e
|
||||
@@ -102,14 +102,26 @@ function version_ge {
|
||||
[ "$1" == "$latest" ]
|
||||
}
|
||||
|
||||
# Attempt to identify Python version
|
||||
# Attempt to detect Python version
|
||||
PYTHON=${PYTHON:-python}
|
||||
if $PYTHON --version |& grep 'Python 2' > /dev/null; then
|
||||
PYTHON_VERSION=2; PYPKG=python
|
||||
else
|
||||
PYTHON_VERSION=3; PYPKG=python3
|
||||
PRINTVERSION='import sys; print(sys.version_info)'
|
||||
PYTHON_VERSION=unknown
|
||||
for python in $PYTHON python2 python3; do
|
||||
if $python -c "$PRINTVERSION" |& grep 'major=2'; then
|
||||
PYTHON=$python; PYTHON_VERSION=2; PYPKG=python
|
||||
break
|
||||
elif $python -c "$PRINTVERSION" |& grep 'major=3'; then
|
||||
PYTHON=$python; PYTHON_VERSION=3; PYPKG=python3
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$PYTHON_VERSION" == unknown ]; then
|
||||
echo "Can't find a working python command ('$PYTHON' doesn't work.)"
|
||||
echo "You may wish to export PYTHON or install a working 'python'."
|
||||
exit 1
|
||||
fi
|
||||
echo "${PYTHON} is version ${PYTHON_VERSION}"
|
||||
|
||||
echo "Detected Python (${PYTHON}) version ${PYTHON_VERSION}"
|
||||
|
||||
# Kernel Deb pkg to be removed:
|
||||
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
|
||||
@@ -152,17 +164,38 @@ function mn_deps {
|
||||
if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
|
||||
$install gcc make socat psmisc xterm openssh-clients iperf \
|
||||
iproute telnet python-setuptools libcgroup-tools \
|
||||
ethtool help2man pyflakes pylint python-pep8 python-pexpect
|
||||
ethtool help2man net-tools
|
||||
$install ${PYPKG}-pyflakes pylint ${PYPKG}-pep8-naming \
|
||||
${PYPKG}-pexpect
|
||||
elif [ "$DIST" = "SUSE LINUX" ]; then
|
||||
$install gcc make socat psmisc xterm openssh iperf \
|
||||
iproute telnet ${PYPKG}-setuptools libcgroup-tools \
|
||||
ethtool help2man python-pyflakes python3-pylint \
|
||||
python-pep8 ${PYPKG}-pexpect ${PYPKG}-tk
|
||||
else # Debian/Ubuntu
|
||||
pf=pyflakes
|
||||
# Starting around 20.04, installing pyflakes instead of pyflakes3
|
||||
# causes Python 2 to be installed, which is exactly NOT what we want.
|
||||
if [ `expr $RELEASE '>=' 20.04` = "1" ]; then
|
||||
pf=pyflakes3
|
||||
fi
|
||||
$install gcc make socat psmisc xterm ssh iperf telnet \
|
||||
cgroup-bin ethtool help2man pyflakes pylint pep8 \
|
||||
${PYPKG}-setuptools ${PYPKG}-pexpect ${PYPKG}-tk
|
||||
ethtool help2man $pf pylint pep8 \
|
||||
net-tools \
|
||||
${PYPKG}-pexpect ${PYPKG}-tk
|
||||
# Install pip
|
||||
$install ${PYPKG}-pip || $install ${PYPKG}-pip-whl
|
||||
if ! ${PYTHON} -m pip -V; then
|
||||
if [ $PYTHON_VERSION == 2 ]; then
|
||||
wget https://bootstrap.pypa.io/2.6/get-pip.py
|
||||
else
|
||||
wget https://bootstrap.pypa.io/get-pip.py
|
||||
fi
|
||||
sudo ${PYTHON} get-pip.py
|
||||
rm get-pip.py
|
||||
fi
|
||||
$install iproute2 || $install iproute
|
||||
$install cgroup-tools || $install cgroup-bin
|
||||
fi
|
||||
|
||||
echo "Installing Mininet core"
|
||||
@@ -171,13 +204,14 @@ function mn_deps {
|
||||
popd
|
||||
}
|
||||
|
||||
# Install Mininet developer dependencies
|
||||
function mn_dev {
|
||||
echo "Installing Mininet developer dependencies"
|
||||
$install doxygen doxypy texlive-fonts-recommended
|
||||
# Install Mininet documentation dependencies
|
||||
function mn_doc {
|
||||
echo "Installing Mininet documentation dependencies"
|
||||
$install doxygen texlive-fonts-recommended
|
||||
if ! $install doxygen-latex; then
|
||||
echo "doxygen-latex not needed"
|
||||
fi
|
||||
sudo pip install doxypy
|
||||
}
|
||||
|
||||
# The following will cause a full OF install, covering:
|
||||
@@ -338,8 +372,8 @@ function ubuntuOvs {
|
||||
|
||||
# Get build deps
|
||||
$install build-essential fakeroot debhelper autoconf automake libssl-dev \
|
||||
pkg-config bzip2 openssl python-all procps python-qt4 \
|
||||
python-zopeinterface python-twisted-conch dkms dh-python dh-autoreconf \
|
||||
pkg-config bzip2 openssl ${PYPKG}-all procps ${PYPKG}-qt4 \
|
||||
${PYPKG}-zopeinterface ${PYPKG}-twisted-conch dkms dh-python dh-autoreconf \
|
||||
uuid-runtime
|
||||
|
||||
# Build OVS
|
||||
@@ -347,20 +381,15 @@ function ubuntuOvs {
|
||||
cd $BUILD_DIR/openvswitch/openvswitch-$OVS_RELEASE
|
||||
DEB_BUILD_OPTIONS='parallel=$parallel nocheck' fakeroot debian/rules binary
|
||||
cd ..
|
||||
# Install packages
|
||||
if [ -e libopenvswitch_$OVS_RELEASE*.deb ]; then
|
||||
$pkginst libopenvswitch_$OVS_RELEASE*.deb 2>/dev/null
|
||||
fi
|
||||
for pkg in common datapath-dkms pki switch; do
|
||||
pkg=openvswitch-${pkg}_$OVS_RELEASE*.deb
|
||||
echo "Installing $pkg"
|
||||
$pkginst $pkg
|
||||
done
|
||||
if [ -e openvswitch-controller_$OVS_RELEASE*.deb ]; then
|
||||
$pkginst openvswitch-controller_$OVS_RELEASE*.deb 2>/dev/null
|
||||
if $pkginst openvswitch-controller_$OVS_RELEASE*.deb 2>/dev/null; then
|
||||
echo "Ignoring error installing openvswitch-controller"
|
||||
fi
|
||||
# Ubuntu/Debian will mask a service if you uninstall it
|
||||
sudo systemctl unmask openvswitch-switch || true
|
||||
|
||||
/sbin/modinfo openvswitch
|
||||
sudo ovs-vsctl show
|
||||
# Switch can run on its own, but
|
||||
@@ -381,7 +410,10 @@ function ovs {
|
||||
echo "Installing Open vSwitch..."
|
||||
|
||||
if [ "$DIST" = "Fedora" -o "$DIST" = "RedHatEnterpriseServer" ]; then
|
||||
$install openvswitch openvswitch-controller
|
||||
$install openvswitch
|
||||
if ! $install openvswitch-controller; then
|
||||
echo "openvswitch-controller not installed"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -414,13 +446,19 @@ function ovs {
|
||||
# Switch can run on its own, but
|
||||
# Mininet should control the controller
|
||||
# This appears to only be an issue on Ubuntu/Debian
|
||||
if sudo service $OVSC stop; then
|
||||
if sudo service $OVSC stop 2>/dev/null; then
|
||||
echo "Stopped running controller"
|
||||
fi
|
||||
if [ -e /etc/init.d/$OVSC ]; then
|
||||
sudo update-rc.d $OVSC disable
|
||||
fi
|
||||
fi
|
||||
# This service seems to hang on 20.04
|
||||
if systemctl list-units | \
|
||||
grep status netplan-ovs-cleanup.service>&/dev/null; then
|
||||
echo 'TimeoutSec=10' | sudo EDITOR='tee -a' \
|
||||
sudo systemctl edit --full netplan-ovs-cleanup.service
|
||||
fi
|
||||
}
|
||||
|
||||
function remove_ovs {
|
||||
@@ -474,7 +512,7 @@ function ryu {
|
||||
# install Ryu dependencies"
|
||||
$install autoconf automake g++ libtool python make
|
||||
if [ "$DIST" = "Ubuntu" -o "$DIST" = "Debian" ]; then
|
||||
$install gcc python-pip python-dev libffi-dev libssl-dev \
|
||||
$install gcc ${PYPKG}-pip ${PYPKG}-dev libffi-dev libssl-dev \
|
||||
libxml2-dev libxslt1-dev zlib1g-dev
|
||||
fi
|
||||
|
||||
@@ -497,17 +535,17 @@ function nox {
|
||||
echo "Installing NOX w/tutorial files..."
|
||||
|
||||
# Install NOX deps:
|
||||
$install autoconf automake g++ libtool python python-twisted \
|
||||
$install autoconf automake g++ libtool python ${PYPKG}-twisted \
|
||||
swig libssl-dev make
|
||||
if [ "$DIST" = "Debian" ]; then
|
||||
$install libboost1.35-dev
|
||||
elif [ "$DIST" = "Ubuntu" ]; then
|
||||
$install python-dev libboost-dev
|
||||
$install ${PYPKG}-dev libboost-dev
|
||||
$install libboost-filesystem-dev
|
||||
$install libboost-test-dev
|
||||
fi
|
||||
# Install NOX optional deps:
|
||||
$install libsqlite3-dev python-simplejson
|
||||
$install libsqlite3-dev ${PYPKG}-simplejson
|
||||
|
||||
# Fetch NOX destiny
|
||||
cd $BUILD_DIR/
|
||||
@@ -545,12 +583,12 @@ function nox13 {
|
||||
echo "Installing NOX w/tutorial files..."
|
||||
|
||||
# Install NOX deps:
|
||||
$install autoconf automake g++ libtool python python-twisted \
|
||||
$install autoconf automake g++ libtool python ${PYPKG}-twisted \
|
||||
swig libssl-dev make
|
||||
if [ "$DIST" = "Debian" ]; then
|
||||
$install libboost1.35-dev
|
||||
elif [ "$DIST" = "Ubuntu" ]; then
|
||||
$install python-dev libboost-dev
|
||||
$install ${PYPKG}-dev libboost-dev
|
||||
$install libboost-filesystem-dev
|
||||
$install libboost-test-dev
|
||||
fi
|
||||
@@ -586,7 +624,8 @@ function oftest {
|
||||
echo "Installing oftest..."
|
||||
|
||||
# Install deps:
|
||||
$install tcpdump python-scapy
|
||||
$install tcpdump
|
||||
$install ${PYPKG}-scapy || sudo $PYTHON -m pip install scapy
|
||||
|
||||
# Install oftest:
|
||||
cd $BUILD_DIR/
|
||||
@@ -612,6 +651,7 @@ function cbench {
|
||||
sh boot.sh || true # possible error in autoreconf, so run twice
|
||||
sh boot.sh
|
||||
./configure --with-openflow-src-dir=$BUILD_DIR/openflow
|
||||
make liboflops_test.la
|
||||
make
|
||||
sudo make install || true # make install fails; force past this
|
||||
}
|
||||
@@ -643,9 +683,10 @@ net.ipv6.conf.default.disable_ipv6 = 1
|
||||
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
|
||||
fi
|
||||
# Since the above doesn't disable neighbor discovery, also do this:
|
||||
# disable via boot line, and also restore eth0 naming for VM use
|
||||
if ! grep 'ipv6.disable' /etc/default/grub; then
|
||||
sudo sed -i -e \
|
||||
's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 /' \
|
||||
's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 net.ifnames=0 /' \
|
||||
/etc/default/grub
|
||||
sudo update-grub
|
||||
fi
|
||||
@@ -723,8 +764,8 @@ function all {
|
||||
echo "Installing all packages except for -eix (doxypy, ivs, nox-classic)..."
|
||||
kernel
|
||||
mn_deps
|
||||
# Skip mn_dev (doxypy/texlive/fonts/etc.) because it's huge
|
||||
# mn_dev
|
||||
# Skip mn_doc (doxypy/texlive/fonts/etc.) because it's huge
|
||||
# mn_doc
|
||||
of
|
||||
install_wireshark
|
||||
ovs
|
||||
@@ -755,8 +796,12 @@ function vm_clean {
|
||||
# Remove SSH keys and regenerate on boot
|
||||
echo 'Removing SSH keys from /etc/ssh/'
|
||||
sudo rm -f /etc/ssh/*key*
|
||||
if [ ! -e /etc/rc.local ]; then
|
||||
echo '#!/bin/bash' | sudo tee /etc/rc.local
|
||||
sudo chmod +x /etc/rc.local
|
||||
fi
|
||||
if ! grep mininet /etc/rc.local >& /dev/null; then
|
||||
sudo sed -i -e "s/exit 0//" /etc/rc.local
|
||||
sudo sed -i -e "s/exit 0//" /etc/rc.local || true
|
||||
echo '
|
||||
# mininet: regenerate ssh keys if we deleted them
|
||||
if ! stat -t /etc/ssh/*key* >/dev/null 2>&1; then
|
||||
@@ -764,15 +809,15 @@ if ! stat -t /etc/ssh/*key* >/dev/null 2>&1; then
|
||||
fi
|
||||
exit 0
|
||||
' | sudo tee -a /etc/rc.local > /dev/null
|
||||
sudo chmod +x /etc/rc.local
|
||||
fi
|
||||
|
||||
# Remove Mininet files
|
||||
#sudo rm -f /lib/modules/python2.5/site-packages/mininet*
|
||||
#sudo rm -f /usr/bin/mnexec
|
||||
|
||||
# Clear optional dev script for SSH keychain load on boot
|
||||
rm -f ~/.bash_profile
|
||||
|
||||
# Remove leftover install script if any
|
||||
rm -f install-mininet-vm.sh
|
||||
|
||||
# Clear git changes
|
||||
git config --global user.name "None"
|
||||
git config --global user.email "None"
|
||||
@@ -799,7 +844,7 @@ function usage {
|
||||
printf -- ' -b: install controller (B)enchmark (oflops)\n' >&2
|
||||
printf -- ' -c: (C)lean up after kernel install\n' >&2
|
||||
printf -- ' -d: (D)elete some sensitive files from a VM image\n' >&2
|
||||
printf -- ' -e: install Mininet d(E)veloper dependencies\n' >&2
|
||||
printf -- ' -e: install Mininet documentation/LaT(e)X dependencies\n' >&2
|
||||
printf -- ' -f: install Open(F)low\n' >&2
|
||||
printf -- ' -h: print this (H)elp message\n' >&2
|
||||
printf -- ' -i: install (I)ndigo Virtual Switch\n' >&2
|
||||
@@ -833,7 +878,7 @@ else
|
||||
b) cbench;;
|
||||
c) kernel_clean;;
|
||||
d) vm_clean;;
|
||||
e) mn_dev;;
|
||||
e) mn_doc;;
|
||||
f) case $OF_VERSION in
|
||||
1.0) of;;
|
||||
1.3) of13;;
|
||||
|
||||
+15
-15
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python2
|
||||
|
||||
"""
|
||||
Translate from PEP8 Python style to Mininet (i.e. Arista-like)
|
||||
Translate from PEP8 Python style to Mininet (i.e. Arista-like)
|
||||
Python style
|
||||
|
||||
usage: unpep8 < old.py > new.py
|
||||
@@ -51,7 +51,7 @@ def fixUnderscoreTriplet( match ):
|
||||
def reinstateCapWords( text ):
|
||||
underscoreTriplet = re.compile( r'[A-Za-z0-9]_[A-Za-z0-9]' )
|
||||
return underscoreTriplet.sub( fixUnderscoreTriplet, text )
|
||||
|
||||
|
||||
def replaceTripleApostrophes( text ):
|
||||
"Replace triple apostrophes with triple quotes."
|
||||
return text.replace( "'''", '"""')
|
||||
@@ -60,7 +60,7 @@ def simplifyTripleQuotes( text ):
|
||||
"Fix single-line doc strings."
|
||||
r = re.compile( r'"""([^\"\n]+)"""' )
|
||||
return r.sub( r'"\1"', text )
|
||||
|
||||
|
||||
def insertExtraSpaces( text ):
|
||||
"Insert extra spaces inside of parentheses and brackets/curly braces."
|
||||
lparen = re.compile( r'\((?![\s\)])' )
|
||||
@@ -76,9 +76,9 @@ def insertExtraSpaces( text ):
|
||||
lcurly = re.compile( r'\{(?![\s\}])' )
|
||||
text = lcurly.sub( r'{ ', text )
|
||||
rcurly = re.compile( r'([^\s\{])(?=\})' )
|
||||
text = rcurly.sub( r'\1 ', text)
|
||||
text = rcurly.sub( r'\1 ', text)
|
||||
return text
|
||||
|
||||
|
||||
def fixDoxygen( text ):
|
||||
"""Translate @param foo to foo:, @return bar to returns: bar, and
|
||||
@author me to author: me"""
|
||||
@@ -96,11 +96,11 @@ def removeCommentFirstBlankLine( text ):
|
||||
"Remove annoying blank lines after first line in comments."
|
||||
line = re.compile( r'("""[^\n]*\n)\s*\n', re.MULTILINE )
|
||||
return line.sub( r'\1', text )
|
||||
|
||||
|
||||
def fixArgs( match, kwarg = re.compile( r'(\w+) = ' ) ):
|
||||
"Replace foo = bar with foo=bar."
|
||||
return kwarg.sub( r'\1=', match.group() )
|
||||
|
||||
|
||||
def fixKeywords( text ):
|
||||
"Change keyword argumentsfrom foo = bar to foo=bar."
|
||||
args = re.compile( r'\(([^\)]+)\)', re.MULTILINE )
|
||||
@@ -115,7 +115,7 @@ def fixKeywords( text ):
|
||||
def lineIter( text ):
|
||||
"Simple iterator over lines in text."
|
||||
for line in text.splitlines(): yield line
|
||||
|
||||
|
||||
def stringIter( strList ):
|
||||
"Yield strings in strList."
|
||||
for s in strList: yield s
|
||||
@@ -134,7 +134,7 @@ def restoreRegex( regex, old, new ):
|
||||
# This is a cheap hack, and it may not work 100%, since
|
||||
# it doesn't handle multiline strings.
|
||||
# However, it should be mostly harmless...
|
||||
|
||||
|
||||
def restoreStrings( oldText, newText ):
|
||||
"Restore strings from oldText into newText, returning result."
|
||||
oldLines, newLines = lineIter( oldText ), lineIter( newText )
|
||||
@@ -149,13 +149,13 @@ def restoreStrings( oldText, newText ):
|
||||
newLine = restoreRegex( tickStrings, oldLine, newLine )
|
||||
result += newLine + '\n'
|
||||
return result
|
||||
|
||||
|
||||
# This might be slightly controversial, since it uses
|
||||
# three spaces to line up multiline comments. However,
|
||||
# I much prefer it. Limitations: if you have deeper
|
||||
# indents in comments, they will be eliminated. ;-(
|
||||
|
||||
def fixComment( match,
|
||||
def fixComment( match,
|
||||
indentExp=re.compile( r'\n([ ]*)(?=[^/s])', re.MULTILINE ),
|
||||
trailingQuotes=re.compile( r'\s+"""' ) ):
|
||||
"Re-indent comment, and join trailing quotes."
|
||||
@@ -166,17 +166,17 @@ def fixComment( match,
|
||||
if len( originalIndent ) is not 0: indent += ' '
|
||||
comment = indentExp.sub( indent, comment )
|
||||
return originalIndent + trailingQuotes.sub( '"""', comment )
|
||||
|
||||
|
||||
def fixCommentIndents( text ):
|
||||
"Fix multiline comment indentation."
|
||||
comments = re.compile( r'^([ ]*)("""[^"]*""")$', re.MULTILINE )
|
||||
return comments.sub( fixComment, text )
|
||||
|
||||
|
||||
def removeBogusLinefeeds( text ):
|
||||
"Remove extra linefeeds at the end of single-line comments."
|
||||
bogusLfs = re.compile( r'"([^"\n]*)\n"', re.MULTILINE )
|
||||
return bogusLfs.sub( '"\1"', text)
|
||||
|
||||
|
||||
def convertFromPep8( program ):
|
||||
oldProgram = program
|
||||
# Program text transforms
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
from subprocess import check_output as co
|
||||
from sys import exit, version_info
|
||||
|
||||
+102
-50
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python2
|
||||
|
||||
"""
|
||||
build.py: build a Mininet VM
|
||||
@@ -31,6 +31,7 @@ from os import stat, path
|
||||
from stat import ST_MODE, ST_SIZE
|
||||
from os.path import abspath
|
||||
from sys import exit, stdout, argv, modules
|
||||
import sys
|
||||
import re
|
||||
from glob import glob
|
||||
from subprocess import check_output, call, Popen
|
||||
@@ -39,11 +40,13 @@ from time import time, strftime, localtime
|
||||
import argparse
|
||||
from distutils.spawn import find_executable
|
||||
import inspect
|
||||
from traceback import print_exc
|
||||
|
||||
|
||||
pexpect = None # For code check - imported dynamically
|
||||
|
||||
# boot can be slooooow!!!! need to debug/optimize somehow
|
||||
TIMEOUT=600
|
||||
TIMEOUT = 600
|
||||
|
||||
# Some configuration options
|
||||
# Possibly change this to use the parsed arguments instead!
|
||||
@@ -60,10 +63,23 @@ VMImageDir = os.environ[ 'HOME' ] + '/vm-images'
|
||||
|
||||
Prompt = '\$ ' # Shell prompt that pexpect will wait for
|
||||
|
||||
|
||||
# URLs for Ubunto .iso images
|
||||
|
||||
def serverURL( version, arch ):
|
||||
"Return .iso URL for Ubuntu version and arch"
|
||||
server = 'http://cdimage.ubuntu.com/ubuntu/releases/%s/release/'
|
||||
iso = 'ubuntu-%s-server-%s.iso'
|
||||
return (server + iso ) % ( version, version, arch )
|
||||
|
||||
def legacyURL( version, arch ):
|
||||
"Return .iso URL for Ubuntu version"
|
||||
server = ( 'http://cdimage.ubuntu.com/ubuntu-legacy-server/'
|
||||
'releases/%s/release/' )
|
||||
iso = 'ubuntu-%s-legacy-server-%s.iso'
|
||||
return (server + iso ) % ( version, version, arch )
|
||||
|
||||
isoURLs = {
|
||||
'precise32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/12.04/'
|
||||
'ubuntu-12.04.5-server-i386.iso',
|
||||
'precise64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/12.04/'
|
||||
'ubuntu-12.04.5-server-amd64.iso',
|
||||
@@ -73,18 +89,14 @@ isoURLs = {
|
||||
'trusty64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/14.04/'
|
||||
'ubuntu-14.04.4-server-amd64.iso',
|
||||
'wily32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/15.10/'
|
||||
'ubuntu-15.10-server-i386.iso',
|
||||
'wily64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/15.10/'
|
||||
'ubuntu-15.10-server-amd64.iso',
|
||||
'xenial32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/16.04/'
|
||||
'ubuntu-16.04.1-server-i386.iso',
|
||||
'ubuntu-16.04.6-server-i386.iso',
|
||||
'xenial64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/16.04/'
|
||||
'ubuntu-16.04.1-server-amd64.iso',
|
||||
'ubuntu-16.04.7-server-amd64.iso',
|
||||
'bionic64server': serverURL( '18.04.5', 'amd64' ),
|
||||
'focal64server': legacyURL( '20.04.1', 'amd64' ),
|
||||
}
|
||||
|
||||
|
||||
@@ -122,7 +134,7 @@ def log( *args, **kwargs ):
|
||||
else:
|
||||
print( output, )
|
||||
# Optionally mirror to LogFile
|
||||
if type( LogFile ) is file:
|
||||
if LogFile:
|
||||
if cr:
|
||||
output += '\n'
|
||||
LogFile.write( output )
|
||||
@@ -131,7 +143,7 @@ def log( *args, **kwargs ):
|
||||
|
||||
def run( cmd, **kwargs ):
|
||||
"Convenient interface to check_output"
|
||||
log( '-', cmd )
|
||||
log( '+', cmd )
|
||||
cmd = cmd.split()
|
||||
arg0 = cmd[ 0 ]
|
||||
if not find_executable( arg0 ):
|
||||
@@ -153,7 +165,7 @@ def depend():
|
||||
log( '* Installing package dependencies' )
|
||||
run( 'sudo apt-get -qy update' )
|
||||
run( 'sudo apt-get -qy install'
|
||||
' kvm cloud-utils genisoimage qemu-kvm qemu-utils'
|
||||
' kvmtool cloud-utils genisoimage qemu-kvm qemu-utils'
|
||||
' e2fsprogs curl'
|
||||
' python-setuptools mtools zip' )
|
||||
run( 'sudo easy_install pexpect' )
|
||||
@@ -179,9 +191,9 @@ def findiso( flavor ):
|
||||
url = isoURLs[ flavor ]
|
||||
name = path.basename( url )
|
||||
iso = path.join( VMImageDir, name )
|
||||
if not path.exists( iso ) or ( stat( iso )[ ST_MODE ] & 0777 != 0444 ):
|
||||
if not path.exists( iso ) or ( stat( iso )[ ST_MODE ] & 0o777 != 0o444 ):
|
||||
log( '* Retrieving', url )
|
||||
run( 'curl -C - -o %s %s' % ( iso, url ) )
|
||||
run( 'curl -L -C - -o %s %s' % ( iso, url ) )
|
||||
# Make sure the file header/type is something reasonable like
|
||||
# 'ISO' or 'x86 boot sector', and not random html or text
|
||||
result = run( 'file ' + iso )
|
||||
@@ -190,7 +202,7 @@ def findiso( flavor ):
|
||||
raise Exception( 'findiso: could not download iso from ' + url )
|
||||
# Write-protect iso, signaling it is complete
|
||||
log( '* Write-protecting iso', iso)
|
||||
os.chmod( iso, 0444 )
|
||||
os.chmod( iso, 0o444 )
|
||||
log( '* Using iso', iso )
|
||||
return iso
|
||||
|
||||
@@ -201,10 +213,11 @@ def attachNBD( cow, flags='' ):
|
||||
# qemu-nbd requires an absolute path
|
||||
cow = abspath( cow )
|
||||
log( '* Checking for unused /dev/nbdX device ' )
|
||||
for i in range ( 0, 63 ):
|
||||
nbd = '/dev/nbd%d' % i
|
||||
for i in range ( 1, 63 ):
|
||||
entry = 'nbd%d' % i
|
||||
nbd = '/dev/' + entry
|
||||
# Check whether someone's already messing with that device
|
||||
if call( [ 'pgrep', '-f', nbd ] ) == 0:
|
||||
if call( [ 'pgrep', '-f', entry ] ) == 0:
|
||||
continue
|
||||
srun( 'modprobe nbd max-part=64' )
|
||||
srun( 'qemu-nbd %s -c %s %s' % ( flags, nbd, cow ) )
|
||||
@@ -222,17 +235,26 @@ def extractKernel( image, flavor, imageDir=VMImageDir ):
|
||||
"Extract kernel and initrd from base image"
|
||||
kernel = path.join( imageDir, flavor + '-vmlinuz' )
|
||||
initrd = path.join( imageDir, flavor + '-initrd' )
|
||||
if path.exists( kernel ) and ( stat( image )[ ST_MODE ] & 0777 ) == 0444:
|
||||
# If kernel is there, then initrd should also be there
|
||||
return kernel, initrd
|
||||
log( '* Extracting kernel to', kernel )
|
||||
nbd = attachNBD( image, flags='-r' )
|
||||
try:
|
||||
print( srun( 'partx ' + nbd ) )
|
||||
except:
|
||||
log( 'Warning - partx failed with error' )
|
||||
# Assume kernel is in partition 1/boot/vmlinuz*generic for now
|
||||
# Guess that kernel is in partition 1/boot/vmlinuz*generic
|
||||
# ...but look for other Linux partitions just in case
|
||||
part = nbd + 'p1'
|
||||
partitions = srun( 'fdisk -l ' + nbd )
|
||||
for line in partitions.split( '\n' ):
|
||||
line = line.strip()
|
||||
if line.endswith( 'Linux' ):
|
||||
part = line.split()[ 0 ]
|
||||
break
|
||||
partnum = int( part.split( 'p' )[ -1 ] )
|
||||
if path.exists( kernel ) and ( stat( image )[ ST_MODE ] & 0o777 ) == 0o444:
|
||||
# If kernel is there, then initrd should also be there
|
||||
detachNBD( nbd )
|
||||
return kernel, initrd, partnum
|
||||
mnt = mkdtemp()
|
||||
srun( 'mount -o ro,noload %s %s' % ( part, mnt ) )
|
||||
kernsrc = glob( '%s/boot/vmlinuz*generic' % mnt )[ 0 ]
|
||||
@@ -244,7 +266,7 @@ def extractKernel( image, flavor, imageDir=VMImageDir ):
|
||||
srun( 'umount ' + mnt )
|
||||
run( 'rmdir ' + mnt )
|
||||
detachNBD( nbd )
|
||||
return kernel, initrd
|
||||
return kernel, initrd, partnum
|
||||
|
||||
|
||||
def findBaseImage( flavor, size='8G' ):
|
||||
@@ -252,8 +274,8 @@ def findBaseImage( flavor, size='8G' ):
|
||||
image = path.join( VMImageDir, flavor + '-base.qcow2' )
|
||||
if path.exists( image ):
|
||||
# Detect race condition with multiple builds
|
||||
perms = stat( image )[ ST_MODE ] & 0777
|
||||
if perms != 0444:
|
||||
perms = stat( image )[ ST_MODE ] & 0o777
|
||||
if perms != 0o444:
|
||||
raise Exception( 'Error - base image %s is writable.' % image +
|
||||
' Are multiple builds running? if not,'
|
||||
' remove %s and try again.' % image )
|
||||
@@ -266,10 +288,11 @@ def findBaseImage( flavor, size='8G' ):
|
||||
installUbuntu( iso, image )
|
||||
# Write-protect image, also signaling it is complete
|
||||
log( '* Write-protecting image', image)
|
||||
os.chmod( image, 0444 )
|
||||
kernel, initrd = extractKernel( image, flavor )
|
||||
log( '* Using base image', image, 'and kernel', kernel )
|
||||
return image, kernel, initrd
|
||||
os.chmod( image, 0o444 )
|
||||
kernel, initrd, partnum = extractKernel( image, flavor )
|
||||
log( '* Using base image', image, 'and kernel', kernel,
|
||||
'and partition #', partnum )
|
||||
return image, kernel, initrd, partnum
|
||||
|
||||
|
||||
# Kickstart and Preseed files for Ubuntu/Debian installer
|
||||
@@ -382,8 +405,20 @@ def installUbuntu( iso, image, logfilename='install.log', memory=1024 ):
|
||||
# Mount iso so we can use its kernel
|
||||
mnt = mkdtemp()
|
||||
srun( 'mount %s %s' % ( iso, mnt ) )
|
||||
kernel = path.join( mnt, 'install/vmlinuz' )
|
||||
initrd = path.join( mnt, 'install/initrd.gz' )
|
||||
for kdir in 'install', 'casper':
|
||||
kernel = path.join( mnt, kdir, 'vmlinuz' )
|
||||
if not path.exists( kernel ):
|
||||
kernel = ''
|
||||
for initrd in 'initrd.gz', 'initrd':
|
||||
initrd = path.join( mnt, kdir, initrd )
|
||||
if path.exists( initrd ):
|
||||
break
|
||||
else:
|
||||
initrd = ''
|
||||
if kernel and initrd:
|
||||
break
|
||||
if not kernel or not initrd:
|
||||
raise Exception( 'unable to locate kernel and initrd in iso image' )
|
||||
if NoKVM:
|
||||
accel = 'tcg'
|
||||
else:
|
||||
@@ -407,6 +442,7 @@ def installUbuntu( iso, image, logfilename='install.log', memory=1024 ):
|
||||
'-append',
|
||||
' ks=floppy:/' + kickstart +
|
||||
' preseed/file=floppy://' + preseed +
|
||||
' net.ifnames=0' +
|
||||
' console=ttyS0' ]
|
||||
ubuntuStart = time()
|
||||
log( '* INSTALLING UBUNTU FROM', iso, 'ONTO', image )
|
||||
@@ -423,6 +459,8 @@ def installUbuntu( iso, image, logfilename='install.log', memory=1024 ):
|
||||
logfile.close()
|
||||
elapsed = time() - ubuntuStart
|
||||
# Unmount iso and clean up
|
||||
### DEBUGGING
|
||||
srun( 'ls -l ' + mnt )
|
||||
srun( 'umount ' + mnt )
|
||||
run( 'rmdir ' + mnt )
|
||||
if vm.returncode != 0:
|
||||
@@ -432,7 +470,7 @@ def installUbuntu( iso, image, logfilename='install.log', memory=1024 ):
|
||||
log( '* Ubuntu installation completed in %.2f seconds' % elapsed )
|
||||
|
||||
|
||||
def boot( cow, kernel, initrd, logfile, memory=1024, cpuCores=1 ):
|
||||
def boot( cow, kernel, initrd, logfile, memory=1024, cpuCores=1, partnum=1 ):
|
||||
"""Boot qemu/kvm with a COW disk and local/user data store
|
||||
cow: COW disk path
|
||||
kernel: kernel path
|
||||
@@ -464,7 +502,9 @@ def boot( cow, kernel, initrd, logfile, memory=1024, cpuCores=1 ):
|
||||
'-kernel', kernel,
|
||||
'-initrd', initrd,
|
||||
'-drive file=%s,if=virtio' % cow,
|
||||
'-append "root=/dev/vda1 init=/sbin/init console=ttyS0" ' ]
|
||||
'-append "root=/dev/vda%d init=/sbin/init'
|
||||
' net.ifnames=0 console=ttyS0" ' % partnum ]
|
||||
log( cmd )
|
||||
if Forward:
|
||||
cmd += sum( [ [ '-redir', f ] for f in Forward ], [] )
|
||||
if cpuCores > 1:
|
||||
@@ -590,13 +630,16 @@ def checkOutBranch( vm, branch, prompt=Prompt ):
|
||||
# The branch will be rebased to its parent on origin.
|
||||
# This probably doesn't matter since we're running on a COW disk
|
||||
# anyway.
|
||||
vm.sendline( 'cd ~/mininet; git fetch --all; git checkout '
|
||||
+ branch + '; git pull --rebase origin ' + branch )
|
||||
vm.sendline( 'cd ~/mininet; git fetch origin ' + branch +
|
||||
'; git checkout ' + branch +
|
||||
'; git pull --rebase origin ' + branch )
|
||||
vm.expect( prompt )
|
||||
vm.sendline( 'sudo -n make install' )
|
||||
# Use install.sh since we may need to identify python version?
|
||||
vm.sendline( 'util/install.sh -n' )
|
||||
|
||||
|
||||
def interact( vm, tests, pre='', post='', prompt=Prompt ):
|
||||
def interact( vm, tests, pre='', post='', prompt=Prompt,
|
||||
clean=True):
|
||||
"Interact with vm, which is a pexpect object"
|
||||
login( vm )
|
||||
log( '* Waiting for login...' )
|
||||
@@ -619,8 +662,11 @@ def interact( vm, tests, pre='', post='', prompt=Prompt ):
|
||||
vm.expect ( 'password for mininet: ' )
|
||||
vm.sendline( 'mininet' )
|
||||
log( '* Waiting for script to complete... ' )
|
||||
# Gigantic timeout for now ;-(
|
||||
vm.expect( 'Done preparing Mininet', timeout=3600 )
|
||||
# Long timeout since we may be on cloud CI
|
||||
# 30min for kvm, 1.5hr for emulation
|
||||
# TODO: detect installation errors
|
||||
timeout = 5200 if NoKVM else 1800
|
||||
vm.expect( 'Done preparing Mininet', timeout=timeout )
|
||||
log( '* Completed successfully' )
|
||||
vm.expect( prompt )
|
||||
version = getMininetVersion( vm )
|
||||
@@ -635,6 +681,10 @@ def interact( vm, tests, pre='', post='', prompt=Prompt ):
|
||||
vm.sendline( "sudo sed -i -e 's/^GRUB_TERMINAL=serial/#GRUB_TERMINAL=serial/' "
|
||||
"/etc/default/grub; sudo update-grub" )
|
||||
vm.expect( prompt )
|
||||
if clean:
|
||||
log( '* Cleaning vm' )
|
||||
vm.sendline( '~/mininet/util/install.sh -d' )
|
||||
vm.expect( prompt )
|
||||
log( '* Shutting down' )
|
||||
vm.sendline( 'sync; sudo shutdown -h now' )
|
||||
log( '* Waiting for EOF/shutdown' )
|
||||
@@ -799,7 +849,7 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
||||
ovfdate = strftime( '%y%m%d', lstart )
|
||||
dir = 'mn-%s-%s' % ( flavor, date )
|
||||
if Branch:
|
||||
dirname = 'mn-%s-%s-%s' % ( Branch, flavor, date )
|
||||
dir = 'mn-%s-%s-%s' % ( Branch, flavor, date )
|
||||
try:
|
||||
os.mkdir( dir)
|
||||
except:
|
||||
@@ -810,7 +860,7 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
||||
LogFile = open( 'build.log', 'w' )
|
||||
log( '* Logging to', abspath( LogFile.name ) )
|
||||
log( '* Created working directory', dir )
|
||||
image, kernel, initrd = findBaseImage( flavor )
|
||||
image, kernel, initrd, partnum = findBaseImage( flavor )
|
||||
basename = 'mininet-' + flavor
|
||||
volume = basename + '.qcow2'
|
||||
run( 'qemu-img create -f qcow2 -b %s %s' % ( image, volume ) )
|
||||
@@ -820,7 +870,7 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
||||
else:
|
||||
logfile = open( flavor + '.log', 'w+' )
|
||||
log( '* Logging results to', abspath( logfile.name ) )
|
||||
vm = boot( volume, kernel, initrd, logfile, memory=memory )
|
||||
vm = boot( volume, kernel, initrd, logfile, memory=memory, partnum=partnum )
|
||||
version = interact( vm, tests=tests, pre=pre, post=post )
|
||||
size = qcow2size( volume )
|
||||
arch = archFor( flavor )
|
||||
@@ -879,7 +929,7 @@ def runTests( vm, tests=None, pre='', post='', prompt=Prompt, uninstallNtpd=Fals
|
||||
|
||||
def getMininetVersion( vm ):
|
||||
"Run mn to find Mininet version in VM"
|
||||
vm.sendline( '~/mininet/bin/mn --version' )
|
||||
vm.sendline( '(cd ~/mininet; PYTHONPATH=. bin/mn --version)' )
|
||||
# Eat command line echo, then read output line
|
||||
vm.readline()
|
||||
version = vm.readline().strip()
|
||||
@@ -904,7 +954,8 @@ def bootAndRun( image, prompt=Prompt, memory=1024, cpuCores=1, outputFile=None,
|
||||
log( '* Creating COW disk', cow )
|
||||
run( 'qemu-img create -f qcow2 -b %s %s' % ( image, cow ) )
|
||||
log( '* Extracting kernel and initrd' )
|
||||
kernel, initrd = extractKernel( image, flavor=basename, imageDir=tmpdir )
|
||||
kernel, initrd, partnum = extractKernel(
|
||||
image, flavor=basename, imageDir=tmpdir )
|
||||
if LogToConsole:
|
||||
logfile = stdout
|
||||
else:
|
||||
@@ -912,7 +963,7 @@ def bootAndRun( image, prompt=Prompt, memory=1024, cpuCores=1, outputFile=None,
|
||||
suffix='.testlog', delete=False )
|
||||
log( '* Logging VM output to', logfile.name )
|
||||
vm = boot( cow=cow, kernel=kernel, initrd=initrd, logfile=logfile,
|
||||
memory=memory, cpuCores=cpuCores )
|
||||
memory=memory, cpuCores=cpuCores, partnum=partnum )
|
||||
login( vm )
|
||||
log( '* Waiting for prompt after login' )
|
||||
vm.expect( prompt )
|
||||
@@ -951,7 +1002,7 @@ def testDict():
|
||||
def testString():
|
||||
"Return string listing valid tests"
|
||||
tests = [ '%s <%s>' % ( name, func.__doc__ )
|
||||
for name, func in testDict().iteritems() ]
|
||||
for name, func in testDict().items() ]
|
||||
return 'valid tests: %s' % ', '.join( tests )
|
||||
|
||||
|
||||
@@ -1031,6 +1082,7 @@ def parseArgs():
|
||||
memory=args.memory )
|
||||
except Exception as e:
|
||||
log( '* BUILD FAILED with exception: ', e )
|
||||
print_exc( e )
|
||||
exit( 1 )
|
||||
for image in args.image:
|
||||
bootAndRun( image, runFunction=runTests, tests=args.test, pre=args.run,
|
||||
|
||||
@@ -15,13 +15,7 @@ sudo sed -i -e 's/splash//' /etc/default/grub
|
||||
sudo sed -i -e 's/quiet/text/' /etc/default/grub
|
||||
sudo update-grub
|
||||
# Update from official archive
|
||||
sudo apt-get update
|
||||
# 12.10 and earlier
|
||||
#sudo sed -i -e 's/us.archive.ubuntu.com/mirrors.kernel.org/' \
|
||||
# /etc/apt/sources.list
|
||||
# 13.04 and later
|
||||
#sudo sed -i -e 's/\/archive.ubuntu.com/\/mirrors.kernel.org/' \
|
||||
# /etc/apt/sources.list
|
||||
sudo apt-get -qq update
|
||||
# Clean up vmware easy install junk if present
|
||||
if [ -e /etc/issue.backup ]; then
|
||||
sudo mv /etc/issue.backup /etc/issue
|
||||
@@ -30,18 +24,22 @@ if [ -e /etc/rc.local.backup ]; then
|
||||
sudo mv /etc/rc.local.backup /etc/rc.local
|
||||
fi
|
||||
# Fetch Mininet
|
||||
sudo apt-get -y install git-core openssh-server
|
||||
sudo apt-get -y -qq install git-core openssh-server
|
||||
git clone git://github.com/mininet/mininet
|
||||
# Optionally check out branch
|
||||
if [ "$1" != "" ]; then
|
||||
pushd mininet
|
||||
#git checkout -b $1 $1
|
||||
# TODO branch will in detached HEAD state if it is not master
|
||||
git checkout $1
|
||||
popd
|
||||
pushd mininet
|
||||
git fetch origin $1
|
||||
git checkout $1
|
||||
popd
|
||||
fi
|
||||
# Install Mininet
|
||||
time mininet/util/install.sh
|
||||
# Install Mininet for Python2 and Python3
|
||||
APT="sudo apt-get -y -qq"
|
||||
$APT install python3
|
||||
$APT install python2 || $APT install python
|
||||
python --version || $APT install python-is-python3
|
||||
time PYTHON=python2 mininet/util/install.sh -n
|
||||
time PYTHON=python3 mininet/util/install.sh
|
||||
# Finalize VM
|
||||
time mininet/util/install.sh -tcd
|
||||
# Ignoring this since NOX classic is deprecated
|
||||
|
||||
Reference in New Issue
Block a user