Compare commits
434 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6eb8973c0b | |||
| 0848c5f3c1 | |||
| 41ac7c4a6e | |||
| 5ae59fdbc9 | |||
| ac7c68089b | |||
| ba569f4d82 | |||
| 615f37dbbe | |||
| aaa8886328 | |||
| 05ee42ee3c | |||
| 7685e41a3e | |||
| 39103f4c9d | |||
| 5b1b376336 | |||
| 8725056d7b | |||
| 88f14e946a | |||
| 0cefa0b8de | |||
| 1b4c7d706d | |||
| 5e909c6e4f | |||
| 740acfb350 | |||
| a978ce9484 | |||
| 1e546cb73b | |||
| a2cb3e4051 | |||
| 4cfe97ee49 | |||
| b762d0bf96 | |||
| 4840bc20c5 | |||
| 30a5fd0df4 | |||
| 4707e90028 | |||
| cf5675876c | |||
| 1169982c0a | |||
| 32a7126d2b | |||
| 678add6202 | |||
| 936d303f5d | |||
| c5413a74f5 | |||
| 3f5503d773 | |||
| aa0176fce6 | |||
| bdd2f8d87f | |||
| 1a47699f21 | |||
| 270a6ba333 | |||
| c3ba039a97 | |||
| 8a50d3867c | |||
| d1b0b32c8c | |||
| 71d3e58d8c | |||
| 9edbb3b4a3 | |||
| 57294d013e | |||
| bfb6b9f4c4 | |||
| 1b55f09c4e | |||
| 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 | |||
| 36d2b21187 | |||
| 1888001555 | |||
| fdc3156a91 | |||
| cf6da391fa | |||
| f170cc6f64 | |||
| fd96de6485 | |||
| 73f530b569 | |||
| c7a27b8876 | |||
| b7a6b8137f | |||
| d072e531c2 | |||
| 8139d7d1b4 | |||
| 273b14b771 | |||
| a73e776695 | |||
| bfda33544a | |||
| 1f4525ed0a | |||
| 1969669f51 | |||
| c639f342e5 | |||
| 6e887d0788 | |||
| 092863f113 | |||
| 5100a38fcd | |||
| 3bcecd8e08 | |||
| 486676d617 | |||
| 9e5280b4d1 | |||
| b70eed69d3 | |||
| d96b35694a | |||
| c7deeae11c | |||
| 323989953b | |||
| 17f9756e5c | |||
| 71f3931f2f | |||
| 1e9ca5f7fc | |||
| 8933c996cb | |||
| afa83cd5ae | |||
| 3e81ea7455 | |||
| 8102704726 | |||
| f4490069ca | |||
| 2ac4f92af3 | |||
| f98154a323 | |||
| 7b48460e9e | |||
| 3a0ef258d1 | |||
| 0d9a6796df | |||
| 08a59783f4 | |||
| e37afe996b | |||
| 6a387faa04 | |||
| 1a134cb4d2 | |||
| af4921adc5 | |||
| f94ee8ec97 | |||
| 356b024d6b | |||
| 2283bb01e6 | |||
| 3eef584c6b | |||
| 2e00a7de97 | |||
| e28348f6cd | |||
| 4b744d1fb0 | |||
| 2822998cad | |||
| 853815500d | |||
| 1a2925923f | |||
| cac884a85e | |||
| f314a6626a | |||
| bf83f4f343 | |||
| 1ef12e450a | |||
| 56fc6c3955 | |||
| 88cbf4ec42 | |||
| 26b3959968 | |||
| 966dd20b4b | |||
| 82998cac8b | |||
| 34b1f4161a | |||
| dfb297901f | |||
| 67236e9db3 | |||
| 8a00c3abf8 | |||
| 037f7f5921 | |||
| 8af3f28b67 | |||
| c5b2efd839 | |||
| a638e0b085 | |||
| f65e1ab936 | |||
| 70d14db881 | |||
| b142cf32ec | |||
| 87e26ef931 | |||
| 7366645c81 | |||
| 2437aba984 | |||
| a6627cd928 | |||
| aa8901268d | |||
| 9d306ad53a | |||
| 69b6c05970 | |||
| e55e18e4ce | |||
| f86db75b79 | |||
| 5728fcbf40 | |||
| 23f4f4a998 | |||
| ba2d91b489 | |||
| 40e2c374d0 | |||
| ce8feb7bfa | |||
| e823c4f93c | |||
| 497a342c27 | |||
| 32565765c1 | |||
| c1d07835bd | |||
| 65acef533a | |||
| bf2bb4c88c | |||
| bfc00c567c | |||
| 92d57db0d0 | |||
| 13331d0ffd | |||
| 359b1feb5a | |||
| a77ddba607 | |||
| caf23f078e | |||
| d5cb865aaa | |||
| 1c0aeb699f | |||
| c458c9e2b4 | |||
| 26a0e351f3 | |||
| 742f5b9af9 | |||
| 40e4546c48 | |||
| 5479117584 | |||
| 02453b02b0 | |||
| d282c55831 | |||
| 6977633de1 | |||
| bc0a72e2f9 | |||
| ef5c80abb3 | |||
| 35a33fc617 | |||
| 494840c908 | |||
| b7d9fdd5bd | |||
| 32299a6808 | |||
| d7cfb729c3 | |||
| 348b526212 | |||
| 18bfa1d6b3 | |||
| 5d2dfa9f40 | |||
| 0b5d24148b | |||
| dfb2594793 | |||
| b5b6beacb0 | |||
| 213563583d | |||
| 9c7638a015 | |||
| fef7e0521c | |||
| 335cb1bdf3 | |||
| 0b2d8461fd | |||
| 9376ccbedd | |||
| 03b1cbb347 | |||
| 51f50e8b8f | |||
| 2e9a79a375 | |||
| 86a26e0baf | |||
| 6f2981134d | |||
| e58cc37c49 | |||
| baebce8b05 | |||
| 2bfaec75e0 | |||
| 36c2e7cd79 | |||
| 3284b04f2b | |||
| 8c662d63bf | |||
| 3cb387ebd0 | |||
| e90a4a74cb | |||
| d338b4425b | |||
| c128712d4d | |||
| 8b2881b0c2 | |||
| 3a9081b5b1 | |||
| 54bd4e4d3a | |||
| cc1cd9619f | |||
| 007261d19e | |||
| dc22b0a877 | |||
| 4178333174 | |||
| f012dac2cb | |||
| 8def6752f3 | |||
| 0f9c1b33c7 | |||
| f530c99415 | |||
| 5470415bfc | |||
| 7e5324c80e | |||
| e893fc9da4 | |||
| b2e1907c3a | |||
| 21086cd79e | |||
| ee15ce2243 | |||
| 1eb6f65e40 | |||
| 238ffe64a7 | |||
| cea176fa9f | |||
| 3276e3fef5 | |||
| e40d9b8c0d | |||
| 30d08cfbb2 | |||
| 29d902918d | |||
| f89a5bcf70 | |||
| 8ac077a721 | |||
| 666635c969 | |||
| 4c1cfcf6f3 | |||
| 76c8afde8a | |||
| 5714495f8c | |||
| d8371615ce | |||
| 7630861fde | |||
| da594dcecd | |||
| 4fe5a19221 | |||
| 330a466503 | |||
| c0b8eddadb | |||
| 76b54e3e44 | |||
| 36489c7470 | |||
| dd8adda3ff | |||
| fb1f0dca2a | |||
| 70fcc45893 | |||
| 511d71a110 | |||
| 57abd9baef | |||
| e6b0430a87 | |||
| 6f286033c5 | |||
| 1600b10131 | |||
| 475bb4d911 | |||
| c5517f7872 | |||
| 40353c9150 | |||
| c7e23ccedf | |||
| 361beab0b0 | |||
| 07fbc894e7 | |||
| 098b39d07a | |||
| 60e537f9bc | |||
| 5cfc9f84b8 | |||
| 6ddce0ac92 | |||
| e87ee10f8b | |||
| e171aba8b5 | |||
| 1bd0e927d2 | |||
| e113f8ed12 | |||
| 336958352a | |||
| 5dc15aeaaf | |||
| 9a22e2b737 | |||
| 76d3252cd0 | |||
| 9756c9a392 | |||
| 0fac568a19 | |||
| 04897513cd | |||
| 5365831de8 | |||
| 6a69c3c743 | |||
| c0793cb58b | |||
| 327af97ccc | |||
| b78b99b695 | |||
| a1bff4b035 | |||
| 0b673d7cb6 | |||
| db134f36ae | |||
| f873068a2c | |||
| 38a4000a97 | |||
| 0f5e05c088 | |||
| 65000d3245 | |||
| 312ed1a4a5 | |||
| ce5738b4a6 | |||
| 447db4c77c | |||
| b47aa5dadc | |||
| af0215fb9f | |||
| 2791333c70 | |||
| 96ea5367db | |||
| 0298e9be7d | |||
| 7c6d645a0a | |||
| 0c2fbaf187 | |||
| d254d7496c | |||
| 2c5d86f197 | |||
| 8df24304d8 | |||
| 93b123761b | |||
| cdbbb5b7a6 | |||
| 86af067e42 | |||
| db3bffa971 | |||
| 2cb17590c2 | |||
| f7601da006 | |||
| 65a0e5f3b6 | |||
| d5d66f1276 | |||
| 9ed14fa0f4 | |||
| f24ebc438e | |||
| 90d50dcbc4 | |||
| ce2458c1df | |||
| 8871893993 | |||
| 5f68be2273 | |||
| 68ae67dc58 | |||
| c4a85ab1d1 | |||
| ef3c885630 | |||
| bb35d04102 | |||
| ba05fd363b | |||
| e988b0f660 | |||
| b27cce08af | |||
| a38896c254 | |||
| 63ae13fcf9 | |||
| c5f6d0ff17 | |||
| ab8c4e9198 | |||
| 8daa4193c7 | |||
| 5c895eaad8 | |||
| 435d0d68b3 | |||
| 66e9845f05 | |||
| fe3340077c | |||
| c589660e17 | |||
| d9117c77e1 | |||
| 6cb68f26c9 | |||
| c60764c34f | |||
| ba723826b7 | |||
| 0165d7bdff | |||
| 1df1f9a1c5 | |||
| 2c916acc06 | |||
| 0a810b226c | |||
| 57c8f5934f | |||
| 125e669723 | |||
| a2486a6d66 | |||
| 15f2898f26 | |||
| 1c4adde1b6 | |||
| 4d22991245 | |||
| 90ea6c6bd1 | |||
| 269cecd3ee | |||
| c2be20f09e | |||
| df56fa2716 | |||
| f49e2539b7 | |||
| 4da7b3b7f0 | |||
| e5a5cd0070 | |||
| c5779deeb6 | |||
| 79c944aef4 | |||
| a23c6a2871 | |||
| 7acc693277 | |||
| 889698f7bd | |||
| f6f6d9282b | |||
| 5224884e5e | |||
| f063b023bd | |||
| a1edb167b1 | |||
| 613fac4bab | |||
| e0cd11ab21 | |||
| 5b818ad75c |
@@ -0,0 +1,20 @@
|
||||
<!--
|
||||
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**,
|
||||
please use the documentation at docs.mininet.org, the FAQ
|
||||
at faq.mininet.org, and the mininet-discuss mailing list.
|
||||
|
||||
For bug reports, please fill in the following information in detail,
|
||||
and also feel free to include additional information such as debug
|
||||
output from mn -v debug, etc.
|
||||
-->
|
||||
### Expected/Desired Behavior:
|
||||
|
||||
### Actual Behavior:
|
||||
|
||||
### Detailed Steps to Reproduce the Behavior:
|
||||
|
||||
### Additional Information:
|
||||
|
||||
@@ -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.15.7
|
||||
- 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-22.04, ubuntu-20.04]
|
||||
py: [python3, python2]
|
||||
steps:
|
||||
- name: Check out Mininet source
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Python ${{ matrix.py }}
|
||||
run: sudo apt install ${{ matrix.py }}
|
||||
- name: Install Mininet and base dependencies
|
||||
run: |
|
||||
sudo apt-get update -qq
|
||||
# This seems too slow unfortunately:
|
||||
# sudo apt-get upgrade -y -qq
|
||||
PYTHON=${{ matrix.py }} util/install.sh -nv
|
||||
- name: Disable slow udevd
|
||||
run: sudo systemctl stop systemd-udevd
|
||||
systemd-udevd-kernel.socket
|
||||
systemd-udevd-control.socket
|
||||
|| echo "couldn't disable udevd"
|
||||
- name: Sanity test
|
||||
run: |
|
||||
export sudo="sudo env PATH=$PATH"
|
||||
export PYTHON=${{ matrix.py }}
|
||||
# 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
|
||||
export PYTHON=${{ matrix.py }}
|
||||
sudo $PYTHON -m pip install pexpect
|
||||
util/install.sh -fw
|
||||
- name: Run core tests
|
||||
run: |
|
||||
export sudo="sudo env PATH=$PATH"
|
||||
export PYTHON=${{ matrix.py }}
|
||||
$sudo $PYTHON mininet/test/runner.py -v
|
||||
- name: Run examples tests
|
||||
run: |
|
||||
export sudo="sudo env PATH=$PATH"
|
||||
export PYTHON=${{ matrix.py }}
|
||||
$sudo $PYTHON examples/test/runner.py -v
|
||||
@@ -16,7 +16,7 @@
|
||||
#init-hook=
|
||||
|
||||
# Profiled execution.
|
||||
profile=no
|
||||
#profile=no
|
||||
|
||||
# Add <file or directory> to the black list. It should be a base name, not a
|
||||
# path. You may set this option multiple times.
|
||||
@@ -41,10 +41,19 @@ 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).
|
||||
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-locals, too-many-public-methods, duplicate-code, bad-whitespace,
|
||||
locally-disabled
|
||||
#
|
||||
# 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=invalid-name, super-init-not-called, fixme,
|
||||
too-many-instance-attributes, too-few-public-methods,
|
||||
too-many-locals, too-many-public-methods, duplicate-code,
|
||||
locally-disabled,
|
||||
useless-object-inheritance, unnecessary-pass, no-else-return,
|
||||
no-else-raise, no-else-continue, super-with-arguments,
|
||||
consider-using-f-string, unspecified-encoding
|
||||
|
||||
# bad-continuation, wrong-import-order
|
||||
|
||||
[REPORTS]
|
||||
|
||||
@@ -54,14 +63,14 @@ output-format=colorized
|
||||
msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'
|
||||
|
||||
# Include message's id in output
|
||||
include-ids=yes
|
||||
# include-ids=yes
|
||||
|
||||
# Put messages in a separate file for each module / package specified on the
|
||||
# command line instead of printing them on stdout. Reports (if any) will be
|
||||
# written in a file name "pylint_global.[txt|html]".
|
||||
files-output=no
|
||||
# files-output=no
|
||||
|
||||
# Tells wether to display a full report or only the messages
|
||||
# Tells whether to display a full report or only the messages
|
||||
reports=no
|
||||
|
||||
# Python expression which should return a note less than 10 (10 is the highes
|
||||
@@ -73,7 +82,7 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme
|
||||
|
||||
# Add a comment according to your evaluation note. This is used by the global
|
||||
# evaluation report (R0004).
|
||||
comment=no
|
||||
#comment=no
|
||||
|
||||
# Enable the report(s) with the given id(s).
|
||||
#enable-report=
|
||||
@@ -95,7 +104,7 @@ comment=no
|
||||
[BASIC]
|
||||
|
||||
# Required attributes for module, separated by a comma
|
||||
required-attributes=
|
||||
#required-attributes=
|
||||
|
||||
# Regular expression which should only match functions or classes name which do
|
||||
# not require a docstring
|
||||
@@ -111,10 +120,10 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||
|
||||
# Regular expression which should only match correct function names
|
||||
function-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
function-rgx=[a-z_][a-z0-9]{2,30}$
|
||||
|
||||
# Regular expression which should only match correct method names
|
||||
method-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
method-rgx=[a-z_][a-z0-9]{2,30}$
|
||||
|
||||
# Regular expression which should only match correct instance attribute names
|
||||
attr-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
@@ -123,7 +132,7 @@ attr-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
argument-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression which should only match correct variable names
|
||||
variable-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
variable-rgx=[a-z_][a-z0-9]{2,30}$
|
||||
|
||||
# Regular expression which should only match correct list comprehension /
|
||||
# generator expression variable names
|
||||
@@ -136,7 +145,7 @@ good-names=i,j,k,ex,Run,_
|
||||
bad-names=foo,bar,baz,toto,tutu,tata
|
||||
|
||||
# List of builtins function names that should not be used, separated by a comma
|
||||
bad-functions=map,filter,apply,inpu
|
||||
#bad-functions=map,filter,apply,inpu
|
||||
|
||||
|
||||
# try to find bugs in the code using type inference
|
||||
@@ -153,7 +162,7 @@ ignored-classes=SQLObjec
|
||||
|
||||
# When zope mode is activated, add a predefined set of Zope acquired attributes
|
||||
# to generated-members.
|
||||
zope=no
|
||||
#zope=no
|
||||
|
||||
# List of members which are set dynamically and missed by pylint inference
|
||||
# system, and so shouldn't trigger E0201 when accessed.
|
||||
@@ -191,7 +200,7 @@ additional-builtins=
|
||||
|
||||
# List of interface methods to ignore, separated by a comma. This is used for
|
||||
# instance to not check methods defines in Zope's Interface base class.
|
||||
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
|
||||
#ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
|
||||
|
||||
# List of method names used to declare (i.e. assign) instance attributes.
|
||||
defining-attr-methods=__init__,__new__,setUp,build
|
||||
@@ -213,7 +222,7 @@ max-locals=15
|
||||
max-returns=6
|
||||
|
||||
# Maximum number of branch for function / method body
|
||||
max-branchs=12
|
||||
#max-branchs=12
|
||||
|
||||
# Maximum number of statements in function / method body
|
||||
max-statements=50
|
||||
|
||||
+37
-6
@@ -18,32 +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
|
||||
Rich Lane
|
||||
Zi Shen Lim
|
||||
Murphy McCauley
|
||||
José Pedro Oliveira
|
||||
James Page
|
||||
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.2.1d1
|
||||
Mininet 2.3.1b4
|
||||
---
|
||||
|
||||
The supported installation methods for Mininet are 1) using a
|
||||
@@ -32,28 +32,31 @@ 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:
|
||||
|
||||
git clone git://github.com/mininet/mininet.git
|
||||
git clone https://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,44 +67,77 @@ 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 `mininet/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:
|
||||
|
||||
mininet/util/install.sh -fnv
|
||||
util/install.sh -fnv
|
||||
|
||||
This should be reasonably quick, and the following command should
|
||||
work after the installation:
|
||||
|
||||
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 Python, 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 version 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:
|
||||
|
||||
mininet/util/install.sh -a
|
||||
util/install.sh -a
|
||||
|
||||
This takes about 4 minutes on our test system.
|
||||
|
||||
You can change the directory where the dependencies are installed using
|
||||
the -s <directory> flag.
|
||||
|
||||
mininet/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,26 +145,14 @@ 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
|
||||
git clone https://github.com/mininet/mininet.git
|
||||
|
||||
* install Mininet, the OpenFlow reference implementation, and
|
||||
Open vSwitch
|
||||
|
||||
mininet/util/install.sh -fnv
|
||||
util/install.sh -fnv
|
||||
|
||||
* enable and start openvswitch
|
||||
|
||||
@@ -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,33 +1,29 @@
|
||||
Mininet 2.2.1d1 License
|
||||
BSD 3-Clause License (original Mininet authors: Bob Lantz and Brandon Heller)
|
||||
|
||||
Copyright (c) 2013-2014 Open Networking Laboratory
|
||||
Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of
|
||||
The Leland Stanford Junior University
|
||||
Copyright (c) 2013-2022 Open Networking Foundation
|
||||
Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of The Leland Stanford Junior University
|
||||
|
||||
Original authors: Bob Lantz and Brandon Heller
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
We are making Mininet available for public use and benefit with the
|
||||
expectation that others will use, modify and enhance the Software and
|
||||
contribute those enhancements back to the community. However, since we
|
||||
would like to make the Software available for broadest use, with as few
|
||||
restrictions as possible permission is hereby granted, free of charge, to
|
||||
any person obtaining a copy of this Software to deal in the Software
|
||||
under the copyrights without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
The name and trademarks of copyright holder(s) may NOT be used in
|
||||
advertising or publicity pertaining to the Software or any derivatives
|
||||
without specific, written prior permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
@@ -2,15 +2,19 @@ MININET = mininet/*.py
|
||||
TEST = mininet/test/*.py
|
||||
EXAMPLES = mininet/examples/*.py
|
||||
MN = bin/mn
|
||||
PYTHON ?= python
|
||||
PYMN = $(PYTHON) -B bin/mn
|
||||
BIN = $(MN)
|
||||
PYSRC = $(MININET) $(TEST) $(EXAMPLES) $(BIN)
|
||||
MNEXEC = mnexec
|
||||
MANPAGES = mn.1 mnexec.1
|
||||
P8IGN = E251,E201,E302,E202,E126,E127,E203,E226
|
||||
BINDIR = /usr/bin
|
||||
MANDIR = /usr/share/man/man1
|
||||
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
|
||||
|
||||
@@ -22,14 +26,14 @@ clean:
|
||||
codecheck: $(PYSRC)
|
||||
-echo "Running code check"
|
||||
util/versioncheck.py
|
||||
pyflakes $(PYSRC)
|
||||
pyflakes3 $(PYSRC) || pyflakes $(PYSRC)
|
||||
pylint --rcfile=.pylint $(PYSRC)
|
||||
# Exclude miniedit from pep8 checking for now
|
||||
pep8 --repeat --ignore=$(P8IGN) `ls $(PYSRC) | grep -v miniedit.py`
|
||||
|
||||
errcheck: $(PYSRC)
|
||||
-echo "Running check for errors only"
|
||||
pyflakes $(PYSRC)
|
||||
pyflakes3 $(PYSRC) || pyflakes $(PYSRC)
|
||||
pylint -E --rcfile=.pylint $(PYSRC)
|
||||
|
||||
test: $(MININET) $(TEST)
|
||||
@@ -43,24 +47,32 @@ slowtest: $(MININET)
|
||||
mininet/examples/test/runner.py -v
|
||||
|
||||
mnexec: mnexec.c $(MN) mininet/net.py
|
||||
cc $(CFLAGS) $(LDFLAGS) -DVERSION=\"`PYTHONPATH=. $(MN) --version`\" $< -o $@
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) \
|
||||
-DVERSION=\"`PYTHONPATH=. $(PYMN) --version 2>&1`\" $< -o $@
|
||||
|
||||
install: $(MNEXEC) $(MANPAGES)
|
||||
install $(MNEXEC) $(BINDIR)
|
||||
install $(MANPAGES) $(MANDIR)
|
||||
python setup.py install
|
||||
install-mnexec: $(MNEXEC)
|
||||
install -D $(MNEXEC) $(BINDIR)/$(MNEXEC)
|
||||
|
||||
install-manpages: $(MANPAGES)
|
||||
install -D -t $(MANDIR) $(MANPAGES)
|
||||
|
||||
install: install-mnexec install-manpages
|
||||
# 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)
|
||||
|
||||
mn.1: $(MN)
|
||||
PYTHONPATH=. help2man -N -n "create a Mininet network." \
|
||||
--no-discard-stderr $< -o $@
|
||||
--no-discard-stderr "$(PYMN)" -o $@
|
||||
|
||||
mnexec.1: mnexec
|
||||
help2man -N -n "execution utility for Mininet." \
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
Mininet: Rapid Prototyping for Software Defined Networks
|
||||
========================================================
|
||||
|
||||
*The best way to emulate almost any network on your laptop!*
|
||||
|
||||
Mininet 2.2.1d1
|
||||
Mininet 2.3.1b4
|
||||
|
||||
[![Build Status][1]](https://github.com/mininet/mininet/actions)
|
||||
|
||||
|
||||
### What is Mininet?
|
||||
|
||||
@@ -66,46 +68,35 @@ Mininet includes:
|
||||
|
||||
`mn -c`
|
||||
|
||||
### New features in this release
|
||||
### Python 3 Support
|
||||
|
||||
This release provides a number of bug fixes as well as
|
||||
several new features, including:
|
||||
- Mininet 2.3.1b4 supports Python 3 and Python 2
|
||||
|
||||
* Improved OpenFlow 1.3 support
|
||||
- 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`.
|
||||
|
||||
- `mn --switch ovs,protocols=openflow13` starts OVS in 1.3 mode
|
||||
- `install.sh -w` installs a 1.3-compatible Wireshark dissector using
|
||||
Loxigen
|
||||
- `install.sh -y` installs the Ryu 1.3-compatible controller
|
||||
- You can run `mn` directly with Python 2 or Python 3,
|
||||
as long as the appropriate version of Mininet is installed,
|
||||
e.g.
|
||||
|
||||
* A new `nodelib.py` node library, and new `Node` types including
|
||||
`LinuxBridge`, `OVSBridge`, `LinuxRouter` (see `examples/`)
|
||||
and `NAT`
|
||||
$ sudo python2 `which mn`
|
||||
|
||||
* A `--nat` option which connects a Mininet network to your LAN using NAT
|
||||
(For this to work correctly, Mininet's `--ipbase` subnet should not
|
||||
overlap with any external or internet IP addresses you wish to use)
|
||||
- More information regarding Python 3 and Python 2 support
|
||||
may be found in the release notes on http://docs.mininet.org.
|
||||
|
||||
* An improved MiniEdit GUI (`examples/miniedit.py`) - thanks to
|
||||
Gregory Gee
|
||||
### Other Enhancements and Information
|
||||
|
||||
* Support for multiple `--custom` arguments to `mn`
|
||||
- Support for Ubuntu 22.04 LTS (and 20.04)
|
||||
|
||||
* Experimental cluster support - consult the
|
||||
[documentation](http://docs.mininet.org) for details -
|
||||
as well as `examples/cluster.py` and an experimental `--cluster`
|
||||
option for topologies built with the default `Host` and `OVSSwitch`
|
||||
classes:
|
||||
- More reliable testing and CI via github actions
|
||||
|
||||
`mn --cluster localhost,server1,server2`
|
||||
- Preliminary support for cgroups v2 (and v1)
|
||||
|
||||
Note that examples contain experimental features which might
|
||||
"graduate" into mainline Mininet in the future, but they should
|
||||
not be considered a stable part of the Mininet API!
|
||||
- Minor bug fixes (2.3.1)
|
||||
|
||||
A number of bugs have also been fixed, most notably multiple link
|
||||
support in `Topo()`. See github issues and the release notes on
|
||||
the Mininet wiki for additional information.
|
||||
- Additional information about this release and previous releases
|
||||
may be found in the release notes on http://docs.mininet.org.
|
||||
|
||||
### Installation
|
||||
|
||||
@@ -118,7 +109,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
|
||||
|
||||
@@ -129,25 +121,22 @@ Mininet mailing list, `mininet-discuss` at:
|
||||
|
||||
### Join Us
|
||||
|
||||
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
|
||||
the code, examine it, modify it, and submit bug reports, bug fixes,
|
||||
feature requests, new features and other issues and pull requests.
|
||||
at <https://github.com/mininet>. You are encouraged to download,
|
||||
examine, and modify the code, and to submit bug reports, bug fixes,
|
||||
feature requests, new features, and other issues and pull requests.
|
||||
Thanks to everyone who has contributed code to the Mininet project
|
||||
(see CONTRIBUTORS for more info!) It is because of everyone's
|
||||
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.
|
||||
|
||||
The Mininet Core Team:
|
||||
|
||||
* Bob Lantz
|
||||
* Brian O'Connor
|
||||
* Cody Burkard
|
||||
|
||||
Thanks again to all of the Mininet contributors, particularly Gregory
|
||||
Gee for his work on MiniEdit.
|
||||
Bob Lantz,
|
||||
on behalf of the Mininet Contributors
|
||||
|
||||
[1]: https://github.com/mininet/mininet/workflows/mininet-tests/badge.svg
|
||||
|
||||
@@ -11,32 +11,35 @@ 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
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import lg, LEVELS, info, debug, warn, error
|
||||
import mininet.cli
|
||||
from mininet.log import lg, LEVELS, info, debug, warn, error, output
|
||||
from mininet.net import Mininet, MininetWithControlNet, VERSION
|
||||
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
|
||||
RYU, NOX, RemoteController, findController,
|
||||
DefaultController,
|
||||
Ryu, NOX, RemoteController, findController,
|
||||
DefaultController, NullController,
|
||||
UserSwitch, OVSSwitch, OVSBridge,
|
||||
OVSLegacyKernelSwitch, IVSSwitch )
|
||||
IVSSwitch )
|
||||
from mininet.nodelib import LinuxBridge
|
||||
from mininet.link import Link, TCLink, OVSLink
|
||||
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||
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 customConstructor, 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,
|
||||
@@ -45,11 +48,12 @@ 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
|
||||
TOPODEF = 'minimal'
|
||||
TOPOS = { 'minimal': lambda: SingleSwitchTopo( k=2 ),
|
||||
TOPOS = { 'minimal': MinimalTopo,
|
||||
'linear': LinearTopo,
|
||||
'reversed': SingleSwitchReversedTopo,
|
||||
'single': SingleSwitchTopo,
|
||||
@@ -62,63 +66,95 @@ SWITCHES = { 'user': UserSwitch,
|
||||
'ovsbr' : OVSBridge,
|
||||
# Keep ovsk for compatibility with 2.0
|
||||
'ovsk': OVSSwitch,
|
||||
'ovsl': OVSLegacyKernelSwitch,
|
||||
'ivs': IVSSwitch,
|
||||
'lxbr': LinuxBridge,
|
||||
'default': OVSSwitch }
|
||||
|
||||
HOSTDEF = 'proc'
|
||||
HOSTS = { 'proc': Host,
|
||||
'rt': partial( CPULimitedHost, sched='rt' ),
|
||||
'cfs': partial( CPULimitedHost, sched='cfs' ) }
|
||||
'rt': specialClass( CPULimitedHost, defaults=dict( sched='rt' ) ),
|
||||
'cfs': specialClass( CPULimitedHost, defaults=dict( sched='cfs' ) ) }
|
||||
|
||||
CONTROLLERDEF = 'default'
|
||||
CONTROLLERS = { 'ref': Controller,
|
||||
'ovsc': OVSController,
|
||||
'nox': NOX,
|
||||
'remote': RemoteController,
|
||||
'ryu': RYU,
|
||||
'default': DefaultController, # Note: replaced below
|
||||
'none': lambda name: None }
|
||||
'ryu': Ryu,
|
||||
'default': DefaultController, # Note: overridden below
|
||||
'none': NullController }
|
||||
|
||||
LINKDEF = 'default'
|
||||
LINKS = { 'default': Link,
|
||||
LINKS = { 'default': Link, # Note: overridden below
|
||||
'tc': TCLink,
|
||||
'tcu': TCULink,
|
||||
'ovs': OVSLink }
|
||||
|
||||
# TESTS dict can contain functions and/or Mininet() method names
|
||||
# XXX: it would be nice if we could specify a default test, but
|
||||
# this may be tricky
|
||||
TESTS = { name: True
|
||||
for name in ( 'pingall', 'pingpair', 'iperf', 'iperfudp' ) }
|
||||
|
||||
# optional tests to run
|
||||
TESTS = [ 'cli', 'build', 'pingall', 'pingpair', 'iperf', 'all', 'iperfudp',
|
||||
'none' ]
|
||||
CLI = None # Set below if needed
|
||||
|
||||
ALTSPELLING = { 'pingall': 'pingAll',
|
||||
'pingpair': 'pingPair',
|
||||
'iperfudp': 'iperfUdp',
|
||||
'iperfUDP': 'iperfUdp' }
|
||||
# Locally defined tests
|
||||
def allTest( net ):
|
||||
"Run ping and iperf tests"
|
||||
net.start()
|
||||
net.ping()
|
||||
net.iperf()
|
||||
|
||||
def nullTest( _net ):
|
||||
"Null 'test' (does nothing)"
|
||||
pass
|
||||
|
||||
|
||||
def addDictOption( opts, choicesDict, default, name, helpStr=None ):
|
||||
TESTS.update( all=allTest, none=nullTest, build=nullTest )
|
||||
|
||||
# Map to alternate spellings of Mininet() methods
|
||||
ALTSPELLING = { 'pingall': 'pingAll', 'pingpair': 'pingPair',
|
||||
'iperfudp': 'iperfUdp' }
|
||||
|
||||
def runTests( mn, options ):
|
||||
"""Run tests
|
||||
mn: Mininet object
|
||||
option: list of test optinos """
|
||||
# Split option into test name and parameters
|
||||
for option in options:
|
||||
# Multiple tests may be separated by '+' for now
|
||||
for test in option.split( '+' ):
|
||||
test, args, kwargs = splitArgs( test )
|
||||
test = ALTSPELLING.get( test.lower(), test )
|
||||
testfn = TESTS.get( test, test )
|
||||
if callable( testfn ):
|
||||
testfn( mn, *args, **kwargs )
|
||||
elif hasattr( mn, test ):
|
||||
getattr( mn, test )( *args, **kwargs )
|
||||
else:
|
||||
raise Exception( 'Test %s is unknown - please specify one of '
|
||||
'%s ' % ( test, TESTS.keys() ) )
|
||||
|
||||
|
||||
def addDictOption( opts, choicesDict, default, name, **kwargs ):
|
||||
"""Convenience function to add choices dicts to OptionParser.
|
||||
opts: OptionParser instance
|
||||
choicesDict: dictionary of valid choices, must include default
|
||||
default: default choice key
|
||||
name: long option name
|
||||
help: string"""
|
||||
if default not in choicesDict:
|
||||
raise Exception( 'Invalid default %s for choices dict: %s' %
|
||||
( default, name ) )
|
||||
if not helpStr:
|
||||
helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
|
||||
'[,param=value...]' )
|
||||
opts.add_option( '--' + name,
|
||||
type='string',
|
||||
default = default,
|
||||
help = helpStr )
|
||||
|
||||
kwargs: additional arguments to add_option"""
|
||||
helpStr = ( '|'.join( sorted( choicesDict.keys() ) ) +
|
||||
'[,param=value...]' )
|
||||
helpList = [ '%s=%s' % ( k, v.__name__ )
|
||||
for k, v in choicesDict.items() ]
|
||||
helpStr += ' ' + ( ' '.join( helpList ) )
|
||||
params = dict( type='string', default=default, help=helpStr )
|
||||
params.update( **kwargs )
|
||||
opts.add_option( '--' + name, **params )
|
||||
|
||||
def version( *_args ):
|
||||
"Print Mininet version and exit"
|
||||
print "%s" % VERSION
|
||||
output( "%s\n" % VERSION )
|
||||
exit()
|
||||
|
||||
|
||||
@@ -152,15 +188,19 @@ class MininetRunner( object ):
|
||||
for fileName in files:
|
||||
customs = {}
|
||||
if os.path.isfile( fileName ):
|
||||
execfile( fileName, customs, customs )
|
||||
for name, val in customs.iteritems():
|
||||
# pylint: disable=exec-used
|
||||
with open( fileName ) as f:
|
||||
exec( compile( f.read(), fileName, 'exec' ),
|
||||
customs, customs )
|
||||
for name, val in customs.items():
|
||||
self.setCustom( name, val )
|
||||
else:
|
||||
raise Exception( 'could not find custom file: %s' % fileName )
|
||||
|
||||
def setCustom( self, name, value ):
|
||||
"Set custom parameters for MininetRunner."
|
||||
if name in ( 'topos', 'switches', 'hosts', 'controllers' ):
|
||||
if name in ( 'topos', 'switches', 'hosts', 'controllers', 'links'
|
||||
'testnames', 'tests' ):
|
||||
# Update dictionaries
|
||||
param = name.upper()
|
||||
globals()[ param ].update( value )
|
||||
@@ -199,7 +239,7 @@ class MininetRunner( object ):
|
||||
opts = OptionParser( description=desc, usage=usage )
|
||||
addDictOption( opts, SWITCHES, SWITCHDEF, 'switch' )
|
||||
addDictOption( opts, HOSTS, HOSTDEF, 'host' )
|
||||
addDictOption( opts, CONTROLLERS, CONTROLLERDEF, 'controller' )
|
||||
addDictOption( opts, CONTROLLERS, [], 'controller', action='append' )
|
||||
addDictOption( opts, LINKS, LINKDEF, 'link' )
|
||||
addDictOption( opts, TOPOS, TOPODEF, 'topo' )
|
||||
|
||||
@@ -210,10 +250,8 @@ class MininetRunner( object ):
|
||||
type='string',
|
||||
help='read custom classes or params from .py file(s)'
|
||||
)
|
||||
|
||||
opts.add_option( '--test', type='choice', choices=TESTS,
|
||||
default=TESTS[ 0 ],
|
||||
help='|'.join( TESTS ) )
|
||||
opts.add_option( '--test', default=[], action='append',
|
||||
dest='test', help='|'.join( TESTS.keys() ) )
|
||||
opts.add_option( '--xterms', '-x', action='store_true',
|
||||
default=False, help='spawn xterms for each node' )
|
||||
opts.add_option( '--ipbase', '-i', type='string', default='10.0.0.0/8',
|
||||
@@ -223,11 +261,11 @@ class MininetRunner( object ):
|
||||
opts.add_option( '--arp', action='store_true',
|
||||
default=False, help='set all-pairs ARP entries' )
|
||||
opts.add_option( '--verbosity', '-v', type='choice',
|
||||
choices=LEVELS.keys(), default = 'info',
|
||||
choices=list( LEVELS.keys() ), default = 'info',
|
||||
help = '|'.join( LEVELS.keys() ) )
|
||||
opts.add_option( '--innamespace', action='store_true',
|
||||
default=False, help='sw and ctrl in namespace?' )
|
||||
opts.add_option( '--listenport', type='int', default=6634,
|
||||
opts.add_option( '--listenport', type='int', default=6654,
|
||||
help='base port for passive switch listening' )
|
||||
opts.add_option( '--nolistenport', action='store_true',
|
||||
default=False, help="don't use passive listening " +
|
||||
@@ -240,7 +278,7 @@ class MininetRunner( object ):
|
||||
default=False, help="pin hosts to CPU cores "
|
||||
"(requires --host cfs or --host rt)" )
|
||||
opts.add_option( '--nat', action='callback', callback=self.setNat,
|
||||
help="adds a NAT to the topology that"
|
||||
help="[option=val...] adds a NAT to the topology that"
|
||||
" connects Mininet hosts to the physical network."
|
||||
" Warning: This may route any traffic on the machine"
|
||||
" that uses Mininet's"
|
||||
@@ -249,11 +287,16 @@ 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!)' ) )
|
||||
opts.add_option( '--placement', type='choice',
|
||||
choices=PLACEMENT.keys(), default='block',
|
||||
choices=list( PLACEMENT.keys() ), default='block',
|
||||
metavar='block|random',
|
||||
help=( 'node placement for --cluster '
|
||||
'(experimental!) ' ) )
|
||||
@@ -270,116 +313,116 @@ class MininetRunner( object ):
|
||||
|
||||
# set logging verbosity
|
||||
if LEVELS[self.options.verbosity] > LEVELS['output']:
|
||||
print ( '*** WARNING: selected verbosity level (%s) will hide CLI '
|
||||
warn( '*** WARNING: selected verbosity level (%s) will hide CLI '
|
||||
'output!\n'
|
||||
'Please restart Mininet with -v [debug, info, output].'
|
||||
'Please restart Mininet with -v [debug, info, output].\n'
|
||||
% self.options.verbosity )
|
||||
lg.setLogLevel( self.options.verbosity )
|
||||
|
||||
# Maybe we'll reorganize this someday...
|
||||
# pylint: disable=too-many-branches,too-many-statements
|
||||
# pylint: disable=too-many-branches,too-many-statements,global-statement
|
||||
|
||||
def begin( self ):
|
||||
"Create and run mininet."
|
||||
|
||||
if self.options.cluster:
|
||||
servers = self.options.cluster.split( ',' )
|
||||
global CLI
|
||||
|
||||
opts = self.options
|
||||
|
||||
if opts.cluster:
|
||||
servers = opts.cluster.split( ',' )
|
||||
for server in servers:
|
||||
ClusterCleanup.add( server )
|
||||
|
||||
if self.options.clean:
|
||||
if opts.clean:
|
||||
cleanup()
|
||||
exit()
|
||||
|
||||
start = time.time()
|
||||
|
||||
if self.options.controller == 'default':
|
||||
if not opts.controller:
|
||||
# Update default based on available controllers
|
||||
CONTROLLERS[ 'default' ] = findController()
|
||||
if CONTROLLERS[ 'default' ] is None:
|
||||
if self.options.switch == 'default':
|
||||
opts.controller = [ 'default' ]
|
||||
if not CONTROLLERS[ 'default' ]:
|
||||
opts.controller = [ 'none' ]
|
||||
if opts.switch == 'default':
|
||||
info( '*** No default OpenFlow controller found '
|
||||
'for default switch!\n' )
|
||||
info( '*** Falling back to OVS Bridge\n' )
|
||||
self.options.switch = 'ovsbr'
|
||||
self.options.controller = 'none'
|
||||
elif self.options.switch in ( 'ovsbr', 'lxbr' ):
|
||||
self.options.controller = 'none'
|
||||
else:
|
||||
opts.switch = 'ovsbr'
|
||||
elif opts.switch not in ( 'ovsbr', 'lxbr' ):
|
||||
raise Exception( "Could not find a default controller "
|
||||
"for switch %s" %
|
||||
self.options.switch )
|
||||
opts.switch )
|
||||
|
||||
topo = buildTopo( TOPOS, self.options.topo )
|
||||
switch = customConstructor( SWITCHES, self.options.switch )
|
||||
host = customConstructor( HOSTS, self.options.host )
|
||||
controller = customConstructor( CONTROLLERS, self.options.controller )
|
||||
link = customConstructor( LINKS, self.options.link )
|
||||
topo = buildTopo( TOPOS, opts.topo )
|
||||
switch = customClass( SWITCHES, opts.switch )
|
||||
host = customClass( HOSTS, opts.host )
|
||||
controller = [ customClass( CONTROLLERS, c )
|
||||
for c in opts.controller ]
|
||||
|
||||
if opts.switch == 'user' and opts.link == 'default':
|
||||
debug( '*** Using TCULink with UserSwitch\n' )
|
||||
# Use link configured correctly for UserSwitch
|
||||
opts.link = 'tcu'
|
||||
|
||||
link = customClass( LINKS, opts.link )
|
||||
|
||||
if self.validate:
|
||||
self.validate( self.options )
|
||||
self.validate( opts )
|
||||
|
||||
ipBase = self.options.ipbase
|
||||
xterms = self.options.xterms
|
||||
mac = self.options.mac
|
||||
arp = self.options.arp
|
||||
pin = self.options.pin
|
||||
listenPort = None
|
||||
if not self.options.nolistenport:
|
||||
listenPort = self.options.listenport
|
||||
if opts.nolistenport:
|
||||
opts.listenport = None
|
||||
|
||||
# Handle inNamespace, cluster options
|
||||
inNamespace = self.options.innamespace
|
||||
cluster = self.options.cluster
|
||||
if inNamespace and cluster:
|
||||
print "Please specify --innamespace OR --cluster"
|
||||
# Handle innamespace, cluster options
|
||||
if opts.innamespace and opts.cluster:
|
||||
error( "Please specify --innamespace OR --cluster\n" )
|
||||
exit()
|
||||
Net = MininetWithControlNet if inNamespace else Mininet
|
||||
cli = ClusterCLI if cluster else CLI
|
||||
if cluster:
|
||||
Net = MininetWithControlNet if opts.innamespace else Mininet
|
||||
if opts.cluster:
|
||||
warn( '*** WARNING: Experimental cluster mode!\n'
|
||||
'*** Using RemoteHost, RemoteOVSSwitch, RemoteLink\n' )
|
||||
host, switch, link = RemoteHost, RemoteOVSSwitch, RemoteLink
|
||||
Net = partial( MininetCluster, servers=servers,
|
||||
placement=PLACEMENT[ self.options.placement ] )
|
||||
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=ipBase,
|
||||
inNamespace=inNamespace,
|
||||
xterms=xterms, autoSetMacs=mac,
|
||||
autoStaticArp=arp, autoPinCpus=pin,
|
||||
listenPort=listenPort )
|
||||
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 self.options.ensure_value( 'nat', False ):
|
||||
nat = mn.addNAT( *self.options.nat_args,
|
||||
**self.options.nat_kwargs )
|
||||
nat.configDefault()
|
||||
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()
|
||||
|
||||
if self.options.pre:
|
||||
cli( mn, script=self.options.pre )
|
||||
# --custom files can set CLI or change mininet.cli.CLI
|
||||
CLI = mininet.cli.CLI if CLI is None else CLI
|
||||
|
||||
test = self.options.test
|
||||
test = ALTSPELLING.get( test, test )
|
||||
if opts.pre:
|
||||
CLI( mn, script=opts.pre )
|
||||
|
||||
mn.start()
|
||||
|
||||
if test == 'none':
|
||||
pass
|
||||
elif test == 'all':
|
||||
mn.waitConnected()
|
||||
mn.start()
|
||||
mn.ping()
|
||||
mn.iperf()
|
||||
elif test == 'cli':
|
||||
cli( mn )
|
||||
elif test != 'build':
|
||||
mn.waitConnected()
|
||||
getattr( mn, test )()
|
||||
if opts.test:
|
||||
runTests( mn, opts.test )
|
||||
else:
|
||||
CLI( mn )
|
||||
|
||||
if self.options.post:
|
||||
cli( mn, script=self.options.post )
|
||||
if opts.post:
|
||||
CLI( mn, script=opts.post )
|
||||
|
||||
mn.stop()
|
||||
|
||||
@@ -393,7 +436,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" +
|
||||
|
||||
@@ -13,12 +13,9 @@ from mininet.topo import Topo
|
||||
class MyTopo( Topo ):
|
||||
"Simple topology example."
|
||||
|
||||
def __init__( self ):
|
||||
def build( self ):
|
||||
"Create custom topo."
|
||||
|
||||
# Initialize topology
|
||||
Topo.__init__( self )
|
||||
|
||||
# Add hosts and switches
|
||||
leftHost = self.addHost( 'h1' )
|
||||
rightHost = self.addHost( 'h2' )
|
||||
|
||||
+1927
-821
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -158,7 +158,7 @@ A simple example of configuring network and CPU bandwidth limits.
|
||||
|
||||
This example shows how to run an `sshd` process in each host, allowing
|
||||
you to log in via `ssh`. This requires connecting the Mininet data network
|
||||
to an interface in the root namespace (generaly the control network
|
||||
to an interface in the root namespace (generally the control network
|
||||
already lives in the root namespace, so it does not need to be explicitly
|
||||
connected.)
|
||||
|
||||
|
||||
+15
-13
@@ -1,34 +1,36 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"This example doesn't use OpenFlow, but attempts to run sshd in a namespace."
|
||||
|
||||
import sys
|
||||
|
||||
from mininet.node import Host
|
||||
from mininet.util import ensureRoot, waitListening
|
||||
from mininet.log import info, warn, output
|
||||
|
||||
|
||||
ensureRoot()
|
||||
timeout = 5
|
||||
|
||||
print "*** Creating nodes"
|
||||
info( "*** Creating nodes\n" )
|
||||
h1 = Host( 'h1' )
|
||||
|
||||
root = Host( 'root', inNamespace=False )
|
||||
|
||||
print "*** Creating links"
|
||||
info( "*** Creating link\n" )
|
||||
h1.linkTo( root )
|
||||
|
||||
print h1
|
||||
info( h1 )
|
||||
|
||||
print "*** Configuring nodes"
|
||||
info( "*** Configuring nodes\n" )
|
||||
h1.setIP( '10.0.0.1', 8 )
|
||||
root.setIP( '10.0.0.2', 8 )
|
||||
|
||||
print "*** Creating banner file"
|
||||
f = open( '/tmp/%s.banner' % h1.name, 'w' )
|
||||
f.write( 'Welcome to %s at %s\n' % ( h1.name, h1.IP() ) )
|
||||
f.close()
|
||||
info( "*** Creating banner file\n" )
|
||||
with open( '/tmp/%s.banner' % h1.name, 'w' ) as f:
|
||||
f.write( 'Welcome to %s at %s\n' % ( h1.name, h1.IP() ) )
|
||||
|
||||
print "*** Running sshd"
|
||||
info( "*** Running sshd\n" )
|
||||
cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name
|
||||
# add arguments from the command line
|
||||
if len( sys.argv ) > 1:
|
||||
@@ -37,7 +39,7 @@ h1.cmd( cmd )
|
||||
listening = waitListening( server=h1, port=22, timeout=timeout )
|
||||
|
||||
if listening:
|
||||
print "*** You may now ssh into", h1.name, "at", h1.IP()
|
||||
output( "*** You may now ssh into", h1.name, "at", h1.IP(), '\n' )
|
||||
else:
|
||||
print ( "*** Warning: after %s seconds, %s is not listening on port 22"
|
||||
% ( timeout, h1.name ) )
|
||||
warn( "*** Warning: after %s seconds, %s is not listening on port 22"
|
||||
% ( timeout, h1.name ), '\n' )
|
||||
|
||||
+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()
|
||||
|
||||
+234
-93
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
cluster.py: prototyping/experimentation for distributed Mininet,
|
||||
@@ -74,16 +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
|
||||
@@ -92,7 +82,18 @@ import sys
|
||||
import re
|
||||
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, StrictVersion
|
||||
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():
|
||||
@@ -103,7 +104,7 @@ def findUser():
|
||||
# Logged-in user (if we have a tty)
|
||||
( quietRun( 'who am i' ).split() or [ False ] )[ 0 ] or
|
||||
# Give up and return effective user
|
||||
quietRun( 'whoami' ) )
|
||||
quietRun( 'whoami' ).strip() )
|
||||
|
||||
|
||||
class ClusterCleanup( object ):
|
||||
@@ -125,7 +126,7 @@ class ClusterCleanup( object ):
|
||||
def cleanup( cls ):
|
||||
"Clean up"
|
||||
info( '*** Cleaning up cluster\n' )
|
||||
for server, user in cls.serveruser.iteritems():
|
||||
for server, user in cls.serveruser.items():
|
||||
if server == 'localhost':
|
||||
# Handled by mininet.clean.cleanup()
|
||||
continue
|
||||
@@ -238,14 +239,14 @@ class RemoteMixin( object ):
|
||||
args: string or list of strings
|
||||
returns: stdout and stderr"""
|
||||
popen = self.rpopen( *cmd, **opts )
|
||||
# print 'RCMD: POPEN:', popen
|
||||
# info( 'RCMD: POPEN:', popen, '\n' )
|
||||
# These loops are tricky to get right.
|
||||
# Once the process exits, we can read
|
||||
# EOF twice if necessary.
|
||||
result = ''
|
||||
while True:
|
||||
poll = popen.poll()
|
||||
result += popen.stdout.read()
|
||||
result += decode( popen.stdout.read() )
|
||||
if poll is not None:
|
||||
break
|
||||
return result
|
||||
@@ -260,7 +261,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:
|
||||
@@ -287,7 +288,8 @@ class RemoteMixin( object ):
|
||||
|
||||
def addIntf( self, *args, **kwargs ):
|
||||
"Override: use RemoteLink.moveIntf"
|
||||
kwargs.update( moveIntfFn=RemoteLink.moveIntf )
|
||||
# kwargs.update( moveIntfFn=RemoteLink.moveIntf )
|
||||
# pylint: disable=useless-super-delegation
|
||||
return super( RemoteMixin, self).addIntf( *args, **kwargs )
|
||||
|
||||
|
||||
@@ -311,7 +313,7 @@ class RemoteOVSSwitch( RemoteMixin, OVSSwitch ):
|
||||
kwargs.update( batch=True )
|
||||
super( RemoteOVSSwitch, self ).__init__( *args, **kwargs )
|
||||
|
||||
def isOldOVS( self ):
|
||||
def isOldOVS( self ): # pylint: disable=arguments-differ
|
||||
"Is remote switch using an old OVS version?"
|
||||
cls = type( self )
|
||||
if self.server not in cls.OVSVersions:
|
||||
@@ -324,6 +326,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' )
|
||||
@@ -335,6 +338,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' )
|
||||
@@ -371,8 +375,9 @@ class RemoteLink( Link ):
|
||||
Link.stop( self )
|
||||
self.tunnel = None
|
||||
|
||||
def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
|
||||
node1=None, node2=None, deleteIntfs=True ):
|
||||
def makeIntfPair( self, # pylint: disable=arguments-renamed
|
||||
intfname1, intfname2, addr1=None, addr2=None,
|
||||
node1=None, node2=None, deleteIntfs=True ):
|
||||
"""Create pair of interfaces
|
||||
intfname1: name of interface 1
|
||||
intfname2: name of interface 2
|
||||
@@ -392,33 +397,31 @@ class RemoteLink( Link ):
|
||||
return self.tunnel
|
||||
|
||||
@staticmethod
|
||||
def moveIntf( intf, node, printError=True ):
|
||||
def moveIntf( intf, node ):
|
||||
"""Move remote interface from root ns to node
|
||||
intf: string, interface
|
||||
dstNode: destination Node
|
||||
srcNode: source Node or None (default) for root ns
|
||||
printError: if true, print error"""
|
||||
srcNode: source Node or None (default) for root ns"""
|
||||
intf = str( intf )
|
||||
cmd = 'ip link set %s netns %s' % ( intf, node.pid )
|
||||
node.rcmd( cmd )
|
||||
links = node.cmd( 'ip link show' )
|
||||
if not ' %s:' % intf in links:
|
||||
if printError:
|
||||
error( '*** Error: RemoteLink.moveIntf: ' + intf +
|
||||
' not successfully moved to ' + node.name + '\n' )
|
||||
return False
|
||||
result = node.rcmd( cmd )
|
||||
if result:
|
||||
raise Exception('error executing command %s' % cmd)
|
||||
return True
|
||||
|
||||
def makeTunnel( self, node1, node2, intfname1, intfname2,
|
||||
addr1=None, addr2=None ):
|
||||
"Make a tunnel across switches on different servers"
|
||||
# We should never try to create a tunnel to ourselves!
|
||||
assert node1.server != 'localhost' or node2.server != 'localhost'
|
||||
assert node1.server != node2.server
|
||||
# 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
|
||||
for node in node1, node2:
|
||||
# For now we are hard-wiring tap9, which we will rename
|
||||
@@ -437,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 ):
|
||||
@@ -474,6 +480,93 @@ class RemoteLink( Link ):
|
||||
return result
|
||||
|
||||
|
||||
class RemoteSSHLink( RemoteLink ):
|
||||
"Remote link using SSH tunnels"
|
||||
def __init__(self, node1, node2, **kwargs):
|
||||
RemoteLink.__init__( self, node1, node2, **kwargs )
|
||||
|
||||
|
||||
class RemoteGRELink( RemoteLink ):
|
||||
"Remote link using GRE tunnels"
|
||||
|
||||
GRE_KEY = 0
|
||||
|
||||
def __init__(self, node1, node2, **kwargs):
|
||||
RemoteLink.__init__( self, node1, node2, **kwargs )
|
||||
|
||||
def stop( self ):
|
||||
"Stop this link"
|
||||
if self.tunnel:
|
||||
self.intf1.delete()
|
||||
self.intf2.delete()
|
||||
else:
|
||||
Link.stop( self )
|
||||
self.tunnel = None
|
||||
|
||||
def makeIntfPair( self, intfname1, intfname2, addr1=None, addr2=None,
|
||||
node1=None, node2=None, deleteIntfs=True ):
|
||||
"""Create pair of interfaces
|
||||
intfname1: name of interface 1
|
||||
intfname2: name of interface 2
|
||||
(override this method [and possibly delete()]
|
||||
to change link type)"""
|
||||
node1 = self.node1 if node1 is None else node1
|
||||
node2 = self.node2 if node2 is None else node2
|
||||
server1 = getattr( node1, 'server', 'localhost' )
|
||||
server2 = getattr( node2, 'server', 'localhost' )
|
||||
if server1 == server2:
|
||||
# Link within same server
|
||||
Link.makeIntfPair( intfname1, intfname2, addr1, addr2,
|
||||
node1, node2, deleteIntfs=deleteIntfs )
|
||||
# Need to reduce the MTU of all emulated hosts to 1450 for GRE
|
||||
# tunneling, otherwise packets larger than 1400 bytes cannot be
|
||||
# successfully transmitted through the tunnel.
|
||||
node1.cmd('ip link set dev %s mtu 1450' % intfname1)
|
||||
node2.cmd('ip link set dev %s mtu 1450' % intfname2)
|
||||
else:
|
||||
# Otherwise, make a tunnel
|
||||
self.makeTunnel( node1, node2, intfname1, intfname2, addr1, addr2 )
|
||||
self.tunnel = 1
|
||||
|
||||
def makeTunnel(self, node1, node2, intfname1, intfname2,
|
||||
addr1=None, addr2=None):
|
||||
"Make a tunnel across switches on different servers"
|
||||
# We should never try to create a tunnel to ourselves!
|
||||
assert node1.server != node2.server
|
||||
if node2.server == 'localhost':
|
||||
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
|
||||
if node1.server == 'localhost':
|
||||
output = quietRun('ip route get %s' % node2.serverIP)
|
||||
IP1 = output.split(' src ')[1].split()[0]
|
||||
debug( '\n*** Make GRE tunnel ' + node1.server + ':' + intfname1 +
|
||||
' == ' + node2.server + ':' + intfname2 )
|
||||
tun1 = 'local ' + IP1 + ' remote ' + IP2
|
||||
tun2 = 'local ' + IP2 + ' remote ' + IP1
|
||||
self.__class__.GRE_KEY += 1
|
||||
for (node, intfname, addr, tun) in [(node1, intfname1, addr1, tun1),
|
||||
(node2, intfname2, addr2, tun2)]:
|
||||
node.rcmd('ip link delete ' + intfname)
|
||||
result = node.rcmd('ip link add name ' + intfname + ' type gretap '
|
||||
+ tun + ' ttl 64 key '
|
||||
+ str( self.__class__.GRE_KEY) )
|
||||
if result:
|
||||
raise Exception('error creating gretap on %s: %s'
|
||||
% (node, result))
|
||||
if addr:
|
||||
node.rcmd('ip link set %s address %s' % (intfname, addr))
|
||||
|
||||
node.rcmd('ip link set dev %s up' % intfname)
|
||||
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
|
||||
|
||||
class Placer( object ):
|
||||
@@ -506,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 ) ) ]
|
||||
|
||||
@@ -523,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 )
|
||||
@@ -564,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"
|
||||
@@ -621,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
|
||||
|
||||
@@ -681,13 +774,16 @@ 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 ):
|
||||
"Popen() for server connections"
|
||||
assert self # please pylint
|
||||
old = signal( SIGINT, SIG_IGN )
|
||||
# pylint: disable=consider-using-with
|
||||
conn = Popen( cmd, stdin=PIPE, stdout=PIPE, close_fds=True )
|
||||
# pylint: enable=consider-using-with
|
||||
signal( SIGINT, old )
|
||||
return conn
|
||||
|
||||
@@ -757,16 +853,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 )
|
||||
# Update IP address for controller that may not be local
|
||||
if ( isinstance( controller, Controller)
|
||||
and controller.IP() == '127.0.0.1'
|
||||
and ' eth0:' in controller.cmd( 'ip link show' ) ):
|
||||
Intf( 'eth0', node=controller ).updateIP()
|
||||
controllerIP = controller.IP()
|
||||
if ( not isinstance( controller, Controller ) or
|
||||
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 != controllerIP ]
|
||||
if not serverIPs:
|
||||
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' )
|
||||
@@ -775,11 +898,14 @@ class MininetCluster( Mininet ):
|
||||
Mininet.buildFromTopo( self, *args, **kwargs )
|
||||
|
||||
|
||||
def testNsTunnels():
|
||||
# Default remote server for tests
|
||||
remoteServer = 'ubuntu2'
|
||||
|
||||
def testNsTunnels( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test tunnels between nodes in namespaces"
|
||||
net = Mininet( host=RemoteHost, link=RemoteLink )
|
||||
h1 = net.addHost( 'h1' )
|
||||
h2 = net.addHost( 'h2', server='ubuntu2' )
|
||||
net = Mininet( host=RemoteHost, link=link, waitConnected=True )
|
||||
h1 = net.addHost( 'h1')
|
||||
h2 = net.addHost( 'h2', server=remote )
|
||||
net.addLink( h1, h2 )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
@@ -790,30 +916,31 @@ def testNsTunnels():
|
||||
# This shows how node options may be used to manage
|
||||
# cluster placement using the net.add*() API
|
||||
|
||||
def testRemoteNet( remote='ubuntu2' ):
|
||||
def testRemoteNet( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test remote Node classes"
|
||||
print '*** Remote Node Test'
|
||||
info( '*** Remote Node Test\n' )
|
||||
net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch,
|
||||
link=RemoteLink )
|
||||
link=link, controller=ClusterController,
|
||||
waitConnected=True )
|
||||
c0 = net.addController( 'c0' )
|
||||
# Make sure controller knows its non-loopback address
|
||||
Intf( 'eth0', node=c0 ).updateIP()
|
||||
print "*** Creating local h1"
|
||||
info( "*** Creating local h1\n" )
|
||||
h1 = net.addHost( 'h1' )
|
||||
print "*** Creating remote h2"
|
||||
info( "*** Creating remote h2\n" )
|
||||
h2 = net.addHost( 'h2', server=remote )
|
||||
print "*** Creating local s1"
|
||||
info( "*** Creating local s1\n" )
|
||||
s1 = net.addSwitch( 's1' )
|
||||
print "*** Creating remote s2"
|
||||
info( "*** Creating remote s2\n" )
|
||||
s2 = net.addSwitch( 's2', server=remote )
|
||||
print "*** Adding links"
|
||||
info( "*** Adding links\n" )
|
||||
net.addLink( h1, s1 )
|
||||
net.addLink( s1, s2 )
|
||||
net.addLink( h2, s2 )
|
||||
net.start()
|
||||
print 'Mininet is running on', quietRun( 'hostname' ).strip()
|
||||
info( 'Mininet is running on', quietRun( 'hostname' ).strip(), '\n' )
|
||||
for node in c0, h1, h2, s1, s2:
|
||||
print 'Node', node, 'is running on', node.cmd( 'hostname' ).strip()
|
||||
info( 'Node', node, 'is running on',
|
||||
node.cmd( 'hostname' ).strip(), '\n' )
|
||||
net.pingAll()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
@@ -828,7 +955,7 @@ def testRemoteNet( remote='ubuntu2' ):
|
||||
|
||||
remoteHosts = [ 'h2' ]
|
||||
remoteSwitches = [ 's2' ]
|
||||
remoteServer = 'ubuntu2'
|
||||
|
||||
|
||||
def HostPlacer( name, *args, **params ):
|
||||
"Custom Host() constructor which places hosts on servers"
|
||||
@@ -845,17 +972,28 @@ 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():
|
||||
def testRemoteTopo( link=RemoteGRELink ):
|
||||
"Test remote Node classes using Mininet()/Topo() API"
|
||||
topo = LinearTopo( 2 )
|
||||
net = Mininet( topo=topo, host=HostPlacer, switch=SwitchPlacer,
|
||||
link=RemoteLink, controller=ClusterController )
|
||||
link=link, controller=ClusterController )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
@@ -865,18 +1003,17 @@ def testRemoteTopo():
|
||||
# do random switch placement rather than completely random
|
||||
# host placement.
|
||||
|
||||
def testRemoteSwitches():
|
||||
def testRemoteSwitches( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test with local hosts and remote switches"
|
||||
servers = [ 'localhost', 'ubuntu2']
|
||||
servers = [ 'localhost', remote]
|
||||
topo = TreeTopo( depth=4, fanout=2 )
|
||||
net = MininetCluster( topo=topo, servers=servers,
|
||||
net = MininetCluster( topo=topo, servers=servers, link=link,
|
||||
placement=RoundRobinPlacer )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
|
||||
|
||||
#
|
||||
# For testing and demo purposes it would be nice to draw the
|
||||
# network graph and color it based on server.
|
||||
|
||||
@@ -884,31 +1021,35 @@ def testRemoteSwitches():
|
||||
# functions, for maximum ease of use. MininetCluster() also
|
||||
# pre-flights and multiplexes server connections.
|
||||
|
||||
def testMininetCluster():
|
||||
def testMininetCluster( remote=remoteServer, link=RemoteGRELink ):
|
||||
"Test MininetCluster()"
|
||||
servers = [ 'localhost', 'ubuntu2' ]
|
||||
servers = [ 'localhost', remote ]
|
||||
topo = TreeTopo( depth=3, fanout=3 )
|
||||
net = MininetCluster( topo=topo, servers=servers,
|
||||
net = MininetCluster( topo=topo, servers=servers, link=link,
|
||||
placement=SwitchBinPlacer )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
|
||||
def signalTest():
|
||||
def signalTest( remote=remoteServer):
|
||||
"Make sure hosts are robust to signals"
|
||||
h = RemoteHost( 'h0', server='ubuntu1' )
|
||||
h = RemoteHost( 'h0', server=remote )
|
||||
h.shell.send_signal( SIGINT )
|
||||
h.shell.poll()
|
||||
if h.shell.returncode is None:
|
||||
print 'OK: ', h, 'has not exited'
|
||||
info( 'signalTest: SUCCESS: ', h, 'has not exited after SIGINT', '\n' )
|
||||
else:
|
||||
print 'FAILURE:', h, 'exited with code', h.shell.returncode
|
||||
info( 'signalTest: FAILURE:', h, 'exited with code',
|
||||
h.shell.returncode, '\n' )
|
||||
h.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
# testRemoteTopo()
|
||||
# testRemoteNet()
|
||||
# testMininetCluster()
|
||||
# testRemoteSwitches()
|
||||
signalTest()
|
||||
remoteLink = RemoteSSHLink
|
||||
testRemoteTopo(link=remoteLink)
|
||||
testNsTunnels( remote=remoteServer, link=remoteLink )
|
||||
testRemoteNet( remote=remoteServer, link=remoteLink)
|
||||
testMininetCluster( remote=remoteServer, link=remoteLink)
|
||||
testRemoteSwitches( remote=remoteServer, link=remoteLink)
|
||||
signalTest( remote=remoteServer )
|
||||
|
||||
@@ -17,6 +17,7 @@ def clusterSanity():
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
clusterSanity()
|
||||
|
||||
+14
-7
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"CLI for Mininet Cluster Edition prototype demo"
|
||||
|
||||
@@ -27,17 +27,23 @@ class ClusterCLI( CLI ):
|
||||
def do_plot( self, _line ):
|
||||
"Plot topology colored by node placement"
|
||||
# Import networkx if needed
|
||||
global nx, plt
|
||||
global nx, plt, graphviz_layout
|
||||
if not nx:
|
||||
try:
|
||||
# pylint: disable=import-error
|
||||
# pylint: disable=import-error,no-member
|
||||
# pylint: disable=import-outside-toplevel
|
||||
import networkx
|
||||
nx = networkx # satisfy pylint
|
||||
from matplotlib import pyplot
|
||||
plt = pyplot # satisfiy pylint
|
||||
plt = pyplot # satisfy pylint
|
||||
import pygraphviz
|
||||
assert pygraphviz # silence pyflakes
|
||||
# pylint: enable=import-error
|
||||
# Networkx moved this around
|
||||
if hasattr( nx, 'graphviz_layout' ):
|
||||
graphviz_layout = nx.graphviz_layout
|
||||
else:
|
||||
graphviz_layout = nx.drawing.nx_agraph.graphviz_layout
|
||||
# pylint: enable=import-error,no-member
|
||||
except ImportError:
|
||||
error( 'plot requires networkx, matplotlib and pygraphviz - '
|
||||
'please install them and try again\n' )
|
||||
@@ -45,7 +51,8 @@ class ClusterCLI( CLI ):
|
||||
# Make a networkx Graph
|
||||
g = nx.Graph()
|
||||
mn = self.mn
|
||||
servers, hosts, switches = mn.servers, mn.hosts, mn.switches
|
||||
servers = getattr( mn, 'servers', [ 'localhost' ] )
|
||||
hosts, switches = mn.hosts, mn.switches
|
||||
nodes = hosts + switches
|
||||
g.add_nodes_from( nodes )
|
||||
links = [ ( link.intf1.node, link.intf2.node )
|
||||
@@ -55,7 +62,7 @@ class ClusterCLI( CLI ):
|
||||
# shapes = hlen * [ 's' ] + slen * [ 'o' ]
|
||||
color = dict( zip( servers, self.colorsFor( servers ) ) )
|
||||
# Plot it!
|
||||
pos = nx.graphviz_layout( g )
|
||||
pos = graphviz_layout( g )
|
||||
opts = { 'ax': None, 'font_weight': 'bold',
|
||||
'width': 2, 'edge_color': 'darkblue' }
|
||||
hcolors = [ color[ getattr( h, 'server', 'localhost' ) ]
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"clusterdemo.py: demo of Mininet Cluster Edition prototype"
|
||||
|
||||
from mininet.examples.cluster import MininetCluster, SwitchBinPlacer
|
||||
from mininet.examples.cluster import ( MininetCluster, SwitchBinPlacer,
|
||||
RemoteLink )
|
||||
# ^ Could also use: RemoteSSHLink, RemoteGRELink
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.examples.clustercli import ClusterCLI as CLI
|
||||
@@ -11,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,
|
||||
net = MininetCluster( topo=topo, servers=servers, link=RemoteLink,
|
||||
placement=SwitchBinPlacer )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
demo()
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"clusterperf.py compare the maximum throughput between SSH and GRE tunnels"
|
||||
|
||||
from mininet.examples.cluster import RemoteSSHLink, RemoteGRELink, RemoteHost
|
||||
from mininet.net import Mininet
|
||||
from mininet.log import setLogLevel
|
||||
|
||||
def perf(Link):
|
||||
"Test connectivity nand performance over Link"
|
||||
net = Mininet( host=RemoteHost, link=Link, waitConnected=True )
|
||||
h1 = net.addHost( 'h1')
|
||||
h2 = net.addHost( 'h2', server='ubuntu2' )
|
||||
net.addLink( h1, h2 )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.iperf()
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel('info')
|
||||
perf( RemoteSSHLink )
|
||||
perf( RemoteGRELink )
|
||||
+14
-9
@@ -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."
|
||||
|
||||
@@ -65,7 +69,10 @@ class Console( Frame ):
|
||||
self.bindEvents()
|
||||
self.sendCmd( 'export TERM=dumb' )
|
||||
|
||||
self.outputHook = None
|
||||
def outputHook( _obj, _text):
|
||||
return True
|
||||
|
||||
self.outputHook = outputHook
|
||||
|
||||
def makeWidgets( self ):
|
||||
"Make a label, a text area, and a scroll bar."
|
||||
@@ -107,10 +114,8 @@ class Console( Frame ):
|
||||
self.text.insert( 'end', text )
|
||||
self.text.mark_set( 'insert', 'end' )
|
||||
self.text.see( 'insert' )
|
||||
outputHook = lambda x, y: True # make pylint happier
|
||||
if self.outputHook:
|
||||
outputHook = self.outputHook
|
||||
outputHook( self, text )
|
||||
if callable( self.outputHook ):
|
||||
self.outputHook( self, text )
|
||||
|
||||
def handleKey( self, event ):
|
||||
"If it's an interactive command, send it to the node."
|
||||
@@ -290,10 +295,10 @@ class ConsoleApp( Frame ):
|
||||
'switches': 'Switch',
|
||||
'controllers': 'Controller'
|
||||
}
|
||||
for name in titles:
|
||||
for name, title in titles.items():
|
||||
nodes = getattr( net, name )
|
||||
frame, consoles = self.createConsoles(
|
||||
cframe, nodes, width, titles[ name ] )
|
||||
cframe, nodes, width, title )
|
||||
self.consoles[ name ] = Object( frame=frame, consoles=consoles )
|
||||
self.selected = None
|
||||
self.select( 'hosts' )
|
||||
@@ -319,7 +324,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
|
||||
@@ -17,7 +17,7 @@ setLogLevel( 'info' )
|
||||
# Ignore the warning message that the remote isn't (yet) running
|
||||
c0 = Controller( 'c0', port=6633 )
|
||||
c1 = Controller( 'c1', port=6634 )
|
||||
c2 = RemoteController( 'c2', ip='127.0.0.1' )
|
||||
c2 = RemoteController( 'c2', ip='127.0.0.1', port=6633 )
|
||||
|
||||
cmap = { 's1': c0, 's2': c1, 's3': c2 }
|
||||
|
||||
@@ -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()
|
||||
|
||||
+16
-13
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example creates a multi-controller network from semi-scratch by
|
||||
@@ -11,51 +11,54 @@ Note that one could also create a custom switch class and pass it into
|
||||
the Mininet() constructor.
|
||||
"""
|
||||
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Controller, OVSSwitch
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import setLogLevel
|
||||
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 )
|
||||
|
||||
print "*** Creating (reference) controllers"
|
||||
info( "*** Creating (reference) controllers\n" )
|
||||
c1 = net.addController( 'c1', port=6633 )
|
||||
c2 = net.addController( 'c2', port=6634 )
|
||||
|
||||
print "*** Creating switches"
|
||||
info( "*** Creating switches\n" )
|
||||
s1 = net.addSwitch( 's1' )
|
||||
s2 = net.addSwitch( 's2' )
|
||||
|
||||
print "*** Creating hosts"
|
||||
hosts1 = [ net.addHost( 'h%d' % n ) for n in 3, 4 ]
|
||||
hosts2 = [ net.addHost( 'h%d' % n ) for n in 5, 6 ]
|
||||
info( "*** Creating hosts\n" )
|
||||
hosts1 = [ net.addHost( 'h%d' % n ) for n in ( 3, 4 ) ]
|
||||
hosts2 = [ net.addHost( 'h%d' % n ) for n in ( 5, 6 ) ]
|
||||
|
||||
print "*** Creating links"
|
||||
info( "*** Creating links\n" )
|
||||
for h in hosts1:
|
||||
net.addLink( s1, h )
|
||||
for h in hosts2:
|
||||
net.addLink( s2, h )
|
||||
net.addLink( s1, s2 )
|
||||
|
||||
print "*** Starting network"
|
||||
info( "*** Starting network\n" )
|
||||
net.build()
|
||||
c1.start()
|
||||
c2.start()
|
||||
s1.start( [ c1 ] )
|
||||
s2.start( [ c2 ] )
|
||||
|
||||
print "*** Testing network"
|
||||
info( "*** Testing network\n" )
|
||||
net.pingAll()
|
||||
|
||||
print "*** Running CLI"
|
||||
info( "*** Running CLI\n" )
|
||||
CLI( net )
|
||||
|
||||
print "*** Stopping network"
|
||||
info( "*** Stopping network\n" )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' ) # for CLI output
|
||||
multiControllerNet()
|
||||
|
||||
+11
-8
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
controlnet.py: Mininet with a custom control network
|
||||
@@ -49,7 +49,7 @@ class MininetFacade( object ):
|
||||
args: unnamed networks passed as arguments
|
||||
kwargs: named networks passed as arguments"""
|
||||
self.net = net
|
||||
self.nets = [ net ] + list( args ) + kwargs.values()
|
||||
self.nets = [ net ] + list( args ) + list( kwargs.values() )
|
||||
self.nameToNet = kwargs
|
||||
self.nameToNet['net'] = net
|
||||
|
||||
@@ -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,10 +101,10 @@ class MininetFacade( object ):
|
||||
|
||||
class ControlNetwork( Topo ):
|
||||
"Control Network Topology"
|
||||
def __init__( self, n, dataController=DataController, **kwargs ):
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, n, dataController=DataController, **_kwargs ):
|
||||
"""n: number of data network controller nodes
|
||||
dataController: class for data network controllers"""
|
||||
Topo.__init__( self, **kwargs )
|
||||
# Connect everything to a single switch
|
||||
cs0 = self.addSwitch( 'cs0' )
|
||||
# Add hosts which will serve as data network controllers
|
||||
@@ -124,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')
|
||||
@@ -134,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):
|
||||
|
||||
+61
-22
@@ -1,17 +1,41 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
cpu.py: test iperf bandwidth for varying cpu limits
|
||||
|
||||
Since we are limiting the hosts (only), we should expect the iperf
|
||||
processes to be affected, as well as any system processing which is
|
||||
billed to the hosts.
|
||||
|
||||
We reserve >50% of cycles for system processing; we assume that
|
||||
this is enough for it not to affect results. Hosts are limited to
|
||||
40% of total cycles, which we assume is enough to make them CPU
|
||||
bound.
|
||||
|
||||
As CPU performance increases over time, we may have to reduce the
|
||||
overall CPU allocation so that the host processing is still CPU bound.
|
||||
This is perhaps an argument for specifying performance in a more
|
||||
system-independent manner.
|
||||
|
||||
It would also be nice to have a better handle on limiting packet
|
||||
processing cycles. It's not entirely clear to me how those are
|
||||
billed to user or system processes if we are using OVS with a kernel
|
||||
datapath. With a user datapath, they are easier to account for, but
|
||||
overall performance is usually lower.
|
||||
|
||||
Although the iperf client uses more CPU and should be CPU bound (?),
|
||||
we measure the received data at the server since the client transmit
|
||||
rate includes buffering.
|
||||
"""
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import custom, waitListening
|
||||
from mininet.util import custom, waitListening, decode
|
||||
from mininet.log import setLogLevel, info
|
||||
from mininet.clean import cleanup
|
||||
|
||||
|
||||
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
||||
def bwtest( cpuLimits, period_us=100000, seconds=10 ):
|
||||
"""Example/test of link and CPU bandwidth limits
|
||||
cpu: cpu limit as fraction of overall CPU time"""
|
||||
|
||||
@@ -20,27 +44,41 @@ def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
||||
results = {}
|
||||
|
||||
for sched in 'rt', 'cfs':
|
||||
print '*** Testing with', sched, 'bandwidth limiting'
|
||||
info( '*** Testing with', sched, 'bandwidth limiting\n' )
|
||||
for cpu in cpuLimits:
|
||||
# cpu is the cpu fraction for all hosts, so we divide
|
||||
# it across two hosts
|
||||
host = custom( CPULimitedHost, sched=sched,
|
||||
period_us=period_us,
|
||||
cpu=cpu )
|
||||
cpu=.5*cpu )
|
||||
try:
|
||||
net = Mininet( topo=topo, host=host )
|
||||
net = Mininet( topo=topo, host=host, waitConnected=True )
|
||||
# pylint: disable=bare-except
|
||||
except:
|
||||
info( '*** Skipping host %s\n' % sched )
|
||||
except: # noqa
|
||||
info( '*** Skipping scheduler %s and cleaning up\n' % sched )
|
||||
cleanup()
|
||||
break
|
||||
net.start()
|
||||
net.pingAll()
|
||||
hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
|
||||
client, server = hosts[ 0 ], hosts[ -1 ]
|
||||
server.cmd( 'iperf -s -p 5001 &' )
|
||||
info( '*** Starting iperf with %d%% of CPU allocated to hosts\n' %
|
||||
( 100.0 * cpu ) )
|
||||
# We measure at the server because it doesn't include
|
||||
# the client's buffer fill rate
|
||||
popen = server.popen( 'iperf -yc -s -p 5001' )
|
||||
waitListening( client, server, 5001 )
|
||||
result = client.cmd( 'iperf -yc -t %s -c %s' % (
|
||||
seconds, server.IP() ) ).split( ',' )
|
||||
bps = float( result[ -1 ] )
|
||||
server.cmdPrint( 'kill %iperf' )
|
||||
client.cmd( 'iperf -yc -t %s -c %s' % ( seconds, server.IP() ) )
|
||||
# ignore empty result from waitListening/telnet for old iperf
|
||||
svals = {}
|
||||
while not svals or int( svals[ 'rate' ] ) == 0:
|
||||
line = decode( popen.stdout.readline() )
|
||||
# Probably shouldn't depend on an internal method, but
|
||||
# this is the easiest way
|
||||
svals = Mininet._iperfVals( # pylint: disable=protected-access
|
||||
line, server.IP() )
|
||||
bps = float( svals[ 'rate' ] )
|
||||
popen.terminate()
|
||||
net.stop()
|
||||
updated = results.get( sched, [] )
|
||||
updated += [ ( cpu, bps ) ]
|
||||
@@ -52,22 +90,23 @@ def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
||||
def dump( results ):
|
||||
"Dump results"
|
||||
|
||||
fmt = '%s\t%s\t%s'
|
||||
fmt = '%s\t%s\t%s\n'
|
||||
|
||||
print
|
||||
print fmt % ( 'sched', 'cpu', 'client MB/s' )
|
||||
print
|
||||
info( '\n' )
|
||||
info( fmt % ( 'sched', 'cpu', 'received bits/sec' ) )
|
||||
|
||||
for sched in sorted( results.keys() ):
|
||||
entries = results[ sched ]
|
||||
for cpu, bps in entries:
|
||||
pct = '%.2f%%' % ( cpu * 100 )
|
||||
mbps = bps / 1e6
|
||||
print fmt % ( sched, pct, mbps )
|
||||
pct = '%d%%' % ( cpu * 100 )
|
||||
mbps = '%.2e' % bps
|
||||
info( fmt % ( sched, pct, mbps ) )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
limits = [ .45, .4, .3, .2, .1 ]
|
||||
# These are the limits for the hosts/iperfs - the
|
||||
# rest is for system processes
|
||||
limits = [ .5, .4, .3, .2, .1 ]
|
||||
out = bwtest( limits )
|
||||
dump( out )
|
||||
|
||||
@@ -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()
|
||||
|
||||
+9
-4
@@ -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,17 +17,20 @@ 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."
|
||||
if ( ' %s:' % intf ) not in quietRun( 'ip link show' ):
|
||||
config = quietRun( 'ifconfig %s 2>/dev/null' % intf, shell=True )
|
||||
if not config:
|
||||
error( 'Error:', intf, 'does not exist!\n' )
|
||||
exit( 1 )
|
||||
ips = re.findall( r'\d+\.\d+\.\d+\.\d+', quietRun( 'ifconfig ' + intf ) )
|
||||
ips = re.findall( r'\d+\.\d+\.\d+\.\d+', config )
|
||||
if ips:
|
||||
error( 'Error:', intf, 'has an IP address,'
|
||||
'and is probably in use!\n' )
|
||||
exit( 1 )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
|
||||
@@ -37,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()
|
||||
|
||||
+33
-33
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test bandwidth (using iperf) on linear networks of varying size,
|
||||
@@ -23,25 +23,26 @@ 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
|
||||
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."
|
||||
|
||||
def __init__( self, N, **params ):
|
||||
|
||||
# Initialize topology
|
||||
Topo.__init__( self, **params )
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, N, **params ):
|
||||
# Create switches and hosts
|
||||
hosts = [ self.addHost( 'h%s' % h )
|
||||
for h in irange( 1, N ) ]
|
||||
@@ -82,45 +83,44 @@ def linearBandwidthTest( lengths ):
|
||||
output = quietRun( 'sysctl -w net.ipv4.tcp_congestion_control=reno' )
|
||||
assert 'reno' in output
|
||||
|
||||
for datapath in switches.keys():
|
||||
print "*** testing", datapath, "datapath"
|
||||
Switch = switches[ datapath ]
|
||||
for datapath, Switch in switches.items():
|
||||
info( "*** testing", datapath, "datapath\n" )
|
||||
results[ datapath ] = []
|
||||
link = partial( TCLink, delay='1ms' )
|
||||
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()
|
||||
print "*** testing basic connectivity"
|
||||
info( "*** testing basic connectivity\n" )
|
||||
for n in lengths:
|
||||
net.ping( [ net.hosts[ 0 ], net.hosts[ n ] ] )
|
||||
print "*** testing bandwidth"
|
||||
info( "*** testing bandwidth\n" )
|
||||
for n in lengths:
|
||||
src, dst = net.hosts[ 0 ], net.hosts[ n ]
|
||||
# Try to prime the pump to reduce PACKET_INs during test
|
||||
# since the reference controller is reactive
|
||||
src.cmd( 'telnet', dst.IP(), '5001' )
|
||||
print "testing", src.name, "<->", dst.name,
|
||||
bandwidth = net.iperf( [ src, dst ], seconds=10 )
|
||||
print bandwidth
|
||||
info( "testing", src.name, "<->", dst.name, '\n' )
|
||||
# serverbw = received; _clientbw = buffered
|
||||
serverbw, _clientbw = net.iperf( [ src, dst ], seconds=5 )
|
||||
info( serverbw, '\n' )
|
||||
flush()
|
||||
results[ datapath ] += [ ( n, bandwidth ) ]
|
||||
results[ datapath ] += [ ( n, serverbw ) ]
|
||||
net.stop()
|
||||
|
||||
for datapath in switches.keys():
|
||||
print
|
||||
print "*** Linear network results for", datapath, "datapath:"
|
||||
print
|
||||
for datapath in switches:
|
||||
info( "\n*** Linear network results for", datapath, "datapath:\n" )
|
||||
result = results[ datapath ]
|
||||
print "SwitchCount\tiperf Results"
|
||||
for switchCount, bandwidth in result:
|
||||
print switchCount, '\t\t',
|
||||
print bandwidth[ 0 ], 'server, ', bandwidth[ 1 ], 'client'
|
||||
print
|
||||
print
|
||||
info( "SwitchCount\tiperf Results\n" )
|
||||
for switchCount, serverbw in result:
|
||||
info( switchCount, '\t\t' )
|
||||
info( serverbw, '\n' )
|
||||
info( '\n')
|
||||
info( '\n' )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info' )
|
||||
sizes = [ 1, 10, 20, 40, 60, 80, 100 ]
|
||||
print "*** Running linearBandwidthTest", sizes
|
||||
sizes = [ 1, 2, 3, 4 ]
|
||||
info( "*** Running linearBandwidthTest", sizes, '\n' )
|
||||
linearBandwidthTest( sizes )
|
||||
|
||||
+10
-4
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
linuxrouter.py: Example network with Linux IP router
|
||||
@@ -27,15 +27,18 @@ Additional routes may be added to the router or hosts by
|
||||
executing 'ip route' or 'route' commands on the router or hosts.
|
||||
"""
|
||||
|
||||
|
||||
from mininet.topo import Topo
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Node
|
||||
from mininet.log import setLogLevel, info
|
||||
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
|
||||
@@ -49,12 +52,13 @@ 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
|
||||
router = self.addNode( 'r0', cls=LinuxRouter, ip=defaultIP )
|
||||
|
||||
s1, s2, s3 = [ self.addSwitch( s ) for s in 's1', 's2', 's3' ]
|
||||
s1, s2, s3 = [ self.addSwitch( s ) for s in ( 's1', 's2', 's3' ) ]
|
||||
|
||||
self.addLink( s1, router, intfName2='r0-eth1',
|
||||
params2={ 'ip' : defaultIP } ) # for clarity
|
||||
@@ -77,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' )
|
||||
print net[ 'r0' ].cmd( 'route' )
|
||||
info( net[ 'r0' ].cmd( 'route' ) )
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
run()
|
||||
|
||||
+187
-172
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
MiniEdit: a simple network editor for Mininet
|
||||
@@ -13,57 +13,71 @@ 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'
|
||||
|
||||
from optparse import OptionParser
|
||||
# from Tkinter import *
|
||||
from Tkinter import ( Frame, Label, LabelFrame, Entry, OptionMenu, Checkbutton,
|
||||
Menu, Toplevel, Button, BitmapImage, PhotoImage, Canvas,
|
||||
Scrollbar, Wm, TclError, StringVar, IntVar,
|
||||
E, W, EW, NW, Y, VERTICAL, SOLID, CENTER,
|
||||
RIGHT, LEFT, BOTH, TRUE, FALSE )
|
||||
from ttk import Notebook
|
||||
from tkMessageBox import showerror
|
||||
from subprocess import call
|
||||
import tkFont
|
||||
import tkFileDialog
|
||||
import tkSimpleDialog
|
||||
import re
|
||||
import json
|
||||
from distutils.version import StrictVersion
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from functools import partial
|
||||
from optparse import OptionParser # pylint: disable=deprecated-module
|
||||
from subprocess import call
|
||||
from sys import exit # pylint: disable=redefined-builtin
|
||||
|
||||
if 'PYTHONPATH' in os.environ:
|
||||
sys.path = os.environ[ 'PYTHONPATH' ].split( ':' ) + sys.path
|
||||
|
||||
# someday: from ttk import *
|
||||
|
||||
from mininet.log import info, setLogLevel
|
||||
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, customConstructor
|
||||
from mininet.util import (netParse, ipAdd, quietRun,
|
||||
buildTopo, custom, customClass, StrictVersion )
|
||||
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.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
|
||||
|
||||
print 'MiniEdit running against Mininet '+VERSION
|
||||
# pylint: disable=import-error
|
||||
if sys.version_info[0] == 2:
|
||||
from Tkinter import ( Frame, Label, LabelFrame, Entry, OptionMenu,
|
||||
Checkbutton, Menu, Toplevel, Button, BitmapImage,
|
||||
PhotoImage, Canvas, Scrollbar, Wm, TclError,
|
||||
StringVar, IntVar, E, W, EW, NW, Y, VERTICAL, SOLID,
|
||||
CENTER, RIGHT, LEFT, BOTH, TRUE, FALSE )
|
||||
from ttk import Notebook
|
||||
from tkMessageBox import showerror
|
||||
import tkFont
|
||||
import tkFileDialog
|
||||
import tkSimpleDialog
|
||||
else:
|
||||
from tkinter import ( Frame, Label, LabelFrame, Entry, OptionMenu,
|
||||
Checkbutton, Menu, Toplevel, Button, BitmapImage,
|
||||
PhotoImage, Canvas, Scrollbar, Wm, TclError,
|
||||
StringVar, IntVar, E, W, EW, NW, Y, VERTICAL, SOLID,
|
||||
CENTER, RIGHT, LEFT, BOTH, TRUE, FALSE )
|
||||
from tkinter.ttk import Notebook
|
||||
from tkinter.messagebox import showerror
|
||||
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
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
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 ),
|
||||
@@ -123,6 +137,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' )
|
||||
@@ -379,14 +394,14 @@ class PrefsDialog(tkSimpleDialog.Dialog):
|
||||
@staticmethod
|
||||
def getOvsVersion():
|
||||
"Return OVS version"
|
||||
outp = quietRun("ovs-vsctl show")
|
||||
r = r'ovs_version: "(.*)"'
|
||||
outp = quietRun("ovs-vsctl --version")
|
||||
r = r'ovs-vsctl \(Open vSwitch\) (.*)'
|
||||
m = re.search(r, outp)
|
||||
if m is None:
|
||||
print 'Version check failed'
|
||||
warn( 'Version check failed' )
|
||||
return None
|
||||
else:
|
||||
print 'Open vSwitch version is '+m.group(1)
|
||||
info( 'Open vSwitch version is '+m.group(1), '\n' )
|
||||
return m.group(1)
|
||||
|
||||
|
||||
@@ -755,7 +770,7 @@ class SwitchDialog(CustomDialog):
|
||||
def apply(self):
|
||||
externalInterfaces = []
|
||||
for row in range(self.tableFrame.rows):
|
||||
#print 'Interface is ' + self.tableFrame.get(row, 0)
|
||||
# debug( 'Interface is ' + self.tableFrame.get(row, 0), '\n' )
|
||||
if len(self.tableFrame.get(row, 0)) > 0:
|
||||
externalInterfaces.append(self.tableFrame.get(row, 0))
|
||||
|
||||
@@ -803,8 +818,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)
|
||||
@@ -840,8 +855,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):
|
||||
|
||||
@@ -866,14 +879,14 @@ class TableFrame(Frame):
|
||||
return widget.get()
|
||||
|
||||
def addRow( self, value=None, readonly=False ):
|
||||
#print "Adding row " + str(self.rows +1)
|
||||
# debug( "Adding row " + str(self.rows +1), '\n' )
|
||||
current_row = []
|
||||
for column in range(self.columns):
|
||||
label = Entry(self, borderwidth=0)
|
||||
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)
|
||||
@@ -1349,7 +1362,7 @@ class MiniEdit( Frame ):
|
||||
|
||||
# Tools
|
||||
for tool in self.tools:
|
||||
cmd = ( lambda t=tool: self.activate( t ) )
|
||||
cmd = partial( self.activate, tool )
|
||||
b = Button( toolbar, text=tool, font=self.smallFont, command=cmd)
|
||||
if tool in self.images:
|
||||
b.config( height=35, image=self.images[ tool ] )
|
||||
@@ -1386,11 +1399,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
|
||||
@@ -1407,14 +1420,14 @@ class MiniEdit( Frame ):
|
||||
|
||||
def convertJsonUnicode(self, text):
|
||||
"Some part of Mininet don't like Unicode"
|
||||
unicode = globals().get( 'unicode', str )
|
||||
if isinstance(text, dict):
|
||||
return {self.convertJsonUnicode(key): self.convertJsonUnicode(value) for key, value in text.iteritems()}
|
||||
elif isinstance(text, list):
|
||||
return {self.convertJsonUnicode(key): self.convertJsonUnicode(value) for key, value in text.items()}
|
||||
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."
|
||||
@@ -1425,14 +1438,14 @@ 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))
|
||||
|
||||
# Load application preferences
|
||||
if 'application' in loadedTopology:
|
||||
self.appPrefs = dict(self.appPrefs.items() + loadedTopology['application'].items())
|
||||
self.appPrefs.update(loadedTopology['application'])
|
||||
if "ovsOf10" not in self.appPrefs["openFlowVersions"]:
|
||||
self.appPrefs["openFlowVersions"]["ovsOf10"] = '0'
|
||||
if "ovsOf11" not in self.appPrefs["openFlowVersions"]:
|
||||
@@ -1586,10 +1599,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 tuple( self.widgetToItem ):
|
||||
self.deleteItem( self.widgetToItem[ widget ] )
|
||||
self.hostCount = 0
|
||||
self.switchCount = 0
|
||||
@@ -1617,10 +1631,10 @@ class MiniEdit( Frame ):
|
||||
hostsToSave = []
|
||||
switchesToSave = []
|
||||
controllersToSave = []
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
x1, y1 = self.canvas.coords( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
x1, y1 = self.canvas.coords( item )
|
||||
if 'Switch' in tags or 'LegacySwitch' in tags or 'LegacyRouter' in tags:
|
||||
nodeNum = self.switchOpts[name]['nodeNum']
|
||||
nodeToSave = {'number':str(nodeNum),
|
||||
@@ -1665,14 +1679,13 @@ class MiniEdit( Frame ):
|
||||
savingDictionary['application'] = self.appPrefs
|
||||
|
||||
try:
|
||||
f = open(fileName, 'wb')
|
||||
f.write(json.dumps(savingDictionary, sort_keys=True, indent=4, separators=(',', ': ')))
|
||||
# pylint: disable=broad-except
|
||||
except Exception as er:
|
||||
print er
|
||||
# pylint: enable=broad-except
|
||||
finally:
|
||||
f.close()
|
||||
with open(fileName, 'w') as f:
|
||||
f.write(
|
||||
json.dumps(savingDictionary,
|
||||
sort_keys=True,
|
||||
indent=4, separators=(',', ': ')))
|
||||
except Exception as er: # pylint: disable=broad-except
|
||||
warn( er, '\n' )
|
||||
|
||||
def exportScript( self ):
|
||||
"Export command."
|
||||
@@ -1683,10 +1696,10 @@ class MiniEdit( Frame ):
|
||||
|
||||
fileName = tkFileDialog.asksaveasfilename(filetypes=myFormats ,title="Export the topology as...")
|
||||
if len(fileName ) > 0:
|
||||
#print "Now saving under %s" % fileName
|
||||
f = open(fileName, 'wb')
|
||||
# debug( "Now saving under %s\n" % fileName )
|
||||
f = open(fileName, 'w') # pylint: disable=consider-using-with
|
||||
|
||||
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")
|
||||
@@ -1700,9 +1713,9 @@ class MiniEdit( Frame ):
|
||||
f.write("from subprocess import call\n")
|
||||
|
||||
inBandCtrl = False
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
|
||||
if 'Controller' in tags:
|
||||
opts = self.controllers[name]
|
||||
@@ -1710,7 +1723,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")
|
||||
@@ -1728,9 +1741,9 @@ class MiniEdit( Frame ):
|
||||
f.write(" ipBase='"+self.appPrefs['ipBase']+"')\n")
|
||||
f.write("\n")
|
||||
f.write(" info( '*** Adding controller\\n' )\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
|
||||
if 'Controller' in tags:
|
||||
opts = self.controllers[name]
|
||||
@@ -1762,9 +1775,9 @@ class MiniEdit( Frame ):
|
||||
|
||||
# Save Switches and Hosts
|
||||
f.write(" info( '*** Add switches\\n')\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'LegacyRouter' in tags:
|
||||
f.write(" "+name+" = net.addHost('"+name+"', cls=Node, ip='0.0.0.0')\n")
|
||||
f.write(" "+name+".cmd('sysctl -w net.ipv4.ip_forward=1')\n")
|
||||
@@ -1802,9 +1815,9 @@ class MiniEdit( Frame ):
|
||||
|
||||
f.write("\n")
|
||||
f.write(" info( '*** Add hosts\\n')\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Host' in tags:
|
||||
opts = self.hostOpts[name]
|
||||
ip = None
|
||||
@@ -1835,7 +1848,7 @@ class MiniEdit( Frame ):
|
||||
|
||||
# Save Links
|
||||
f.write(" info( '*** Add links\\n')\n")
|
||||
for key,linkDetail in self.links.iteritems():
|
||||
for key,linkDetail in self.links.items():
|
||||
tags = self.canvas.gettags(key)
|
||||
if 'data' in tags:
|
||||
optsExist = False
|
||||
@@ -1897,9 +1910,9 @@ class MiniEdit( Frame ):
|
||||
f.write("\n")
|
||||
|
||||
f.write(" info( '*** Starting switches\\n')\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Switch' in tags or 'LegacySwitch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
ctrlList = ",".join(opts['controllers'])
|
||||
@@ -1908,9 +1921,9 @@ class MiniEdit( Frame ):
|
||||
f.write("\n")
|
||||
|
||||
f.write(" info( '*** Post configure switches and hosts\\n')\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
if opts['switchType'] == 'default':
|
||||
@@ -1938,9 +1951,9 @@ class MiniEdit( Frame ):
|
||||
if 'switchIP' in opts:
|
||||
if len(opts['switchIP']) > 0:
|
||||
f.write(" "+name+".cmd('ifconfig "+name+" "+opts['switchIP']+"')\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Host' in tags:
|
||||
opts = self.hostOpts[name]
|
||||
# Attach vlan interfaces
|
||||
@@ -1962,9 +1975,9 @@ class MiniEdit( Frame ):
|
||||
if len(nflowValues['nflowTarget']) > 0:
|
||||
nflowEnabled = False
|
||||
nflowSwitches = ''
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
@@ -1986,9 +1999,9 @@ class MiniEdit( Frame ):
|
||||
if len(sflowValues['sflowTarget']) > 0:
|
||||
sflowEnabled = False
|
||||
sflowSwitches = ''
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
@@ -2003,9 +2016,9 @@ class MiniEdit( Frame ):
|
||||
|
||||
f.write("\n")
|
||||
f.write(" CLI(net)\n")
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem:
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Host' in tags:
|
||||
opts = self.hostOpts[name]
|
||||
# Run User Defined Stop Command
|
||||
@@ -2107,7 +2120,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] = {}
|
||||
@@ -2115,14 +2128,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] = {}
|
||||
@@ -2130,13 +2143,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,
|
||||
@@ -2154,15 +2167,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 ):
|
||||
@@ -2232,7 +2245,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 )
|
||||
@@ -2240,14 +2253,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
|
||||
@@ -2359,6 +2372,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
|
||||
@@ -2425,7 +2440,8 @@ class MiniEdit( Frame ):
|
||||
line3.pack(pady=10 )
|
||||
line4.pack(pady=10 )
|
||||
line5.pack(pady=10 )
|
||||
hide = ( lambda about=about: about.withdraw() )
|
||||
def hide():
|
||||
about.withdraw()
|
||||
self.aboutBox = about
|
||||
# Hide on close rather than destroying window
|
||||
Wm.wm_protocol( about, name='WM_DELETE_WINDOW', func=hide )
|
||||
@@ -2489,7 +2505,7 @@ class MiniEdit( Frame ):
|
||||
if len(hostBox.result['privateDirectory']) > 0:
|
||||
newHostOpts['privateDirectory'] = hostBox.result['privateDirectory']
|
||||
self.hostOpts[name] = newHostOpts
|
||||
print 'New host details for ' + name + ' = ' + str(newHostOpts)
|
||||
info( 'New host details for ' + name + ' = ' + str(newHostOpts), '\n' )
|
||||
|
||||
def switchDetails( self, _ignore=None ):
|
||||
if ( self.selection is None or
|
||||
@@ -2527,7 +2543,7 @@ class MiniEdit( Frame ):
|
||||
newSwitchOpts['sflow'] = switchBox.result['sflow']
|
||||
newSwitchOpts['netflow'] = switchBox.result['netflow']
|
||||
self.switchOpts[name] = newSwitchOpts
|
||||
print 'New switch details for ' + name + ' = ' + str(newSwitchOpts)
|
||||
info( 'New switch details for ' + name + ' = ' + str(newSwitchOpts), '\n' )
|
||||
|
||||
def linkUp( self ):
|
||||
if ( self.selection is None or
|
||||
@@ -2566,12 +2582,12 @@ class MiniEdit( Frame ):
|
||||
linkBox = LinkDialog(self, title='Link Details', linkDefaults=linkopts)
|
||||
if linkBox.result is not None:
|
||||
linkDetail['linkOpts'] = linkBox.result
|
||||
print 'New link details = ' + str(linkBox.result)
|
||||
info( 'New link details = ' + str(linkBox.result), '\n' )
|
||||
|
||||
def prefDetails( self ):
|
||||
prefDefaults = self.appPrefs
|
||||
prefBox = PrefsDialog(self, title='Preferences', prefDefaults=prefDefaults)
|
||||
print 'New Prefs = ' + str(prefBox.result)
|
||||
info( 'New Prefs = ' + str(prefBox.result), '\n' )
|
||||
if prefBox.result:
|
||||
self.appPrefs = prefBox.result
|
||||
|
||||
@@ -2590,19 +2606,19 @@ class MiniEdit( Frame ):
|
||||
|
||||
ctrlrBox = ControllerDialog(self, title='Controller Details', ctrlrDefaults=self.controllers[name])
|
||||
if ctrlrBox.result:
|
||||
#print 'Controller is ' + ctrlrBox.result[0]
|
||||
# debug( 'Controller is ' + ctrlrBox.result[0], '\n' )
|
||||
if len(ctrlrBox.result['hostname']) > 0:
|
||||
name = ctrlrBox.result['hostname']
|
||||
widget[ 'text' ] = name
|
||||
else:
|
||||
ctrlrBox.result['hostname'] = name
|
||||
self.controllers[name] = ctrlrBox.result
|
||||
print 'New controller details for ' + name + ' = ' + str(self.controllers[name])
|
||||
info( 'New controller details for ' + name + ' = ' + str(self.controllers[name]), '\n' )
|
||||
# Find references to controller and change name
|
||||
if oldName != name:
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
switchName = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Switch' in tags:
|
||||
switch = self.switchOpts[switchName]
|
||||
if oldName in switch['controllers']:
|
||||
@@ -2642,7 +2658,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}
|
||||
@@ -2683,14 +2699,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, searchitem in self.widgetToItem.items():
|
||||
name = searchwidget[ 'text' ]
|
||||
tags = self.canvas.gettags( searchitem )
|
||||
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 ]
|
||||
@@ -2698,15 +2713,15 @@ class MiniEdit( Frame ):
|
||||
|
||||
def buildNodes( self, net):
|
||||
# Make nodes
|
||||
print "Getting Hosts and Switches."
|
||||
for widget in self.widgetToItem:
|
||||
info( "Getting Hosts and Switches.\n" )
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
#print name+' has '+str(tags)
|
||||
tags = self.canvas.gettags( item )
|
||||
# debug( name+' has '+str(tags), '\n' )
|
||||
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
#print str(opts)
|
||||
# debug( str(opts), '\n' )
|
||||
|
||||
# Create the correct switch class
|
||||
switchClass = customOvs
|
||||
@@ -2772,7 +2787,7 @@ class MiniEdit( Frame ):
|
||||
newSwitch = net.addHost( name , cls=LegacyRouter)
|
||||
elif 'Host' in tags:
|
||||
opts = self.hostOpts[name]
|
||||
#print str(opts)
|
||||
# debug( str(opts), '\n' )
|
||||
ip = None
|
||||
defaultRoute = None
|
||||
if 'defaultRoute' in opts and len(opts['defaultRoute']) > 0:
|
||||
@@ -2797,7 +2812,7 @@ class MiniEdit( Frame ):
|
||||
privateDirs=opts['privateDirectory'] )
|
||||
else:
|
||||
hostCls=Host
|
||||
print hostCls
|
||||
debug( hostCls, '\n' )
|
||||
newHost = net.addHost( name,
|
||||
cls=hostCls,
|
||||
ip=ip,
|
||||
@@ -2817,7 +2832,7 @@ class MiniEdit( Frame ):
|
||||
Intf( extInterface, node=newHost )
|
||||
if 'vlanInterfaces' in opts:
|
||||
if len(opts['vlanInterfaces']) > 0:
|
||||
print 'Checking that OS is VLAN prepared'
|
||||
info( 'Checking that OS is VLAN prepared\n' )
|
||||
self.pathCheck('vconfig', moduleName='vlan package')
|
||||
moduleDeps( add='8021q' )
|
||||
elif 'Controller' in tags:
|
||||
@@ -2834,7 +2849,7 @@ class MiniEdit( Frame ):
|
||||
controllerPort = opts['remotePort']
|
||||
|
||||
# Make controller
|
||||
print 'Getting controller selection:'+controllerType
|
||||
info( 'Getting controller selection:'+controllerType, '\n' )
|
||||
if controllerType == 'remote':
|
||||
net.addController(name=name,
|
||||
controller=RemoteController,
|
||||
@@ -2874,8 +2889,8 @@ class MiniEdit( Frame ):
|
||||
|
||||
def buildLinks( self, net):
|
||||
# Make links
|
||||
print "Getting Links."
|
||||
for key,link in self.links.iteritems():
|
||||
info( "Getting Links.\n" )
|
||||
for key,link in self.links.items():
|
||||
tags = self.canvas.gettags(key)
|
||||
if 'data' in tags:
|
||||
src=link['src']
|
||||
@@ -2886,14 +2901,14 @@ class MiniEdit( Frame ):
|
||||
if linkopts:
|
||||
net.addLink(srcNode, dstNode, cls=TCLink, **linkopts)
|
||||
else:
|
||||
#print str(srcNode)
|
||||
#print str(dstNode)
|
||||
# debug( str(srcNode) )
|
||||
# debug( str(dstNode), '\n' )
|
||||
net.addLink(srcNode, dstNode)
|
||||
self.canvas.itemconfig(key, dash=())
|
||||
|
||||
|
||||
def build( self ):
|
||||
print "Build network based on our topology."
|
||||
"Build network based on our topology."
|
||||
|
||||
dpctl = None
|
||||
if len(self.appPrefs['dpctl']) > 0:
|
||||
@@ -2915,16 +2930,16 @@ class MiniEdit( Frame ):
|
||||
def postStartSetup( self ):
|
||||
|
||||
# Setup host details
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Host' in tags:
|
||||
newHost = self.net.get(name)
|
||||
opts = self.hostOpts[name]
|
||||
# Attach vlan interfaces
|
||||
if 'vlanInterfaces' in opts:
|
||||
for vlanInterface in opts['vlanInterfaces']:
|
||||
print 'adding vlan interface '+vlanInterface[1]
|
||||
info( 'adding vlan interface '+vlanInterface[1], '\n' )
|
||||
newHost.cmdPrint('ifconfig '+name+'-eth0.'+vlanInterface[1]+' '+vlanInterface[0])
|
||||
# Run User Defined Start Command
|
||||
if 'startCommand' in opts:
|
||||
@@ -2942,15 +2957,15 @@ class MiniEdit( Frame ):
|
||||
if len(nflowValues['nflowTarget']) > 0:
|
||||
nflowEnabled = False
|
||||
nflowSwitches = ''
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
if 'netflow' in opts:
|
||||
if opts['netflow'] == '1':
|
||||
print name+' has Netflow enabled'
|
||||
info( name+' has Netflow enabled\n' )
|
||||
nflowSwitches = nflowSwitches+' -- set Bridge '+name+' netflow=@MiniEditNF'
|
||||
nflowEnabled=True
|
||||
if nflowEnabled:
|
||||
@@ -2959,44 +2974,44 @@ class MiniEdit( Frame ):
|
||||
nflowCmd = nflowCmd + ' add_id_to_interface=true'
|
||||
else:
|
||||
nflowCmd = nflowCmd + ' add_id_to_interface=false'
|
||||
print 'cmd = '+nflowCmd+nflowSwitches
|
||||
info( 'cmd = '+nflowCmd+nflowSwitches, '\n' )
|
||||
call(nflowCmd+nflowSwitches, shell=True)
|
||||
|
||||
else:
|
||||
print 'No switches with Netflow'
|
||||
info( 'No switches with Netflow\n' )
|
||||
else:
|
||||
print 'No NetFlow targets specified.'
|
||||
info( 'No NetFlow targets specified.\n' )
|
||||
|
||||
# Configure sFlow
|
||||
sflowValues = self.appPrefs['sflow']
|
||||
if len(sflowValues['sflowTarget']) > 0:
|
||||
sflowEnabled = False
|
||||
sflowSwitches = ''
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
if 'sflow' in opts:
|
||||
if opts['sflow'] == '1':
|
||||
print name+' has sflow enabled'
|
||||
info( name+' has sflow enabled\n' )
|
||||
sflowSwitches = sflowSwitches+' -- set Bridge '+name+' sflow=@MiniEditSF'
|
||||
sflowEnabled=True
|
||||
if sflowEnabled:
|
||||
sflowCmd = 'ovs-vsctl -- --id=@MiniEditSF create sFlow '+ 'target=\\\"'+sflowValues['sflowTarget']+'\\\" '+ 'header='+sflowValues['sflowHeader']+' '+ 'sampling='+sflowValues['sflowSampling']+' '+ 'polling='+sflowValues['sflowPolling']
|
||||
print 'cmd = '+sflowCmd+sflowSwitches
|
||||
info( 'cmd = '+sflowCmd+sflowSwitches, '\n' )
|
||||
call(sflowCmd+sflowSwitches, shell=True)
|
||||
|
||||
else:
|
||||
print 'No switches with sflow'
|
||||
info( 'No switches with sflow\n' )
|
||||
else:
|
||||
print 'No sFlow targets specified.'
|
||||
info( 'No sFlow targets specified.\n' )
|
||||
|
||||
## 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 ):
|
||||
@@ -3017,9 +3032,9 @@ class MiniEdit( Frame ):
|
||||
#for switch in self.net.switches:
|
||||
# info( switch.name + ' ')
|
||||
# switch.start( self.net.controllers )
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Switch' in tags:
|
||||
opts = self.switchOpts[name]
|
||||
switchControllers = []
|
||||
@@ -3039,9 +3054,9 @@ class MiniEdit( Frame ):
|
||||
"Stop network."
|
||||
if self.net is not None:
|
||||
# Stop host details
|
||||
for widget in self.widgetToItem:
|
||||
for widget, item in self.widgetToItem.items():
|
||||
name = widget[ 'text' ]
|
||||
tags = self.canvas.gettags( self.widgetToItem[ widget ] )
|
||||
tags = self.canvas.gettags( item )
|
||||
if 'Host' in tags:
|
||||
newHost = self.net.get(name)
|
||||
opts = self.hostOpts[name]
|
||||
@@ -3184,7 +3199,7 @@ class MiniEdit( Frame ):
|
||||
addDictOption( opts, LINKS, LINKDEF, 'link' )
|
||||
|
||||
opts.add_option( '--custom', type='string', default=None,
|
||||
help='read custom topo and node params from .py' +
|
||||
help='read custom topo and node params from .py ' +
|
||||
'file' )
|
||||
|
||||
self.options, self.args = opts.parse_args()
|
||||
@@ -3210,19 +3225,20 @@ class MiniEdit( Frame ):
|
||||
"Parse custom file and add params before parsing cmd-line options."
|
||||
customs = {}
|
||||
if os.path.isfile( fileName ):
|
||||
execfile( fileName, customs, customs )
|
||||
for name, val in customs.iteritems():
|
||||
with open( fileName, 'r' ) as f:
|
||||
exec( f.read() ) # pylint: disable=exec-used
|
||||
for name, val in customs.items():
|
||||
self.setCustom( name, val )
|
||||
else:
|
||||
raise Exception( 'could not find custom file: %s' % fileName )
|
||||
|
||||
def importTopo( self ):
|
||||
print 'topo='+self.options.topo
|
||||
info( 'topo='+self.options.topo, '\n' )
|
||||
if self.options.topo == 'none':
|
||||
return
|
||||
self.newTopology()
|
||||
topo = buildTopo( TOPOS, self.options.topo )
|
||||
link = customConstructor( LINKS, self.options.link )
|
||||
link = customClass( LINKS, self.options.link )
|
||||
importNet = Mininet(topo=topo, build=False, link=link)
|
||||
importNet.build()
|
||||
|
||||
@@ -3231,7 +3247,7 @@ class MiniEdit( Frame ):
|
||||
currentY = 100
|
||||
|
||||
# Add Controllers
|
||||
print 'controllers:'+str(len(importNet.controllers))
|
||||
info( 'controllers:'+str(len(importNet.controllers)), '\n' )
|
||||
for controller in importNet.controllers:
|
||||
name = controller.name
|
||||
x = self.controllerCount*100+100
|
||||
@@ -3251,7 +3267,7 @@ class MiniEdit( Frame ):
|
||||
currentY = currentY + rowIncrement
|
||||
|
||||
# Add switches
|
||||
print 'switches:'+str(len(importNet.switches))
|
||||
info( 'switches:'+str(len(importNet.switches)), '\n' )
|
||||
columnCount = 0
|
||||
for switch in importNet.switches:
|
||||
name = switch.name
|
||||
@@ -3292,7 +3308,7 @@ class MiniEdit( Frame ):
|
||||
|
||||
currentY = currentY + rowIncrement
|
||||
# Add hosts
|
||||
print 'hosts:'+str(len(importNet.hosts))
|
||||
info( 'hosts:'+str(len(importNet.hosts)), '\n' )
|
||||
columnCount = 0
|
||||
for host in importNet.hosts:
|
||||
name = host.name
|
||||
@@ -3312,10 +3328,10 @@ class MiniEdit( Frame ):
|
||||
else:
|
||||
columnCount =columnCount+1
|
||||
|
||||
print 'links:'+str(len(topo.links()))
|
||||
info( 'links:'+str(len(topo.links())), '\n' )
|
||||
#[('h1', 's3'), ('h2', 's4'), ('s3', 's4')]
|
||||
for link in topo.links():
|
||||
print str(link)
|
||||
info( str(link), '\n' )
|
||||
srcNode = link[0]
|
||||
src = self.findWidgetByName(srcNode)
|
||||
sx, sy = self.canvas.coords( self.widgetToItem[ src ] )
|
||||
@@ -3325,7 +3341,7 @@ class MiniEdit( Frame ):
|
||||
dx, dy = self.canvas.coords( self.widgetToItem[ dest] )
|
||||
|
||||
params = topo.linkInfo( srcNode, destNode )
|
||||
print 'Link Parameters='+str(params)
|
||||
info( 'Link Parameters='+str(params), '\n' )
|
||||
|
||||
self.link = self.canvas.create_line( sx, sy, dx, dy, width=4,
|
||||
fill='blue', tag='link' )
|
||||
@@ -3577,8 +3593,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()
|
||||
|
||||
+18
-14
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Simple example of Mobility with Mininet
|
||||
@@ -19,12 +19,12 @@ 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 output, warn
|
||||
|
||||
from random import randint
|
||||
from mininet.log import info, output, warn, setLogLevel
|
||||
|
||||
|
||||
class MobilitySwitch( OVSSwitch ):
|
||||
@@ -37,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 )
|
||||
@@ -105,30 +106,33 @@ def moveHost( host, oldSwitch, newSwitch, newPort=None ):
|
||||
|
||||
def mobilityTest():
|
||||
"A simple test of mobility"
|
||||
print '* Simple mobility test'
|
||||
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch )
|
||||
print '* Starting network:'
|
||||
info( '* Simple mobility test\n' )
|
||||
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch,
|
||||
waitConnected=True )
|
||||
info( '* Starting network:\n' )
|
||||
net.start()
|
||||
printConnections( net.switches )
|
||||
print '* Testing network'
|
||||
info( '* Testing network\n' )
|
||||
net.pingAll()
|
||||
print '* Identifying switch interface for h1'
|
||||
info( '* Identifying switch interface for h1\n' )
|
||||
h1, old = net.get( 'h1', 's1' )
|
||||
for s in 2, 3, 1:
|
||||
new = net[ 's%d' % s ]
|
||||
port = randint( 10, 20 )
|
||||
print '* Moving', h1, 'from', old, 'to', new, 'port', port
|
||||
info( '* Moving', h1, 'from', old, 'to', new, 'port', port, '\n' )
|
||||
hintf, sintf = moveHost( h1, old, new, newPort=port )
|
||||
print '*', hintf, 'is now connected to', sintf
|
||||
print '* Clearing out old flows'
|
||||
info( '*', hintf, 'is now connected to', sintf, '\n' )
|
||||
info( '* Clearing out old flows\n' )
|
||||
for sw in net.switches:
|
||||
sw.dpctl( 'del-flows' )
|
||||
print '* New network:'
|
||||
info( '* New network:\n' )
|
||||
printConnections( net.switches )
|
||||
print '* Testing connectivity:'
|
||||
info( '* Testing connectivity:\n' )
|
||||
net.pingAll()
|
||||
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,9 +21,8 @@ def runMultiLink():
|
||||
class simpleMultiLinkTopo( Topo ):
|
||||
"Simple topology with multiple links"
|
||||
|
||||
def __init__( self, n, **kwargs ):
|
||||
Topo.__init__( self, **kwargs )
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def build( self, n, **_kwargs ):
|
||||
h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' )
|
||||
s1 = self.addSwitch( 's1' )
|
||||
|
||||
@@ -31,6 +30,7 @@ class simpleMultiLinkTopo( Topo ):
|
||||
self.addLink( s1, h1 )
|
||||
self.addLink( s1, h2 )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
runMultiLink()
|
||||
|
||||
+14
-13
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
multiping.py: monitor multiple sets of hosts using ping
|
||||
@@ -8,17 +8,18 @@ multiple hosts and monitor their output interactively for a period=
|
||||
of time.
|
||||
"""
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Node
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import setLogLevel
|
||||
|
||||
from select import poll, POLLIN
|
||||
from time import time
|
||||
|
||||
def chunks( l, n ):
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Node
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import info, setLogLevel
|
||||
|
||||
|
||||
def chunks( items, n ):
|
||||
"Divide list l into chunks of size n - thanks Stackoverflow"
|
||||
return [ l[ i: i + n ] for i in range( 0, len( l ), n ) ]
|
||||
return [ items[ i: i + n ] for i in range( 0, len( items ), n ) ]
|
||||
|
||||
def startpings( host, targetips ):
|
||||
"Tell host to repeatedly ping targets"
|
||||
@@ -34,8 +35,8 @@ def startpings( host, targetips ):
|
||||
' done; '
|
||||
'done &' )
|
||||
|
||||
print ( '*** Host %s (%s) will be pinging ips: %s' %
|
||||
( host.name, host.IP(), targetips ) )
|
||||
info( '*** Host %s (%s) will be pinging ips: %s\n' %
|
||||
( host.name, host.IP(), targetips ) )
|
||||
|
||||
host.cmd( cmd )
|
||||
|
||||
@@ -44,7 +45,7 @@ def multiping( netsize, chunksize, seconds):
|
||||
|
||||
# Create network and identify subnets
|
||||
topo = SingleSwitchTopo( netsize )
|
||||
net = Mininet( topo=topo )
|
||||
net = Mininet( topo=topo, waitConnected=True )
|
||||
net.start()
|
||||
hosts = net.hosts
|
||||
subnets = chunks( hosts, chunksize )
|
||||
@@ -58,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 )
|
||||
@@ -69,7 +70,7 @@ def multiping( netsize, chunksize, seconds):
|
||||
readable = poller.poll(1000)
|
||||
for fd, _mask in readable:
|
||||
node = Node.outToNode[ fd ]
|
||||
print '%s:' % node.name, node.monitor().strip()
|
||||
info( '%s:' % node.name, node.monitor().strip(), '\n' )
|
||||
|
||||
# Stop pings
|
||||
for host in hosts:
|
||||
|
||||
+17
-13
@@ -1,25 +1,29 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Simple example of sending output to multiple files and
|
||||
monitoring them
|
||||
"""
|
||||
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.net import Mininet
|
||||
from mininet.log import setLogLevel
|
||||
|
||||
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
|
||||
|
||||
|
||||
def monitorFiles( outfiles, seconds, timeoutms ):
|
||||
"Monitor set of files and return [(host, line)...]"
|
||||
devnull = open( '/dev/null', 'w' )
|
||||
devnull = open( '/dev/null', 'w' ) # pylint: disable=consider-using-with
|
||||
tails, fdToFile, fdToHost = {}, {}, {}
|
||||
for h, outfile in outfiles.iteritems():
|
||||
tail = Popen( [ 'tail', '-f', outfile ],
|
||||
stdout=PIPE, stderr=devnull )
|
||||
for h, outfile in outfiles.items():
|
||||
tail = Popen( # pylint: disable=consider-using-with
|
||||
[ 'tail', '-f', outfile ],
|
||||
stdout=PIPE, stderr=devnull )
|
||||
fd = tail.stdout.fileno()
|
||||
tails[ h ] = tail
|
||||
fdToFile[ fd ] = tail.stdout
|
||||
@@ -38,7 +42,7 @@ def monitorFiles( outfiles, seconds, timeoutms ):
|
||||
host = fdToHost[ fd ]
|
||||
# Wait for a line of output
|
||||
line = f.readline().strip()
|
||||
yield host, line
|
||||
yield host, decode( line )
|
||||
else:
|
||||
# If we timed out, return nothing
|
||||
yield None, ''
|
||||
@@ -50,10 +54,10 @@ 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
|
||||
print "Starting test..."
|
||||
info( "Starting test...\n" )
|
||||
server = hosts[ 0 ]
|
||||
outfiles, errfiles = {}, {}
|
||||
for h in hosts:
|
||||
@@ -67,10 +71,10 @@ def monitorTest( N=3, seconds=3 ):
|
||||
'>', outfiles[ h ],
|
||||
'2>', errfiles[ h ],
|
||||
'&' )
|
||||
print "Monitoring output for", seconds, "seconds"
|
||||
info( "Monitoring output for", seconds, "seconds\n" )
|
||||
for h, line in monitorFiles( outfiles, seconds, timeoutms=500 ):
|
||||
if h:
|
||||
print '%s: %s' % ( h.name, line )
|
||||
info( '%s: %s\n' % ( h.name, line ) )
|
||||
for h in hosts:
|
||||
h.cmd('kill %ping')
|
||||
net.stop()
|
||||
|
||||
@@ -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" )
|
||||
|
||||
+9
-98
@@ -1,112 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Example to create a Mininet topology and connect it to the internet via NAT
|
||||
through eth0 on the host.
|
||||
|
||||
Glen Gibb, February 2011
|
||||
|
||||
(slight modifications by BL, 5/13)
|
||||
"""
|
||||
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import lg
|
||||
from mininet.node import Node
|
||||
from mininet.log import lg, info
|
||||
from mininet.topolib import TreeNet
|
||||
|
||||
#################################
|
||||
def startNAT( root, inetIntf='eth0', subnet='10.0/8' ):
|
||||
"""Start NAT/forwarding between Mininet and external network
|
||||
root: node to access iptables from
|
||||
inetIntf: interface for internet access
|
||||
subnet: Mininet subnet (default 10.0/8)="""
|
||||
|
||||
# Identify the interface connecting to the mininet network
|
||||
localIntf = root.defaultIntf()
|
||||
|
||||
# Flush any currently active rules
|
||||
root.cmd( 'iptables -F' )
|
||||
root.cmd( 'iptables -t nat -F' )
|
||||
|
||||
# Create default entries for unmatched traffic
|
||||
root.cmd( 'iptables -P INPUT ACCEPT' )
|
||||
root.cmd( 'iptables -P OUTPUT ACCEPT' )
|
||||
root.cmd( 'iptables -P FORWARD DROP' )
|
||||
|
||||
# Configure NAT
|
||||
root.cmd( 'iptables -I FORWARD -i', localIntf, '-d', subnet, '-j DROP' )
|
||||
root.cmd( 'iptables -A FORWARD -i', localIntf, '-s', subnet, '-j ACCEPT' )
|
||||
root.cmd( 'iptables -A FORWARD -i', inetIntf, '-d', subnet, '-j ACCEPT' )
|
||||
root.cmd( 'iptables -t nat -A POSTROUTING -o ', inetIntf, '-j MASQUERADE' )
|
||||
|
||||
# Instruct the kernel to perform forwarding
|
||||
root.cmd( 'sysctl net.ipv4.ip_forward=1' )
|
||||
|
||||
def stopNAT( root ):
|
||||
"""Stop NAT/forwarding between Mininet and external network"""
|
||||
# Flush any currently active rules
|
||||
root.cmd( 'iptables -F' )
|
||||
root.cmd( 'iptables -t nat -F' )
|
||||
|
||||
# Instruct the kernel to stop forwarding
|
||||
root.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
|
||||
def fixNetworkManager( root, intf ):
|
||||
"""Prevent network-manager from messing with our interface,
|
||||
by specifying manual configuration in /etc/network/interfaces
|
||||
root: a node in the root namespace (for running commands)
|
||||
intf: interface name"""
|
||||
cfile = '/etc/network/interfaces'
|
||||
line = '\niface %s inet manual\n' % intf
|
||||
config = open( cfile ).read()
|
||||
if line not in config:
|
||||
print '*** Adding', line.strip(), 'to', cfile
|
||||
with open( cfile, 'a' ) as f:
|
||||
f.write( line )
|
||||
# Probably need to restart network-manager to be safe -
|
||||
# hopefully this won't disconnect you
|
||||
root.cmd( 'service network-manager restart' )
|
||||
|
||||
def connectToInternet( network, switch='s1', rootip='10.254', subnet='10.0/8'):
|
||||
"""Connect the network to the internet
|
||||
switch: switch to connect to root namespace
|
||||
rootip: address for interface in root namespace
|
||||
subnet: Mininet subnet"""
|
||||
switch = network.get( switch )
|
||||
prefixLen = subnet.split( '/' )[ 1 ]
|
||||
|
||||
# Create a node in root namespace
|
||||
root = Node( 'root', inNamespace=False )
|
||||
|
||||
# Prevent network-manager from interfering with our interface
|
||||
fixNetworkManager( root, 'root-eth0' )
|
||||
|
||||
# Create link between root NS and switch
|
||||
link = network.addLink( root, switch )
|
||||
link.intf1.setIP( rootip, prefixLen )
|
||||
|
||||
# Start network that now includes link to root namespace
|
||||
network.start()
|
||||
|
||||
# Start NAT and establish forwarding
|
||||
startNAT( root )
|
||||
|
||||
# Establish routes from end hosts
|
||||
for host in network.hosts:
|
||||
host.cmd( 'ip route flush root 0/0' )
|
||||
host.cmd( 'route add -net', subnet, 'dev', host.defaultIntf() )
|
||||
host.cmd( 'route add default gw', rootip )
|
||||
|
||||
return root
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info')
|
||||
net = TreeNet( depth=1, fanout=4 )
|
||||
# Configure and start NATted connectivity
|
||||
rootnode = connectToInternet( net )
|
||||
print "*** Hosts are running and should have internet connectivity"
|
||||
print "*** Type 'exit' or control-D to shut down network"
|
||||
net = TreeNet( depth=1, fanout=4, waitConnected=True )
|
||||
# Add NAT connectivity
|
||||
net.addNAT().configDefault()
|
||||
net.start()
|
||||
info( "*** Hosts are running and should have internet connectivity\n" )
|
||||
info( "*** Type 'exit' or control-D to shut down network\n" )
|
||||
CLI( net )
|
||||
# Shut down NAT
|
||||
stopNAT( rootnode )
|
||||
net.stop()
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
natnet.py: Example network with NATs
|
||||
@@ -27,9 +27,8 @@ from mininet.util import irange
|
||||
|
||||
class InternetTopo(Topo):
|
||||
"Single switch connected to n hosts."
|
||||
def __init__(self, n=2, **opts):
|
||||
Topo.__init__(self, **opts)
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def build(self, n=2, **_kwargs ):
|
||||
# set up inet switch
|
||||
inetSwitch = self.addSwitch('s0')
|
||||
# add inet host
|
||||
@@ -59,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.
|
||||
@@ -6,6 +6,7 @@ Validate that the port numbers match to the interface name,
|
||||
and that the ovs ports match the mininet ports.
|
||||
"""
|
||||
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Controller
|
||||
from mininet.log import setLogLevel, info, warn
|
||||
@@ -27,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' )
|
||||
@@ -65,15 +66,16 @@ def testPortNumbering():
|
||||
'is actually on port', s1.ports[intfs], '... ' )
|
||||
if validatePort( s1, intfs ):
|
||||
info( 'Validated.\n' )
|
||||
print '\n'
|
||||
info( '\n' )
|
||||
|
||||
# test the network with pingall
|
||||
net.pingAll()
|
||||
print '\n'
|
||||
info( '\n' )
|
||||
|
||||
info( '*** Stopping network' )
|
||||
info( '*** Stopping network\n' )
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
testPortNumbering()
|
||||
|
||||
+7
-9
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This example monitors a number of hosts using host.popen() and
|
||||
@@ -6,17 +6,14 @@ pmonitor()
|
||||
"""
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import custom, pmonitor
|
||||
from mininet.log import setLogLevel, info
|
||||
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 = {}
|
||||
@@ -27,10 +24,11 @@ def monitorhosts( hosts=5, sched='cfs' ):
|
||||
# Monitor them and print output
|
||||
for host, line in pmonitor( popens ):
|
||||
if host:
|
||||
print "<%s>: %s" % ( host.name, line.strip() )
|
||||
info( "<%s>: %s" % ( host.name, line ) )
|
||||
# Done
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
monitorhosts( hosts=5 )
|
||||
|
||||
+12
-7
@@ -1,33 +1,38 @@
|
||||
#!/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 time import time
|
||||
from signal import SIGINT
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
|
||||
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
|
||||
print "Starting test..."
|
||||
info( "Starting test...\n" )
|
||||
server = hosts[ 0 ]
|
||||
popens = {}
|
||||
for h in hosts:
|
||||
popens[ h ] = h.popen('ping', server.IP() )
|
||||
print "Monitoring output for", seconds, "seconds"
|
||||
info( "Monitoring output for", seconds, "seconds\n" )
|
||||
endTime = time() + seconds
|
||||
for h, line in pmonitor( popens, timeoutms=500 ):
|
||||
if h:
|
||||
print '<%s>: %s' % ( h.name, line ),
|
||||
info( '<%s>: %s' % ( h.name, line ) )
|
||||
if time() >= endTime:
|
||||
for p in popens.values():
|
||||
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,13 +8,14 @@ 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
|
||||
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."
|
||||
@@ -40,7 +41,7 @@ def scratchNet( cname='controller', cargs='-v ptcp:' ):
|
||||
switch.cmd( 'ovs-vsctl del-br dp0' )
|
||||
switch.cmd( 'ovs-vsctl add-br dp0' )
|
||||
for intf in switch.intfs.values():
|
||||
print switch.cmd( 'ovs-vsctl add-port dp0 %s' % intf )
|
||||
switch.cmd( 'ovs-vsctl add-port dp0 %s\n' % intf )
|
||||
|
||||
# Note: controller and switch are in root namespace, and we
|
||||
# can connect via loopback interface
|
||||
@@ -61,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.
|
||||
@@ -52,7 +52,7 @@ def scratchNetUser( cname='controller', cargs='ptcp:' ):
|
||||
info( '*** Starting controller and user datapath\n' )
|
||||
controller.cmd( cname + ' ' + cargs + '&' )
|
||||
switch.cmd( 'ifconfig lo 127.0.0.1' )
|
||||
intfs = [ str( i ) for i in sintf1, sintf2 ]
|
||||
intfs = str( sintf1 ), str( sintf2 )
|
||||
switch.cmd( 'ofdatapath -i ' + ','.join( intfs ) + ' ptcp: &' )
|
||||
switch.cmd( 'ofprotocol tcp:' + controller.IP() + ' tcp:localhost &' )
|
||||
|
||||
@@ -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' )
|
||||
|
||||
+33
-14
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Simple example of setting network and CPU parameters
|
||||
@@ -9,40 +9,59 @@ 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
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.link import TCLink
|
||||
from mininet.util import dumpNodeConnections
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
class SingleSwitchTopo(Topo):
|
||||
|
||||
# It would be nice if we didn't have to do this:
|
||||
# pylint: disable=arguments-differ
|
||||
|
||||
class SingleSwitchTopo( Topo ):
|
||||
"Single switch connected to n hosts."
|
||||
def __init__(self, n=2, **opts):
|
||||
Topo.__init__(self, **opts)
|
||||
def build( self, n=2, lossy=True ):
|
||||
switch = self.addSwitch('s1')
|
||||
for h in range(n):
|
||||
# Each host gets 50%/n of system CPU
|
||||
host = self.addHost('h%s' % (h + 1),
|
||||
cpu=.5 / n)
|
||||
# 10 Mbps, 5ms delay, 10% loss
|
||||
self.addLink(host, switch,
|
||||
bw=10, delay='5ms', loss=10, use_htb=True)
|
||||
if lossy:
|
||||
# 10 Mbps, 5ms delay, 10% packet loss
|
||||
self.addLink(host, switch,
|
||||
bw=10, delay='5ms', loss=10, use_htb=True)
|
||||
else:
|
||||
# 10 Mbps, 5ms delay, no packet loss
|
||||
self.addLink(host, switch,
|
||||
bw=10, delay='5ms', loss=0, use_htb=True)
|
||||
|
||||
def perfTest():
|
||||
|
||||
def perfTest( lossy=True ):
|
||||
"Create network and run simple performance test"
|
||||
topo = SingleSwitchTopo( n=4 )
|
||||
topo = SingleSwitchTopo( n=4, lossy=lossy )
|
||||
net = Mininet( topo=topo,
|
||||
host=CPULimitedHost, link=TCLink,
|
||||
autoStaticArp=True )
|
||||
net.start()
|
||||
print "Dumping host connections"
|
||||
info( "Dumping host connections\n" )
|
||||
dumpNodeConnections(net.hosts)
|
||||
print "Testing bandwidth between h1 and h4"
|
||||
info( "Testing bandwidth between h1 and h4 (lossy=%s)\n" % lossy )
|
||||
h1, h4 = net.getNodeByName('h1', 'h4')
|
||||
net.iperf( ( h1, h4 ), l4Type='UDP' )
|
||||
# Debugging
|
||||
h1.cmd('jobs')
|
||||
h4.cmd('jobs')
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel('info')
|
||||
perfTest()
|
||||
setLogLevel( 'info' )
|
||||
# Debug for now
|
||||
if 'testmode' in argv:
|
||||
setLogLevel( 'debug' )
|
||||
# Prevent test_simpleperf from failing due to packet loss
|
||||
perfTest( lossy=( 'testmode' not in argv ) )
|
||||
|
||||
+10
-10
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Create a network and start sshd(8) on each host.
|
||||
@@ -20,15 +20,16 @@ import sys
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import lg
|
||||
from mininet.log import lg, info
|
||||
from mininet.node import Node
|
||||
from mininet.topolib import TreeTopo
|
||||
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.
|
||||
@@ -46,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.
|
||||
@@ -59,22 +61,20 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D',
|
||||
connectToRootNS( network, switch, ip, routes )
|
||||
for host in network.hosts:
|
||||
host.cmd( cmd + ' ' + opts + '&' )
|
||||
print "*** Waiting for ssh daemons to start"
|
||||
info( "*** Waiting for ssh daemons to start\n" )
|
||||
for server in network.hosts:
|
||||
waitListening( server=server, port=22, timeout=5 )
|
||||
|
||||
print
|
||||
print "*** Hosts are running sshd at the following addresses:"
|
||||
print
|
||||
info( "\n*** Hosts are running sshd at the following addresses:\n" )
|
||||
for host in network.hosts:
|
||||
print host.name, host.IP()
|
||||
print
|
||||
print "*** Type 'exit' or control-D to shut down network"
|
||||
info( host.name, host.IP(), '\n' )
|
||||
info( "\n*** Type 'exit' or control-D to shut down network\n" )
|
||||
CLI( network )
|
||||
for host in network.hosts:
|
||||
host.cmd( 'kill %' + cmd )
|
||||
network.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
lg.setLogLevel( 'info')
|
||||
net = TreeNet( depth=1, fanout=4 )
|
||||
|
||||
@@ -32,7 +32,8 @@ def runTests( testDir, verbosity=1 ):
|
||||
# discover all tests in testDir
|
||||
testSuite = unittest.defaultTestLoader.discover( testDir )
|
||||
# run tests
|
||||
MininetTestRunner( verbosity=verbosity ).run( testSuite )
|
||||
success = MininetTestRunner( verbosity=verbosity ).run( testSuite ).wasSuccessful()
|
||||
sys.exit( 0 if success else 1 )
|
||||
|
||||
if __name__ == '__main__':
|
||||
# get the directory containing example tests
|
||||
|
||||
@@ -5,8 +5,9 @@ Tests for baresshd.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from mininet.clean import cleanup, sh
|
||||
from sys import stdout
|
||||
|
||||
class testBareSSHD( unittest.TestCase ):
|
||||
|
||||
@@ -14,7 +15,9 @@ class testBareSSHD( unittest.TestCase ):
|
||||
|
||||
def connected( self ):
|
||||
"Log into ssh server, check banner, then exit"
|
||||
p = pexpect.spawn( 'ssh 10.0.0.1 -o StrictHostKeyChecking=no -i /tmp/ssh/test_rsa exit' )
|
||||
p = pexpect.spawn( 'ssh 10.0.0.1 -o ConnectTimeout=1 '
|
||||
'-o StrictHostKeyChecking=no '
|
||||
'-i /tmp/ssh/test_rsa exit' )
|
||||
while True:
|
||||
index = p.expect( self.opts )
|
||||
if index == 0:
|
||||
@@ -22,6 +25,7 @@ class testBareSSHD( unittest.TestCase ):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def setUp( self ):
|
||||
# verify that sshd is not running
|
||||
self.assertFalse( self.connected() )
|
||||
@@ -55,7 +59,7 @@ class testBareSSHD( unittest.TestCase ):
|
||||
|
||||
def tearDown( self ):
|
||||
# kill the ssh process
|
||||
sh( "ps aux | grep 'ssh.*Banner' | awk '{ print $2 }' | xargs kill" )
|
||||
sh( "ps aux | grep ssh |grep Banner| awk '{ print $2 }' | xargs kill" )
|
||||
cleanup()
|
||||
# remove public key pair
|
||||
sh( 'rm -rf /tmp/ssh' )
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests for bind.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testBind( unittest.TestCase ):
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ A simple sanity check test for cluster edition
|
||||
'''
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class clusterSanityCheck( unittest.TestCase ):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@ Tests for controllers.py and controllers2.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testControllers( unittest.TestCase ):
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ Test for controlnet.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
from sys import stdout
|
||||
|
||||
class testControlNet( unittest.TestCase ):
|
||||
|
||||
@@ -13,7 +15,7 @@ class testControlNet( unittest.TestCase ):
|
||||
|
||||
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
-12
@@ -5,18 +5,17 @@ Test for cpu.py
|
||||
|
||||
results format:
|
||||
|
||||
sched cpu client MB/s
|
||||
|
||||
cfs 45.00% 13254.669841
|
||||
cfs 40.00% 11822.441399
|
||||
cfs 30.00% 5112.963009
|
||||
cfs 20.00% 3449.090009
|
||||
cfs 10.00% 2271.741564
|
||||
sched cpu received bits/sec
|
||||
cfs 50% 8.14e+09
|
||||
cfs 40% 6.48e+09
|
||||
cfs 30% 4.56e+09
|
||||
cfs 20% 2.84e+09
|
||||
cfs 10% 1.29e+09
|
||||
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
|
||||
class testCPU( unittest.TestCase ):
|
||||
@@ -26,13 +25,13 @@ class testCPU( unittest.TestCase ):
|
||||
@unittest.skipIf( '-quick' in sys.argv, 'long test' )
|
||||
def testCPU( self ):
|
||||
"Verify that CPU utilization is monotonically decreasing for each scheduler"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.cpu' )
|
||||
p = pexpect.spawn( 'python -m mininet.examples.cpu', timeout=300 )
|
||||
# matches each line from results( shown above )
|
||||
opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)',
|
||||
opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.e\+]+)',
|
||||
pexpect.EOF ]
|
||||
scheds = []
|
||||
while True:
|
||||
index = p.expect( opts, timeout=600 )
|
||||
index = p.expect( opts )
|
||||
if index == 0:
|
||||
sched = p.match.group( 1 )
|
||||
cpu = float( p.match.group( 2 ) )
|
||||
@@ -40,7 +39,9 @@ class testCPU( unittest.TestCase ):
|
||||
if sched not in scheds:
|
||||
scheds.append( sched )
|
||||
else:
|
||||
self.assertTrue( bw < previous_bw )
|
||||
self.assertTrue( bw < previous_bw,
|
||||
"%e should be less than %e\n" %
|
||||
( bw, previous_bw ) )
|
||||
previous_bw = bw
|
||||
else:
|
||||
break
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for emptynet.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testEmptyNet( unittest.TestCase ):
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Test for hwintf.py
|
||||
import unittest
|
||||
import re
|
||||
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.node import Node
|
||||
@@ -57,8 +57,8 @@ class testHwintf( unittest.TestCase ):
|
||||
p.wait()
|
||||
|
||||
def tearDown( self ):
|
||||
self.h3.terminate()
|
||||
self.n0.terminate()
|
||||
self.h3.stop( deleteIntfs=True )
|
||||
self.n0.stop( deleteIntfs=True )
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for intfOptions.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
|
||||
class testIntfOptions( unittest.TestCase ):
|
||||
@@ -13,27 +13,31 @@ class testIntfOptions( unittest.TestCase ):
|
||||
def testIntfOptions( self ):
|
||||
"verify that intf.config is correctly limiting traffic"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.intfoptions ' )
|
||||
tolerance = .8
|
||||
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), rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
|
||||
"h(\d+)->h(\d+): (\d)/(\d),"
|
||||
"rtt min/avg/max/mdev ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms",
|
||||
pexpect.EOF ]
|
||||
while True:
|
||||
index = p.expect( opts, timeout=600 )
|
||||
if index == 0:
|
||||
BW = 10
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertGreaterEqual( bw, float( 5 * tolerance ) )
|
||||
self.assertLessEqual( bw, float( 5 + 5 * ( 1 - tolerance ) ) )
|
||||
self.assertGreaterEqual( bw, BW * ( 1 - tolerance ) )
|
||||
self.assertLessEqual( bw, BW * ( 1 + tolerance ) )
|
||||
elif index == 1:
|
||||
BW = 10
|
||||
measuredBw = float( p.match.group( 1 ) )
|
||||
loss = ( measuredBw / BW ) * 100
|
||||
self.assertGreaterEqual( loss, 50 * tolerance )
|
||||
self.assertLessEqual( loss, 50 + 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 * tolerance )
|
||||
self.assertLessEqual( delay, 15 + 15 * ( 1 - tolerance ) )
|
||||
self.assertGreaterEqual( delay, 15 * ( 1 - tolerance ) )
|
||||
self.assertLessEqual( delay, 15 * ( 1 + tolerance ) )
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for limit.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
|
||||
class testLimit( unittest.TestCase ):
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for linearbandwidth.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
|
||||
class testLinearBandwidth( unittest.TestCase ):
|
||||
@@ -34,8 +34,8 @@ class testLinearBandwidth( unittest.TestCase ):
|
||||
bw *= 10 ** 9
|
||||
# check that we have a previous result to compare to
|
||||
if n != 1:
|
||||
info = ( 'bw: %d bits/s across %d switches, '
|
||||
'previous: %d bits/s across %d switches' %
|
||||
info = ( 'bw: %.2e bits/s across %d switches, '
|
||||
'previous: %.2e bits/s across %d switches' %
|
||||
( bw, n, previous_bw, previous_n ) )
|
||||
self.assertTrue( bw < previous_bw, info )
|
||||
previous_bw, previous_n = bw, n
|
||||
|
||||
Regular → Executable
+1
-1
@@ -5,7 +5,7 @@ Test for linuxrouter.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from mininet.util import quietRun
|
||||
|
||||
class testLinuxRouter( unittest.TestCase ):
|
||||
|
||||
@@ -6,7 +6,7 @@ validates mininet interfaces against systems interfaces
|
||||
'''
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testMultiLink( unittest.TestCase ):
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for multiping.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from collections import defaultdict
|
||||
|
||||
class testMultiPing( unittest.TestCase ):
|
||||
@@ -31,18 +31,20 @@ class testMultiPing( unittest.TestCase ):
|
||||
target = p.match.group(3)
|
||||
received = int( p.match.group(4) )
|
||||
if target == '10.0.0.200':
|
||||
self.assertEqual( received, 0 )
|
||||
self.assertEqual( received, 0, p.match.group(0) + '\n' +
|
||||
target + ' received %d != 0 packets' % received )
|
||||
else:
|
||||
self.assertEqual( received, 1 )
|
||||
self.assertEqual( received, 1, p.match.group(0) + '\n' +
|
||||
target + ' received %d != 1 packets' % received )
|
||||
try:
|
||||
pings[ name ].remove( target )
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
self.assertTrue( len( pings ) > 0 )
|
||||
self.assertTrue( len( pings ) > 0, 'too few pings' )
|
||||
for t in pings.values():
|
||||
self.assertEqual( len( t ), 0 )
|
||||
self.assertEqual( len( t ), 0, 'missed ping target(s): %s' % t )
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for multipoll.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testMultiPoll( unittest.TestCase ):
|
||||
|
||||
@@ -16,7 +16,7 @@ class testMultiPoll( unittest.TestCase ):
|
||||
"(h\d+): \d+ bytes from",
|
||||
"Monitoring output for (\d+) seconds",
|
||||
pexpect.EOF ]
|
||||
pings = {}
|
||||
pings, seconds = {}, -1
|
||||
while True:
|
||||
index = p.expect( opts )
|
||||
if index == 0:
|
||||
@@ -32,7 +32,8 @@ class testMultiPoll( unittest.TestCase ):
|
||||
self.assertTrue( len( pings ) > 0 )
|
||||
# make sure we have received at least one ping per second
|
||||
for count in pings.values():
|
||||
self.assertTrue( count >= seconds )
|
||||
self.assertTrue( count >= seconds,
|
||||
'%d pings < %d seconds' % ( count, seconds ) )
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for multitest.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testMultiTest( unittest.TestCase ):
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for nat.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from mininet.util import quietRun
|
||||
|
||||
destIP = '8.8.8.8' # Google DNS
|
||||
|
||||
Regular → Executable
+1
-1
@@ -5,7 +5,7 @@ Test for natnet.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from mininet.util import quietRun
|
||||
|
||||
class testNATNet( unittest.TestCase ):
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for numberedports.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from collections import defaultdict
|
||||
from mininet.node import OVSSwitch
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for popen.py and popenpoll.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testPopen( unittest.TestCase ):
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for scratchnet.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
|
||||
class testScratchNet( unittest.TestCase ):
|
||||
|
||||
@@ -14,8 +14,9 @@ class testScratchNet( unittest.TestCase ):
|
||||
def pingTest( self, name ):
|
||||
"Verify that no ping packets were dropped"
|
||||
p = pexpect.spawn( 'python -m %s' % name )
|
||||
index = p.expect( self.opts )
|
||||
index = p.expect( self.opts, timeout=120 )
|
||||
self.assertEqual( index, 0 )
|
||||
p.wait()
|
||||
|
||||
def testPingKernel( self ):
|
||||
self.pingTest( 'mininet.examples.scratchnet' )
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for simpleperf.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
from mininet.log import setLogLevel
|
||||
|
||||
@@ -16,19 +16,22 @@ class testSimplePerf( unittest.TestCase ):
|
||||
@unittest.skipIf( '-quick' in sys.argv, 'long test' )
|
||||
def testE2E( self ):
|
||||
"Run the example and verify iperf results"
|
||||
# 10 Mb/s, plus or minus 20% tolerance
|
||||
BW = 10
|
||||
TOLERANCE = .8
|
||||
expectedBw = BW * TOLERANCE
|
||||
p = pexpect.spawn( 'python -m mininet.examples.simpleperf' )
|
||||
TOLERANCE = .2
|
||||
p = pexpect.spawn(
|
||||
'python -m mininet.examples.simpleperf testmode' )
|
||||
# Log since this seems to be failing intermittently
|
||||
p.logfile = sys.stdout
|
||||
# check iperf results
|
||||
p.expect( "Results: \['10M', '([\d\.]+) .bits/sec", timeout=480 )
|
||||
p.expect( "Results: \['10M', '([\d\.]+) .bits/sec", timeout=90 )
|
||||
measuredBw = float( p.match.group( 1 ) )
|
||||
lowerBound = expectedBw * TOLERANCE
|
||||
upperBound = expectedBw + expectedBw * ( 1 - TOLERANCE )
|
||||
lowerBound = BW * ( 1 - TOLERANCE )
|
||||
upperBound = BW + ( 1 + TOLERANCE )
|
||||
self.assertGreaterEqual( measuredBw, lowerBound )
|
||||
self.assertLessEqual( measuredBw, upperBound )
|
||||
p.wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
setLogLevel( 'debug' )
|
||||
unittest.main()
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for sshd.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
from mininet.clean import sh
|
||||
|
||||
class testSSHD( unittest.TestCase ):
|
||||
@@ -16,11 +16,12 @@ 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:
|
||||
print p.match.group(0)
|
||||
print( p.match.group(0) )
|
||||
p.sendline( 'yes' )
|
||||
elif index == 1:
|
||||
return False
|
||||
@@ -57,4 +58,3 @@ class testSSHD( unittest.TestCase ):
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for tree1024.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
|
||||
class testTree1024( unittest.TestCase ):
|
||||
@@ -17,13 +17,15 @@ class testTree1024( unittest.TestCase ):
|
||||
"Run the example and do a simple ping test from h1 to h1024"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.tree1024' )
|
||||
p.expect( self.prompt, timeout=6000 ) # it takes awhile to set up
|
||||
p.sendline( 'h1 ping -c 1 h1024' )
|
||||
p.sendline( 'h1 ping -c 20 h1024' )
|
||||
p.expect ( '(\d+)% packet loss' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
packetLossPercent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( percent, 0 )
|
||||
# Tolerate slow startup on some systems - we should revisit this
|
||||
# and determine the root cause.
|
||||
self.assertLess( packetLossPercent, 60 )
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
@@ -5,7 +5,7 @@ Test for treeping64.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
|
||||
class testTreePing64( unittest.TestCase ):
|
||||
|
||||
Regular → Executable
+1
-1
@@ -5,7 +5,7 @@ Test for vlanhost.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import pexpect
|
||||
import sys
|
||||
from mininet.util import quietRun
|
||||
|
||||
|
||||
@@ -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 )
|
||||
|
||||
+25
-14
@@ -1,31 +1,42 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/env python
|
||||
|
||||
"Create a 64-node tree network, and test connectivity using ping."
|
||||
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch # , KernelSwitch
|
||||
|
||||
from mininet.log import setLogLevel, info
|
||||
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:
|
||||
print "*** Testing", name, "datapath"
|
||||
switch = switches[ name ]
|
||||
network = TreeNet( depth=2, fanout=8, switch=switch )
|
||||
for name, switch in switches.items():
|
||||
info( "*** Testing", name, "datapath\n" )
|
||||
network = TreeNet( depth=2, fanout=8, switch=switch,
|
||||
waitConnected=True )
|
||||
result = network.run( network.pingAll )
|
||||
results[ name ] = result
|
||||
|
||||
print
|
||||
print "*** Tree network ping results:"
|
||||
info( "\n*** Tree network ping results:\n" )
|
||||
for name in switches:
|
||||
print "%s: %d%% packet loss" % ( name, results[ name ] )
|
||||
print
|
||||
info( "%s: %d%% packet loss\n" % ( name, results[ name ] ) )
|
||||
info( '\n' )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
|
||||
@@ -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
|
||||
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../bin/mn
|
||||
+9
-6
@@ -16,12 +16,15 @@ import time
|
||||
|
||||
from mininet.log import info
|
||||
from mininet.term import cleanUpScreens
|
||||
|
||||
from mininet.util import decode
|
||||
|
||||
def sh( cmd ):
|
||||
"Print a command and send it to the shell"
|
||||
info( cmd + '\n' )
|
||||
return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
|
||||
p = Popen( # pylint: disable=consider-using-with
|
||||
[ '/bin/sh', '-c', cmd ], stdout=PIPE )
|
||||
result = p.communicate()[ 0 ]
|
||||
return decode( result )
|
||||
|
||||
def killprocs( pattern ):
|
||||
"Reliably terminate processes matching a pattern (including args)"
|
||||
@@ -50,8 +53,9 @@ class Cleanup( object ):
|
||||
|
||||
info( "*** Removing excess controllers/ofprotocols/ofdatapaths/"
|
||||
"pings/noxes\n" )
|
||||
zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core '
|
||||
zombies += 'ovs-openflowd ovs-controller udpbwtest mnexec ivs'
|
||||
zombies = ( 'controller ofprotocol ofdatapath ping nox_core '
|
||||
'lt-nox_core ovs-openflowd ovs-controller '
|
||||
'ovs-testcontroller udpbwtest mnexec ivs ryu-manager ' )
|
||||
# Note: real zombie processes can't actually be killed, since they
|
||||
# are already (un)dead. Then again,
|
||||
# you can't connect to them either, so they're mostly harmless.
|
||||
@@ -75,7 +79,6 @@ class Cleanup( object ):
|
||||
for dp in dps:
|
||||
if dp:
|
||||
sh( 'dpctl deldp ' + dp )
|
||||
|
||||
info( "*** Removing OVS datapaths\n" )
|
||||
dps = sh("ovs-vsctl --timeout=1 list-br").strip().splitlines()
|
||||
if dps:
|
||||
@@ -92,7 +95,7 @@ class Cleanup( object ):
|
||||
).splitlines()
|
||||
# Delete blocks of links
|
||||
n = 1000 # chunk size
|
||||
for i in xrange( 0, len( links ), n ):
|
||||
for i in range( 0, len( links ), n ):
|
||||
cmd = ';'.join( 'ip link del %s' % link
|
||||
for link in links[ i : i + n ] )
|
||||
sh( '( %s ) 2> /dev/null' % cmd )
|
||||
|
||||
+88
-34
@@ -29,6 +29,8 @@ from subprocess import call
|
||||
from cmd import Cmd
|
||||
from os import isatty
|
||||
from select import poll, POLLIN
|
||||
import select
|
||||
import errno
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
@@ -44,45 +46,81 @@ 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
|
||||
script: script to run in batch mode"""
|
||||
self.mn = mininet
|
||||
# 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' )
|
||||
|
||||
# Set up history if readline is available
|
||||
try:
|
||||
import readline
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
history_path = os.path.expanduser('~/.mininet_history')
|
||||
if os.path.isfile(history_path):
|
||||
readline.read_history_file(history_path)
|
||||
atexit.register(lambda: readline.write_history_file(history_path))
|
||||
|
||||
if self.inputFile:
|
||||
self.do_source( self.inputFile )
|
||||
return
|
||||
|
||||
self.initReadline()
|
||||
self.run()
|
||||
|
||||
readlineInited = False
|
||||
|
||||
@classmethod
|
||||
def initReadline( cls ):
|
||||
"Set up history if readline is available"
|
||||
# Only set up readline once to prevent multiplying the history file
|
||||
if cls.readlineInited:
|
||||
return
|
||||
cls.readlineInited = True
|
||||
try:
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from readline import ( read_history_file, write_history_file,
|
||||
set_history_length )
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
history_path = os.path.expanduser( '~/.mininet_history' )
|
||||
if os.path.isfile( history_path ):
|
||||
read_history_file( history_path )
|
||||
set_history_length( 1000 )
|
||||
|
||||
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"
|
||||
while True:
|
||||
try:
|
||||
# Make sure no nodes are still waiting
|
||||
for node in self.mn.values():
|
||||
while node.waiting:
|
||||
info( 'stopping', node, '\n' )
|
||||
node.sendInt()
|
||||
node.waitOutput()
|
||||
if self.isatty():
|
||||
quietRun( 'stty echo sane intr "^C"' )
|
||||
quietRun( 'stty echo sane intr ^C' )
|
||||
self.cmdloop()
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
output( '\nInterrupt\n' )
|
||||
# Output a message - unless it's also interrupted
|
||||
# pylint: disable=broad-except
|
||||
try:
|
||||
output( '\nInterrupt\n' )
|
||||
except Exception:
|
||||
pass
|
||||
# pylint: enable=broad-except
|
||||
|
||||
def emptyline( self ):
|
||||
"Don't repeat last command when you hit return."
|
||||
@@ -112,10 +150,10 @@ class CLI( Cmd ):
|
||||
' mininet> xterm h2\n\n'
|
||||
)
|
||||
|
||||
def do_help( self, line ):
|
||||
def do_help( self, line ): # pylint: disable=arguments-renamed
|
||||
"Describe available CLI commands."
|
||||
Cmd.do_help( self, line )
|
||||
if line is '':
|
||||
if line == '':
|
||||
output( self.helpStr )
|
||||
|
||||
def do_nodes( self, _line ):
|
||||
@@ -144,14 +182,15 @@ 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:
|
||||
if result is None:
|
||||
return
|
||||
elif isinstance( result, str ):
|
||||
output( result + '\n' )
|
||||
else:
|
||||
output( repr( result ) + '\n' )
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
output( str( e ) + '\n' )
|
||||
|
||||
# We are in fact using the exec() pseudo-function
|
||||
@@ -162,7 +201,7 @@ class CLI( Cmd ):
|
||||
Node names may be used, e.g.: px print h1.cmd('ls')"""
|
||||
try:
|
||||
exec( line, globals(), self.getLocals() )
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
output( str( e ) + '\n' )
|
||||
|
||||
# pylint: enable=broad-except,exec-used
|
||||
@@ -313,13 +352,13 @@ class CLI( Cmd ):
|
||||
error( 'usage: source <file>\n' )
|
||||
return
|
||||
try:
|
||||
self.inputFile = open( args[ 0 ] )
|
||||
while True:
|
||||
line = self.inputFile.readline()
|
||||
if len( line ) > 0:
|
||||
self.onecmd( line )
|
||||
else:
|
||||
break
|
||||
with open( args[ 0 ] ) as self.inputFile:
|
||||
while True:
|
||||
line = self.inputFile.readline()
|
||||
if len( line ) > 0:
|
||||
self.onecmd( line )
|
||||
else:
|
||||
break
|
||||
except IOError:
|
||||
error( 'error reading file %s\n' % args[ 0 ] )
|
||||
self.inputFile.close()
|
||||
@@ -346,7 +385,7 @@ class CLI( Cmd ):
|
||||
def do_links( self, _line ):
|
||||
"Report on links"
|
||||
for link in self.mn.links:
|
||||
print link, link.status()
|
||||
output( link, link.status(), '\n' )
|
||||
|
||||
def do_switch( self, line ):
|
||||
"Starts or stops a switch"
|
||||
@@ -370,17 +409,22 @@ 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 CLI argument.
|
||||
Past the first CLI argument, node names are automatically replaced with
|
||||
corresponding IP addrs."""
|
||||
Overridden to run shell commands when a node is the first
|
||||
CLI argument. Past the first CLI argument, node names are
|
||||
automatically replaced with corresponding IP addrs."""
|
||||
|
||||
first, args, line = self.parseline( line )
|
||||
|
||||
if first in self.mn:
|
||||
if not args:
|
||||
print "*** Enter a command for node: %s <cmd>" % first
|
||||
error( '*** Please enter a command for node: %s <cmd>\n'
|
||||
% first )
|
||||
return
|
||||
node = self.mn[ first ]
|
||||
rest = args.split( ' ' )
|
||||
@@ -412,12 +456,14 @@ class CLI( Cmd ):
|
||||
try:
|
||||
bothPoller.poll()
|
||||
# XXX BL: this doesn't quite do what we want.
|
||||
# pylint: disable=condition-evals-to-constant
|
||||
if False and self.inputFile:
|
||||
key = self.inputFile.read( 1 )
|
||||
if key is not '':
|
||||
if key != '':
|
||||
node.write( key )
|
||||
else:
|
||||
self.inputFile = None
|
||||
# pylint: enable=condition-evals-to-constant
|
||||
if isReadable( self.inPoller ):
|
||||
key = self.stdin.read( 1 )
|
||||
node.write( key )
|
||||
@@ -431,6 +477,13 @@ class CLI( Cmd ):
|
||||
# it's possible to interrupt ourselves after we've
|
||||
# read data but before it has been printed.
|
||||
node.sendInt()
|
||||
except select.error as e:
|
||||
# pylint: disable=unpacking-non-sequence
|
||||
# pylint: disable=unbalanced-tuple-unpacking
|
||||
errno_, errmsg = e.args
|
||||
if errno_ != errno.EINTR:
|
||||
error( "select.error: %s, %s" % (errno_, errmsg) )
|
||||
node.sendInt()
|
||||
|
||||
def precmd( self, line ):
|
||||
"allow for comments in the cli"
|
||||
@@ -447,3 +500,4 @@ def isReadable( poller ):
|
||||
mask = fdmask[ 1 ]
|
||||
if mask & POLLIN:
|
||||
return True
|
||||
return False
|
||||
|
||||
+99
-51
@@ -24,10 +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 mininet.node
|
||||
import re
|
||||
|
||||
# Make pylint happy:
|
||||
# pylint: disable=too-many-arguments
|
||||
|
||||
|
||||
class Intf( object ):
|
||||
|
||||
@@ -49,12 +53,14 @@ class Intf( object ):
|
||||
# This saves an ifconfig command per node
|
||||
if self.name == 'lo':
|
||||
self.ip = '127.0.0.1'
|
||||
self.prefixLen = 8
|
||||
# Add to node (and move ourselves if necessary )
|
||||
moveIntfFn = params.pop( 'moveIntfFn', None )
|
||||
if moveIntfFn:
|
||||
node.addIntf( self, port=port, moveIntfFn=moveIntfFn )
|
||||
else:
|
||||
node.addIntf( self, port=port )
|
||||
if node:
|
||||
moveIntfFn = params.pop( 'moveIntfFn', None )
|
||||
if moveIntfFn:
|
||||
node.addIntf( self, port=port, moveIntfFn=moveIntfFn )
|
||||
else:
|
||||
node.addIntf( self, port=port )
|
||||
# Save params for future reference
|
||||
self.params = params
|
||||
self.config( **params )
|
||||
@@ -145,6 +151,9 @@ class Intf( object ):
|
||||
|
||||
def rename( self, newname ):
|
||||
"Rename interface"
|
||||
if self.node and self.name in self.node.nameToIntf:
|
||||
# rename intf in node's nameToIntf
|
||||
self.node.nameToIntf[newname] = self.node.nameToIntf.pop(self.name)
|
||||
self.ifconfig( 'down' )
|
||||
result = self.cmd( 'ip link set', self.name, 'name', newname )
|
||||
self.name = newname
|
||||
@@ -163,10 +172,10 @@ class Intf( object ):
|
||||
method: config method name
|
||||
param: arg=value (ignore if value=None)
|
||||
value may also be list or dict"""
|
||||
name, value = param.items()[ 0 ]
|
||||
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 ):
|
||||
@@ -201,6 +210,8 @@ class Intf( object ):
|
||||
# if self.node.inNamespace:
|
||||
# Link may have been dumped into root NS
|
||||
# quietRun( 'ip link del ' + self.name )
|
||||
self.node.delIntf( self )
|
||||
self.link = None
|
||||
|
||||
def status( self ):
|
||||
"Return intf status as a string"
|
||||
@@ -250,7 +261,7 @@ class TCIntf( Intf ):
|
||||
+ 'rate %fMbit ul rate %fMbit' % ( bw, bw ) ]
|
||||
elif use_tbf:
|
||||
if latency_ms is None:
|
||||
latency_ms = 15 * 8 / bw
|
||||
latency_ms = 15.0 * 8 / bw
|
||||
cmds += [ '%s qdisc add dev %s root handle 5: tbf ' +
|
||||
'rate %fMbit burst 15000 latency %fms' %
|
||||
( bw, latency_ms ) ]
|
||||
@@ -282,18 +293,14 @@ class TCIntf( Intf ):
|
||||
loss=None, max_queue_size=None ):
|
||||
"Internal method: return tc commands for delay and loss"
|
||||
cmds = []
|
||||
if delay and delay < 0:
|
||||
error( 'Negative delay', delay, '\n' )
|
||||
elif jitter and jitter < 0:
|
||||
error( 'Negative jitter', jitter, '\n' )
|
||||
elif loss and ( loss < 0 or loss > 100 ):
|
||||
if loss and ( loss < 0 or loss > 100 ):
|
||||
error( 'Bad loss percentage', loss, '%%\n' )
|
||||
else:
|
||||
# Delay/jitter/loss/max queue size
|
||||
netemargs = '%s%s%s%s' % (
|
||||
'delay %s ' % delay if delay is not None else '',
|
||||
'%s ' % jitter if jitter is not None else '',
|
||||
'loss %d ' % 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:
|
||||
@@ -309,27 +316,53 @@ class TCIntf( Intf ):
|
||||
debug(" *** executing command: %s\n" % c)
|
||||
return self.cmd( c )
|
||||
|
||||
def config( self, bw=None, delay=None, jitter=None, loss=None,
|
||||
disable_gro=True, speedup=0, use_hfsc=False, use_tbf=False,
|
||||
def config( # pylint: disable=arguments-renamed,arguments-differ
|
||||
self,
|
||||
bw=None, delay=None, jitter=None, loss=None,
|
||||
gro=False, txo=True, rxo=True,
|
||||
speedup=0, use_hfsc=False, use_tbf=False,
|
||||
latency_ms=None, enable_ecn=False, enable_red=False,
|
||||
max_queue_size=None, **params ):
|
||||
"Configure the port and set its properties."
|
||||
"""Configure the port and set its properties.
|
||||
bw: bandwidth in b/s (e.g. '10m')
|
||||
delay: transmit delay (e.g. '1ms' )
|
||||
jitter: jitter (e.g. '1ms')
|
||||
loss: loss (e.g. '1%' )
|
||||
gro: enable GRO (False)
|
||||
txo: enable transmit checksum offload (True)
|
||||
rxo: enable receive checksum offload (True)
|
||||
speedup: experimental switch-side bw option
|
||||
use_hfsc: use HFSC scheduling
|
||||
use_tbf: use TBF scheduling
|
||||
latency_ms: TBF latency parameter
|
||||
enable_ecn: enable ECN (False)
|
||||
enable_red: enable RED (False)
|
||||
max_queue_size: queue limit parameter for netem"""
|
||||
|
||||
# Support old names for parameters
|
||||
gro = not params.pop( 'disable_gro', not gro )
|
||||
|
||||
result = Intf.config( self, **params)
|
||||
|
||||
# Disable GRO
|
||||
if disable_gro:
|
||||
self.cmd( 'ethtool -K %s gro off' % self )
|
||||
def on( isOn ):
|
||||
"Helper method: bool -> 'on'/'off'"
|
||||
return 'on' if isOn else 'off'
|
||||
|
||||
# Set offload parameters with ethool
|
||||
self.cmd( 'ethtool -K', self,
|
||||
'gro', on( gro ),
|
||||
'tx', on( txo ),
|
||||
'rx', on( rxo ) )
|
||||
|
||||
# Optimization: return if nothing else to configure
|
||||
# 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' )
|
||||
if "priomap" not in tcoutput:
|
||||
if "priomap" not in tcoutput and "noqueue" not in tcoutput:
|
||||
cmds = [ '%s qdisc del dev %s root' ]
|
||||
else:
|
||||
cmds = []
|
||||
@@ -353,7 +386,7 @@ class TCIntf( Intf ):
|
||||
stuff = ( ( [ '%.2fMbit' % bw ] if bw is not None else [] ) +
|
||||
( [ '%s delay' % delay ] if delay is not None else [] ) +
|
||||
( [ '%s jitter' % jitter ] if jitter is not None else [] ) +
|
||||
( ['%d%% loss' % loss ] if loss is not None else [] ) +
|
||||
( ['%.5f%% loss' % loss ] if loss is not None else [] ) +
|
||||
( [ 'ECN' ] if enable_ecn else [ 'RED' ]
|
||||
if enable_red else [] ) )
|
||||
info( '(' + ' '.join( stuff ) + ') ' )
|
||||
@@ -381,7 +414,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
|
||||
@@ -391,18 +424,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:
|
||||
@@ -416,6 +446,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 )
|
||||
@@ -437,6 +471,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
|
||||
@@ -470,9 +505,9 @@ class Link( object ):
|
||||
def delete( self ):
|
||||
"Delete this link"
|
||||
self.intf1.delete()
|
||||
# We only need to delete one side, though this doesn't seem to
|
||||
# cost us much and might help subclasses.
|
||||
# self.intf2.delete()
|
||||
self.intf1 = None
|
||||
self.intf2.delete()
|
||||
self.intf2 = None
|
||||
|
||||
def stop( self ):
|
||||
"Override to stop and clean up link as needed"
|
||||
@@ -505,13 +540,17 @@ class OVSLink( Link ):
|
||||
|
||||
def __init__( self, node1, node2, **kwargs ):
|
||||
"See Link.__init__() for options"
|
||||
if 'OVSSwitch' not in globals():
|
||||
# pylint: disable=import-outside-toplevel,cyclic-import
|
||||
from mininet.node import OVSSwitch
|
||||
self.isPatchLink = False
|
||||
if ( isinstance( node1, mininet.node.OVSSwitch ) and
|
||||
isinstance( node2, mininet.node.OVSSwitch ) ):
|
||||
if ( isinstance( node1, OVSSwitch ) and
|
||||
isinstance( node2, OVSSwitch ) ):
|
||||
self.isPatchLink = True
|
||||
kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
|
||||
Link.__init__( self, node1, node2, **kwargs )
|
||||
|
||||
# pylint: disable=arguments-renamed, arguments-differ, signature-differs
|
||||
def makeIntfPair( self, *args, **kwargs ):
|
||||
"Usually delegated to OVSSwitch"
|
||||
if self.isPatchLink:
|
||||
@@ -521,14 +560,23 @@ 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 ):
|
||||
"""TCLink with default settings optimized for UserSwitch
|
||||
(txo=rxo=0/False). Unfortunately with recent Linux kernels,
|
||||
enabling TX and RX checksum offload on veth pairs doesn't work
|
||||
well with UserSwitch: either it gets terrible performance or
|
||||
TCP packets with bad checksums are generated, forwarded, and
|
||||
*dropped* due to having bad checksums! OVS and LinuxBridge seem
|
||||
to cope with this somehow, but it is likely to be an issue with
|
||||
many software Ethernet bridges."""
|
||||
|
||||
def __init__( self, *args, **kwargs ):
|
||||
kwargs.update( txo=False, rxo=False )
|
||||
TCLink.__init__( self, *args, **kwargs )
|
||||
|
||||
+24
-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' )
|
||||
@@ -160,7 +151,7 @@ def makeListCompatible( fn ):
|
||||
"Generated function. Closure-ish."
|
||||
if len( args ) == 1:
|
||||
return fn( *args )
|
||||
args = ' '.join( [ str( arg ) for arg in args ] )
|
||||
args = ' '.join( str( arg ) for arg in args )
|
||||
return fn( args )
|
||||
|
||||
# Fix newfn's name and docstring
|
||||
@@ -168,9 +159,14 @@ def makeListCompatible( fn ):
|
||||
setattr( newfn, '__doc__', fn.__doc__ )
|
||||
return newfn
|
||||
|
||||
info, output, warn, error, debug = (
|
||||
lg.info, lg.output, lg.warn, lg.error, lg.debug ) = [
|
||||
makeListCompatible( f ) for f in
|
||||
lg.info, lg.output, lg.warn, lg.error, lg.debug ]
|
||||
|
||||
# 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 mininet.util import quietRun
|
||||
from mininet.log import info, error, debug
|
||||
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
|
||||
|
||||
|
||||
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'
|
||||
@@ -28,9 +32,9 @@ def moduleDeps( subtract=None, add=None ):
|
||||
add: string or list of module names to add, if not already loaded"""
|
||||
subtract = subtract if subtract is not None else []
|
||||
add = add if add is not None else []
|
||||
if isinstance( subtract, basestring ):
|
||||
if isinstance( subtract, BaseString ):
|
||||
subtract = [ subtract ]
|
||||
if isinstance( add, basestring ):
|
||||
if isinstance( add, BaseString ):
|
||||
add = [ add ]
|
||||
for mod in subtract:
|
||||
if mod in lsmod():
|
||||
|
||||
+137
-51
@@ -92,27 +92,29 @@ 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
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import info, error, debug, output, warn
|
||||
from mininet.log import info, error, output, warn, debug
|
||||
from mininet.node import ( Node, Host, OVSKernelSwitch, DefaultController,
|
||||
Controller )
|
||||
from mininet.nodelib import NAT
|
||||
from mininet.link import Link, Intf
|
||||
from mininet.util import ( quietRun, fixLimits, numCores, ensureRoot,
|
||||
macColonHex, ipStr, ipParse, netParse, ipAdd,
|
||||
waitListening )
|
||||
waitListening, BaseString, fmtBps )
|
||||
from mininet.term import cleanUpScreens, makeTerms
|
||||
|
||||
# Mininet version: should be consistent with README and LICENSE
|
||||
VERSION = "2.2.1d1"
|
||||
VERSION = "2.3.1b4"
|
||||
|
||||
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
|
||||
@@ -144,7 +148,9 @@ class Mininet( object ):
|
||||
self.intf = intf
|
||||
self.ipBase = ipBase
|
||||
self.ipBaseNum, self.prefixLen = netParse( self.ipBase )
|
||||
self.nextIP = 1 # start for address allocation
|
||||
hostIP = ( 0xffffffff >> self.prefixLen ) & self.ipBaseNum
|
||||
# Start for address allocation
|
||||
self.nextIP = hostIP if hostIP > 0 else 1
|
||||
self.inNamespace = inNamespace
|
||||
self.xterms = xterms
|
||||
self.cleanup = cleanup
|
||||
@@ -172,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():
|
||||
@@ -188,12 +196,12 @@ class Mininet( object ):
|
||||
if not remaining:
|
||||
info( '\n' )
|
||||
return True
|
||||
if time > timeout and timeout is not None:
|
||||
if timeout is not None and time >= timeout:
|
||||
break
|
||||
sleep( delay )
|
||||
time += delay
|
||||
warn( 'Timed out after %d seconds\n' % time )
|
||||
for switch in remaining:
|
||||
for switch in remaining.copy():
|
||||
if not switch.connected():
|
||||
warn( 'Warning: %s is not connected to a controller\n'
|
||||
% switch.name )
|
||||
@@ -226,6 +234,24 @@ class Mininet( object ):
|
||||
self.nameToNode[ name ] = h
|
||||
return h
|
||||
|
||||
def delNode( self, node, nodes=None):
|
||||
"""Delete node
|
||||
node: node to delete
|
||||
nodes: optional list to delete from (e.g. self.hosts)"""
|
||||
if nodes is None:
|
||||
nodes = ( self.hosts if node in self.hosts else
|
||||
( self.switches if node in self.switches else
|
||||
( self.controllers if node in self.controllers else
|
||||
[] ) ) )
|
||||
node.stop( deleteIntfs=True )
|
||||
node.terminate()
|
||||
nodes.remove( node )
|
||||
del self.nameToNode[ node.name ]
|
||||
|
||||
def delHost( self, host ):
|
||||
"Delete a host"
|
||||
self.delNode( host, nodes=self.hosts )
|
||||
|
||||
def addSwitch( self, name, cls=None, **params ):
|
||||
"""Add switch.
|
||||
name: name of switch to add
|
||||
@@ -244,6 +270,10 @@ class Mininet( object ):
|
||||
self.nameToNode[ name ] = sw
|
||||
return sw
|
||||
|
||||
def delSwitch( self, switch ):
|
||||
"Delete a switch"
|
||||
self.delNode( switch, nodes=self.switches )
|
||||
|
||||
def addController( self, name='c0', controller=None, **params ):
|
||||
"""Add controller.
|
||||
controller: Controller class"""
|
||||
@@ -265,6 +295,12 @@ class Mininet( object ):
|
||||
self.nameToNode[ name ] = controller_new
|
||||
return controller_new
|
||||
|
||||
def delController( self, controller ):
|
||||
"""Delete a controller
|
||||
Warning - does not reconfigure switches, so they
|
||||
may still attempt to connect to it!"""
|
||||
self.delNode( controller )
|
||||
|
||||
def addNAT( self, name='nat0', connect=True, inNamespace=False,
|
||||
**params):
|
||||
"""Add a NAT to the Mininet network
|
||||
@@ -281,7 +317,7 @@ class Mininet( object ):
|
||||
# Use first switch if not specified
|
||||
connect = self.switches[ 0 ]
|
||||
# Connect the nat to the switch
|
||||
self.addLink( nat, self.switches[ 0 ] )
|
||||
self.addLink( nat, connect )
|
||||
# Set the default route on hosts
|
||||
natIP = nat.params[ 'ip' ].split('/')[ 0 ]
|
||||
for host in self.hosts:
|
||||
@@ -303,9 +339,13 @@ class Mininet( object ):
|
||||
|
||||
# Even more convenient syntax for node lookup and iteration
|
||||
def __getitem__( self, key ):
|
||||
"""net [ name ] operator: Return node(s) with given name(s)"""
|
||||
"net[ name ] operator: Return node with given name"
|
||||
return self.nameToNode[ key ]
|
||||
|
||||
def __delitem__( self, key ):
|
||||
"del net[ name ] operator - delete node with given name"
|
||||
self.delNode( self.nameToNode[ key ] )
|
||||
|
||||
def __iter__( self ):
|
||||
"return iterator over node names"
|
||||
for node in chain( self.hosts, self.switches, self.controllers ):
|
||||
@@ -349,14 +389,16 @@ class Mininet( object ):
|
||||
params: additional link params (optional)
|
||||
returns: link object"""
|
||||
# Accept node objects or names
|
||||
node1 = node1 if not isinstance( node1, basestring ) else self[ node1 ]
|
||||
node2 = node2 if not isinstance( node2, basestring ) else self[ node2 ]
|
||||
node1 = node1 if not isinstance( node1, BaseString ) else self[ node1 ]
|
||||
node2 = node2 if not isinstance( node2, BaseString ) else self[ node2 ]
|
||||
options = dict( params )
|
||||
# Port is optional
|
||||
if port1 is not None:
|
||||
options.setdefault( 'port1', port1 )
|
||||
if port2 is not None:
|
||||
options.setdefault( 'port2', port2 )
|
||||
if self.intf is not None:
|
||||
options.setdefault( 'intf', self.intf )
|
||||
# Set default MAC - this should probably be in Link
|
||||
options.setdefault( 'addr1', self.randMac() )
|
||||
options.setdefault( 'addr2', self.randMac() )
|
||||
@@ -365,6 +407,30 @@ class Mininet( object ):
|
||||
self.links.append( link )
|
||||
return link
|
||||
|
||||
def delLink( self, link ):
|
||||
"Remove a link from this network"
|
||||
link.delete()
|
||||
self.links.remove( link )
|
||||
|
||||
def linksBetween( self, node1, node2 ):
|
||||
"Return Links between node1 and node2"
|
||||
return [ link for link in self.links
|
||||
if ( node1, node2 ) in (
|
||||
( link.intf1.node, link.intf2.node ),
|
||||
( link.intf2.node, link.intf1.node ) ) ]
|
||||
|
||||
def delLinkBetween( self, node1, node2, index=0, allLinks=False ):
|
||||
"""Delete link(s) between node1 and node2
|
||||
index: index of link to delete if multiple links (0)
|
||||
allLinks: ignore index and delete all such links (False)
|
||||
returns: deleted link(s)"""
|
||||
links = self.linksBetween( node1, node2 )
|
||||
if not allLinks:
|
||||
links = [ links[ index ] ]
|
||||
for link in links:
|
||||
self.delLink( link )
|
||||
return links
|
||||
|
||||
def configHosts( self ):
|
||||
"Configure a set of hosts."
|
||||
for host in self.hosts:
|
||||
@@ -377,7 +443,7 @@ class Mininet( object ):
|
||||
host.configDefault( ip=None, mac=None )
|
||||
# You're low priority, dude!
|
||||
# BL: do we want to do this here or not?
|
||||
# May not make sense if we have CPU lmiting...
|
||||
# May not make sense if we have CPU limiting...
|
||||
# quietRun( 'renice +18 -p ' + repr( host.pid ) )
|
||||
# This may not be the right place to do this, but
|
||||
# it needs to be done somewhere.
|
||||
@@ -402,7 +468,7 @@ class Mininet( object ):
|
||||
if not isinstance( classes, list ):
|
||||
classes = [ classes ]
|
||||
for i, cls in enumerate( classes ):
|
||||
# Allow Controller objects because nobody understands currying
|
||||
# Allow Controller objects because nobody understands partial()
|
||||
if isinstance( cls, Controller ):
|
||||
self.addController( cls )
|
||||
else:
|
||||
@@ -489,14 +555,15 @@ class Mininet( object ):
|
||||
switch.start( self.controllers )
|
||||
started = {}
|
||||
for swclass, switches in groupby(
|
||||
sorted( self.switches, key=type ), type ):
|
||||
sorted( self.switches,
|
||||
key=lambda s: str( type( s ) ) ), type ):
|
||||
switches = tuple( switches )
|
||||
if hasattr( swclass, 'batchStartup' ):
|
||||
success = swclass.batchStartup( switches )
|
||||
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"
|
||||
@@ -505,6 +572,10 @@ class Mininet( object ):
|
||||
info( controller.name + ' ' )
|
||||
controller.stop()
|
||||
info( '\n' )
|
||||
# Unlimit cfs hosts to speed up shutdown
|
||||
for h in self.hosts:
|
||||
if hasattr( h, 'unlimit' ):
|
||||
h.unlimit()
|
||||
if self.terms:
|
||||
info( '*** Stopping %i terms\n' % len( self.terms ) )
|
||||
self.stopXterms()
|
||||
@@ -516,7 +587,8 @@ class Mininet( object ):
|
||||
info( '*** Stopping %i switches\n' % len( self.switches ) )
|
||||
stopped = {}
|
||||
for swclass, switches in groupby(
|
||||
sorted( self.switches, key=type ), type ):
|
||||
sorted( self.switches,
|
||||
key=lambda s: str( type( s ) ) ), type ):
|
||||
switches = tuple( switches )
|
||||
if hasattr( swclass, 'batchShutdown' ):
|
||||
success = swclass.batchShutdown( switches )
|
||||
@@ -574,7 +646,7 @@ class Mininet( object ):
|
||||
# Check for downed link
|
||||
if 'connect: Network is unreachable' in pingOutput:
|
||||
return 1, 0
|
||||
r = r'(\d+) packets transmitted, (\d+) received'
|
||||
r = r'(\d+) packets transmitted, (\d+)( packets)? received'
|
||||
m = re.search( r, pingOutput )
|
||||
if m is None:
|
||||
error( '*** Error: could not parse ping output: %s\n' %
|
||||
@@ -603,7 +675,7 @@ class Mininet( object ):
|
||||
if timeout:
|
||||
opts = '-W %s' % timeout
|
||||
if dest.intfs:
|
||||
result = node.cmd( 'ping -c1 %s %s' %
|
||||
result = node.cmd( 'LANG=C ping -c1 %s %s' %
|
||||
(opts, dest.IP()) )
|
||||
sent, received = self._parsePing( result )
|
||||
else:
|
||||
@@ -636,7 +708,7 @@ class Mininet( object ):
|
||||
m = re.search( r, pingOutput )
|
||||
if m is not None:
|
||||
return errorTuple
|
||||
r = r'(\d+) packets transmitted, (\d+) received'
|
||||
r = r'(\d+) packets transmitted, (\d+)( packets)? received'
|
||||
m = re.search( r, pingOutput )
|
||||
if m is None:
|
||||
error( '*** Error: could not parse ping output: %s\n' %
|
||||
@@ -714,18 +786,26 @@ class Mininet( object ):
|
||||
return self.pingFull( hosts=hosts )
|
||||
|
||||
@staticmethod
|
||||
def _parseIperf( iperfOutput ):
|
||||
"""Parse iperf output and return bandwidth.
|
||||
iperfOutput: string
|
||||
returns: result string"""
|
||||
r = r'([\d\.]+ \w+/sec)'
|
||||
m = re.findall( r, iperfOutput )
|
||||
if m:
|
||||
return m[-1]
|
||||
else:
|
||||
# was: raise Exception(...)
|
||||
error( 'could not parse iperf output: ' + iperfOutput )
|
||||
return ''
|
||||
def _iperfVals( iperfcsv, serverip ):
|
||||
"""Return iperf CSV as dict
|
||||
iperfcsv: iperf -y C output
|
||||
serverip: iperf server IP address
|
||||
"""
|
||||
fields = 'date cip cport sip sport ipver interval sent rate'
|
||||
lines = iperfcsv.strip().split('\n')
|
||||
svals = {}
|
||||
for line in lines:
|
||||
if ',' not in line:
|
||||
continue
|
||||
line = line.split( ',' )
|
||||
svals = dict( zip( fields.split(), line ) )
|
||||
# Return client in cip:cport, server in sip:sport
|
||||
if svals[ 'cip' ] == serverip:
|
||||
svals[ 'cip' ], svals[ 'sip' ] = (
|
||||
svals[ 'sip' ], svals[ 'cip' ] )
|
||||
svals[ 'cport' ], svals[ 'sport' ] = (
|
||||
svals[ 'sport' ], svals[ 'cport' ] )
|
||||
return svals
|
||||
|
||||
# XXX This should be cleaned up
|
||||
|
||||
@@ -735,7 +815,7 @@ class Mininet( object ):
|
||||
hosts: list of hosts; if None, uses first and last hosts
|
||||
l4Type: string, one of [ TCP, UDP ]
|
||||
udpBw: bandwidth target for UDP test
|
||||
fmt: iperf format argument if any
|
||||
fmt: scale/format argument (e.g. m/M for Mbps)
|
||||
seconds: iperf time to transmit
|
||||
port: iperf port
|
||||
returns: two-element array of [ server, client ] speeds
|
||||
@@ -748,27 +828,36 @@ class Mininet( object ):
|
||||
output( '*** Iperf: testing', l4Type, 'bandwidth between',
|
||||
client, 'and', server, '\n' )
|
||||
server.cmd( 'killall -9 iperf' )
|
||||
iperfArgs = 'iperf -p %d ' % port
|
||||
# Note: CSV mode
|
||||
iperfArgs = 'iperf -y C -p %d ' % port
|
||||
bwArgs = ''
|
||||
if l4Type == 'UDP':
|
||||
iperfArgs += '-u '
|
||||
bwArgs = '-b ' + udpBw + ' '
|
||||
elif l4Type != 'TCP':
|
||||
raise Exception( 'Unexpected l4 type: %s' % l4Type )
|
||||
if fmt:
|
||||
iperfArgs += '-f %s ' % fmt
|
||||
server.sendCmd( iperfArgs + '-s' )
|
||||
serverip = server.IP()
|
||||
if l4Type == 'TCP':
|
||||
if not waitListening( client, server.IP(), port ):
|
||||
if not waitListening( client, serverip, port ):
|
||||
raise Exception( 'Could not connect to iperf on port %d'
|
||||
% port )
|
||||
cliout = client.cmd( iperfArgs + '-t %d -c ' % seconds +
|
||||
server.IP() + ' ' + bwArgs )
|
||||
debug( 'Client output: %s\n' % cliout )
|
||||
cvals = self._iperfVals( cliout, serverip )
|
||||
debug( 'iperf client output:', cliout, cvals )
|
||||
serverout = ''
|
||||
# Wait for output from the client session
|
||||
while True:
|
||||
serverout += server.monitor( timeoutms=5000 )
|
||||
svals = self._iperfVals( serverout, serverip )
|
||||
# Check for the client's source/output port
|
||||
if ( svals and cvals[ 'sport' ] == svals[ 'sport' ]
|
||||
and int( svals[ 'rate' ] ) > 0 ):
|
||||
break
|
||||
debug( 'iperf server output:', serverout, svals )
|
||||
server.sendInt()
|
||||
servout = server.waitOutput()
|
||||
debug( 'Server output: %s\n' % servout )
|
||||
result = [ self._parseIperf( servout ), self._parseIperf( cliout ) ]
|
||||
serverout += server.waitOutput()
|
||||
result = [ fmtBps( svals[ 'rate'], fmt ),
|
||||
fmtBps( cvals[ 'rate' ], fmt ) ]
|
||||
if l4Type == 'UDP':
|
||||
result.insert( 0, udpBw )
|
||||
output( '*** Results: %s\n' % result )
|
||||
@@ -780,7 +869,6 @@ class Mininet( object ):
|
||||
duration: test duration in seconds (integer)
|
||||
returns a single list of measured CPU fractions as floats.
|
||||
"""
|
||||
cores = int( quietRun( 'nproc' ) )
|
||||
pct = cpu * 100
|
||||
info( '*** Testing CPU %.0f%% bandwidth limit\n' % pct )
|
||||
hosts = self.hosts
|
||||
@@ -832,10 +920,8 @@ class Mininet( object ):
|
||||
elif dst not in self.nameToNode:
|
||||
error( 'dst not in network: %s\n' % dst )
|
||||
else:
|
||||
if isinstance( src, basestring ):
|
||||
src = self.nameToNode[ src ]
|
||||
if isinstance( dst, basestring ):
|
||||
dst = self.nameToNode[ dst ]
|
||||
src = self.nameToNode[ src ]
|
||||
dst = self.nameToNode[ dst ]
|
||||
connections = src.connectionsTo( dst )
|
||||
if len( connections ) == 0:
|
||||
error( 'src and dst not connected: %s %s\n' % ( src, dst) )
|
||||
|
||||
+235
-173
@@ -23,20 +23,26 @@ Switch: superclass for switch nodes.
|
||||
UserSwitch: a switch using the user-space switch from the OpenFlow
|
||||
reference implementation.
|
||||
|
||||
KernelSwitch: a switch using the kernel switch from the OpenFlow reference
|
||||
implementation.
|
||||
|
||||
OVSSwitch: a switch using the OpenVSwitch OpenFlow-compatible switch
|
||||
OVSSwitch: a switch using the Open vSwitch OpenFlow-compatible switch
|
||||
implementation (openvswitch.org).
|
||||
|
||||
OVSBridge: an Ethernet bridge implemented using Open vSwitch.
|
||||
Supports STP.
|
||||
|
||||
IVSSwitch: OpenFlow switch using the Indigo Virtual Switch.
|
||||
|
||||
Controller: superclass for OpenFlow controllers. The default controller
|
||||
is controller(8) from the reference implementation.
|
||||
|
||||
OVSController: The test controller from Open vSwitch.
|
||||
|
||||
NOXController: a controller node using NOX (noxrepo.org).
|
||||
|
||||
Ryu: The Ryu controller (https://osrg.github.io/ryu/)
|
||||
|
||||
RemoteController: a remote controller node, which may use any
|
||||
arbitrary OpenFlow-compatible controller, and which is not
|
||||
created or managed by mininet.
|
||||
created or managed by Mininet.
|
||||
|
||||
Future enhancements:
|
||||
|
||||
@@ -51,16 +57,22 @@ import pty
|
||||
import re
|
||||
import signal
|
||||
import select
|
||||
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 )
|
||||
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
|
||||
numCores, retry, mountCgroups, BaseString, decode,
|
||||
encode, getincrementaldecoder, Python3, which,
|
||||
StrictVersion )
|
||||
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.
|
||||
@@ -81,12 +93,19 @@ class Node( object ):
|
||||
self.privateDirs = params.get( 'privateDirs', [] )
|
||||
self.inNamespace = params.get( 'inNamespace', inNamespace )
|
||||
|
||||
# Python 3 complains if we don't wait for shell exit
|
||||
self.waitExited = params.get( 'waitExited', Python3 )
|
||||
|
||||
# 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 interfaces
|
||||
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
|
||||
@@ -96,7 +115,11 @@ 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()
|
||||
self.mountPrivateDirs()
|
||||
|
||||
@@ -129,14 +152,18 @@ class Node( object ):
|
||||
# -s: pass $* to shell, and make process easy to find in ps
|
||||
# prompt is set to sentinel chr( 127 )
|
||||
cmd = [ 'mnexec', opts, 'env', 'PS1=' + chr( 127 ),
|
||||
'bash', '--norc', '-is', 'mininet:' + self.name ]
|
||||
'bash', '--norc', '--noediting',
|
||||
'-is', 'mininet:' + self.name ]
|
||||
|
||||
# Spawn a shell subprocess in a pseudo-tty, to disable buffering
|
||||
# in the subprocess and insulate it from signals (e.g. SIGINT)
|
||||
# received by the parent
|
||||
master, slave = pty.openpty()
|
||||
self.shell = self._popen( cmd, stdin=slave, stdout=slave, stderr=slave,
|
||||
close_fds=False )
|
||||
self.stdin = os.fdopen( master, 'rw' )
|
||||
self.master, self.slave = pty.openpty()
|
||||
self.shell = self._popen( cmd, stdin=self.slave, stdout=self.slave,
|
||||
stderr=self.slave, close_fds=False )
|
||||
# XXX BL: This doesn't seem right, and we should also probably
|
||||
# close our files when we exit...
|
||||
self.stdin = os.fdopen( self.master, 'r' )
|
||||
self.stdout = self.stdin
|
||||
self.pid = self.shell.pid
|
||||
self.pollOut = select.poll()
|
||||
@@ -162,6 +189,8 @@ class Node( object ):
|
||||
|
||||
def mountPrivateDirs( self ):
|
||||
"mount private directories"
|
||||
# Avoid expanding a string into a list of chars
|
||||
assert not isinstance( self.privateDirs, BaseString )
|
||||
for directory in self.privateDirs:
|
||||
if isinstance( directory, tuple ):
|
||||
# mount given private directory
|
||||
@@ -190,7 +219,9 @@ class Node( object ):
|
||||
params: parameters to Popen()"""
|
||||
# Leave this is as an instance method for now
|
||||
assert self
|
||||
return Popen( cmd, **params )
|
||||
popen = Popen( cmd, **params ) # pylint: disable=consider-using-with
|
||||
debug( '_popen', cmd, popen.pid )
|
||||
return popen
|
||||
|
||||
def cleanup( self ):
|
||||
"Help python collect its garbage."
|
||||
@@ -199,27 +230,34 @@ class Node( object ):
|
||||
# for intfName in self.intfNames():
|
||||
# if self.name in intfName:
|
||||
# quietRun( 'ip link del ' + intfName )
|
||||
if self.shell:
|
||||
# Close ptys
|
||||
self.stdin.close()
|
||||
os.close(self.slave)
|
||||
if self.waitExited:
|
||||
debug( 'waiting for', self.pid, 'to terminate\n' )
|
||||
self.shell.wait()
|
||||
self.shell = None
|
||||
|
||||
# Subshell I/O, commands and control
|
||||
|
||||
def read( self, maxbytes=1024 ):
|
||||
"""Buffered read from node, non-blocking.
|
||||
maxbytes: maximum number of bytes to return"""
|
||||
def read( self, size=1024 ):
|
||||
"""Buffered read from node, potentially blocking.
|
||||
size: maximum number of characters to return"""
|
||||
count = len( self.readbuf )
|
||||
if count < maxbytes:
|
||||
data = 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 ):
|
||||
"""Buffered readline from node, non-blocking.
|
||||
"""Buffered readline from node, potentially blocking.
|
||||
returns: line (minus newline) or None"""
|
||||
self.readbuf += self.read( 1024 )
|
||||
if '\n' not in self.readbuf:
|
||||
@@ -232,7 +270,7 @@ class Node( object ):
|
||||
def write( self, data ):
|
||||
"""Write data to node.
|
||||
data: string"""
|
||||
os.write( self.stdin.fileno(), data )
|
||||
os.write( self.stdin.fileno(), encode( data ) )
|
||||
|
||||
def terminate( self ):
|
||||
"Send kill signal to Node and clean up after it."
|
||||
@@ -251,9 +289,11 @@ class Node( object ):
|
||||
|
||||
def waitReadable( self, timeoutms=None ):
|
||||
"""Wait until node's output is readable.
|
||||
timeoutms: timeout in ms or None to wait indefinitely."""
|
||||
timeoutms: timeout in ms or None to wait indefinitely.
|
||||
returns: result of poll()"""
|
||||
if len( self.readbuf ) == 0:
|
||||
self.pollOut.poll( timeoutms )
|
||||
return self.pollOut.poll( timeoutms )
|
||||
return None
|
||||
|
||||
def sendCmd( self, *args, **kwargs ):
|
||||
"""Send a command, followed by a command to echo a sentinel,
|
||||
@@ -295,7 +335,9 @@ class Node( object ):
|
||||
Set self.waiting to False if command has completed.
|
||||
timeoutms: timeout in ms or None to wait indefinitely
|
||||
findPid: look for PID from mnexec -p"""
|
||||
self.waitReadable( timeoutms )
|
||||
ready = self.waitReadable( timeoutms )
|
||||
if not ready:
|
||||
return ''
|
||||
data = self.read( 1024 )
|
||||
pidre = r'\[\d+\] \d+\r\n'
|
||||
# Look for PID
|
||||
@@ -345,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
|
||||
@@ -359,23 +402,23 @@ class Node( object ):
|
||||
'mncmd':
|
||||
[ 'mnexec', '-da', str( self.pid ) ] }
|
||||
defaults.update( kwargs )
|
||||
shell = defaults.pop( 'shell', False )
|
||||
if len( args ) == 1:
|
||||
if isinstance( args[ 0 ], list ):
|
||||
# popen([cmd, arg1, arg2...])
|
||||
cmd = args[ 0 ]
|
||||
elif isinstance( args[ 0 ], basestring ):
|
||||
elif isinstance( args[ 0 ], BaseString ):
|
||||
# popen("cmd arg1 arg2...")
|
||||
cmd = args[ 0 ].split()
|
||||
cmd = [ args[ 0 ] ] if shell else args[ 0 ].split()
|
||||
else:
|
||||
raise Exception( 'popen() requires a string or list' )
|
||||
elif len( args ) > 0:
|
||||
# popen( cmd, arg1, arg2... )
|
||||
cmd = list( args )
|
||||
if shell:
|
||||
cmd = [ os.environ[ 'SHELL' ], '-c' ] + [ ' '.join( cmd ) ]
|
||||
# Attach to our namespace using mnexec -a
|
||||
cmd = defaults.pop( 'mncmd' ) + cmd
|
||||
# Shell requires a string, not a list!
|
||||
if defaults.get( 'shell', False ):
|
||||
cmd = ' '.join( cmd )
|
||||
popen = self._popen( cmd, **defaults )
|
||||
return popen
|
||||
|
||||
@@ -387,7 +430,7 @@ class Node( object ):
|
||||
# Warning: this can fail with large numbers of fds!
|
||||
out, err = popen.communicate()
|
||||
exitcode = popen.wait()
|
||||
return out, err, exitcode
|
||||
return decode( out ), decode( err ), exitcode
|
||||
|
||||
# Interface management, configuration, and routing
|
||||
|
||||
@@ -420,6 +463,15 @@ class Node( object ):
|
||||
debug( 'moving', intf, 'into namespace for', self.name, '\n' )
|
||||
moveIntfFn( intf.name, self )
|
||||
|
||||
def delIntf( self, intf ):
|
||||
"""Remove interface from Node's known interfaces
|
||||
Note: to fully delete interface, call intf.delete() instead"""
|
||||
port = self.ports.get( intf )
|
||||
if port is not None:
|
||||
del self.intfs[ port ]
|
||||
del self.ports[ intf ]
|
||||
del self.nameToIntf[ intf.name ]
|
||||
|
||||
def defaultIntf( self ):
|
||||
"Return interface for lowest port"
|
||||
ports = self.intfs.keys()
|
||||
@@ -428,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,
|
||||
@@ -440,7 +493,7 @@ class Node( object ):
|
||||
"""
|
||||
if not intf:
|
||||
return self.defaultIntf()
|
||||
elif isinstance( intf, basestring):
|
||||
elif isinstance( intf, BaseString):
|
||||
return self.nameToIntf[ intf ]
|
||||
else:
|
||||
return intf
|
||||
@@ -467,7 +520,7 @@ class Node( object ):
|
||||
# explicitly so that we won't get errors if we run before they
|
||||
# have been removed by the kernel. Unfortunately this is very slow,
|
||||
# at least with Linux kernels before 2.6.33
|
||||
for intf in self.intfs.values():
|
||||
for intf in list( self.intfs.values() ):
|
||||
# Protect against deleting hardware interfaces
|
||||
if ( self.name in intf.name ) or ( not checkName ):
|
||||
intf.delete()
|
||||
@@ -492,7 +545,7 @@ class Node( object ):
|
||||
"""Set the default route to go through intf.
|
||||
intf: Intf or {dev <intfname> via <gw-ip> ...}"""
|
||||
# Note setParam won't call us if intf is none
|
||||
if isinstance( intf, basestring ) and ' ' in intf:
|
||||
if isinstance( intf, BaseString ) and ' ' in intf:
|
||||
params = intf
|
||||
else:
|
||||
params = 'dev %s' % intf
|
||||
@@ -507,15 +560,13 @@ class Node( object ):
|
||||
mac: MAC address as string"""
|
||||
return self.intf( intf ).setMAC( mac )
|
||||
|
||||
def setIP( self, ip, prefixLen=8, intf=None ):
|
||||
def setIP( self, ip, prefixLen=8, intf=None, **kwargs ):
|
||||
"""Set the IP address for an interface.
|
||||
intf: intf or intf name
|
||||
ip: IP address as a string
|
||||
prefixLen: prefix length, e.g. 8 for /8 or 16M addrs"""
|
||||
# This should probably be rethought
|
||||
if '/' not in ip:
|
||||
ip = '%s/%s' % ( ip, prefixLen )
|
||||
return self.intf( intf ).setIP( ip )
|
||||
prefixLen: prefix length, e.g. 8 for /8 or 16M addrs
|
||||
kwargs: any additional arguments for intf.setIP"""
|
||||
return self.intf( intf ).setIP( ip, prefixLen, **kwargs )
|
||||
|
||||
def IP( self, intf=None ):
|
||||
"Return IP address of a node or specific interface."
|
||||
@@ -541,12 +592,12 @@ class Node( object ):
|
||||
method: config method name
|
||||
param: arg=value (ignore if value=None)
|
||||
value may also be list or dict"""
|
||||
name, value = param.items()[ 0 ]
|
||||
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 ):
|
||||
@@ -590,7 +641,7 @@ class Node( object ):
|
||||
|
||||
def intfList( self ):
|
||||
"List of our interfaces sorted by port number"
|
||||
return [ self.intfs[ p ] for p in sorted( self.intfs.iterkeys() ) ]
|
||||
return [ self.intfs[ p ] for p in sorted( self.intfs.keys() ) ]
|
||||
|
||||
def intfNames( self ):
|
||||
"The names of our interfaces sorted by port number"
|
||||
@@ -614,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 ):
|
||||
@@ -633,8 +685,21 @@ class CPULimitedHost( Host ):
|
||||
|
||||
"CPU limited host"
|
||||
|
||||
def __init__( self, name, sched='cfs', **kwargs ):
|
||||
Host.__init__( self, name, **kwargs )
|
||||
def __init__( self, name, sched='cfs', **params ):
|
||||
Host.__init__( self, name, **params )
|
||||
# BL: Setting the correct period/quota is tricky, particularly
|
||||
# for RT. RT allows very small quotas, but the overhead
|
||||
# seems to be high. CFS has a minimum quota of 1 ms, but
|
||||
# still does better with larger period values.
|
||||
self.period_us = params.get( 'period_us', 100000 )
|
||||
self.sched = sched
|
||||
self.cgroupsInited = False
|
||||
self.cgroup, self.rtprio = None, None
|
||||
|
||||
def initCgroups( self ):
|
||||
"Deferred cgroup initialization"
|
||||
if self.cgroupsInited:
|
||||
return
|
||||
# Initialize class if necessary
|
||||
if not CPULimitedHost.inited:
|
||||
CPULimitedHost.init()
|
||||
@@ -644,46 +709,42 @@ class CPULimitedHost( Host ):
|
||||
# We don't add ourselves to a cpuset because you must
|
||||
# specify the cpu and memory placement first
|
||||
errFail( 'cgclassify -g cpu,cpuacct:/%s %s' % ( self.name, self.pid ) )
|
||||
# BL: Setting the correct period/quota is tricky, particularly
|
||||
# for RT. RT allows very small quotas, but the overhead
|
||||
# seems to be high. CFS has a mininimum quota of 1 ms, but
|
||||
# still does better with larger period values.
|
||||
self.period_us = kwargs.get( 'period_us', 100000 )
|
||||
self.sched = sched
|
||||
if sched == 'rt':
|
||||
if self.sched == 'rt':
|
||||
self.checkRtGroupSched()
|
||||
self.rtprio = 20
|
||||
|
||||
def cgroupSet( self, param, value, resource='cpu' ):
|
||||
"Set a cgroup parameter and return its value"
|
||||
cmd = 'cgset -r %s.%s=%s /%s' % (
|
||||
resource, param, value, self.name )
|
||||
quietRun( cmd )
|
||||
nvalue = int( self.cgroupGet( param, resource ) )
|
||||
if nvalue != value:
|
||||
cmd = [ 'cgset', '-r', "%s.%s=%s" % (
|
||||
resource, param, value), '/' + self.name ]
|
||||
errFail( cmd )
|
||||
nvalue = self.cgroupGet( param, resource )
|
||||
if nvalue != str( value ):
|
||||
error( '*** error: cgroupSet: %s set to %s instead of %s\n'
|
||||
% ( param, nvalue, value ) )
|
||||
return nvalue
|
||||
|
||||
def cgroupGet( self, param, resource='cpu' ):
|
||||
"Return value of cgroup parameter"
|
||||
cmd = 'cgget -r %s.%s /%s' % (
|
||||
resource, param, self.name )
|
||||
return int( quietRun( cmd ).split()[ -1 ] )
|
||||
pname = '%s.%s' % ( resource, param )
|
||||
cmd = 'cgget -n -r %s /%s' % ( pname, self.name )
|
||||
return quietRun( cmd )[len(pname)+1:].strip()
|
||||
|
||||
def cgroupDel( self ):
|
||||
"Clean up our cgroup"
|
||||
# info( '*** deleting cgroup', self.cgroup, '\n' )
|
||||
_out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup )
|
||||
return exitcode == 0 # success condition
|
||||
# Sometimes cgdelete returns a resource busy error but still
|
||||
# deletes the group; next attempt will give "no such file"
|
||||
return exitcode == 0 or ( 'no such file' in _err.lower() )
|
||||
|
||||
def popen( self, *args, **kwargs ):
|
||||
"""Return a Popen() object in node's namespace
|
||||
args: Popen() args, single list, or string
|
||||
kwargs: Popen() keyword args"""
|
||||
# Tell mnexec to execute command in our cgroup
|
||||
mncmd = [ 'mnexec', '-g', self.name,
|
||||
'-da', str( self.pid ) ]
|
||||
mncmd = kwargs.pop( 'mncmd', [ 'mnexec', '-g', self.name,
|
||||
'-da', str( self.pid ) ] )
|
||||
# if our cgroup is not given any cpu time,
|
||||
# we cannot assign the RR Scheduler.
|
||||
if self.sched == 'rt':
|
||||
@@ -697,7 +758,7 @@ class CPULimitedHost( Host ):
|
||||
def cleanup( self ):
|
||||
"Clean up Node, then clean up our cgroup"
|
||||
super( CPULimitedHost, self ).cleanup()
|
||||
retry( retries=3, delaySecs=1, fn=self.cgroupDel )
|
||||
retry( retries=3, delaySecs=.1, fn=self.cgroupDel )
|
||||
|
||||
_rtGroupSched = False # internal class var: Is CONFIG_RT_GROUP_SCHED set?
|
||||
|
||||
@@ -734,6 +795,8 @@ class CPULimitedHost( Host ):
|
||||
def cfsInfo( self, f ):
|
||||
"Internal method: return parameters for CFS bandwidth"
|
||||
pstr, qstr = 'cfs_period_us', 'cfs_quota_us'
|
||||
if self.cgversion == 'cgroup2':
|
||||
pstr, qstr = 'max', ''
|
||||
# CFS uses wall clock time for period and CPU time for quota.
|
||||
quota = int( self.period_us * f * numCores() )
|
||||
period = self.period_us
|
||||
@@ -743,7 +806,7 @@ class CPULimitedHost( Host ):
|
||||
period = int( quota / f / numCores() )
|
||||
# Reset to unlimited on negative quota
|
||||
if quota < 0:
|
||||
quota = -1
|
||||
quota = 'max' if self.cgversion == 'cgroup2' else -1
|
||||
return pstr, qstr, period, quota
|
||||
|
||||
# BL comment:
|
||||
@@ -773,12 +836,16 @@ class CPULimitedHost( Host ):
|
||||
else:
|
||||
return
|
||||
# Set cgroup's period and quota
|
||||
setPeriod = self.cgroupSet( pstr, period )
|
||||
setQuota = self.cgroupSet( qstr, quota )
|
||||
if self.cgversion == 'cgroup':
|
||||
setPeriod = self.cgroupSet( pstr, period )
|
||||
setQuota = self.cgroupSet( qstr, quota )
|
||||
else:
|
||||
setQuota, setPeriod = self.cgroupSet(
|
||||
pstr, '%s %s' % (quota, period) ).split()
|
||||
if sched == 'rt':
|
||||
# Set RT priority if necessary
|
||||
sched = self.chrt()
|
||||
info( '(%s %d/%dus) ' % ( sched, setQuota, setPeriod ) )
|
||||
info( '(%s %s/%dus) ' % ( sched, setQuota, int( setPeriod ) ) )
|
||||
|
||||
def setCPUs( self, cores, mems=0 ):
|
||||
"Specify (real) cores that our cgroup can run on"
|
||||
@@ -797,11 +864,13 @@ 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
|
||||
params: parameters for Node.config()"""
|
||||
r = Node.config( self, **params )
|
||||
self.initCgroups()
|
||||
# Was considering cpu={'cpu': cpu , 'sched': sched}, but
|
||||
# that seems redundant
|
||||
self.setParam( r, 'setCPUFrac', cpu=cpu )
|
||||
@@ -809,13 +878,19 @@ class CPULimitedHost( Host ):
|
||||
return r
|
||||
|
||||
inited = False
|
||||
cgversion = 'cgroup2'
|
||||
|
||||
@classmethod
|
||||
def init( cls ):
|
||||
"Initialization for CPULimitedHost class"
|
||||
mountCgroups()
|
||||
cls.cgversion = mountCgroups()
|
||||
cls.inited = True
|
||||
|
||||
def unlimit( self ):
|
||||
"Unlimit cpu for cfs"
|
||||
if self.sched == 'cfs' and self.params.get( 'cpu', -1 ) != -1:
|
||||
self.setCPUFrac( -1, sched=self.sched )
|
||||
|
||||
|
||||
# Some important things to note:
|
||||
#
|
||||
@@ -859,7 +934,7 @@ class Switch( Node ):
|
||||
"Return correctly formatted dpid from dpid or switch name (s1 -> 1)"
|
||||
if dpid:
|
||||
# Remove any colons and make sure it's a good hex number
|
||||
dpid = dpid.translate( None, ':' )
|
||||
dpid = dpid.replace( ':', '' )
|
||||
assert len( dpid ) <= self.dpidLen and int( dpid, 16 ) >= 0
|
||||
else:
|
||||
# Use hex of the first number in the switch name
|
||||
@@ -867,6 +942,7 @@ class Switch( Node ):
|
||||
if nums:
|
||||
dpid = hex( int( nums[ 0 ] ) )[ 2: ]
|
||||
else:
|
||||
self.terminate() # Python 3.6 crash workaround
|
||||
raise Exception( 'Unable to derive default datapath ID - '
|
||||
'please either specify a dpid or use a '
|
||||
'canonical switch name such as s23.' )
|
||||
@@ -888,6 +964,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)"
|
||||
@@ -897,6 +974,12 @@ class Switch( Node ):
|
||||
debug( 'Assuming', repr( self ), 'is connected to a controller\n' )
|
||||
return True
|
||||
|
||||
def stop( self, deleteIntfs=True ):
|
||||
"""Stop switch
|
||||
deleteIntfs: delete interfaces? (True)"""
|
||||
if deleteIntfs:
|
||||
self.deleteIntfs()
|
||||
|
||||
def __repr__( self ):
|
||||
"More informative string representation"
|
||||
intfs = ( ','.join( [ '%s:%s' % ( i.name, i.IP() )
|
||||
@@ -1003,56 +1086,6 @@ class UserSwitch( Switch ):
|
||||
self.cmd( 'kill %ofprotocol' )
|
||||
super( UserSwitch, self ).stop( deleteIntfs )
|
||||
|
||||
class OVSLegacyKernelSwitch( Switch ):
|
||||
"""Open VSwitch legacy kernel-space switch using ovs-openflowd.
|
||||
Currently only works in the root namespace."""
|
||||
|
||||
def __init__( self, name, dp=None, **kwargs ):
|
||||
"""Init.
|
||||
name: name for switch
|
||||
dp: netlink id (0, 1, 2, ...)
|
||||
defaultMAC: default MAC as unsigned int; random value if None"""
|
||||
Switch.__init__( self, name, **kwargs )
|
||||
self.dp = dp if dp else self.name
|
||||
self.intf = self.dp
|
||||
if self.inNamespace:
|
||||
error( "OVSKernelSwitch currently only works"
|
||||
" in the root namespace.\n" )
|
||||
exit( 1 )
|
||||
|
||||
@classmethod
|
||||
def setup( cls ):
|
||||
"Ensure any dependencies are loaded; if not, try to load them."
|
||||
pathCheck( 'ovs-dpctl', 'ovs-openflowd',
|
||||
moduleName='Open vSwitch (openvswitch.org)')
|
||||
moduleDeps( subtract=OF_KMOD, add=OVS_KMOD )
|
||||
|
||||
def start( self, controllers ):
|
||||
"Start up kernel datapath."
|
||||
ofplog = '/tmp/' + self.name + '-ofp.log'
|
||||
# Delete local datapath if it exists;
|
||||
# then create a new one monitoring the given interfaces
|
||||
self.cmd( 'ovs-dpctl del-dp ' + self.dp )
|
||||
self.cmd( 'ovs-dpctl add-dp ' + self.dp )
|
||||
intfs = [ str( i ) for i in self.intfList() if not i.IP() ]
|
||||
self.cmd( 'ovs-dpctl', 'add-if', self.dp, ' '.join( intfs ) )
|
||||
# Run protocol daemon
|
||||
clist = ','.join( [ 'tcp:%s:%d' % ( c.IP(), c.port )
|
||||
for c in controllers ] )
|
||||
self.cmd( 'ovs-openflowd ' + self.dp +
|
||||
' ' + clist +
|
||||
' --fail=secure ' + self.opts +
|
||||
' --datapath-id=' + self.dpid +
|
||||
' 1>' + ofplog + ' 2>' + ofplog + '&' )
|
||||
self.execed = False
|
||||
|
||||
def stop( self, deleteIntfs=True ):
|
||||
"""Terminate kernel datapath."
|
||||
deleteIntfs: delete interfaces? (True)"""
|
||||
quietRun( 'ovs-dpctl del-dp ' + self.dp )
|
||||
self.cmd( 'kill %ovs-openflowd' )
|
||||
super( OVSLegacyKernelSwitch, self ).stop( deleteIntfs )
|
||||
|
||||
|
||||
class OVSSwitch( Switch ):
|
||||
"Open vSwitch switch. Depends on ovs-vsctl."
|
||||
@@ -1061,7 +1094,7 @@ class OVSSwitch( Switch ):
|
||||
inband=False, protocols=None,
|
||||
reconnectms=1000, stp=False, batch=False, **params ):
|
||||
"""name: name for switch
|
||||
failMode: controller loss behavior (secure|open)
|
||||
failMode: controller loss behavior (secure|standalone)
|
||||
datapath: userspace or kernel mode (kernel|user)
|
||||
inband: use in-band control (False)
|
||||
protocols: use specific OpenFlow version(s) (e.g. OpenFlow13)
|
||||
@@ -1117,6 +1150,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 )
|
||||
|
||||
@@ -1183,7 +1217,8 @@ class OVSSwitch( Switch ):
|
||||
if self.protocols and not self.isOldOVS():
|
||||
opts += ' protocols=%s' % self.protocols
|
||||
if self.stp and self.failMode == 'standalone':
|
||||
opts += ' stp_enable=true' % self
|
||||
opts += ' stp_enable=true'
|
||||
opts += ' other-config:dp-desc=%s' % self.name
|
||||
return opts
|
||||
|
||||
def start( self, controllers ):
|
||||
@@ -1253,7 +1288,7 @@ class OVSSwitch( Switch ):
|
||||
run( cmds, shell=True )
|
||||
# Reapply link config if necessary...
|
||||
for switch in switches:
|
||||
for intf in switch.intfs.itervalues():
|
||||
for intf in switch.intfs.values():
|
||||
if isinstance( intf, TCIntf ):
|
||||
intf.config( **intf.params )
|
||||
return switches
|
||||
@@ -1279,7 +1314,7 @@ class OVSSwitch( Switch ):
|
||||
pids = ' '.join( str( switch.pid ) for switch in switches )
|
||||
run( 'kill -HUP ' + pids )
|
||||
for switch in switches:
|
||||
switch.shell = None
|
||||
switch.terminate()
|
||||
return switches
|
||||
|
||||
|
||||
@@ -1289,18 +1324,21 @@ OVSKernelSwitch = OVSSwitch
|
||||
class OVSBridge( OVSSwitch ):
|
||||
"OVSBridge is an OVSSwitch in standalone/bridge mode"
|
||||
|
||||
def __init__( self, args, **kwargs ):
|
||||
def __init__( self, *args, **kwargs ):
|
||||
"""stp: enable Spanning Tree Protocol (False)
|
||||
see OVSSwitch for other options"""
|
||||
kwargs.update( failMode='standalone' )
|
||||
OVSSwitch.__init__( self, args, **kwargs )
|
||||
OVSSwitch.__init__( self, *args, **kwargs )
|
||||
|
||||
def start( self, controllers ):
|
||||
"Start bridge, ignoring controllers argument"
|
||||
OVSSwitch.start( self, controllers=[] )
|
||||
|
||||
def connected( self ):
|
||||
"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
|
||||
|
||||
@@ -1380,10 +1418,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=6633, 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:
|
||||
@@ -1425,6 +1465,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 )
|
||||
@@ -1448,20 +1489,21 @@ class Controller( Node ):
|
||||
@classmethod
|
||||
def isAvailable( cls ):
|
||||
"Is controller available?"
|
||||
return quietRun( 'which controller' )
|
||||
return which( 'controller' )
|
||||
|
||||
|
||||
class OVSController( Controller ):
|
||||
"Open vSwitch controller"
|
||||
def __init__( self, name, command='ovs-controller', **kwargs ):
|
||||
if quietRun( 'which test-controller' ):
|
||||
command = 'test-controller'
|
||||
Controller.__init__( self, name, command=command, **kwargs )
|
||||
def __init__( self, name, **kwargs ):
|
||||
kwargs.setdefault( 'command', self.isAvailable() or
|
||||
'ovs-controller' )
|
||||
Controller.__init__( self, name, **kwargs )
|
||||
|
||||
@classmethod
|
||||
def isAvailable( cls ):
|
||||
return ( quietRun( 'which ovs-controller' ) or
|
||||
quietRun( 'which test-controller' ) )
|
||||
return (which( 'ovs-controller' ) or
|
||||
which( 'test-controller' ) or
|
||||
which( 'ovs-testcontroller' ))
|
||||
|
||||
class NOX( Controller ):
|
||||
"Controller to run a NOX application."
|
||||
@@ -1474,7 +1516,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,38 +1525,33 @@ 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 ):
|
||||
class Ryu( Controller ):
|
||||
"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 ]
|
||||
name: name to give controller.
|
||||
ryuArgs: modules to pass to Ryu (ryu.app.simple_switch)
|
||||
command: command 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 )
|
||||
|
||||
Controller.__init__( self, name,
|
||||
command='ryu-manager',
|
||||
cargs='--ofp-tcp-listen-port %s ' +
|
||||
' '.join( ryuArgs ),
|
||||
cdir=ryuCoreDir,
|
||||
**kwargs )
|
||||
|
||||
class RemoteController( Controller ):
|
||||
"Controller running outside of Mininet's control."
|
||||
|
||||
def __init__( self, name, ip='127.0.0.1',
|
||||
port=6633, **kwargs):
|
||||
port=None, **kwargs):
|
||||
"""Init.
|
||||
name: name to give controller
|
||||
ip: the IP address where the remote controller is
|
||||
@@ -1526,17 +1563,37 @@ class RemoteController( Controller ):
|
||||
"Overridden to do nothing."
|
||||
return
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
def stop( self ):
|
||||
"Overridden to do nothing."
|
||||
return
|
||||
|
||||
def checkListening( self ):
|
||||
"Warn if remote controller is not accessible"
|
||||
listening = self.cmd( "echo A | telnet -e A %s %d" %
|
||||
( self.ip, self.port ) )
|
||||
if self.port is not None:
|
||||
self.isListening( self.ip, self.port )
|
||||
else:
|
||||
for port in 6653, 6633:
|
||||
if self.isListening( self.ip, port ):
|
||||
self.port = port
|
||||
info( "Connecting to remote controller"
|
||||
" at %s:%d\n" % ( self.ip, self.port ))
|
||||
break
|
||||
|
||||
if self.port is None:
|
||||
self.port = 6653
|
||||
warn( "Setting remote controller"
|
||||
" to %s:%d\n" % ( self.ip, self.port ))
|
||||
|
||||
def isListening( self, ip, port ):
|
||||
"Check if a remote controller is listening at a specific ip and port"
|
||||
listening = self.cmd( "echo A | telnet -e A %s %d" % ( ip, port ) )
|
||||
if 'Connected' not in listening:
|
||||
warn( "Unable to contact the remote controller"
|
||||
" at %s:%d\n" % ( self.ip, self.port ) )
|
||||
" at %s:%d\n" % ( ip, port ) )
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
DefaultControllers = ( Controller, OVSController )
|
||||
@@ -1546,6 +1603,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"
|
||||
@@ -1553,3 +1611,7 @@ def DefaultController( name, controllers=DefaultControllers, **kwargs ):
|
||||
if not controller:
|
||||
raise Exception( 'Could not find a default OpenFlow controller' )
|
||||
return controller( name, **kwargs )
|
||||
|
||||
def NullController( *_args, **_kwargs ):
|
||||
"Nonexistent controller - simply returns None"
|
||||
return None
|
||||
|
||||
+61
-55
@@ -7,8 +7,8 @@ This contains additional Node types which you may find to be useful.
|
||||
from mininet.node import Node, Switch
|
||||
from mininet.log import info, warn
|
||||
from mininet.moduledeps import pathCheck
|
||||
from mininet.util import quietRun
|
||||
|
||||
import re
|
||||
|
||||
class LinuxBridge( Switch ):
|
||||
"Linux Bridge (with optional spanning tree)"
|
||||
@@ -59,90 +59,96 @@ class LinuxBridge( Switch ):
|
||||
|
||||
@classmethod
|
||||
def setup( cls ):
|
||||
"Make sure our class dependencies are available"
|
||||
"Check dependencies and warn about firewalling"
|
||||
pathCheck( 'brctl', moduleName='bridge-utils' )
|
||||
# Disable Linux bridge firewalling so that traffic can flow!
|
||||
for table in 'arp', 'ip', 'ip6':
|
||||
cmd = 'sysctl net.bridge.bridge-nf-call-%stables' % table
|
||||
out = quietRun( cmd ).strip()
|
||||
if out.endswith( '1' ):
|
||||
warn( 'Warning: Linux bridge may not work with', out, '\n' )
|
||||
|
||||
|
||||
class NAT( Node ):
|
||||
"NAT: Provides connectivity to external network"
|
||||
|
||||
def __init__( self, name, inetIntf=None, subnet='10.0/8',
|
||||
localIntf=None, **params):
|
||||
def __init__( self, name, subnet='10.0/8',
|
||||
localIntf=None, flush=False, **params):
|
||||
"""Start NAT/forwarding between Mininet and external network
|
||||
inetIntf: interface for internet access
|
||||
subnet: Mininet subnet (default 10.0/8)="""
|
||||
subnet: Mininet subnet (default 10.0/8)
|
||||
flush: flush iptables before installing NAT rules"""
|
||||
super( NAT, self ).__init__( name, **params )
|
||||
|
||||
self.inetIntf = inetIntf if inetIntf else self.getGatewayIntf()
|
||||
self.subnet = subnet
|
||||
self.localIntf = localIntf
|
||||
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.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
self.setManualConfig( self.localIntf )
|
||||
|
||||
# Flush any currently active rules
|
||||
# TODO: is this safe?
|
||||
self.cmd( 'iptables -F' )
|
||||
self.cmd( 'iptables -t nat -F' )
|
||||
# Now we can configure manually without interference
|
||||
super( NAT, self).config( **params )
|
||||
|
||||
# Create default entries for unmatched traffic
|
||||
self.cmd( 'iptables -P INPUT ACCEPT' )
|
||||
self.cmd( 'iptables -P OUTPUT ACCEPT' )
|
||||
self.cmd( 'iptables -P FORWARD DROP' )
|
||||
if self.flush:
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
self.cmd( 'iptables -F' )
|
||||
self.cmd( 'iptables -t nat -F' )
|
||||
# Create default entries for unmatched traffic
|
||||
self.cmd( 'iptables -P INPUT ACCEPT' )
|
||||
self.cmd( 'iptables -P OUTPUT ACCEPT' )
|
||||
self.cmd( 'iptables -P FORWARD DROP' )
|
||||
|
||||
# Configure NAT
|
||||
# Install NAT rules
|
||||
self.cmd( 'iptables -I FORWARD',
|
||||
'-i', self.localIntf, '-d', self.subnet, '-j DROP' )
|
||||
self.cmd( 'iptables -A FORWARD',
|
||||
'-i', self.localIntf, '-s', self.subnet, '-j ACCEPT' )
|
||||
self.cmd( 'iptables -A FORWARD',
|
||||
'-i', self.inetIntf, '-d', self.subnet, '-j ACCEPT' )
|
||||
'-o', self.localIntf, '-d', self.subnet, '-j ACCEPT' )
|
||||
self.cmd( 'iptables -t nat -A POSTROUTING',
|
||||
'-o', self.inetIntf, '-s', self.subnet, '-j MASQUERADE' )
|
||||
'-s', self.subnet, "'!'", '-d', self.subnet,
|
||||
'-j MASQUERADE' )
|
||||
|
||||
# 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 getGatewayIntf( self, fallback='eth0' ):
|
||||
"""Return gateway interface name
|
||||
fallback: default device to fall back to"""
|
||||
routes = self.cmd( 'ip route show' )
|
||||
match = re.search( r'default via \S+ dev (\S+)', routes )
|
||||
if match:
|
||||
return match.group( 1 )
|
||||
else:
|
||||
warn( 'There is no default route set.',
|
||||
'Using', fallback, 'as gateway interface...\n' )
|
||||
return fallback
|
||||
|
||||
def terminate( self ):
|
||||
"""Stop NAT/forwarding between Mininet and external network"""
|
||||
# Flush any currently active rules
|
||||
# TODO: is this safe?
|
||||
self.cmd( 'iptables -F' )
|
||||
self.cmd( 'iptables -t nat -F' )
|
||||
|
||||
# Instruct the kernel to stop forwarding
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
|
||||
"Stop NAT/forwarding between Mininet and external network"
|
||||
# Remote NAT rules
|
||||
self.cmd( 'iptables -D FORWARD',
|
||||
'-i', self.localIntf, '-d', self.subnet, '-j DROP' )
|
||||
self.cmd( 'iptables -D FORWARD',
|
||||
'-i', self.localIntf, '-s', self.subnet, '-j ACCEPT' )
|
||||
self.cmd( 'iptables -D FORWARD',
|
||||
'-o', self.localIntf, '-d', self.subnet, '-j ACCEPT' )
|
||||
self.cmd( 'iptables -t nat -D POSTROUTING',
|
||||
'-s', self.subnet, '\'!\'', '-d', self.subnet,
|
||||
'-j MASQUERADE' )
|
||||
# Put the forwarding state back to what it was
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=%s' % self.forwardState )
|
||||
super( NAT, self ).terminate()
|
||||
|
||||
+4
-3
@@ -35,7 +35,7 @@ def tunnelX11( node, display=None):
|
||||
"EXEC:'mnexec -a 1 socat STDIO %s'" % connection ]
|
||||
return 'localhost:' + screen, node.popen( cmd )
|
||||
|
||||
def makeTerm( node, title='Node', term='xterm', display=None ):
|
||||
def makeTerm( node, title='Node', term='xterm', display=None, cmd='bash'):
|
||||
"""Create an X11 tunnel to the node and start up a terminal.
|
||||
node: Node object
|
||||
title: base title
|
||||
@@ -50,11 +50,12 @@ def makeTerm( node, title='Node', term='xterm', display=None ):
|
||||
}
|
||||
if term not in cmds:
|
||||
error( 'invalid terminal type: %s' % term )
|
||||
return
|
||||
return None
|
||||
display, tunnel = tunnelX11( node, display )
|
||||
if display is None:
|
||||
return []
|
||||
term = node.popen( cmds[ term ] + [ display, '-e', 'env TERM=ansi bash'] )
|
||||
term = node.popen( cmds[ term ] +
|
||||
[ display, '-e', 'env TERM=ansi %s' % cmd ] )
|
||||
return [ tunnel, term ] if tunnel else [ term ]
|
||||
|
||||
def runX11( node, cmd ):
|
||||
|
||||
@@ -21,7 +21,10 @@ def runTests( testDir, verbosity=1 ):
|
||||
# discover all tests in testDir
|
||||
testSuite = defaultTestLoader.discover( testDir )
|
||||
# run tests
|
||||
TextTestRunner( verbosity=verbosity ).run( testSuite )
|
||||
success = ( TextTestRunner( verbosity=verbosity )
|
||||
.run( testSuite ).wasSuccessful() )
|
||||
sys.exit( 0 if success else 1 )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -131,7 +131,7 @@ class testOptionsTopoCommon( object ):
|
||||
BW_TOLERANCE = 0.8 # BW fraction below which test should fail
|
||||
# Verify ability to create limited-link topo first;
|
||||
lopts = { 'bw': BW, 'use_htb': True }
|
||||
# Also verify correctness of limit limitng within a bound.
|
||||
# Also verify correctness of limit limiting within a bound.
|
||||
mn = Mininet( SingleSwitchOptionsTopo( n=N, lopts=lopts ),
|
||||
link=TCLink, switch=self.switchClass,
|
||||
waitConnected=True )
|
||||
@@ -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 ):
|
||||
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Regression test for pty leak in Node()
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.clean import cleanup
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
|
||||
class TestPtyLeak( unittest.TestCase ):
|
||||
"Verify that there is no pty leakage"
|
||||
|
||||
@staticmethod
|
||||
def testPtyLeak():
|
||||
"Test for pty leakage"
|
||||
net = Mininet( SingleSwitchTopo() )
|
||||
net.start()
|
||||
host = net[ 'h1' ]
|
||||
for _ in range( 0, 10 ):
|
||||
oldptys = host.slave, host.master
|
||||
net.delHost( host )
|
||||
host = net.addHost( 'h1' )
|
||||
assert ( host.slave, host.master ) == oldptys
|
||||
net.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
cleanup()
|
||||
@@ -8,8 +8,7 @@ import sys
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Host, Controller
|
||||
from mininet.node import ( UserSwitch, OVSSwitch, OVSLegacyKernelSwitch,
|
||||
IVSSwitch )
|
||||
from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
|
||||
from mininet.topo import Topo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import quietRun
|
||||
@@ -25,16 +24,16 @@ 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 ):
|
||||
"""Verify that the default dpid is assigned using a valid provided
|
||||
canonical switchname if no dpid is passed in switch creation."""
|
||||
switch = Mininet( Topo(),
|
||||
self.switchClass,
|
||||
Host, Controller ).addSwitch( 's1' )
|
||||
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||
switch = net.addSwitch( 's1' )
|
||||
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
||||
net.stop()
|
||||
|
||||
def dpidFrom( self, num ):
|
||||
"Compute default dpid from number"
|
||||
@@ -45,31 +44,34 @@ class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
"""Verify that Switch dpid is the actual dpid assigned if dpid is
|
||||
passed in switch creation."""
|
||||
dpid = self.dpidFrom( 0xABCD )
|
||||
switch = Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch(
|
||||
's1', dpid=dpid )
|
||||
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||
switch = net.addSwitch( 's1', dpid=dpid )
|
||||
self.assertEqual( switch.dpid, dpid )
|
||||
net.stop()
|
||||
|
||||
def testDefaultDpidAssignmentFailure( self ):
|
||||
"""Verify that Default dpid assignment raises an Exception if the
|
||||
name of the switch does not contin a digit. Also verify the
|
||||
name of the switch does not contain a digit. Also verify the
|
||||
exception message."""
|
||||
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||
with self.assertRaises( Exception ) as raises_cm:
|
||||
Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch( 'A' )
|
||||
self.assertEqual(raises_cm.exception.message, 'Unable to derive '
|
||||
net.addSwitch( 'A' )
|
||||
self.assertTrue( 'Unable to derive '
|
||||
'default datapath ID - please either specify a dpid '
|
||||
'or use a canonical switch name such as s23.')
|
||||
'or use a canonical switch name such as s23.'
|
||||
in str( raises_cm.exception ) )
|
||||
net.stop()
|
||||
|
||||
def testDefaultDpidLen( self ):
|
||||
"""Verify that Default dpid length is 16 characters consisting of
|
||||
16 - len(hex of first string of contiguous digits passed in switch
|
||||
name) 0's followed by hex of first string of contiguous digits passed
|
||||
in switch name."""
|
||||
switch = Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch( 's123' )
|
||||
|
||||
net = Mininet( Topo(), self.switchClass, Host, Controller )
|
||||
switch = net.addSwitch( 's123' )
|
||||
self.assertEqual( switch.dpid, self.dpidFrom( 123 ) )
|
||||
net.stop()
|
||||
|
||||
|
||||
class OVSUser( OVSSwitch):
|
||||
"OVS User Switch convenience class"
|
||||
@@ -78,15 +80,9 @@ class OVSUser( OVSSwitch):
|
||||
OVSSwitch.__init__( self, *args, **kwargs )
|
||||
|
||||
class testSwitchOVSUser( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignnment of OVS User Switch."
|
||||
"Test dpid assignment of OVS User Switch."
|
||||
switchClass = OVSUser
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ovs-openflowd' ),
|
||||
'OVS Legacy Kernel switch is not installed' )
|
||||
class testSwitchOVSLegacyKernel( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignnment of OVS Legacy Kernel Switch."
|
||||
switchClass = OVSLegacyKernelSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ivs-ctl' ),
|
||||
'IVS switch is not installed' )
|
||||
class testSwitchIVS( TestSwitchDpidAssignmentOVS ):
|
||||
@@ -99,6 +95,8 @@ class testSwitchUserspace( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignment of Userspace switch."
|
||||
switchClass = UserSwitch
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
cleanup()
|
||||
|
||||
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,18 +6,21 @@ Tests for the Mininet Walkthrough
|
||||
TODO: missing xterm test
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
import os
|
||||
import re
|
||||
from mininet.util import quietRun
|
||||
from distutils.version import StrictVersion
|
||||
import unittest
|
||||
|
||||
from sys import stdout
|
||||
|
||||
from mininet.util import quietRun, pexpect, StrictVersion
|
||||
from mininet.clean import cleanup
|
||||
|
||||
|
||||
def tsharkVersion():
|
||||
"Return tshark version"
|
||||
versionStr = quietRun( 'tshark -v' )
|
||||
versionMatch = re.findall( r'TShark \d+.\d+.\d+', versionStr )[0]
|
||||
return versionMatch.split()[ 1 ]
|
||||
versionMatch = re.findall( r'TShark[^\d]*(\d+.\d+.\d+)', versionStr )
|
||||
return versionMatch[ 0 ]
|
||||
|
||||
# pylint doesn't understand pexpect.match, unfortunately!
|
||||
# pylint:disable=maybe-no-member
|
||||
@@ -27,6 +30,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"
|
||||
@@ -42,15 +50,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' )
|
||||
@@ -64,7 +75,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 )
|
||||
@@ -89,15 +100,18 @@ 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 )
|
||||
interfaces = [ 'h1-eth0', 's1-eth1', '[^-]eth0', 'lo', self.prompt ]
|
||||
# Third pattern is a local interface beginning with 'eth' or 'en'
|
||||
interfaces = [ r'h1-eth0[:\s]', r's1-eth1[:\s]',
|
||||
r'[^-](eth|en)\w*\d[:\s]', r'lo[:\s]',
|
||||
self.prompt ]
|
||||
# h1 ifconfig
|
||||
p.sendline( 'h1 ifconfig -a' )
|
||||
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"' )
|
||||
@@ -113,11 +127,11 @@ 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
|
||||
self.assertEqual( ifcount, 3, 'Missing interfaces on s1')
|
||||
self.assertTrue( ifcount >= 3, 'Missing interfaces on s1')
|
||||
# h1 ps
|
||||
p.sendline( "h1 ps -a | egrep -v 'ps|grep'" )
|
||||
p.expect( self.prompt )
|
||||
@@ -126,16 +140,19 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p.sendline( "s1 ps -a | egrep -v 'ps|grep'" )
|
||||
p.expect( self.prompt )
|
||||
s1Output = p.before
|
||||
# strip command from ps output
|
||||
h1Output = h1Output.split( '\n', 1 )[ 1 ]
|
||||
s1Output = s1Output.split( '\n', 1 )[ 1 ]
|
||||
self.assertEqual( h1Output, s1Output, 'h1 and s1 "ps" output differs')
|
||||
# strip command from ps output and compute diffs
|
||||
h1Output = h1Output.split( '\n' )[ 1: ]
|
||||
s1Output = s1Output.split( '\n' )[ 1: ]
|
||||
diffs = set( h1Output ).difference( set( s1Output ) )
|
||||
# allow up to two diffs to account for daemons, etc.
|
||||
self.assertTrue( len( diffs ) <= 2,
|
||||
'h1 and s1 "ps" output differ too much: %s' % diffs )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
|
||||
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' )
|
||||
@@ -148,9 +165,20 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
def testSimpleHTTP( self ):
|
||||
"Start an HTTP server on h1 and wget from h2"
|
||||
p = pexpect.spawn( 'mn' )
|
||||
if 'Python 2' in quietRun( 'python --version' ):
|
||||
httpserver = 'SimpleHTTPServer'
|
||||
else:
|
||||
httpserver = 'http.server'
|
||||
p = pexpect.spawn( 'mn -w', logfile=stdout )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 python -m SimpleHTTPServer 80 &' )
|
||||
p.sendline( 'h1 python -m %s 80 >& /dev/null &' % httpserver )
|
||||
p.expect( self.prompt )
|
||||
# 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 number of seconds to make
|
||||
# it less likely to fail due to the race condition.
|
||||
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' )
|
||||
@@ -195,22 +223,24 @@ 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' )
|
||||
p.expect( r"Results: \['([\d\.]+) Mbits/sec'," )
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertTrue( bw < 10.1, 'Bandwidth > 10 Mb/s')
|
||||
self.assertTrue( bw > 9.0, 'Bandwidth < 9 Mb/s')
|
||||
self.assertTrue( bw < 10.1, 'Bandwidth %.2f >= 10.1 Mb/s' % bw )
|
||||
self.assertTrue( bw > 9.0, 'Bandwidth %.2f <= 9 Mb/s' % bw )
|
||||
p.expect( self.prompt )
|
||||
# test delay
|
||||
p.sendline( 'h1 ping -c 4 h2' )
|
||||
p.expect( r'rtt min/avg/max/mdev = '
|
||||
r'([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms' )
|
||||
delay = float( p.match.group( 2 ) )
|
||||
self.assertTrue( delay > 40, 'Delay < 40ms' )
|
||||
self.assertTrue( delay < 45, 'Delay > 40ms' )
|
||||
self.assertTrue( delay >= 40, 'Delay < 40ms' )
|
||||
self.assertTrue( delay <= 50, 'Delay > 50ms' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
@@ -247,8 +277,10 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p.expect( self.prompt )
|
||||
for i in range( 1, 3 ):
|
||||
p.sendline( 'h%d ifconfig' % i )
|
||||
p.expect( 'HWaddr 00:00:00:00:00:0%d' % i )
|
||||
p.expect( r'\s00:00:00:00:00:0%d\s' % i )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.expect( pexpect.EOF )
|
||||
|
||||
def testSwitches( self ):
|
||||
"Run iperf test using user and ovsk switches"
|
||||
@@ -271,12 +303,14 @@ class testWalkthrough( unittest.TestCase ):
|
||||
"Test running user switch in its own namespace"
|
||||
p = pexpect.spawn( 'mn --innamespace --switch user' )
|
||||
p.expect( self.prompt )
|
||||
interfaces = [ 'h1-eth0', 's1-eth1', '[^-]eth0', 'lo', self.prompt ]
|
||||
interfaces = [ r'h1-eth0[:\s]', r's1-eth1[:\s]',
|
||||
r'[^-](eth|en)\w*\d[:\s]', r'lo[:\s]',
|
||||
self.prompt ]
|
||||
p.sendline( 's1 ifconfig -a' )
|
||||
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"' )
|
||||
@@ -297,7 +331,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()' )
|
||||
@@ -319,7 +353,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 )
|
||||
|
||||
+19
-9
@@ -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, {} )
|
||||
@@ -56,13 +59,13 @@ class MultiGraph( object ):
|
||||
return self.node.items() if data else self.node.keys()
|
||||
|
||||
def edges_iter( self, data=False, keys=False ):
|
||||
"Iterator: return graph edges"
|
||||
for src, entry in self.edge.iteritems():
|
||||
for dst, keys in entry.iteritems():
|
||||
"Iterator: return graph edges, optionally with data and keys"
|
||||
for src, entry in self.edge.items():
|
||||
for dst, entrykeys in entry.items():
|
||||
if src > dst:
|
||||
# Skip duplicate edges
|
||||
continue
|
||||
for k, attrs in keys.iteritems():
|
||||
for k, attrs in entrykeys.items():
|
||||
if data:
|
||||
if keys:
|
||||
yield( src, dst, k, attrs )
|
||||
@@ -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"
|
||||
@@ -318,6 +320,12 @@ class SingleSwitchReversedTopo( Topo ):
|
||||
port1=0, port2=( k - h + 1 ) )
|
||||
|
||||
|
||||
class MinimalTopo( SingleSwitchTopo ):
|
||||
"Minimal topology with two hosts and one switch"
|
||||
def build( self ):
|
||||
return SingleSwitchTopo.build( self, k=2 )
|
||||
|
||||
|
||||
class LinearTopo( Topo ):
|
||||
"Linear topology of k switches, with n hosts per switch."
|
||||
|
||||
@@ -328,9 +336,11 @@ class LinearTopo( Topo ):
|
||||
self.n = n
|
||||
|
||||
if n == 1:
|
||||
genHostName = lambda i, j: 'h%s' % i
|
||||
def genHostName( i, _j ):
|
||||
return 'h%s' % i
|
||||
else:
|
||||
genHostName = lambda i, j: 'h%ss%d' % ( j, i )
|
||||
def genHostName( i, j ):
|
||||
return 'h%ss%d' % ( j, i )
|
||||
|
||||
lastSwitch = None
|
||||
for i in irange( 1, k ):
|
||||
|
||||
+16
-4
@@ -45,10 +45,20 @@ class TorusTopo( Topo ):
|
||||
without STP turned on! It can be used with STP, e.g.:
|
||||
# mn --topo torus,3,3 --switch lxbr,stp=1 --test pingall"""
|
||||
|
||||
def build( self, x, y ):
|
||||
def build( self, x, y, n=1 ):
|
||||
"""x: dimension of torus in x-direction
|
||||
y: dimension of torus in y-direction
|
||||
n: number of hosts per switch"""
|
||||
if x < 3 or y < 3:
|
||||
raise Exception( 'Please use 3x3 or greater for compatibility '
|
||||
'with 2.1' )
|
||||
if n == 1:
|
||||
def genHostName( loc, _k ):
|
||||
return 'h%s' % ( loc )
|
||||
else:
|
||||
def genHostName( loc, k ):
|
||||
return 'h%sx%d' % ( loc, k )
|
||||
|
||||
hosts, switches, dpid = {}, {}, 0
|
||||
# Create and wire interior
|
||||
for i in range( 0, x ):
|
||||
@@ -57,9 +67,11 @@ class TorusTopo( Topo ):
|
||||
# dpid cannot be zero for OVS
|
||||
dpid = ( i + 1 ) * 256 + ( j + 1 )
|
||||
switch = switches[ i, j ] = self.addSwitch(
|
||||
's' + loc, dpid='%016x' % dpid )
|
||||
host = hosts[ i, j ] = self.addHost( 'h' + loc )
|
||||
self.addLink( host, switch )
|
||||
's' + loc, dpid='%x' % dpid )
|
||||
for k in range( 0, n ):
|
||||
host = hosts[ i, j, k ] = self.addHost(
|
||||
genHostName( loc, k + 1 ) )
|
||||
self.addLink( host, switch )
|
||||
# Connect switches
|
||||
for i in range( 0, x ):
|
||||
for j in range( 0, y ):
|
||||
|
||||
+224
-90
@@ -1,16 +1,86 @@
|
||||
"Utility functions for Mininet."
|
||||
|
||||
from mininet.log import output, info, error, warn, debug
|
||||
import codecs
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from time import sleep
|
||||
from collections import namedtuple
|
||||
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
|
||||
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
|
||||
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:
|
||||
import packaging.version # replacement for distutils.version
|
||||
StrictVersion = packaging.version.parse
|
||||
except ImportError: # python2.7 lacks ModuleNotFoundError
|
||||
import distutils.version # pylint: disable=deprecated-module
|
||||
StrictVersion = distutils.version.StrictVersion
|
||||
|
||||
try:
|
||||
oldpexpect = None
|
||||
import pexpect as oldpexpect # pylint: disable=import-error
|
||||
|
||||
class Pexpect( object ):
|
||||
"Custom pexpect that is compatible with str"
|
||||
@staticmethod
|
||||
def spawn( *args, **kwargs):
|
||||
"pexpect.spawn that is compatible with str"
|
||||
if Python3 and 'encoding' not in kwargs:
|
||||
kwargs.update( encoding='utf-8' )
|
||||
return oldpexpect.spawn( *args, **kwargs )
|
||||
|
||||
def __getattr__( self, name ):
|
||||
return getattr( oldpexpect, name )
|
||||
pexpect = Pexpect()
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
# Command execution support
|
||||
|
||||
@@ -32,13 +102,14 @@ def oldQuietRun( *cmd ):
|
||||
cmd: list of command params"""
|
||||
if len( cmd ) == 1:
|
||||
cmd = cmd[ 0 ]
|
||||
if isinstance( cmd, str ):
|
||||
if isinstance( cmd, BaseString ):
|
||||
cmd = cmd.split( ' ' )
|
||||
popen = Popen( cmd, stdout=PIPE, stderr=STDOUT )
|
||||
out = ''
|
||||
popen = Popen( # pylint: disable=consider-using-with
|
||||
cmd, stdout=PIPE, stderr=STDOUT )
|
||||
# We can't use Popen.communicate() because it uses
|
||||
# select(), which can't handle
|
||||
# high file descriptor numbers! poll() can, however.
|
||||
out = ''
|
||||
readable = poll()
|
||||
readable.register( popen.stdout )
|
||||
while True:
|
||||
@@ -56,7 +127,9 @@ def oldQuietRun( *cmd ):
|
||||
# This is a bit complicated, but it enables us to
|
||||
# monitor command output as it is happening
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
CmdResult = namedtuple( 'CmdResult', 'out err ret' )
|
||||
|
||||
# pylint: disable=too-many-branches,too-many-statements
|
||||
def errRun( *cmd, **kwargs ):
|
||||
"""Run a command and return stdout, stderr and return code
|
||||
cmd: string or list of command and args
|
||||
@@ -73,30 +146,34 @@ def errRun( *cmd, **kwargs ):
|
||||
if len( cmd ) == 1:
|
||||
cmd = cmd[ 0 ]
|
||||
# Allow passing in a list or a string
|
||||
if isinstance( cmd, str ) and not shell:
|
||||
if isinstance( cmd, BaseString ) and not shell:
|
||||
cmd = cmd.split( ' ' )
|
||||
cmd = [ str( arg ) for arg in cmd ]
|
||||
elif isinstance( cmd, list ) and shell:
|
||||
cmd = " ".join( arg for arg in cmd )
|
||||
debug( '*** errRun:', cmd, '\n' )
|
||||
# pylint: disable=consider-using-with
|
||||
popen = Popen( cmd, stdout=PIPE, stderr=stderr, shell=shell )
|
||||
# We use poll() because select() doesn't work with large fd numbers,
|
||||
# and thus communicate() doesn't work either
|
||||
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 )
|
||||
f = fdToFile[ fd ]
|
||||
decoder = fdToDecoder[ fd ]
|
||||
if event & ( POLLIN | POLLHUP ):
|
||||
data = decoder.decode( f.read( 1024 ) )
|
||||
if echo:
|
||||
output( data )
|
||||
if f == popen.stdout:
|
||||
@@ -107,7 +184,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:
|
||||
@@ -115,8 +192,13 @@ def errRun( *cmd, **kwargs ):
|
||||
poller.unregister( fd )
|
||||
|
||||
returncode = popen.wait()
|
||||
# Python 3 complains if we don't explicitly close these
|
||||
popen.stdout.close()
|
||||
if stderr == PIPE:
|
||||
popen.stderr.close()
|
||||
debug( out, err, returncode )
|
||||
return out, err, returncode
|
||||
return CmdResult( out, err, returncode )
|
||||
|
||||
# pylint: enable=too-many-branches
|
||||
|
||||
def errFail( *cmd, **kwargs ):
|
||||
@@ -125,25 +207,32 @@ def errFail( *cmd, **kwargs ):
|
||||
if ret:
|
||||
raise Exception( "errFail: %s failed with return code %s: %s"
|
||||
% ( cmd, ret, err ) )
|
||||
return out, err, ret
|
||||
return CmdResult( out, err, ret )
|
||||
|
||||
def quietRun( cmd, **kwargs ):
|
||||
"Run a command and return merged stdout and stderr"
|
||||
return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ]
|
||||
return errRun( cmd, stderr=STDOUT, **kwargs ).out
|
||||
|
||||
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
|
||||
@@ -320,7 +409,7 @@ def ipParse( ip ):
|
||||
"Parse an IP address and return an unsigned int."
|
||||
args = [ int( arg ) for arg in ip.split( '.' ) ]
|
||||
while len(args) < 4:
|
||||
args.append( 0 )
|
||||
args.insert( len(args) - 1, 0 )
|
||||
return ipNum( *args )
|
||||
|
||||
def netParse( ipstr ):
|
||||
@@ -330,7 +419,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
|
||||
@@ -373,30 +462,34 @@ def pmonitor(popens, timeoutms=500, readline=True,
|
||||
terminates: when all EOFs received"""
|
||||
poller = poll()
|
||||
fdToHost = {}
|
||||
for host, popen in popens.iteritems():
|
||||
fdToDecoder = {}
|
||||
for host, popen in popens.items():
|
||||
fd = popen.stdout.fileno()
|
||||
fdToHost[ fd ] = host
|
||||
fdToDecoder[ fd ] = getincrementaldecoder()
|
||||
poller.register( fd, POLLIN )
|
||||
if not readline:
|
||||
# Use non-blocking reads
|
||||
flags = fcntl( fd, F_GETFL )
|
||||
fcntl( fd, F_SETFL, flags | O_NONBLOCK )
|
||||
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:
|
||||
if readline:
|
||||
# Attempt to read a line of output
|
||||
# This blocks until we receive a newline!
|
||||
line = popen.stdout.readline()
|
||||
else:
|
||||
line = popen.stdout.read( readmax )
|
||||
yield host, line
|
||||
# Check for EOF
|
||||
elif event & POLLHUP:
|
||||
if event & ( POLLIN | POLLHUP ):
|
||||
while True:
|
||||
try:
|
||||
f = popen.stdout
|
||||
line = decoder.decode( f.readline() if readline
|
||||
else f.read( readmax ) )
|
||||
except IOError:
|
||||
line = ''
|
||||
if line == '':
|
||||
break
|
||||
yield host, line
|
||||
if event & POLLHUP:
|
||||
poller.unregister( fd )
|
||||
del popens[ host ]
|
||||
else:
|
||||
@@ -405,19 +498,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 )
|
||||
|
||||
@@ -434,21 +527,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:
|
||||
@@ -456,18 +549,25 @@ def fixLimits():
|
||||
"Mininet's performance may be affected.\n" )
|
||||
# pylint: enable=broad-except
|
||||
|
||||
|
||||
def mountCgroups():
|
||||
"Make sure cgroups file system is mounted"
|
||||
mounts = quietRun( 'cat /proc/mounts' )
|
||||
cgdir = '/sys/fs/cgroup'
|
||||
csdir = cgdir + '/cpuset'
|
||||
if ('cgroup %s' % cgdir not in mounts and
|
||||
'cgroups %s' % cgdir not in mounts):
|
||||
raise Exception( "cgroups not mounted on " + cgdir )
|
||||
if 'cpuset %s' % csdir not in mounts:
|
||||
errRun( 'mkdir -p ' + csdir )
|
||||
errRun( 'mount -t cgroup -ocpuset cpuset ' + csdir )
|
||||
def mountCgroups( cgcontrol='cpu cpuacct cpuset' ):
|
||||
"""Mount cgroupfs if needed and return cgroup version
|
||||
cgcontrol: cgroup controllers to check ('cpu cpuacct cpuset')
|
||||
Returns: 'cgroup' | 'cgroup2' """
|
||||
# Try to read the cgroup controllers in cgcontrol
|
||||
cglist = cgcontrol.split()
|
||||
paths = ' '.join( '-g ' + c for c in cglist )
|
||||
cmd = 'cgget -n %s /' % paths
|
||||
result = errRun( cmd )
|
||||
# If it failed, mount cgroupfs and retry
|
||||
if result.ret or result.err or any(
|
||||
c not in result.out for c in cglist ):
|
||||
errFail( 'cgroupfs-mount' )
|
||||
result = errRun( cmd )
|
||||
errFail( cmd )
|
||||
# cpu.cfs_period_us is used for cgroup but not cgroup2
|
||||
if 'cpu.cfs_period_us' in result.out:
|
||||
return 'cgroup'
|
||||
return 'cgroup2'
|
||||
|
||||
def natural( text ):
|
||||
"To sort sanely/alphabetically: sorted( l, key=natural )"
|
||||
@@ -523,43 +623,55 @@ def splitArgs( argstr ):
|
||||
kwargs[ key ] = makeNumeric( val )
|
||||
return fn, args, kwargs
|
||||
|
||||
def customConstructor( constructors, argStr ):
|
||||
"""Return custom constructor based on argStr
|
||||
The args and key/val pairs in argsStr will be automatically applied
|
||||
when the generated constructor is later used.
|
||||
def customClass( classes, argStr ):
|
||||
"""Return customized class based on argStr
|
||||
The args and key/val pairs in argStr will be automatically applied
|
||||
when the generated class is later used.
|
||||
"""
|
||||
cname, newargs, kwargs = splitArgs( argStr )
|
||||
constructor = constructors.get( cname, None )
|
||||
|
||||
if not constructor:
|
||||
cname, args, kwargs = splitArgs( argStr )
|
||||
cls = classes.get( cname, None )
|
||||
if not cls:
|
||||
raise Exception( "error: %s is unknown - please specify one of %s" %
|
||||
( cname, constructors.keys() ) )
|
||||
( cname, classes.keys() ) )
|
||||
if not args and not kwargs:
|
||||
return cls
|
||||
|
||||
if not newargs and not kwargs:
|
||||
return constructor
|
||||
return specialClass( cls, append=args, defaults=kwargs )
|
||||
|
||||
if not isinstance( constructor, type ):
|
||||
raise Exception( "error: invalid arguments %s" % argStr )
|
||||
def specialClass( cls, prepend=None, append=None,
|
||||
defaults=None, override=None ):
|
||||
"""Like functools.partial, but it returns a class
|
||||
prepend: arguments to prepend to argument list
|
||||
append: arguments to append to argument list
|
||||
defaults: default values for keyword arguments
|
||||
override: keyword arguments to override"""
|
||||
|
||||
# Return a customized subclass
|
||||
cls = constructor
|
||||
if prepend is None:
|
||||
prepend = []
|
||||
|
||||
if append is None:
|
||||
append = []
|
||||
|
||||
if defaults is None:
|
||||
defaults = {}
|
||||
|
||||
if override is None:
|
||||
override = {}
|
||||
|
||||
class CustomClass( cls ):
|
||||
"Customized subclass, useful for Node, Link, and other classes"
|
||||
def __init__( self, name, *args, **params ):
|
||||
params = params.copy()
|
||||
params.update( kwargs )
|
||||
if not newargs:
|
||||
cls.__init__( self, name, *args, **params )
|
||||
return
|
||||
if args:
|
||||
warn( 'warning: %s replacing %s with %s\n' %
|
||||
( constructor, args, newargs ) )
|
||||
cls.__init__( self, name, *newargs, **params )
|
||||
"Customized subclass with preset args/params"
|
||||
def __init__( self, *args, **params ):
|
||||
newparams = defaults.copy()
|
||||
newparams.update( params )
|
||||
newparams.update( override )
|
||||
cls.__init__( self, *( list( prepend ) + list( args ) +
|
||||
list( append ) ),
|
||||
**newparams )
|
||||
|
||||
CustomClass.__name__ = '%s%s' % ( cls.__name__, kwargs )
|
||||
CustomClass.__name__ = '%s%s' % ( cls.__name__, defaults )
|
||||
return CustomClass
|
||||
|
||||
|
||||
def buildTopo( topos, topoStr ):
|
||||
"""Create topology from string with format (object, arg1, arg2,...).
|
||||
input topos is a dict of topo names to constructors, possibly w/args.
|
||||
@@ -575,9 +687,8 @@ def ensureRoot():
|
||||
Probably we should only sudo when needed as per Big Switch's patch.
|
||||
"""
|
||||
if os.getuid() != 0:
|
||||
print "*** Mininet must run as root."
|
||||
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.
|
||||
@@ -587,7 +698,7 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
|
||||
if not runCmd( 'which telnet' ):
|
||||
raise Exception('Could not find telnet' )
|
||||
# pylint: disable=maybe-no-member
|
||||
serverIP = server if isinstance( server, basestring ) else server.IP()
|
||||
serverIP = server if isinstance( server, BaseString ) else server.IP()
|
||||
cmd = ( 'echo A | telnet -e A %s %s' % ( serverIP, port ) )
|
||||
time = 0
|
||||
result = runCmd( cmd )
|
||||
@@ -605,3 +716,26 @@ def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
|
||||
time += .5
|
||||
result = runCmd( cmd )
|
||||
return True
|
||||
|
||||
def unitScale( num, prefix='' ):
|
||||
"Return unit scale prefix and factor"
|
||||
scale = 'kMGTP'
|
||||
if prefix:
|
||||
pos = scale.lower().index( prefix.lower() )
|
||||
return prefix, float( 10**(3*(pos+1)) )
|
||||
num, prefix, factor = float( num ), '', 1
|
||||
for i, c in enumerate(scale, start=1):
|
||||
f = 10**(3*i)
|
||||
if num < f:
|
||||
break
|
||||
prefix, factor = c, f
|
||||
return prefix, float( factor )
|
||||
|
||||
def fmtBps( bps, prefix='', fmt='%.1f %sbits/sec' ):
|
||||
"""Return bps as iperf-style formatted rate string
|
||||
prefix: lock to specific prefix (k, M, G, ...)
|
||||
fmt: default format string for bps, prefix"""
|
||||
bps = float( bps )
|
||||
prefix, factor = unitScale( bps, prefix )
|
||||
bps /= factor
|
||||
return fmt % ( bps, prefix)
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#include <sched.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#if !defined(VERSION)
|
||||
#define VERSION "(devel)"
|
||||
@@ -96,18 +99,26 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int fd;
|
||||
DIR *dir;
|
||||
struct dirent *de;
|
||||
char path[PATH_MAX];
|
||||
int nsid;
|
||||
int pid;
|
||||
char *cwd = get_current_dir_name();
|
||||
|
||||
static struct sched_param sp;
|
||||
|
||||
while ((c = getopt(argc, argv, "+cdnpa:g:r:vh")) != -1)
|
||||
switch(c) {
|
||||
case 'c':
|
||||
/* close file descriptors except stdin/out/error */
|
||||
for (fd = getdtablesize(); fd > 2; fd--)
|
||||
close(fd);
|
||||
if ((dir = opendir("/proc/self/fd"))) {
|
||||
while ((de = readdir(dir)))
|
||||
if ((fd = atoi(de->d_name)) > 2)
|
||||
close(fd);
|
||||
}
|
||||
/* fall back to old method if needed */
|
||||
else for (fd = getdtablesize(); fd > 2; fd--)
|
||||
close(fd);
|
||||
break;
|
||||
case 'd':
|
||||
/* detach from tty */
|
||||
@@ -130,6 +141,16 @@ int main(int argc, char *argv[])
|
||||
perror("unshare");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Mark our whole hierarchy recursively as private, so that our
|
||||
* mounts do not propagate to other processes.
|
||||
*/
|
||||
|
||||
if (mount("none", "/", NULL, MS_REC|MS_PRIVATE, NULL) == -1) {
|
||||
perror("remount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* mount sysfs to pick up the new network namespace */
|
||||
if (mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL) == -1) {
|
||||
perror("mount");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
"Setuptools params"
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools import setup
|
||||
from os.path import join
|
||||
|
||||
# Get version number from source tree
|
||||
|
||||
+25
-25
@@ -25,20 +25,20 @@ clean=false
|
||||
declare -a hosts=()
|
||||
user=$(whoami)
|
||||
SSHDIR=/tmp/mn/ssh
|
||||
USERDIR=/home/$user/.ssh
|
||||
usage=$'./clustersetup.sh [ -p|h|c ] [ host1 ] [ host2 ] ...\n
|
||||
USERDIR=$HOME/.ssh
|
||||
usage="./clustersetup.sh [ -p|h|c ] [ host1 ] [ host2 ] ...\n
|
||||
Authenticate yourself and other cluster nodes to each other
|
||||
via ssh for mininet cluster edition. By default, we use a
|
||||
temporary ssh setup. An ssh directory is mounted over
|
||||
/home/user/.ssh on each machine in the cluster.
|
||||
$USERDIR on each machine in the cluster.
|
||||
|
||||
-h: display this help
|
||||
-p: create a persistent ssh setup. This will add
|
||||
new ssh keys and known_hosts to each nodes
|
||||
/home/user/.ssh directory
|
||||
$USERDIR directory
|
||||
-c: method to clean up a temporary ssh setup.
|
||||
Any hosts taken as arguments will be cleaned
|
||||
'
|
||||
"
|
||||
|
||||
persistentSetup() {
|
||||
echo "***creating key pair"
|
||||
@@ -74,40 +74,40 @@ tempSetup() {
|
||||
echo "***creating temporary ssh directory"
|
||||
mkdir -p $SSHDIR
|
||||
echo "***creating key pair"
|
||||
ssh-keygen -t rsa -C "Cluster_Edition_Key" -f /tmp/mn/ssh/id_rsa -N '' &> /dev/null
|
||||
ssh-keygen -t rsa -C "Cluster_Edition_Key" -f $SSHDIR/id_rsa -N '' &> /dev/null
|
||||
|
||||
echo "***mounting temporary ssh directory"
|
||||
sudo mount --bind $SSHDIR /home/$user/.ssh
|
||||
sudo mount --bind $SSHDIR $USERDIR
|
||||
cp $SSHDIR/id_rsa.pub $SSHDIR/authorized_keys
|
||||
|
||||
for host in $hosts; do
|
||||
echo "***copying public key to $host"
|
||||
ssh-copy-id $user@$host &> /dev/null
|
||||
echo "***mounting remote temporary ssh directory for $host"
|
||||
ssh -o ForwardAgent=yes $user@$host "
|
||||
mkdir -p /tmp/mn/ssh
|
||||
cp /home/$user/.ssh/authorized_keys $SSHDIR/authorized_keys
|
||||
sudo mount --bind $SSHDIR /home/$user/.ssh"
|
||||
echo "***copying key pair to $host"
|
||||
scp $SSHDIR/{id_rsa,id_rsa.pub} $user@$host:$SSHDIR
|
||||
done
|
||||
for host in $hosts; do
|
||||
echo "***copying public key to $host"
|
||||
ssh-copy-id $user@$host &> /dev/null
|
||||
echo "***mounting remote temporary ssh directory for $host"
|
||||
ssh -o ForwardAgent=yes $user@$host "
|
||||
mkdir -p $SSHDIR
|
||||
cp $USERDIR/authorized_keys $SSHDIR/authorized_keys
|
||||
sudo mount --bind $SSHDIR $USERDIR"
|
||||
echo "***copying key pair to $host"
|
||||
scp $SSHDIR/{id_rsa,id_rsa.pub} $user@$host:$SSHDIR
|
||||
done
|
||||
|
||||
for host in $hosts; do
|
||||
echo "***copying known_hosts to $host"
|
||||
scp $SSHDIR/known_hosts $user@$host:$SSHDIR
|
||||
done
|
||||
for host in $hosts; do
|
||||
echo "***copying known_hosts to $host"
|
||||
scp $SSHDIR/known_hosts $user@$host:$SSHDIR
|
||||
done
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
|
||||
for host in $hosts; do
|
||||
echo "***cleaning up $host"
|
||||
ssh $user@$host "sudo umount /home/$user/.ssh
|
||||
ssh $user@$host "sudo umount $USERDIR
|
||||
sudo rm -rf $SSHDIR"
|
||||
done
|
||||
|
||||
echo "**unmounting local directories"
|
||||
sudo umount /home/$user/.ssh
|
||||
sudo umount $USERDIR
|
||||
echo "***removing temporary ssh directory"
|
||||
sudo rm -rf $SSHDIR
|
||||
echo "done!"
|
||||
@@ -169,7 +169,7 @@ echo
|
||||
if $persistent; then
|
||||
echo '***Setting up persistent SSH configuration between all nodes'
|
||||
persistentSetup
|
||||
echo $'\n*** Sucessfully set up ssh throughout the cluster!'
|
||||
echo $'\n*** Successfully set up ssh throughout the cluster!'
|
||||
|
||||
else
|
||||
echo '*** Setting up temporary SSH configuration between all nodes'
|
||||
|
||||
+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 ] )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user