Compare commits
606 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8df24304d8 | |||
| 93b123761b | |||
| cdbbb5b7a6 | |||
| 2cb17590c2 | |||
| f7601da006 | |||
| 65a0e5f3b6 | |||
| d5d66f1276 | |||
| 9ed14fa0f4 | |||
| f24ebc438e | |||
| 90d50dcbc4 | |||
| 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 | |||
| 17ba6a7c4d | |||
| f77a8b9e17 | |||
| 3dd8c2cda6 | |||
| 48a8ed857e | |||
| 74c3511d5c | |||
| 5ac113cfaa | |||
| cd02954c91 | |||
| 93be1d0401 | |||
| 6a38811f1a | |||
| 4ac45a3967 | |||
| d7e01bb821 | |||
| 340bf3cb7a | |||
| 5f8547a5e0 | |||
| 09e9c0550a | |||
| c1dc80571a | |||
| ec9b23ba9c | |||
| 7c0b56f9ba | |||
| d90a45514f | |||
| b2fe0778dc | |||
| 3e4f254573 | |||
| 2e4dd13482 | |||
| 19331ca287 | |||
| 9483f6378f | |||
| a4e933688a | |||
| c11e9f3316 | |||
| acdcf9b6ae | |||
| c702840a0a | |||
| 254fae2dc9 | |||
| bdad3e8c8e | |||
| 574d634fc2 | |||
| eafbd2a597 | |||
| 7485b035af | |||
| 8014a7023c | |||
| bec34e7227 | |||
| 9ca6322603 | |||
| 957fe1db93 | |||
| 3b4738c2ca | |||
| 30ebb852a3 | |||
| 959586bc8f | |||
| 9bda98486d | |||
| c68e4e76f4 | |||
| 98a8231cef | |||
| 28ce13d18e | |||
| ef59cd88dc | |||
| 9db6cdc261 | |||
| f7b29333f5 | |||
| 24520fc982 | |||
| b93cc989f4 | |||
| a8cc243aa7 | |||
| e65dc4c6d6 | |||
| d4be92713a | |||
| 79f5d39db5 | |||
| 6da3fcdef1 | |||
| 026130bd5f | |||
| c1b48fb5c8 | |||
| b1983548aa | |||
| c62812a944 | |||
| d66b96260a | |||
| d7e9c3bbfd | |||
| 7a4a865bdb | |||
| da4dcf3753 | |||
| 5383b0e603 | |||
| 9d2e6404b3 | |||
| 91a73bd191 | |||
| c069542c5c | |||
| 127f35a9bc | |||
| 171e815122 | |||
| 3ac5cafe53 | |||
| a7ad739036 | |||
| a84bec9709 | |||
| 05dbf82edb | |||
| c75eb47158 | |||
| 9945864a32 | |||
| beeea4b292 | |||
| 7a3159c9af | |||
| ccd6b5cd7d | |||
| 908e85d9f9 | |||
| e341526f46 | |||
| 03461ce908 | |||
| 8c37975d44 | |||
| 4d55ef1132 | |||
| 342d47cfb5 | |||
| 554abdd57a | |||
| 061598f011 | |||
| d754a7ceea | |||
| 643c9f912f | |||
| 4965421215 | |||
| 18aab5b786 | |||
| b905dddf19 | |||
| 11a9c46904 | |||
| b1ec912db5 | |||
| db45b7c644 | |||
| 2256a53830 | |||
| 03ef55672d | |||
| c45bfab318 | |||
| b2fcab827d | |||
| 1471da95a9 | |||
| 5a530af189 | |||
| 3c9f5ad56e | |||
| c5d9e0e03c | |||
| 0094997aa1 | |||
| 7a411b6bb5 | |||
| c2341cd47a | |||
| 4219b22978 | |||
| 08ab7e8de7 | |||
| 3ef6bcface | |||
| ab97dfa19c | |||
| af1ccf93a5 | |||
| 015cd9e776 | |||
| 3d44bcdcc4 | |||
| 1817cbc3a4 | |||
| e0bf8ece3c | |||
| 37bdf14b49 | |||
| 292e69f89a | |||
| dd876e69c8 | |||
| 4e644d7465 | |||
| 596fd9d0c6 | |||
| 474f68600e | |||
| 50774e407c | |||
| 8e63e2c540 | |||
| 273c4e9403 | |||
| c273f49077 | |||
| 9a8bdfd765 | |||
| 23dfbe4ae2 | |||
| b57e5d93b8 | |||
| f0f9907b9d | |||
| c4fc630413 | |||
| aabbf29542 | |||
| b7898befef | |||
| 6721f0655e | |||
| d37d6ecd99 | |||
| e4db698184 | |||
| e661a4b1c3 | |||
| f5164f86b7 | |||
| 9e0c1549f4 | |||
| 55b455e9ae | |||
| 34933ef741 | |||
| bbf94cdb63 | |||
| 593fc365d0 | |||
| 1edf3515e3 | |||
| 0d271f9477 | |||
| 3534f77761 | |||
| 64bbaeccc4 | |||
| de002b0d9a | |||
| 307302ed32 | |||
| a60f77ad36 | |||
| 383c3fb3e4 | |||
| a64f8c28bd | |||
| 377d1b1cd8 | |||
| dde2263fe7 | |||
| 434619053a | |||
| b739cd11c8 | |||
| bc6ef0dad8 | |||
| 3ac0dd7093 | |||
| 0f0fe82350 | |||
| 6be4bfd026 | |||
| d9d209f34d | |||
| 2059786f7b | |||
| 6008f987d3 | |||
| 635e8f11f3 | |||
| 9b5fa1d7ed | |||
| 1955e90493 | |||
| 222e87daeb | |||
| a89ccb789e | |||
| 2013b7ae81 | |||
| 3e1100b71a | |||
| 086afe852b | |||
| abcdf18547 | |||
| 4a304688f4 | |||
| d3377bf911 | |||
| 481cbea10c | |||
| b817cbc0ed | |||
| 15275048b6 | |||
| 3baccfee3a | |||
| bb76c21275 | |||
| c92c4efb66 | |||
| 39203484a6 | |||
| 2a2d605074 | |||
| 0676346aeb | |||
| 93fdb69ee3 | |||
| c7921fe402 | |||
| 3660e6d02f | |||
| 083322a217 | |||
| 8225105cf2 | |||
| ccd3276dcf | |||
| f51eddef6d | |||
| 4f8aa1d8a0 | |||
| 060d46a282 | |||
| 820c3be7df | |||
| a562ca1be3 | |||
| 658761d953 | |||
| 1b69ea13f5 | |||
| 6e5ac34bc2 | |||
| ec9f02c7ab | |||
| f75bee62b5 | |||
| e77123cf0e | |||
| 8dea57d271 | |||
| 634761b8a7 | |||
| 01aac350fa | |||
| 08d611f49b | |||
| f6de358b06 | |||
| f66904ab90 | |||
| 6a363f65e3 | |||
| 736db20c9f | |||
| ba8ea8f0cc | |||
| eab4ea3fb9 | |||
| 06d9e4bba7 | |||
| 38ce329e7e | |||
| 94f088d7e8 | |||
| 89fb081983 | |||
| aae0affae4 | |||
| 8190e81ba8 | |||
| 16a2a6dc55 | |||
| b7999978f9 | |||
| e1711f357a | |||
| 501eb4f916 | |||
| f341159300 | |||
| cac98f5fd5 | |||
| 5eca0802d2 | |||
| 6159e923e6 | |||
| 2ceb57915a | |||
| 61c144b9f6 | |||
| 8537e8d9fa | |||
| 33d42e25e6 | |||
| 7c5d2771f7 | |||
| 098bede0ec | |||
| 629e58ca5b | |||
| e3ab3fc239 | |||
| f1123e71ae | |||
| 778267aa75 | |||
| d6da13d4e3 | |||
| 92a4f2ddbf | |||
| ded25a9ef8 | |||
| 1bae1aab03 | |||
| 01a1e8e400 | |||
| 9487cb508d | |||
| 461751e5cd | |||
| 762479c15b | |||
| c8607467bd | |||
| f8e98d6a7f | |||
| 4aa0b82381 | |||
| f9522b30dc | |||
| ec26c7492d | |||
| 684092bae1 | |||
| 9cbf4688b2 | |||
| 74857ba474 | |||
| f1b61c629a | |||
| a565bdd57d | |||
| cf5bbd597a | |||
| c0d8fc0d37 | |||
| eef43402b6 | |||
| 54bd9e6112 | |||
| fa7edec7c8 | |||
| 89cc29b4c2 | |||
| 686a9993f5 | |||
| e16c5fe905 | |||
| dedb06b2f5 | |||
| 5fc3f57ede | |||
| 5789dae8be | |||
| 0efde9c4ed | |||
| 7eeaed992c | |||
| f0ce6f501d | |||
| 823d1b9990 | |||
| 61760eabc5 | |||
| 12095a12f4 | |||
| 412726d39c | |||
| 136c959191 | |||
| 2ac4cd43da | |||
| f603052b35 | |||
| 47be38e63c | |||
| 9ca775cba3 | |||
| e4d49e6df7 | |||
| 02bf34aa96 | |||
| 73ef3e9a39 | |||
| 55ef99b667 | |||
| 57686d3149 | |||
| 8396960ec0 | |||
| 3e8df323b3 | |||
| 706229da77 | |||
| 2c10a8e687 | |||
| e4c4891a47 | |||
| 80d647a9b0 | |||
| c5e8f09b10 | |||
| 08643fe679 | |||
| 3df3610199 | |||
| 00cbb348a7 | |||
| cde6c3aaf4 | |||
| c265deedef | |||
| 0333d3dbf4 | |||
| 58324bdc50 | |||
| 04c1c098ed | |||
| f2458d1dcf | |||
| ce781a1832 | |||
| b85943dc0a | |||
| d4ca1db60b | |||
| 47d567e53c | |||
| 6b8d3538ef | |||
| 05f3fbae73 | |||
| 65e33fed9b | |||
| d334c1ccfe | |||
| fe8358add2 | |||
| 2c76ab718b | |||
| aa4dfda44c | |||
| 66ae58de17 | |||
| ce1673803f | |||
| 73adba8b81 | |||
| c11d577349 | |||
| be1ed10363 | |||
| 8a987b9c55 | |||
| c75ff7ecd9 | |||
| 92075113d8 | |||
| 13bdd914dc | |||
| 60b0c7a914 | |||
| 212399feaf | |||
| 08d83d136d | |||
| dd6424fee8 | |||
| 720a846cf8 | |||
| bfdbb7089a | |||
| 16a384ab4b | |||
| a3e1a9a44d | |||
| 6a69c2f699 | |||
| db888fa5d4 | |||
| c9b844a721 | |||
| 604ad455ee | |||
| 8d493b686e | |||
| c0e7e34916 | |||
| 1a53141502 | |||
| 1285fb22dc | |||
| 4550fff1af | |||
| 7c4e5b14cb | |||
| f72d3dfa32 | |||
| e67539752e | |||
| db0f36f431 | |||
| 7e9d3f2b50 | |||
| 4015e0666e | |||
| cee62eb28e | |||
| 735080a84b | |||
| 161e7997fa | |||
| 417d79780f | |||
| 41a54f05cb | |||
| 84c1c24ce2 | |||
| af4c9719b3 | |||
| 39a3b73f85 | |||
| e8623fdc91 | |||
| 06dbd774a1 | |||
| a280501ff1 | |||
| 891a9e8bdf | |||
| 7ae39fffc2 | |||
| a56d9a6661 | |||
| b0048c0aca | |||
| 0983ed29bb | |||
| 88763cfbe1 | |||
| 19dd7f70c1 | |||
| 42cdda38bb | |||
| f0fd84770a | |||
| a2d0ea78be | |||
| e9d034bd31 | |||
| a3d51b77e9 | |||
| 4b65110e4d | |||
| eba13f0ca8 | |||
| c1934706bb | |||
| f67a7b64c8 | |||
| 628e84068e | |||
| 78a32e93fd | |||
| 859bfea502 | |||
| 2973798ca1 | |||
| b9a15f071c | |||
| f11dbe81d2 | |||
| 6bc9d68485 | |||
| 5cd6b553a5 | |||
| 5b13dc62ce | |||
| 4d381f0b58 | |||
| 84ce84f501 | |||
| 5b0897701b | |||
| 5465246245 | |||
| e183e69997 | |||
| 779ea5f0ad | |||
| 00d1963484 | |||
| 5ac3cde2bd | |||
| 2a08dec648 | |||
| b7268856d7 | |||
| 1b2c7a3193 | |||
| b5962e8ee9 | |||
| ece509d579 | |||
| 2935000485 | |||
| 708b184397 | |||
| 9a11544d87 | |||
| 2451d757bd | |||
| ea97dea902 | |||
| a19cc91537 | |||
| 796b281bf1 | |||
| 72fd120dc8 | |||
| 4794871a9a | |||
| 13d25b4109 | |||
| 21b50c962e | |||
| 54b29af818 | |||
| 8f34fa4c88 | |||
| 872e336462 | |||
| b7a112cbec | |||
| 5a9c74be03 | |||
| 38addf2e24 | |||
| 3878c000fe | |||
| 1324ae6262 | |||
| 3a52ad2f53 | |||
| c23c992f14 | |||
| 73f477be9d | |||
| 4797b42005 | |||
| 6845fd8339 | |||
| 8e2443ada4 | |||
| 84ea8d7f90 | |||
| 1aed2b8abd | |||
| 191df1cb73 | |||
| b6be1e2810 | |||
| a1acfa89c2 | |||
| 93ddd92662 | |||
| 3131c90344 | |||
| 3b484491ce | |||
| 3b24bd7abd | |||
| e9013d761f | |||
| c49b216c1f | |||
| 16ddf6560a | |||
| 0e733c7754 | |||
| 9c3ecfe338 | |||
| 771850b9cf | |||
| 355696f3dd | |||
| 342b743b13 | |||
| 40a4a25dd8 | |||
| 25979e715e | |||
| 82e0e9f38f | |||
| 549f1ebc8f | |||
| 00803bcd7f | |||
| af2f67d98c | |||
| 752c2d6e7c | |||
| 3c3344e1f5 | |||
| 68e2e45f7d | |||
| 6a81b6dfb3 | |||
| 4e76439c79 | |||
| 0d39f11034 | |||
| 893cf61c21 | |||
| ebc1eae679 | |||
| 29e5bee34e | |||
| de41192ea7 | |||
| b3055067ac | |||
| 9109233886 | |||
| e49c9d2600 | |||
| 87b6021428 | |||
| 50f5080912 | |||
| 3641723193 | |||
| 8b215af818 | |||
| 586a9bb631 | |||
| 00c3238e50 | |||
| e07775c7c3 | |||
| 4579b303e6 | |||
| 32d3c2bc79 | |||
| ba43451bd6 | |||
| f1e42ba5fa | |||
| 163a66c64c | |||
| 876e66e555 | |||
| 93cd5583eb | |||
| 5797f5852e | |||
| 15d2d76972 | |||
| 5cb4a5424d | |||
| 4d1a9cdc1d | |||
| c3bf407adf | |||
| 14e14f1b87 | |||
| bffe045267 | |||
| 92a28881b1 | |||
| ebac6784d4 | |||
| d9376439b1 | |||
| d718bb72e9 | |||
| 40ea9172f9 | |||
| 787f8234ce | |||
| cc20908bb3 | |||
| a7eb557680 | |||
| 0fe73a6780 | |||
| a905be2260 | |||
| 8f5f38c6a5 | |||
| d82900d3a8 | |||
| e62715870a | |||
| 2e19ceb0aa | |||
| a0bc100289 | |||
| 5e60ee266b | |||
| 7c29c2ebf2 | |||
| 4b7b23cf20 | |||
| 2dee3413cf | |||
| 59cbec3fc9 | |||
| 3e2eb71316 | |||
| 06115a0456 | |||
| 9cf9b7b223 | |||
| 1fda4865c8 | |||
| f0e55e1096 | |||
| 74c71bc8a4 | |||
| 0b5609f587 | |||
| 2fc5e46f1b | |||
| ef6774325a | |||
| 7450cfc627 | |||
| 29988c8b1d | |||
| 34bb64eddd | |||
| 873049c346 | |||
| a722a3a110 | |||
| f2942a7f92 | |||
| ae367d3645 | |||
| 6022e96b4d | |||
| 2286ef4b36 | |||
| 0dd96ebc57 | |||
| 06b99c8ef2 | |||
| b357a212dd | |||
| 2e704f996b | |||
| 284547080c | |||
| 07e3da08d0 | |||
| dfd79bde56 | |||
| 317d6482e4 | |||
| 5f51abd142 | |||
| b9288efc4a | |||
| c90fb34d6d | |||
| 75abd94bf5 | |||
| 55e48112f8 | |||
| 4b65570ba5 | |||
| 9aefda7c1a | |||
| bb485009c3 | |||
| 24fe68d925 | |||
| 3780d9cda8 | |||
| e10703cd7b | |||
| 824afb84c9 | |||
| aee33863c8 | |||
| 90c29d8f23 | |||
| e686911210 | |||
| 8bb830824b | |||
| a6a0cb4331 | |||
| 2200d8d173 | |||
| c34a000e78 | |||
| fb51cdaca3 | |||
| 50423936b2 | |||
| 49994c8915 | |||
| 3e2333e5ed | |||
| fc7c919b43 | |||
| 5461565945 | |||
| 09b06509a8 | |||
| e0af160213 | |||
| ffeb16eb66 | |||
| a802d8b19a | |||
| 555d10dea7 | |||
| 3f2355a36a | |||
| bceb298edb | |||
| 47b9466fad |
@@ -41,16 +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=W0704,C0103,W0231,E1102,W0511,W0142,R0902,R0903,R0904,R0913,R0914,R0801,I0011
|
||||
|
||||
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
|
||||
|
||||
[REPORTS]
|
||||
|
||||
# Set the output format. Available formats are text, parseable, colorized, msvs
|
||||
# (visual studio) and html
|
||||
output-format=colorized
|
||||
msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}'
|
||||
|
||||
# Include message's id in outpu
|
||||
# Include message's id in output
|
||||
include-ids=yes
|
||||
|
||||
# Put messages in a separate file for each module / package specified on the
|
||||
@@ -191,7 +194,7 @@ additional-builtins=
|
||||
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
|
||||
defining-attr-methods=__init__,__new__,setUp,build
|
||||
|
||||
|
||||
# checks for sign of poor/misdesign:
|
||||
@@ -264,7 +267,8 @@ int-import-graph=
|
||||
max-line-length=80
|
||||
|
||||
# Maximum number of lines in a module
|
||||
max-module-lines=1500
|
||||
# XXX 1500 -> 4000 for miniedit.py
|
||||
max-module-lines=4000
|
||||
|
||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||
# tab).
|
||||
|
||||
+14
-1
@@ -7,32 +7,45 @@ or send a pull request.
|
||||
|
||||
Contributors include:
|
||||
|
||||
Mininet Core Team
|
||||
Mininet Core Team (and alumni)
|
||||
|
||||
Bob Lantz
|
||||
Brandon Heller
|
||||
Nikhil Handigol
|
||||
Vimal Jeyakumar
|
||||
Brian O'Connor
|
||||
Cody Burkard
|
||||
|
||||
Additional Mininet Contributors
|
||||
|
||||
Tomasz Buchert
|
||||
Gustavo Pantuza Coelho Pinto
|
||||
Fernando Cappi
|
||||
Ryan Cox
|
||||
Shaun Crampton
|
||||
David Erickson
|
||||
Glen Gibb
|
||||
Andrew Ferguson
|
||||
Eder Leao Fernandes
|
||||
Gregory Gee
|
||||
Jon Hall
|
||||
Roan Huang
|
||||
Vitaly Ivanov
|
||||
Babis Kaidos
|
||||
Rich Lane
|
||||
Rémy Léone
|
||||
Zi Shen Lim
|
||||
David Mahler
|
||||
Murphy McCauley
|
||||
José Pedro Oliveira
|
||||
James Page
|
||||
Angad Singh
|
||||
Piyush Srivastava
|
||||
Ed Swierk
|
||||
Darshan Thaker
|
||||
Andreas Wundsam
|
||||
Isaku Yamahata
|
||||
Baohua Yang
|
||||
|
||||
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.1.0+
|
||||
Mininet 2.2.1
|
||||
---
|
||||
|
||||
The supported installation methods for Mininet are 1) using a
|
||||
@@ -51,14 +51,29 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
git clone git://github.com/mininet/mininet.git
|
||||
|
||||
If you are running Ubuntu, you may be able to use our handy
|
||||
`install.sh` script, which is in `mininet/util`.
|
||||
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
|
||||
|
||||
cd mininet
|
||||
git tag
|
||||
|
||||
and then
|
||||
|
||||
git checkout <release tag>
|
||||
|
||||
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`.
|
||||
|
||||
*WARNING: USE AT YOUR OWN RISK!*
|
||||
|
||||
`install.sh` is 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..
|
||||
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.
|
||||
|
||||
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!
|
||||
@@ -146,10 +161,8 @@ like to contribute an installation script, we would welcome it!)
|
||||
|
||||
* A Linux kernel compiled with network namespace support enabled
|
||||
|
||||
* An OpenFlow implementation (either the reference user or kernel
|
||||
space implementations, or Open vSwitch.) Appropriate kernel
|
||||
modules (e.g. tun and ofdatapath for the reference kernel
|
||||
implementation) must be loaded.
|
||||
* An compatible software switch such as Open vSwitch or
|
||||
the Linux bridge.
|
||||
|
||||
* Python, `bash`, `ping`, `iperf`, etc.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Mininet 2.1.0+ License
|
||||
Mininet 2.2.1 License
|
||||
|
||||
Copyright (c) 2013 Open Networking Laboratory
|
||||
Copyright (c) 2013-2015 Open Networking Laboratory
|
||||
Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of
|
||||
The Leland Stanford Junior University
|
||||
|
||||
|
||||
@@ -2,11 +2,12 @@ MININET = mininet/*.py
|
||||
TEST = mininet/test/*.py
|
||||
EXAMPLES = mininet/examples/*.py
|
||||
MN = bin/mn
|
||||
PYMN = python -B bin/mn
|
||||
BIN = $(MN)
|
||||
PYSRC = $(MININET) $(TEST) $(EXAMPLES) $(BIN)
|
||||
MNEXEC = mnexec
|
||||
MANPAGES = mn.1 mnexec.1
|
||||
P8IGN = E251,E201,E302,E202
|
||||
P8IGN = E251,E201,E302,E202,E126,E127,E203,E226
|
||||
BINDIR = /usr/bin
|
||||
MANDIR = /usr/share/man/man1
|
||||
DOCDIRS = doc/html doc/latex
|
||||
@@ -24,7 +25,8 @@ codecheck: $(PYSRC)
|
||||
util/versioncheck.py
|
||||
pyflakes $(PYSRC)
|
||||
pylint --rcfile=.pylint $(PYSRC)
|
||||
pep8 --repeat --ignore=$(P8IGN) $(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"
|
||||
@@ -36,8 +38,13 @@ test: $(MININET) $(TEST)
|
||||
mininet/test/test_nets.py
|
||||
mininet/test/test_hifi.py
|
||||
|
||||
slowtest: $(MININET)
|
||||
-echo "Running slower tests (walkthrough, examples)"
|
||||
mininet/test/test_walkthrough.py -v
|
||||
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`\" $< -o $@
|
||||
|
||||
install: $(MNEXEC) $(MANPAGES)
|
||||
install $(MNEXEC) $(BINDIR)
|
||||
@@ -45,7 +52,7 @@ install: $(MNEXEC) $(MANPAGES)
|
||||
python setup.py install
|
||||
|
||||
develop: $(MNEXEC) $(MANPAGES)
|
||||
# Perhaps we should link these as well
|
||||
# Perhaps we should link these as well
|
||||
install $(MNEXEC) $(BINDIR)
|
||||
install $(MANPAGES) $(MANDIR)
|
||||
python setup.py develop
|
||||
@@ -54,11 +61,11 @@ 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." \
|
||||
-h "-h" -v "-v" --no-discard-stderr ./$< -o $@
|
||||
-h "-h" -v "-v" --no-discard-stderr ./$< -o $@
|
||||
|
||||
.PHONY: doc
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ Mininet: Rapid Prototyping for Software Defined Networks
|
||||
|
||||
*The best way to emulate almost any network on your laptop!*
|
||||
|
||||
Version 2.1.0+
|
||||
Mininet 2.2.1
|
||||
|
||||
### What is Mininet?
|
||||
|
||||
@@ -66,32 +66,27 @@ Mininet includes:
|
||||
|
||||
`mn -c`
|
||||
|
||||
### New features in 2.1.0+
|
||||
### New features in this release
|
||||
|
||||
Mininet 2.1.0+ provides a number of bug fixes as well as
|
||||
several new features, including:
|
||||
This is primarily a performance improvement and bug fix release.
|
||||
|
||||
* Convenient access to `Mininet()` as a dict of nodes
|
||||
* X11 tunneling (wireshark in Mininet hosts, finally!)
|
||||
* Accurate reflection of the `Mininet()` object in the CLI
|
||||
* Automatically detecting and adjusting resource limits
|
||||
* Automatic cleanup on failure of the `mn` command
|
||||
* Preliminary support for running OVS in user space mode
|
||||
* Preliminary support (`IVSSwitch()`) for the Indigo Virtual Switch
|
||||
* support for installing the OpenFlow 1.3 versions of the reference
|
||||
user switch and NOX from CPqD
|
||||
* The ability to import modules from `mininet.examples`
|
||||
- Batch startup has been implemented for Open vSwitch, improving
|
||||
startup performance.
|
||||
|
||||
We have provided several new examples (which can easily be
|
||||
imported to provide useful functionality) including:
|
||||
- OVS patch links have been implemented via OVSLink and --link ovs
|
||||
|
||||
* Modeling separate control and data networks: `mininet.examples.controlnet`
|
||||
* Connecting Mininet hosts the internet (or a LAN) using NAT: `mininet.examples.nat`
|
||||
* Creating per-host custom directories using bind mounts: `mininet.examples.bind`
|
||||
Warning! These links have *serious limitations* compared to
|
||||
virtual Ethernet pairs: they are not attached to real Linux
|
||||
interfaces so you cannot use tcpdump or wireshark with them;
|
||||
they also cannot be used in long chains - we don't recommend more
|
||||
than 64 OVSLinks, for example --linear,64. However, they can offer
|
||||
significantly better performance than veth pairs, for certain
|
||||
configurations.
|
||||
|
||||
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!
|
||||
- You can now easily install Mininet on a Raspberry Pi ;-)
|
||||
|
||||
- Additional information for this release and previous releases
|
||||
may be found in the release notes on docs.mininet.org
|
||||
|
||||
### Installation
|
||||
|
||||
@@ -113,21 +108,22 @@ Mininet mailing list, `mininet-discuss` at:
|
||||
|
||||
<https://mailman.stanford.edu/mailman/listinfo/mininet-discuss>
|
||||
|
||||
### Contributing
|
||||
### Join Us
|
||||
|
||||
Thanks again to all of the Mininet contributors!
|
||||
|
||||
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.
|
||||
Thanks to everyone who has contributed to the project
|
||||
(see CONTRIBUTORS for more info!)
|
||||
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!
|
||||
|
||||
### Credits
|
||||
|
||||
The Mininet 2.1.0+ Team:
|
||||
|
||||
* Bob Lantz
|
||||
* Brian O'Connor
|
||||
Bob Lantz
|
||||
Mininet Core Team
|
||||
|
||||
@@ -22,47 +22,70 @@ if 'PYTHONPATH' in os.environ:
|
||||
|
||||
from mininet.clean import cleanup
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import lg, LEVELS, info, debug, error
|
||||
from mininet.log import lg, LEVELS, info, debug, warn, error
|
||||
from mininet.net import Mininet, MininetWithControlNet, VERSION
|
||||
from mininet.node import ( Host, CPULimitedHost, Controller, OVSController,
|
||||
NOX, RemoteController, UserSwitch, OVSKernelSwitch,
|
||||
OVSLegacyKernelSwitch, IVSSwitch )
|
||||
from mininet.link import Link, TCLink
|
||||
from mininet.topo import SingleSwitchTopo, LinearTopo, SingleSwitchReversedTopo
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import custom, customConstructor
|
||||
Ryu, NOX, RemoteController, findController,
|
||||
DefaultController, NullController,
|
||||
UserSwitch, OVSSwitch, OVSBridge,
|
||||
IVSSwitch )
|
||||
from mininet.nodelib import LinuxBridge
|
||||
from mininet.link import Link, TCLink, OVSLink
|
||||
from mininet.topo import ( SingleSwitchTopo, LinearTopo,
|
||||
SingleSwitchReversedTopo, MinimalTopo )
|
||||
from mininet.topolib import TreeTopo, TorusTopo
|
||||
from mininet.util import customClass, specialClass, splitArgs
|
||||
from mininet.util import buildTopo
|
||||
|
||||
from functools import partial
|
||||
|
||||
# Experimental! cluster edition prototype
|
||||
from mininet.examples.cluster import ( MininetCluster, RemoteHost,
|
||||
RemoteOVSSwitch, RemoteLink,
|
||||
SwitchBinPlacer, RandomPlacer,
|
||||
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,
|
||||
'tree': TreeTopo }
|
||||
'tree': TreeTopo,
|
||||
'torus': TorusTopo }
|
||||
|
||||
SWITCHDEF = 'ovsk'
|
||||
SWITCHDEF = 'default'
|
||||
SWITCHES = { 'user': UserSwitch,
|
||||
'ovsk': OVSKernelSwitch,
|
||||
'ovsl': OVSLegacyKernelSwitch,
|
||||
'ivs': IVSSwitch }
|
||||
'ovs': OVSSwitch,
|
||||
'ovsbr' : OVSBridge,
|
||||
# Keep ovsk for compatibility with 2.0
|
||||
'ovsk': OVSSwitch,
|
||||
'ivs': IVSSwitch,
|
||||
'lxbr': LinuxBridge,
|
||||
'default': OVSSwitch }
|
||||
|
||||
HOSTDEF = 'proc'
|
||||
HOSTS = { 'proc': Host,
|
||||
'rt': custom( CPULimitedHost, sched='rt' ),
|
||||
'cfs': custom( CPULimitedHost, sched='cfs' ) }
|
||||
'rt': specialClass( CPULimitedHost, defaults=dict( sched='rt' ) ),
|
||||
'cfs': specialClass( CPULimitedHost, defaults=dict( sched='cfs' ) ) }
|
||||
|
||||
CONTROLLERDEF = 'default'
|
||||
|
||||
CONTROLLERDEF = 'ovsc'
|
||||
CONTROLLERS = { 'ref': Controller,
|
||||
'ovsc': OVSController,
|
||||
'nox': NOX,
|
||||
'remote': RemoteController,
|
||||
'none': lambda name: None }
|
||||
'ryu': Ryu,
|
||||
'default': DefaultController, # Note: replaced below
|
||||
'none': NullController }
|
||||
|
||||
LINKDEF = 'default'
|
||||
LINKS = { 'default': Link,
|
||||
'tc': TCLink }
|
||||
'tc': TCLink,
|
||||
'ovs': OVSLink }
|
||||
|
||||
|
||||
# optional tests to run
|
||||
@@ -75,30 +98,28 @@ ALTSPELLING = { 'pingall': 'pingAll',
|
||||
'iperfUDP': 'iperfUdp' }
|
||||
|
||||
|
||||
def addDictOption( opts, choicesDict, default, name, helpStr=None ):
|
||||
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
|
||||
exit()
|
||||
|
||||
|
||||
class MininetRunner( object ):
|
||||
"Build, setup, and run Mininet."
|
||||
|
||||
@@ -112,9 +133,32 @@ class MininetRunner( object ):
|
||||
self.setup()
|
||||
self.begin()
|
||||
|
||||
def custom( self, _option, _opt_str, value, _parser ):
|
||||
"""Parse custom file and add params.
|
||||
option: option e.g. --custom
|
||||
opt_str: option string e.g. --custom
|
||||
value: the value the follows the option
|
||||
parser: option parser instance"""
|
||||
files = []
|
||||
if os.path.isfile( value ):
|
||||
# Accept any single file (including those with commas)
|
||||
files.append( value )
|
||||
else:
|
||||
# Accept a comma-separated list of filenames
|
||||
files += value.split(',')
|
||||
|
||||
for fileName in files:
|
||||
customs = {}
|
||||
if os.path.isfile( fileName ):
|
||||
execfile( fileName, customs, customs )
|
||||
for name, val in customs.iteritems():
|
||||
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' ):
|
||||
# Update dictionaries
|
||||
param = name.upper()
|
||||
globals()[ param ].update( value )
|
||||
@@ -125,26 +169,23 @@ class MininetRunner( object ):
|
||||
# Add or modify global variable or class
|
||||
globals()[ name ] = value
|
||||
|
||||
def parseCustomFile( self, fileName ):
|
||||
"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():
|
||||
self.setCustom( name, val )
|
||||
def setNat( self, _option, opt_str, value, parser ):
|
||||
"Set NAT option(s)"
|
||||
assert self # satisfy pylint
|
||||
parser.values.nat = True
|
||||
# first arg, first char != '-'
|
||||
if parser.rargs and parser.rargs[ 0 ][ 0 ] != '-':
|
||||
value = parser.rargs.pop( 0 )
|
||||
_, args, kwargs = splitArgs( opt_str + ',' + value )
|
||||
parser.values.nat_args = args
|
||||
parser.values.nat_kwargs = kwargs
|
||||
else:
|
||||
raise Exception( 'could not find custom file: %s' % fileName )
|
||||
parser.values.nat_args = []
|
||||
parser.values.nat_kwargs = {}
|
||||
|
||||
def parseArgs( self ):
|
||||
"""Parse command-line args and return options object.
|
||||
returns: opts parse options dict"""
|
||||
if '--custom' in sys.argv:
|
||||
index = sys.argv.index( '--custom' )
|
||||
if len( sys.argv ) > index + 1:
|
||||
filename = sys.argv[ index + 1 ]
|
||||
self.parseCustomFile( filename )
|
||||
else:
|
||||
raise Exception( 'Custom file name not found' )
|
||||
|
||||
desc = ( "The %prog utility creates Mininet network from the\n"
|
||||
"command line. It can create parametrized topologies,\n"
|
||||
@@ -156,15 +197,18 @@ 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' )
|
||||
|
||||
opts.add_option( '--clean', '-c', action='store_true',
|
||||
default=False, help='clean and exit' )
|
||||
opts.add_option( '--custom', type='string', default=None,
|
||||
help='read custom topo and node params from .py' +
|
||||
'file' )
|
||||
opts.add_option( '--custom', action='callback',
|
||||
callback=self.custom,
|
||||
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 ) )
|
||||
@@ -193,7 +237,24 @@ class MininetRunner( object ):
|
||||
opts.add_option( '--pin', action='store_true',
|
||||
default=False, help="pin hosts to CPU cores "
|
||||
"(requires --host cfs or --host rt)" )
|
||||
opts.add_option( '--version', action='callback', callback=version )
|
||||
opts.add_option( '--nat', action='callback', callback=self.setNat,
|
||||
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"
|
||||
" IP subnet into the Mininet network."
|
||||
" If you need to change"
|
||||
" 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( '--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',
|
||||
metavar='block|random',
|
||||
help=( 'node placement for --cluster '
|
||||
'(experimental!) ' ) )
|
||||
|
||||
self.options, self.args = opts.parse_args()
|
||||
|
||||
@@ -213,26 +274,49 @@ class MininetRunner( object ):
|
||||
% self.options.verbosity )
|
||||
lg.setLogLevel( self.options.verbosity )
|
||||
|
||||
# Maybe we'll reorganize this someday...
|
||||
# pylint: disable=too-many-branches,too-many-statements
|
||||
|
||||
def begin( self ):
|
||||
"Create and run mininet."
|
||||
|
||||
if self.options.cluster:
|
||||
servers = self.options.cluster.split( ',' )
|
||||
for server in servers:
|
||||
ClusterCleanup.add( server )
|
||||
|
||||
if self.options.clean:
|
||||
cleanup()
|
||||
exit()
|
||||
|
||||
start = time.time()
|
||||
|
||||
if not self.options.controller:
|
||||
# Update default based on available controllers
|
||||
CONTROLLERS[ 'default' ] = findController()
|
||||
self.options.controller = [ 'default' ]
|
||||
if not CONTROLLERS[ 'default' ]:
|
||||
self.options.controller = [ 'none' ]
|
||||
if self.options.switch == 'default':
|
||||
info( '*** No default OpenFlow controller found '
|
||||
'for default switch!\n' )
|
||||
info( '*** Falling back to OVS Bridge\n' )
|
||||
self.options.switch = 'ovsbr'
|
||||
elif self.options.switch not in ( 'ovsbr', 'lxbr' ):
|
||||
raise Exception( "Could not find a default controller "
|
||||
"for switch %s" %
|
||||
self.options.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 )
|
||||
switch = customClass( SWITCHES, self.options.switch )
|
||||
host = customClass( HOSTS, self.options.host )
|
||||
controller = [ customClass( CONTROLLERS, c )
|
||||
for c in self.options.controller ]
|
||||
link = customClass( LINKS, self.options.link )
|
||||
|
||||
if self.validate:
|
||||
self.validate( self.options )
|
||||
|
||||
inNamespace = self.options.innamespace
|
||||
Net = MininetWithControlNet if inNamespace else Mininet
|
||||
ipBase = self.options.ipbase
|
||||
xterms = self.options.xterms
|
||||
mac = self.options.mac
|
||||
@@ -241,6 +325,22 @@ class MininetRunner( object ):
|
||||
listenPort = None
|
||||
if not self.options.nolistenport:
|
||||
listenPort = self.options.listenport
|
||||
|
||||
# Handle inNamespace, cluster options
|
||||
inNamespace = self.options.innamespace
|
||||
cluster = self.options.cluster
|
||||
if inNamespace and cluster:
|
||||
print "Please specify --innamespace OR --cluster"
|
||||
exit()
|
||||
Net = MininetWithControlNet if inNamespace else Mininet
|
||||
cli = ClusterCLI if cluster else CLI
|
||||
if 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 ] )
|
||||
|
||||
mn = Net( topo=topo,
|
||||
switch=switch, host=host, controller=controller,
|
||||
link=link,
|
||||
@@ -250,8 +350,13 @@ class MininetRunner( object ):
|
||||
autoStaticArp=arp, autoPinCpus=pin,
|
||||
listenPort=listenPort )
|
||||
|
||||
if self.options.ensure_value( 'nat', False ):
|
||||
nat = mn.addNAT( *self.options.nat_args,
|
||||
**self.options.nat_kwargs )
|
||||
nat.configDefault()
|
||||
|
||||
if self.options.pre:
|
||||
CLI( mn, script=self.options.pre )
|
||||
cli( mn, script=self.options.pre )
|
||||
|
||||
test = self.options.test
|
||||
test = ALTSPELLING.get( test, test )
|
||||
@@ -261,16 +366,18 @@ class MininetRunner( object ):
|
||||
if test == 'none':
|
||||
pass
|
||||
elif test == 'all':
|
||||
mn.waitConnected()
|
||||
mn.start()
|
||||
mn.ping()
|
||||
mn.iperf()
|
||||
elif test == 'cli':
|
||||
CLI( mn )
|
||||
cli( mn )
|
||||
elif test != 'build':
|
||||
mn.waitConnected()
|
||||
getattr( mn, test )()
|
||||
|
||||
if self.options.post:
|
||||
CLI( mn, script=self.options.post )
|
||||
cli( mn, script=self.options.post )
|
||||
|
||||
mn.stop()
|
||||
|
||||
|
||||
+62
-2
@@ -11,9 +11,34 @@ Mininet's Python API.
|
||||
This example uses Mininet's medium-level API to create an sshd
|
||||
process running in a namespace. Doesn't use OpenFlow.
|
||||
|
||||
#### bind.py:
|
||||
|
||||
This example shows how you can create private directories for each
|
||||
node in a Mininet topology.
|
||||
|
||||
#### cluster.py:
|
||||
|
||||
This example contains all of the code for experimental cluster
|
||||
edition. Remote classes and MininetCluster can be imported from
|
||||
here to create a topology with nodes on remote machines.
|
||||
|
||||
#### clusterSanity.py:
|
||||
|
||||
This example runs cluster edition locally as a sanity check to test
|
||||
basic functionality.
|
||||
|
||||
#### clustercli.py:
|
||||
|
||||
This example contains a CLI for experimental cluster edition.
|
||||
|
||||
#### clusterdemo.py:
|
||||
|
||||
This example is a basic demo of cluster edition on 3 servers with
|
||||
a tree topology of depth 3 and fanout 3.
|
||||
|
||||
#### consoles.py:
|
||||
|
||||
This example creates a grid of console windows, one for each node,
|
||||
This example creates a grid of console windows, one for each node,
|
||||
and allows interaction with and monitoring of each console, including
|
||||
graphical monitoring.
|
||||
|
||||
@@ -47,6 +72,11 @@ topology object) and adding nodes to it.
|
||||
This example shows how to add an interface (for example a real
|
||||
hardware interface) to a network after the network is created.
|
||||
|
||||
#### intfoptions.py:
|
||||
|
||||
This example reconfigures a TCIntf during runtime with different
|
||||
traffic control commands to test bandwidth, loss, and delay.
|
||||
|
||||
#### limit.py:
|
||||
|
||||
This example shows how to use link and CPU limits.
|
||||
@@ -56,13 +86,28 @@ This example shows how to use link and CPU limits.
|
||||
This example shows how to create a custom topology programatically
|
||||
by subclassing Topo, and how to run a series of tests on it.
|
||||
|
||||
#### linuxrouter.py:
|
||||
|
||||
This example shows how to create and configure a router in Mininet
|
||||
that uses Linux IP forwarding.
|
||||
|
||||
#### miniedit.py:
|
||||
|
||||
This example demonstrates creating a network via a graphical editor.
|
||||
|
||||
#### mobility.py:
|
||||
|
||||
This example demonstrates detaching an interface from one switch and
|
||||
attaching it another as a basic way to move a host around a network.
|
||||
|
||||
#### multiLink.py:
|
||||
|
||||
This example demonstrates the creation of multiple links between
|
||||
nodes using a custom Topology class.
|
||||
|
||||
#### multiping.py:
|
||||
|
||||
This example demonstrates one method for
|
||||
This example demonstrates one method for
|
||||
monitoring output from multiple hosts, using `node.monitor()`.
|
||||
|
||||
#### multipoll.py:
|
||||
@@ -79,6 +124,16 @@ This example shows how to connect a Mininet network to the Internet
|
||||
using NAT. It also answers the eternal question "why can't I ping
|
||||
`google.com`?"
|
||||
|
||||
#### natnet.py:
|
||||
|
||||
This example demonstrates how to create a network using a NAT node
|
||||
to connect hosts to the internet.
|
||||
|
||||
#### numberedports.py:
|
||||
|
||||
This example verifies the mininet ofport numbers match up to the ovs port numbers.
|
||||
It also verifies that the port numbers match up to the interface numbers
|
||||
|
||||
#### popen.py:
|
||||
|
||||
This example monitors a number of hosts using `host.popen()` and
|
||||
@@ -117,3 +172,8 @@ memory and `sysctl` configuration (see `INSTALL`.)
|
||||
|
||||
This example creates a 64-host tree network, and attempts to check full
|
||||
connectivity using `ping`, for different switch/datapath types.
|
||||
|
||||
#### vlanhost.py:
|
||||
|
||||
An example of how to subclass Host to use a VLAN on its primary interface.
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
import sys
|
||||
from mininet.node import Host
|
||||
from mininet.util import ensureRoot
|
||||
from mininet.util import ensureRoot, waitListening
|
||||
|
||||
ensureRoot()
|
||||
timeout = 5
|
||||
|
||||
print "*** Creating nodes"
|
||||
h1 = Host( 'h1' )
|
||||
@@ -33,5 +34,10 @@ cmd = '/usr/sbin/sshd -o UseDNS=no -u0 -o "Banner /tmp/%s.banner"' % h1.name
|
||||
if len( sys.argv ) > 1:
|
||||
cmd += ' ' + ' '.join( sys.argv[ 1: ] )
|
||||
h1.cmd( cmd )
|
||||
listening = waitListening( server=h1, port=22, timeout=timeout )
|
||||
|
||||
print "*** You may now ssh into", h1.name, "at", h1.IP()
|
||||
if listening:
|
||||
print "*** You may now ssh into", h1.name, "at", h1.IP()
|
||||
else:
|
||||
print ( "*** Warning: after %s seconds, %s is not listening on port 22"
|
||||
% ( timeout, h1.name ) )
|
||||
|
||||
+39
-169
@@ -1,197 +1,67 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
bind.py: Bind mount prototype
|
||||
bind.py: Bind mount example
|
||||
|
||||
This creates hosts with private directories as desired.
|
||||
This creates hosts with private directories that the user specifies.
|
||||
These hosts may have persistent directories that will be available
|
||||
across multiple mininet session, or temporary directories that will
|
||||
only last for one mininet session. To specify a persistent
|
||||
directory, add a tuple to a list of private directories:
|
||||
|
||||
[ ( 'directory to be mounted on', 'directory to be mounted' ) ]
|
||||
|
||||
String expansion may be used to create a directory template for
|
||||
each host. To do this, add a %(name)s in place of the host name
|
||||
when creating your list of directories:
|
||||
|
||||
[ ( '/var/run', '/tmp/%(name)s/var/run' ) ]
|
||||
|
||||
If no persistent directory is specified, the directories will default
|
||||
to temporary private directories. To do this, simply create a list of
|
||||
directories to be made private. A tmpfs will then be mounted on them.
|
||||
|
||||
You may use both temporary and persistent directories at the same
|
||||
time. In the following privateDirs string, each host will have a
|
||||
persistent directory in the root filesystem at
|
||||
"/tmp/(hostname)/var/run" mounted on "/var/run". Each host will also
|
||||
have a temporary private directory mounted on "/var/log".
|
||||
|
||||
[ ( '/var/run', '/tmp/%(name)s/var/run' ), '/var/log' ]
|
||||
|
||||
This example has both persistent directories mounted on '/var/log'
|
||||
and '/var/run'. It also has a temporary private directory mounted
|
||||
on '/var/mn'
|
||||
"""
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Host
|
||||
from mininet.cli import CLI
|
||||
from mininet.util import errFail, quietRun, errRun
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import setLogLevel, info, debug
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
from os.path import realpath
|
||||
from functools import partial
|
||||
|
||||
|
||||
# Utility functions for unmounting a tree
|
||||
|
||||
MNRUNDIR = realpath( '/var/run/mn' )
|
||||
|
||||
def mountPoints():
|
||||
"Return list of mounted file systems"
|
||||
mtab, _err, _ret = errFail( 'cat /proc/mounts' )
|
||||
lines = mtab.split( '\n' )
|
||||
mounts = []
|
||||
for line in lines:
|
||||
if not line:
|
||||
continue
|
||||
fields = line.split( ' ')
|
||||
mount = fields[ 1 ]
|
||||
mounts.append( mount )
|
||||
return mounts
|
||||
|
||||
def unmountAll( rootdir=MNRUNDIR ):
|
||||
"Unmount all mounts under a directory tree"
|
||||
rootdir = realpath( rootdir )
|
||||
# Find all mounts below rootdir
|
||||
# This is subtle because /foo is not
|
||||
# a parent of /foot
|
||||
dirslash = rootdir + '/'
|
||||
mounts = [ m for m in mountPoints()
|
||||
if m == dir or m.find( dirslash ) == 0 ]
|
||||
# Unmount them from bottom to top
|
||||
mounts.sort( reverse=True )
|
||||
for mount in mounts:
|
||||
debug( 'Unmounting', mount, '\n' )
|
||||
_out, err, code = errRun( 'umount', mount )
|
||||
if code != 0:
|
||||
info( '*** Warning: failed to umount', mount, '\n' )
|
||||
info( err )
|
||||
|
||||
|
||||
class HostWithPrivateDirs( Host ):
|
||||
"Host with private directories"
|
||||
|
||||
mnRunDir = MNRUNDIR
|
||||
|
||||
def __init__(self, name, *args, **kwargs ):
|
||||
"""privateDirs: list of private directories
|
||||
remounts: dirs to remount
|
||||
unmount: unmount dirs in cleanup? (True)
|
||||
Note: if unmount is False, you must call unmountAll()
|
||||
manually."""
|
||||
self.privateDirs = kwargs.pop( 'privateDirs', [] )
|
||||
self.remounts = kwargs.pop( 'remounts', [] )
|
||||
self.unmount = kwargs.pop( 'unmount', True )
|
||||
Host.__init__( self, name, *args, **kwargs )
|
||||
self.rundir = '%s/%s' % ( self.mnRunDir, name )
|
||||
self.root, self.private = None, None # set in createBindMounts
|
||||
if self.privateDirs:
|
||||
self.privateDirs = [ realpath( d ) for d in self.privateDirs ]
|
||||
self.createBindMounts()
|
||||
# These should run in the namespace before we chroot,
|
||||
# in order to put the right entries in /etc/mtab
|
||||
# Eventually this will allow a local pid space
|
||||
# Now we chroot and cd to wherever we were before.
|
||||
pwd = self.cmd( 'pwd' ).strip()
|
||||
self.sendCmd( 'exec chroot', self.root, 'bash -ms mininet:'
|
||||
+ self.name )
|
||||
self.waiting = False
|
||||
self.cmd( 'cd', pwd )
|
||||
# In order for many utilities to work,
|
||||
# we need to remount /proc and /sys
|
||||
self.cmd( 'mount /proc' )
|
||||
self.cmd( 'mount /sys' )
|
||||
|
||||
def mountPrivateDirs( self ):
|
||||
"Create and bind mount private dirs"
|
||||
for dir_ in self.privateDirs:
|
||||
privateDir = self.private + dir_
|
||||
errFail( 'mkdir -p ' + privateDir )
|
||||
mountPoint = self.root + dir_
|
||||
errFail( 'mount -B %s %s' %
|
||||
( privateDir, mountPoint) )
|
||||
|
||||
def mountDirs( self, dirs ):
|
||||
"Mount a list of directories"
|
||||
for dir_ in dirs:
|
||||
mountpoint = self.root + dir_
|
||||
errFail( 'mount -B %s %s' %
|
||||
( dir_, mountpoint ) )
|
||||
|
||||
@classmethod
|
||||
def findRemounts( cls, fstypes=None ):
|
||||
"""Identify mount points in /proc/mounts to remount
|
||||
fstypes: file system types to match"""
|
||||
if fstypes is None:
|
||||
fstypes = [ 'nfs' ]
|
||||
dirs = quietRun( 'cat /proc/mounts' ).strip().split( '\n' )
|
||||
remounts = []
|
||||
for dir_ in dirs:
|
||||
line = dir_.split()
|
||||
mountpoint, fstype = line[ 1 ], line[ 2 ]
|
||||
# Don't re-remount directories!!!
|
||||
if mountpoint.find( cls.mnRunDir ) == 0:
|
||||
continue
|
||||
if fstype in fstypes:
|
||||
remounts.append( mountpoint )
|
||||
return remounts
|
||||
|
||||
def createBindMounts( self ):
|
||||
"""Create a chroot directory structure,
|
||||
with self.privateDirs as private dirs"""
|
||||
errFail( 'mkdir -p '+ self.rundir )
|
||||
unmountAll( self.rundir )
|
||||
# Create /root and /private directories
|
||||
self.root = self.rundir + '/root'
|
||||
self.private = self.rundir + '/private'
|
||||
errFail( 'mkdir -p ' + self.root )
|
||||
errFail( 'mkdir -p ' + self.private )
|
||||
# Recursively mount / in private doort
|
||||
# note we'll remount /sys and /proc later
|
||||
errFail( 'mount -B / ' + self.root )
|
||||
self.mountDirs( self.remounts )
|
||||
self.mountPrivateDirs()
|
||||
|
||||
def unmountBindMounts( self ):
|
||||
"Unmount all of our bind mounts"
|
||||
unmountAll( self.rundir )
|
||||
|
||||
def popen( self, *args, **kwargs ):
|
||||
"Popen with chroot support"
|
||||
chroot = kwargs.pop( 'chroot', True )
|
||||
mncmd = kwargs.get( 'mncmd',
|
||||
[ 'mnexec', '-a', str( self.pid ) ] )
|
||||
if chroot:
|
||||
mncmd = [ 'chroot', self.root ] + mncmd
|
||||
kwargs[ 'mncmd' ] = mncmd
|
||||
return Host.popen( self, *args, **kwargs )
|
||||
|
||||
def cleanup( self ):
|
||||
"""Clean up, then unmount bind mounts
|
||||
unmount: actually unmount bind mounts?"""
|
||||
# Wait for process to actually terminate
|
||||
self.shell.wait()
|
||||
Host.cleanup( self )
|
||||
if self.unmount:
|
||||
self.unmountBindMounts()
|
||||
errFail( 'rmdir ' + self.root )
|
||||
|
||||
|
||||
# Convenience aliases
|
||||
|
||||
findRemounts = HostWithPrivateDirs.findRemounts
|
||||
|
||||
|
||||
# Sample usage
|
||||
|
||||
def testHostWithPrivateDirs():
|
||||
"Test bind mounts"
|
||||
topo = SingleSwitchTopo( 10 )
|
||||
remounts = findRemounts( fstypes=[ 'nfs' ] )
|
||||
privateDirs = [ '/var/log', '/var/run' ]
|
||||
host = partial( HostWithPrivateDirs, remounts=remounts,
|
||||
privateDirs=privateDirs, unmount=False )
|
||||
privateDirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ),
|
||||
( '/var/run', '/tmp/%(name)s/var/run' ),
|
||||
'/var/mn' ]
|
||||
host = partial( Host,
|
||||
privateDirs=privateDirs )
|
||||
net = Mininet( topo=topo, host=host )
|
||||
net.start()
|
||||
info( 'Private Directories:', privateDirs, '\n' )
|
||||
directories = [ directory[ 0 ] if isinstance( directory, tuple )
|
||||
else directory for directory in privateDirs ]
|
||||
info( 'Private Directories:', directories, '\n' )
|
||||
CLI( net )
|
||||
net.stop()
|
||||
# We do this all at once to save a bit of time
|
||||
info( 'Unmounting host bind mounts...\n' )
|
||||
unmountAll()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unmountAll()
|
||||
setLogLevel( 'info' )
|
||||
testHostWithPrivateDirs()
|
||||
info( 'Done.\n')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Executable
+914
@@ -0,0 +1,914 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
cluster.py: prototyping/experimentation for distributed Mininet,
|
||||
aka Mininet: Cluster Edition
|
||||
|
||||
Author: Bob Lantz
|
||||
|
||||
Core classes:
|
||||
|
||||
RemoteNode: a Node() running on a remote server
|
||||
RemoteOVSSwitch(): an OVSSwitch() running on a remote server
|
||||
RemoteLink: a Link() on a remote server
|
||||
Tunnel: a Link() between a local Node() and a RemoteNode()
|
||||
|
||||
These are largely interoperable with local objects.
|
||||
|
||||
- One Mininet to rule them all
|
||||
|
||||
It is important that the same topologies, APIs, and CLI can be used
|
||||
with minimal or no modification in both local and distributed environments.
|
||||
|
||||
- Multiple placement models
|
||||
|
||||
Placement should be as easy as possible. We should provide basic placement
|
||||
support and also allow for explicit placement.
|
||||
|
||||
Questions:
|
||||
|
||||
What is the basic communication mechanism?
|
||||
|
||||
To start with? Probably a single multiplexed ssh connection between each
|
||||
pair of mininet servers that needs to communicate.
|
||||
|
||||
How are tunnels created?
|
||||
|
||||
We have several options including ssh, GRE, OF capsulator, socat, VDE, l2tp,
|
||||
etc.. It's not clear what the best one is. For now, we use ssh tunnels since
|
||||
they are encrypted and semi-automatically shared. We will probably want to
|
||||
support GRE as well because it's very easy to set up with OVS.
|
||||
|
||||
How are tunnels destroyed?
|
||||
|
||||
They are destroyed when the links are deleted in Mininet.stop()
|
||||
|
||||
How does RemoteNode.popen() work?
|
||||
|
||||
It opens a shared ssh connection to the remote server and attaches to
|
||||
the namespace using mnexec -a -g.
|
||||
|
||||
Is there any value to using Paramiko vs. raw ssh?
|
||||
|
||||
Maybe, but it doesn't seem to support L2 tunneling.
|
||||
|
||||
Should we preflight the entire network, including all server-to-server
|
||||
connections?
|
||||
|
||||
Yes! We don't yet do this with remote server-to-server connections yet.
|
||||
|
||||
Should we multiplex the link ssh connections?
|
||||
|
||||
Yes, this is done automatically with ControlMaster=auto.
|
||||
|
||||
Note on ssh and DNS:
|
||||
Please add UseDNS: no to your /etc/ssh/sshd_config!!!
|
||||
|
||||
Things to do:
|
||||
|
||||
- asynchronous/pipelined/parallel startup
|
||||
- ssh debugging/profiling
|
||||
- make connections into real objects
|
||||
- support for other tunneling schemes
|
||||
- tests and benchmarks
|
||||
- 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
|
||||
from random import randrange
|
||||
import sys
|
||||
import re
|
||||
from itertools import groupby
|
||||
from operator import attrgetter
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
|
||||
def findUser():
|
||||
"Try to return logged-in (usually non-root) user"
|
||||
return (
|
||||
# If we're running sudo
|
||||
os.environ.get( 'SUDO_USER', False ) or
|
||||
# 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' ).strip() )
|
||||
|
||||
|
||||
class ClusterCleanup( object ):
|
||||
"Cleanup callback"
|
||||
|
||||
inited = False
|
||||
serveruser = {}
|
||||
|
||||
@classmethod
|
||||
def add( cls, server, user='' ):
|
||||
"Add an entry to server: user dict"
|
||||
if not cls.inited:
|
||||
addCleanupCallback( cls.cleanup )
|
||||
if not user:
|
||||
user = findUser()
|
||||
cls.serveruser[ server ] = user
|
||||
|
||||
@classmethod
|
||||
def cleanup( cls ):
|
||||
"Clean up"
|
||||
info( '*** Cleaning up cluster\n' )
|
||||
for server, user in cls.serveruser.iteritems():
|
||||
if server == 'localhost':
|
||||
# Handled by mininet.clean.cleanup()
|
||||
continue
|
||||
else:
|
||||
cmd = [ 'su', user, '-c',
|
||||
'ssh %s@%s sudo mn -c' % ( user, server ) ]
|
||||
info( cmd, '\n' )
|
||||
info( quietRun( cmd ) )
|
||||
|
||||
# BL note: so little code is required for remote nodes,
|
||||
# we will probably just want to update the main Node()
|
||||
# class to enable it for remote access! However, there
|
||||
# are a large number of potential failure conditions with
|
||||
# remote nodes which we may want to detect and handle.
|
||||
# Another interesting point is that we could put everything
|
||||
# in a mix-in class and easily add cluster mode to 2.0.
|
||||
|
||||
class RemoteMixin( object ):
|
||||
|
||||
"A mix-in class to turn local nodes into remote nodes"
|
||||
|
||||
# ssh base command
|
||||
# -q: don't print stupid diagnostic messages
|
||||
# BatchMode yes: don't ask for password
|
||||
# ForwardAgent yes: forward authentication credentials
|
||||
sshbase = [ 'ssh', '-q',
|
||||
'-o', 'BatchMode=yes',
|
||||
'-o', 'ForwardAgent=yes', '-tt' ]
|
||||
|
||||
def __init__( self, name, server='localhost', user=None, serverIP=None,
|
||||
controlPath=False, splitInit=False, **kwargs):
|
||||
"""Instantiate a remote node
|
||||
name: name of remote node
|
||||
server: remote server (optional)
|
||||
user: user on remote server (optional)
|
||||
controlPath: specify shared ssh control path (optional)
|
||||
splitInit: split initialization?
|
||||
**kwargs: see Node()"""
|
||||
# We connect to servers by IP address
|
||||
self.server = server if server else 'localhost'
|
||||
self.serverIP = ( serverIP if serverIP
|
||||
else self.findServerIP( self.server ) )
|
||||
self.user = user if user else findUser()
|
||||
ClusterCleanup.add( server=server, user=user )
|
||||
if controlPath is True:
|
||||
# Set a default control path for shared SSH connections
|
||||
controlPath = '/tmp/mn-%r@%h:%p'
|
||||
self.controlPath = controlPath
|
||||
self.splitInit = splitInit
|
||||
if self.user and self.server != 'localhost':
|
||||
self.dest = '%s@%s' % ( self.user, self.serverIP )
|
||||
self.sshcmd = [ 'sudo', '-E', '-u', self.user ] + self.sshbase
|
||||
if self.controlPath:
|
||||
self.sshcmd += [ '-o', 'ControlPath=' + self.controlPath,
|
||||
'-o', 'ControlMaster=auto',
|
||||
'-o', 'ControlPersist=' + '1' ]
|
||||
self.sshcmd += [ self.dest ]
|
||||
self.isRemote = True
|
||||
else:
|
||||
self.dest = None
|
||||
self.sshcmd = []
|
||||
self.isRemote = False
|
||||
# Satisfy pylint
|
||||
self.shell, self.pid = None, None
|
||||
super( RemoteMixin, self ).__init__( name, **kwargs )
|
||||
|
||||
# Determine IP address of local host
|
||||
_ipMatchRegex = re.compile( r'\d+\.\d+\.\d+\.\d+' )
|
||||
|
||||
@classmethod
|
||||
def findServerIP( cls, server ):
|
||||
"Return our server's IP address"
|
||||
# First, check for an IP address
|
||||
ipmatch = cls._ipMatchRegex.findall( server )
|
||||
if ipmatch:
|
||||
return ipmatch[ 0 ]
|
||||
# Otherwise, look up remote server
|
||||
output = quietRun( 'getent ahostsv4 %s' % server )
|
||||
ips = cls._ipMatchRegex.findall( output )
|
||||
ip = ips[ 0 ] if ips else None
|
||||
return ip
|
||||
|
||||
# Command support via shell process in namespace
|
||||
def startShell( self, *args, **kwargs ):
|
||||
"Start a shell process for running commands"
|
||||
if self.isRemote:
|
||||
kwargs.update( mnopts='-c' )
|
||||
super( RemoteMixin, self ).startShell( *args, **kwargs )
|
||||
# Optional split initialization
|
||||
self.sendCmd( 'echo $$' )
|
||||
if not self.splitInit:
|
||||
self.finishInit()
|
||||
|
||||
def finishInit( self ):
|
||||
"Wait for split initialization to complete"
|
||||
self.pid = int( self.waitOutput() )
|
||||
|
||||
def rpopen( self, *cmd, **opts ):
|
||||
"Return a Popen object on underlying server in root namespace"
|
||||
params = { 'stdin': PIPE,
|
||||
'stdout': PIPE,
|
||||
'stderr': STDOUT,
|
||||
'sudo': True }
|
||||
params.update( opts )
|
||||
return self._popen( *cmd, **params )
|
||||
|
||||
def rcmd( self, *cmd, **opts):
|
||||
"""rcmd: run a command on underlying server
|
||||
in root namespace
|
||||
args: string or list of strings
|
||||
returns: stdout and stderr"""
|
||||
popen = self.rpopen( *cmd, **opts )
|
||||
# print 'RCMD: POPEN:', popen
|
||||
# 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()
|
||||
if poll is not None:
|
||||
break
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def _ignoreSignal():
|
||||
"Detach from process group to ignore all signals"
|
||||
os.setpgrp()
|
||||
|
||||
def _popen( self, cmd, sudo=True, tt=True, **params):
|
||||
"""Spawn a process on a remote node
|
||||
cmd: remote command to run (list)
|
||||
**params: parameters to Popen()
|
||||
returns: Popen() object"""
|
||||
if type( cmd ) is str:
|
||||
cmd = cmd.split()
|
||||
if self.isRemote:
|
||||
if sudo:
|
||||
cmd = [ 'sudo', '-E' ] + cmd
|
||||
if tt:
|
||||
cmd = self.sshcmd + cmd
|
||||
else:
|
||||
# Hack: remove -tt
|
||||
sshcmd = list( self.sshcmd )
|
||||
sshcmd.remove( '-tt' )
|
||||
cmd = sshcmd + cmd
|
||||
else:
|
||||
if self.user and not sudo:
|
||||
# Drop privileges
|
||||
cmd = [ 'sudo', '-E', '-u', self.user ] + cmd
|
||||
params.update( preexec_fn=self._ignoreSignal )
|
||||
debug( '_popen', cmd, '\n' )
|
||||
popen = super( RemoteMixin, self )._popen( cmd, **params )
|
||||
return popen
|
||||
|
||||
def popen( self, *args, **kwargs ):
|
||||
"Override: disable -tt"
|
||||
return super( RemoteMixin, self).popen( *args, tt=False, **kwargs )
|
||||
|
||||
def addIntf( self, *args, **kwargs ):
|
||||
"Override: use RemoteLink.moveIntf"
|
||||
kwargs.update( moveIntfFn=RemoteLink.moveIntf )
|
||||
return super( RemoteMixin, self).addIntf( *args, **kwargs )
|
||||
|
||||
|
||||
class RemoteNode( RemoteMixin, Node ):
|
||||
"A node on a remote server"
|
||||
pass
|
||||
|
||||
|
||||
class RemoteHost( RemoteNode ):
|
||||
"A RemoteHost is simply a RemoteNode"
|
||||
pass
|
||||
|
||||
|
||||
class RemoteOVSSwitch( RemoteMixin, OVSSwitch ):
|
||||
"Remote instance of Open vSwitch"
|
||||
|
||||
OVSVersions = {}
|
||||
|
||||
def __init__( self, *args, **kwargs ):
|
||||
# No batch startup yet
|
||||
kwargs.update( batch=True )
|
||||
super( RemoteOVSSwitch, self ).__init__( *args, **kwargs )
|
||||
|
||||
def isOldOVS( self ):
|
||||
"Is remote switch using an old OVS version?"
|
||||
cls = type( self )
|
||||
if self.server not in cls.OVSVersions:
|
||||
# pylint: disable=not-callable
|
||||
vers = self.cmd( 'ovs-vsctl --version' )
|
||||
# pylint: enable=not-callable
|
||||
cls.OVSVersions[ self.server ] = re.findall(
|
||||
r'\d+\.\d+', vers )[ 0 ]
|
||||
return ( StrictVersion( cls.OVSVersions[ self.server ] ) <
|
||||
StrictVersion( '1.10' ) )
|
||||
|
||||
@classmethod
|
||||
def batchStartup( cls, switches, **_kwargs ):
|
||||
"Start up switches in per-server batches"
|
||||
key = attrgetter( 'server' )
|
||||
for server, switchGroup in groupby( sorted( switches, key=key ), key ):
|
||||
info( '(%s)' % server )
|
||||
group = tuple( switchGroup )
|
||||
switch = group[ 0 ]
|
||||
OVSSwitch.batchStartup( group, run=switch.cmd )
|
||||
return switches
|
||||
|
||||
@classmethod
|
||||
def batchShutdown( cls, switches, **_kwargs ):
|
||||
"Stop switches in per-server batches"
|
||||
key = attrgetter( 'server' )
|
||||
for server, switchGroup in groupby( sorted( switches, key=key ), key ):
|
||||
info( '(%s)' % server )
|
||||
group = tuple( switchGroup )
|
||||
switch = group[ 0 ]
|
||||
OVSSwitch.batchShutdown( group, run=switch.rcmd )
|
||||
return switches
|
||||
|
||||
|
||||
class RemoteLink( Link ):
|
||||
"A RemoteLink is a link between nodes which may be on different servers"
|
||||
|
||||
def __init__( self, node1, node2, **kwargs ):
|
||||
"""Initialize a RemoteLink
|
||||
see Link() for parameters"""
|
||||
# Create links on remote node
|
||||
self.node1 = node1
|
||||
self.node2 = node2
|
||||
self.tunnel = None
|
||||
kwargs.setdefault( 'params1', {} )
|
||||
kwargs.setdefault( 'params2', {} )
|
||||
self.cmd = None # satisfy pylint
|
||||
Link.__init__( self, node1, node2, **kwargs )
|
||||
|
||||
def stop( self ):
|
||||
"Stop this link"
|
||||
if self.tunnel:
|
||||
self.tunnel.terminate()
|
||||
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
|
||||
return Link.makeIntfPair( intfname1, intfname2, addr1, addr2,
|
||||
node1, node2, deleteIntfs=deleteIntfs )
|
||||
# Otherwise, make a tunnel
|
||||
self.tunnel = self.makeTunnel( node1, node2, intfname1, intfname2,
|
||||
addr1, addr2 )
|
||||
return self.tunnel
|
||||
|
||||
@staticmethod
|
||||
def moveIntf( intf, node, printError=True ):
|
||||
"""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"""
|
||||
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
|
||||
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'
|
||||
# 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 )
|
||||
# 1. Create tap interfaces
|
||||
for node in node1, node2:
|
||||
# For now we are hard-wiring tap9, which we will rename
|
||||
cmd = 'ip tuntap add dev tap9 mode tap user ' + node.user
|
||||
result = node.rcmd( cmd )
|
||||
if result:
|
||||
raise Exception( 'error creating tap9 on %s: %s' %
|
||||
( node, result ) )
|
||||
# 2. Create ssh tunnel between tap interfaces
|
||||
# -n: close stdin
|
||||
dest = '%s@%s' % ( node2.user, node2.serverIP )
|
||||
cmd = [ 'ssh', '-n', '-o', 'Tunnel=Ethernet', '-w', '9:9',
|
||||
dest, 'echo @' ]
|
||||
self.cmd = cmd
|
||||
tunnel = node1.rpopen( cmd, sudo=False )
|
||||
# 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 )
|
||||
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' )
|
||||
# 3. Move interfaces if necessary
|
||||
for node in node1, node2:
|
||||
if not self.moveIntf( 'tap9', node ):
|
||||
raise Exception( 'interface move failed on node %s' % node )
|
||||
# 4. Rename tap interfaces to desired names
|
||||
for node, intf, addr in ( ( node1, intfname1, addr1 ),
|
||||
( node2, intfname2, addr2 ) ):
|
||||
if not addr:
|
||||
result = node.cmd( 'ip link set tap9 name', intf )
|
||||
else:
|
||||
result = node.cmd( 'ip link set tap9 name', intf,
|
||||
'address', addr )
|
||||
if result:
|
||||
raise Exception( 'error renaming %s: %s' % ( intf, result ) )
|
||||
return tunnel
|
||||
|
||||
def status( self ):
|
||||
"Detailed representation of link"
|
||||
if self.tunnel:
|
||||
if self.tunnel.poll() is not None:
|
||||
status = "Tunnel EXITED %s" % self.tunnel.returncode
|
||||
else:
|
||||
status = "Tunnel Running (%s: %s)" % (
|
||||
self.tunnel.pid, self.cmd )
|
||||
else:
|
||||
status = "OK"
|
||||
result = "%s %s" % ( Link.status( self ), status )
|
||||
return result
|
||||
|
||||
|
||||
# Some simple placement algorithms for MininetCluster
|
||||
|
||||
class Placer( object ):
|
||||
"Node placement algorithm for MininetCluster"
|
||||
|
||||
def __init__( self, servers=None, nodes=None, hosts=None,
|
||||
switches=None, controllers=None, links=None ):
|
||||
"""Initialize placement object
|
||||
servers: list of servers
|
||||
nodes: list of all nodes
|
||||
hosts: list of hosts
|
||||
switches: list of switches
|
||||
controllers: list of controllers
|
||||
links: list of links
|
||||
(all arguments are optional)
|
||||
returns: server"""
|
||||
self.servers = servers or []
|
||||
self.nodes = nodes or []
|
||||
self.hosts = hosts or []
|
||||
self.switches = switches or []
|
||||
self.controllers = controllers or []
|
||||
self.links = links or []
|
||||
|
||||
def place( self, node ):
|
||||
"Return server for a given node"
|
||||
assert self, node # satisfy pylint
|
||||
# Default placement: run locally
|
||||
return 'localhost'
|
||||
|
||||
|
||||
class RandomPlacer( Placer ):
|
||||
"Random placement"
|
||||
def place( self, nodename ):
|
||||
"""Random placement function
|
||||
nodename: node name"""
|
||||
assert nodename # please pylint
|
||||
# This may be slow with lots of servers
|
||||
return self.servers[ randrange( 0, len( self.servers ) ) ]
|
||||
|
||||
|
||||
class RoundRobinPlacer( Placer ):
|
||||
"""Round-robin placement
|
||||
Note this will usually result in cross-server links between
|
||||
hosts and switches"""
|
||||
|
||||
def __init__( self, *args, **kwargs ):
|
||||
Placer.__init__( self, *args, **kwargs )
|
||||
self.next = 0
|
||||
|
||||
def place( self, nodename ):
|
||||
"""Round-robin placement function
|
||||
nodename: node name"""
|
||||
assert nodename # please pylint
|
||||
# This may be slow with lots of servers
|
||||
server = self.servers[ self.next ]
|
||||
self.next = ( self.next + 1 ) % len( self.servers )
|
||||
return server
|
||||
|
||||
|
||||
class SwitchBinPlacer( Placer ):
|
||||
"""Place switches (and controllers) into evenly-sized bins,
|
||||
and attempt to co-locate hosts and switches"""
|
||||
|
||||
def __init__( self, *args, **kwargs ):
|
||||
Placer.__init__( self, *args, **kwargs )
|
||||
# Easy lookup for servers and node sets
|
||||
self.servdict = dict( enumerate( self.servers ) )
|
||||
self.hset = frozenset( self.hosts )
|
||||
self.sset = frozenset( self.switches )
|
||||
self.cset = frozenset( self.controllers )
|
||||
# Server and switch placement indices
|
||||
self.placement = self.calculatePlacement()
|
||||
|
||||
@staticmethod
|
||||
def bin( nodes, servers ):
|
||||
"Distribute nodes evenly over servers"
|
||||
# Calculate base bin size
|
||||
nlen = len( nodes )
|
||||
slen = len( servers )
|
||||
# Basic bin size
|
||||
quotient = int( nlen / slen )
|
||||
binsizes = { server: quotient for server in servers }
|
||||
# Distribute remainder
|
||||
remainder = nlen % slen
|
||||
for server in servers[ 0 : remainder ]:
|
||||
binsizes[ server ] += 1
|
||||
# Create binsize[ server ] tickets for each server
|
||||
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 ) }
|
||||
|
||||
def calculatePlacement( self ):
|
||||
"Pre-calculate node placement"
|
||||
placement = {}
|
||||
# Create host-switch connectivity map,
|
||||
# associating host with last switch that it's
|
||||
# connected to
|
||||
switchFor = {}
|
||||
for src, dst in self.links:
|
||||
if src in self.hset and dst in self.sset:
|
||||
switchFor[ src ] = dst
|
||||
if dst in self.hset and src in self.sset:
|
||||
switchFor[ dst ] = src
|
||||
# Place switches
|
||||
placement = self.bin( self.switches, self.servers )
|
||||
# Place controllers and merge into placement dict
|
||||
placement.update( self.bin( self.controllers, self.servers ) )
|
||||
# Co-locate hosts with their switches
|
||||
for h in self.hosts:
|
||||
if h in placement:
|
||||
# Host is already placed - leave it there
|
||||
continue
|
||||
if h in switchFor:
|
||||
placement[ h ] = placement[ switchFor[ h ] ]
|
||||
else:
|
||||
raise Exception(
|
||||
"SwitchBinPlacer: cannot place isolated host " + h )
|
||||
return placement
|
||||
|
||||
def place( self, node ):
|
||||
"""Simple placement algorithm:
|
||||
place switches into evenly sized bins,
|
||||
and place hosts near their switches"""
|
||||
return self.placement[ node ]
|
||||
|
||||
|
||||
class HostSwitchBinPlacer( Placer ):
|
||||
"""Place switches *and hosts* into evenly-sized bins
|
||||
Note that this will usually result in cross-server
|
||||
links between hosts and switches"""
|
||||
|
||||
def __init__( self, *args, **kwargs ):
|
||||
Placer.__init__( self, *args, **kwargs )
|
||||
# Calculate bin sizes
|
||||
scount = len( self.servers )
|
||||
self.hbin = max( int( len( self.hosts ) / scount ), 1 )
|
||||
self.sbin = max( int( len( self.switches ) / scount ), 1 )
|
||||
self.cbin = max( int( len( self.controllers ) / scount ), 1 )
|
||||
info( 'scount:', scount )
|
||||
info( 'bins:', self.hbin, self.sbin, self.cbin, '\n' )
|
||||
self.servdict = dict( enumerate( self.servers ) )
|
||||
self.hset = frozenset( self.hosts )
|
||||
self.sset = frozenset( self.switches )
|
||||
self.cset = frozenset( self.controllers )
|
||||
self.hind, self.sind, self.cind = 0, 0, 0
|
||||
|
||||
def place( self, nodename ):
|
||||
"""Simple placement algorithm:
|
||||
place nodes into evenly sized bins"""
|
||||
# Place nodes into bins
|
||||
if nodename in self.hset:
|
||||
server = self.servdict[ self.hind / self.hbin ]
|
||||
self.hind += 1
|
||||
elif nodename in self.sset:
|
||||
server = self.servdict[ self.sind / self.sbin ]
|
||||
self.sind += 1
|
||||
elif nodename in self.cset:
|
||||
server = self.servdict[ self.cind / self.cbin ]
|
||||
self.cind += 1
|
||||
else:
|
||||
info( 'warning: unknown node', nodename )
|
||||
server = self.servdict[ 0 ]
|
||||
return server
|
||||
|
||||
|
||||
# The MininetCluster class is not strictly necessary.
|
||||
# However, it has several purposes:
|
||||
# 1. To set up ssh connection sharing/multiplexing
|
||||
# 2. To pre-flight the system so that everything is more likely to work
|
||||
# 3. To allow connection/connectivity monitoring
|
||||
# 4. To support pluggable placement algorithms
|
||||
|
||||
class MininetCluster( Mininet ):
|
||||
|
||||
"Cluster-enhanced version of Mininet class"
|
||||
|
||||
# Default ssh command
|
||||
# BatchMode yes: don't ask for password
|
||||
# ForwardAgent yes: forward authentication credentials
|
||||
sshcmd = [ 'ssh', '-o', 'BatchMode=yes', '-o', 'ForwardAgent=yes' ]
|
||||
|
||||
def __init__( self, *args, **kwargs ):
|
||||
"""servers: a list of servers to use (note: include
|
||||
localhost or None to use local system as well)
|
||||
user: user name for server ssh
|
||||
placement: Placer() subclass"""
|
||||
params = { 'host': RemoteHost,
|
||||
'switch': RemoteOVSSwitch,
|
||||
'link': RemoteLink,
|
||||
'precheck': True }
|
||||
params.update( kwargs )
|
||||
servers = params.pop( 'servers', [ 'localhost' ] )
|
||||
servers = [ s if s else 'localhost' for s in servers ]
|
||||
self.servers = servers
|
||||
self.serverIP = params.pop( 'serverIP', {} )
|
||||
if not self.serverIP:
|
||||
self.serverIP = { server: RemoteMixin.findServerIP( server )
|
||||
for server in self.servers }
|
||||
self.user = params.pop( 'user', findUser() )
|
||||
if params.pop( 'precheck' ):
|
||||
self.precheck()
|
||||
self.connections = {}
|
||||
self.placement = params.pop( 'placement', SwitchBinPlacer )
|
||||
# Make sure control directory exists
|
||||
self.cdir = os.environ[ 'HOME' ] + '/.ssh/mn'
|
||||
errRun( [ 'mkdir', '-p', self.cdir ] )
|
||||
Mininet.__init__( self, *args, **params )
|
||||
|
||||
def popen( self, cmd ):
|
||||
"Popen() for server connections"
|
||||
assert self # please pylint
|
||||
old = signal( SIGINT, SIG_IGN )
|
||||
conn = Popen( cmd, stdin=PIPE, stdout=PIPE, close_fds=True )
|
||||
signal( SIGINT, old )
|
||||
return conn
|
||||
|
||||
def baddLink( self, *args, **kwargs ):
|
||||
"break addlink for testing"
|
||||
pass
|
||||
|
||||
def precheck( self ):
|
||||
"""Pre-check to make sure connection works and that
|
||||
we can call sudo without a password"""
|
||||
result = 0
|
||||
info( '*** Checking servers\n' )
|
||||
for server in self.servers:
|
||||
ip = self.serverIP[ server ]
|
||||
if not server or server == 'localhost':
|
||||
continue
|
||||
info( server, '' )
|
||||
dest = '%s@%s' % ( self.user, ip )
|
||||
cmd = [ 'sudo', '-E', '-u', self.user ]
|
||||
cmd += self.sshcmd + [ '-n', dest, 'sudo true' ]
|
||||
debug( ' '.join( cmd ), '\n' )
|
||||
_out, _err, code = errRun( cmd )
|
||||
if code != 0:
|
||||
error( '\nstartConnection: server connection check failed '
|
||||
'to %s using command:\n%s\n'
|
||||
% ( server, ' '.join( cmd ) ) )
|
||||
result |= code
|
||||
if result:
|
||||
error( '*** Server precheck failed.\n'
|
||||
'*** Make sure that the above ssh command works'
|
||||
' correctly.\n'
|
||||
'*** You may also need to run mn -c on all nodes, and/or\n'
|
||||
'*** use sudo -E.\n' )
|
||||
sys.exit( 1 )
|
||||
info( '\n' )
|
||||
|
||||
def modifiedaddHost( self, *args, **kwargs ):
|
||||
"Slightly modify addHost"
|
||||
assert self # please pylint
|
||||
kwargs[ 'splitInit' ] = True
|
||||
return Mininet.addHost( *args, **kwargs )
|
||||
|
||||
def placeNodes( self ):
|
||||
"""Place nodes on servers (if they don't have a server), and
|
||||
start shell processes"""
|
||||
if not self.servers or not self.topo:
|
||||
# No shirt, no shoes, no service
|
||||
return
|
||||
nodes = self.topo.nodes()
|
||||
placer = self.placement( servers=self.servers,
|
||||
nodes=self.topo.nodes(),
|
||||
hosts=self.topo.hosts(),
|
||||
switches=self.topo.switches(),
|
||||
links=self.topo.links() )
|
||||
for node in nodes:
|
||||
config = self.topo.nodeInfo( node )
|
||||
# keep local server name consistent accross nodes
|
||||
if 'server' in config.keys() and config[ 'server' ] is None:
|
||||
config[ 'server' ] = 'localhost'
|
||||
server = config.setdefault( 'server', placer.place( node ) )
|
||||
if server:
|
||||
config.setdefault( 'serverIP', self.serverIP[ server ] )
|
||||
info( '%s:%s ' % ( node, server ) )
|
||||
key = ( None, server )
|
||||
_dest, cfile, _conn = self.connections.get(
|
||||
key, ( None, None, None ) )
|
||||
if cfile:
|
||||
config.setdefault( 'controlPath', cfile )
|
||||
|
||||
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()
|
||||
return controller
|
||||
|
||||
def buildFromTopo( self, *args, **kwargs ):
|
||||
"Start network"
|
||||
info( '*** Placing nodes\n' )
|
||||
self.placeNodes()
|
||||
info( '\n' )
|
||||
Mininet.buildFromTopo( self, *args, **kwargs )
|
||||
|
||||
|
||||
def testNsTunnels():
|
||||
"Test tunnels between nodes in namespaces"
|
||||
net = Mininet( host=RemoteHost, link=RemoteLink )
|
||||
h1 = net.addHost( 'h1' )
|
||||
h2 = net.addHost( 'h2', server='ubuntu2' )
|
||||
net.addLink( h1, h2 )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
|
||||
# Manual topology creation with net.add*()
|
||||
#
|
||||
# This shows how node options may be used to manage
|
||||
# cluster placement using the net.add*() API
|
||||
|
||||
def testRemoteNet( remote='ubuntu2' ):
|
||||
"Test remote Node classes"
|
||||
print '*** Remote Node Test'
|
||||
net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch,
|
||||
link=RemoteLink )
|
||||
c0 = net.addController( 'c0' )
|
||||
# Make sure controller knows its non-loopback address
|
||||
Intf( 'eth0', node=c0 ).updateIP()
|
||||
print "*** Creating local h1"
|
||||
h1 = net.addHost( 'h1' )
|
||||
print "*** Creating remote h2"
|
||||
h2 = net.addHost( 'h2', server=remote )
|
||||
print "*** Creating local s1"
|
||||
s1 = net.addSwitch( 's1' )
|
||||
print "*** Creating remote s2"
|
||||
s2 = net.addSwitch( 's2', server=remote )
|
||||
print "*** Adding links"
|
||||
net.addLink( h1, s1 )
|
||||
net.addLink( s1, s2 )
|
||||
net.addLink( h2, s2 )
|
||||
net.start()
|
||||
print 'Mininet is running on', quietRun( 'hostname' ).strip()
|
||||
for node in c0, h1, h2, s1, s2:
|
||||
print 'Node', node, 'is running on', node.cmd( 'hostname' ).strip()
|
||||
net.pingAll()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
|
||||
# High-level/Topo API example
|
||||
#
|
||||
# This shows how existing Mininet topologies may be used in cluster
|
||||
# mode by creating node placement functions and a controller which
|
||||
# can be accessed remotely. This implements a very compatible version
|
||||
# of cluster edition with a minimum of code!
|
||||
|
||||
remoteHosts = [ 'h2' ]
|
||||
remoteSwitches = [ 's2' ]
|
||||
remoteServer = 'ubuntu2'
|
||||
|
||||
def HostPlacer( name, *args, **params ):
|
||||
"Custom Host() constructor which places hosts on servers"
|
||||
if name in remoteHosts:
|
||||
return RemoteHost( name, *args, server=remoteServer, **params )
|
||||
else:
|
||||
return Host( name, *args, **params )
|
||||
|
||||
def SwitchPlacer( name, *args, **params ):
|
||||
"Custom Switch() constructor which places switches on servers"
|
||||
if name in remoteSwitches:
|
||||
return RemoteOVSSwitch( name, *args, server=remoteServer, **params )
|
||||
else:
|
||||
return RemoteOVSSwitch( name, *args, **params )
|
||||
|
||||
def ClusterController( *args, **kwargs):
|
||||
"Custom Controller() constructor which updates its eth0 IP address"
|
||||
controller = Controller( *args, **kwargs )
|
||||
# Find out its IP address so that cluster switches can connect
|
||||
Intf( 'eth0', node=controller ).updateIP()
|
||||
return controller
|
||||
|
||||
def testRemoteTopo():
|
||||
"Test remote Node classes using Mininet()/Topo() API"
|
||||
topo = LinearTopo( 2 )
|
||||
net = Mininet( topo=topo, host=HostPlacer, switch=SwitchPlacer,
|
||||
link=RemoteLink, controller=ClusterController )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
|
||||
# Need to test backwards placement, where each host is on
|
||||
# a server other than its switch!! But seriously we could just
|
||||
# do random switch placement rather than completely random
|
||||
# host placement.
|
||||
|
||||
def testRemoteSwitches():
|
||||
"Test with local hosts and remote switches"
|
||||
servers = [ 'localhost', 'ubuntu2']
|
||||
topo = TreeTopo( depth=4, fanout=2 )
|
||||
net = MininetCluster( topo=topo, servers=servers,
|
||||
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.
|
||||
|
||||
# The MininetCluster() class integrates pluggable placement
|
||||
# functions, for maximum ease of use. MininetCluster() also
|
||||
# pre-flights and multiplexes server connections.
|
||||
|
||||
def testMininetCluster():
|
||||
"Test MininetCluster()"
|
||||
servers = [ 'localhost', 'ubuntu2' ]
|
||||
topo = TreeTopo( depth=3, fanout=3 )
|
||||
net = MininetCluster( topo=topo, servers=servers,
|
||||
placement=SwitchBinPlacer )
|
||||
net.start()
|
||||
net.pingAll()
|
||||
net.stop()
|
||||
|
||||
def signalTest():
|
||||
"Make sure hosts are robust to signals"
|
||||
h = RemoteHost( 'h0', server='ubuntu1' )
|
||||
h.shell.send_signal( SIGINT )
|
||||
h.shell.poll()
|
||||
if h.shell.returncode is None:
|
||||
print 'OK: ', h, 'has not exited'
|
||||
else:
|
||||
print 'FAILURE:', h, 'exited with code', h.shell.returncode
|
||||
h.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
# testRemoteTopo()
|
||||
# testRemoteNet()
|
||||
# testMininetCluster()
|
||||
# testRemoteSwitches()
|
||||
signalTest()
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
'''
|
||||
A sanity check for cluster edition
|
||||
'''
|
||||
|
||||
from mininet.examples.cluster import MininetCluster
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.examples.clustercli import ClusterCLI as CLI
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
|
||||
def clusterSanity():
|
||||
"Sanity check for cluster mode"
|
||||
topo = SingleSwitchTopo()
|
||||
net = MininetCluster( topo=topo )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
clusterSanity()
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"CLI for Mininet Cluster Edition prototype demo"
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import output, error
|
||||
|
||||
# pylint: disable=global-statement
|
||||
nx, graphviz_layout, plt = None, None, None # Will be imported on demand
|
||||
|
||||
|
||||
class ClusterCLI( CLI ):
|
||||
"CLI with additional commands for Cluster Edition demo"
|
||||
|
||||
@staticmethod
|
||||
def colorsFor( seq ):
|
||||
"Return a list of background colors for a sequence"
|
||||
colors = [ 'red', 'lightgreen', 'cyan', 'yellow', 'orange',
|
||||
'magenta', 'pink', 'grey', 'brown',
|
||||
'white' ]
|
||||
slen, clen = len( seq ), len( colors )
|
||||
reps = max( 1, slen / clen )
|
||||
colors = colors * reps
|
||||
colors = colors[ 0 : slen ]
|
||||
return colors
|
||||
|
||||
def do_plot( self, _line ):
|
||||
"Plot topology colored by node placement"
|
||||
# Import networkx if needed
|
||||
global nx, plt
|
||||
if not nx:
|
||||
try:
|
||||
# pylint: disable=import-error
|
||||
import networkx
|
||||
nx = networkx # satisfy pylint
|
||||
from matplotlib import pyplot
|
||||
plt = pyplot # satisfiy pylint
|
||||
import pygraphviz
|
||||
assert pygraphviz # silence pyflakes
|
||||
# pylint: enable=import-error
|
||||
except ImportError:
|
||||
error( 'plot requires networkx, matplotlib and pygraphviz - '
|
||||
'please install them and try again\n' )
|
||||
return
|
||||
# Make a networkx Graph
|
||||
g = nx.Graph()
|
||||
mn = self.mn
|
||||
servers, hosts, switches = mn.servers, mn.hosts, mn.switches
|
||||
nodes = hosts + switches
|
||||
g.add_nodes_from( nodes )
|
||||
links = [ ( link.intf1.node, link.intf2.node )
|
||||
for link in self.mn.links ]
|
||||
g.add_edges_from( links )
|
||||
# Pick some shapes and colors
|
||||
# shapes = hlen * [ 's' ] + slen * [ 'o' ]
|
||||
color = dict( zip( servers, self.colorsFor( servers ) ) )
|
||||
# Plot it!
|
||||
pos = nx.graphviz_layout( g )
|
||||
opts = { 'ax': None, 'font_weight': 'bold',
|
||||
'width': 2, 'edge_color': 'darkblue' }
|
||||
hcolors = [ color[ getattr( h, 'server', 'localhost' ) ]
|
||||
for h in hosts ]
|
||||
scolors = [ color[ getattr( s, 'server', 'localhost' ) ]
|
||||
for s in switches ]
|
||||
nx.draw_networkx( g, pos=pos, nodelist=hosts, node_size=800,
|
||||
label='host', node_color=hcolors, node_shape='s',
|
||||
**opts )
|
||||
nx.draw_networkx( g, pos=pos, nodelist=switches, node_size=1000,
|
||||
node_color=scolors, node_shape='o', **opts )
|
||||
# Get rid of axes, add title, and show
|
||||
fig = plt.gcf()
|
||||
ax = plt.gca()
|
||||
ax.get_xaxis().set_visible( False )
|
||||
ax.get_yaxis().set_visible( False )
|
||||
fig.canvas.set_window_title( 'Mininet')
|
||||
plt.title( 'Node Placement', fontweight='bold' )
|
||||
plt.show()
|
||||
|
||||
def do_status( self, _line ):
|
||||
"Report on node shell status"
|
||||
nodes = self.mn.hosts + self.mn.switches
|
||||
for node in nodes:
|
||||
node.shell.poll()
|
||||
exited = [ node for node in nodes
|
||||
if node.shell.returncode is not None ]
|
||||
if exited:
|
||||
for node in exited:
|
||||
output( '%s has exited with code %d\n'
|
||||
% ( node, node.shell.returncode ) )
|
||||
else:
|
||||
output( 'All nodes are still running.\n' )
|
||||
|
||||
def do_placement( self, _line ):
|
||||
"Describe node placement"
|
||||
mn = self.mn
|
||||
nodes = mn.hosts + mn.switches + mn.controllers
|
||||
for server in mn.servers:
|
||||
names = [ n.name for n in nodes if hasattr( n, 'server' )
|
||||
and n.server == server ]
|
||||
output( '%s: %s\n' % ( server, ' '.join( names ) ) )
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"clusterdemo.py: demo of Mininet Cluster Edition prototype"
|
||||
|
||||
from mininet.examples.cluster import MininetCluster, SwitchBinPlacer
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.examples.clustercli import ClusterCLI as CLI
|
||||
|
||||
def demo():
|
||||
"Simple Demo of Cluster Mode"
|
||||
servers = [ 'localhost', 'ubuntu2', 'ubuntu3' ]
|
||||
topo = TreeTopo( depth=3, fanout=3 )
|
||||
net = MininetCluster( topo=topo, servers=servers,
|
||||
placement=SwitchBinPlacer )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
demo()
|
||||
@@ -327,7 +327,7 @@ class ConsoleApp( Frame ):
|
||||
elif units[0] == 'b':
|
||||
val *= 10 ** -9
|
||||
self.updates += 1
|
||||
self.bw += val
|
||||
self.bw += val
|
||||
if self.updates >= self.hostCount:
|
||||
self.graph.addBar( self.bw )
|
||||
self.bw = 0
|
||||
|
||||
@@ -19,7 +19,7 @@ from mininet.log import setLogLevel
|
||||
def multiControllerNet():
|
||||
"Create a network from semi-scratch with multiple controllers."
|
||||
|
||||
net = Mininet( controller=Controller, switch=OVSSwitch, build=False )
|
||||
net = Mininet( controller=Controller, switch=OVSSwitch )
|
||||
|
||||
print "*** Creating (reference) controllers"
|
||||
c1 = net.addController( 'c1', port=6633 )
|
||||
|
||||
+10
-3
@@ -27,15 +27,22 @@ from mininet.log import setLogLevel, info
|
||||
|
||||
class DataController( Controller ):
|
||||
"""Data Network Controller.
|
||||
patched to avoid checkListening error"""
|
||||
patched to avoid checkListening error and to delete intfs"""
|
||||
|
||||
def checkListening( self ):
|
||||
"Ignore spurious error"
|
||||
pass
|
||||
|
||||
def stop( self, *args, **kwargs ):
|
||||
"Make sure intfs are deleted"
|
||||
kwargs.update( deleteIntfs=True )
|
||||
super( DataController, self ).stop( *args, **kwargs )
|
||||
|
||||
|
||||
class MininetFacade( object ):
|
||||
"""Mininet object facade that allows a single CLI to
|
||||
talk to one or more networks"""
|
||||
|
||||
|
||||
def __init__( self, net, *args, **kwargs ):
|
||||
"""Create MininetFacade object.
|
||||
net: Primary Mininet object
|
||||
@@ -114,7 +121,7 @@ class ControlNetwork( Topo ):
|
||||
|
||||
def run():
|
||||
"Create control and data networks, and invoke the CLI"
|
||||
|
||||
|
||||
info( '* Creating Control Network\n' )
|
||||
ctopo = ControlNetwork( n=4, dataController=DataController )
|
||||
cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None )
|
||||
|
||||
+8
-16
@@ -7,21 +7,8 @@ cpu.py: test iperf bandwidth for varying cpu limits
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import custom
|
||||
from mininet.log import setLogLevel, output
|
||||
|
||||
from time import sleep
|
||||
|
||||
def waitListening(client, server, port):
|
||||
"Wait until server is listening on port"
|
||||
if not client.cmd('which telnet'):
|
||||
raise Exception('Could not find telnet')
|
||||
cmd = ('sh -c "echo A | telnet -e A %s %s"' %
|
||||
(server.IP(), port))
|
||||
while 'Connected' not in client.cmd(cmd):
|
||||
output('waiting for', server,
|
||||
'to listen on port', port, '\n')
|
||||
sleep(.5)
|
||||
from mininet.util import custom, waitListening
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
|
||||
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
||||
@@ -38,7 +25,12 @@ def bwtest( cpuLimits, period_us=100000, seconds=5 ):
|
||||
host = custom( CPULimitedHost, sched=sched,
|
||||
period_us=period_us,
|
||||
cpu=cpu )
|
||||
net = Mininet( topo=topo, host=host )
|
||||
try:
|
||||
net = Mininet( topo=topo, host=host )
|
||||
# pylint: disable=bare-except
|
||||
except:
|
||||
info( '*** Skipping host %s\n' % sched )
|
||||
break
|
||||
net.start()
|
||||
net.pingAll()
|
||||
hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@ This example shows how to add an interface (for example a real
|
||||
hardware interface) to a network after the network is created.
|
||||
"""
|
||||
|
||||
import re, sys
|
||||
import re
|
||||
import sys
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import setLogLevel, info, error
|
||||
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
'''
|
||||
example of using various TCIntf options.
|
||||
reconfigures a single interface using intf.config()
|
||||
to use different traffic control commands to test
|
||||
bandwidth, loss, and delay
|
||||
'''
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.log import setLogLevel, info
|
||||
from mininet.link import TCLink
|
||||
|
||||
def intfOptions():
|
||||
"run various traffic control commands on a single interface"
|
||||
net = Mininet( autoStaticArp=True )
|
||||
net.addController( 'c0' )
|
||||
h1 = net.addHost( 'h1' )
|
||||
h2 = net.addHost( 'h2' )
|
||||
s1 = net.addSwitch( 's1' )
|
||||
link1 = net.addLink( h1, s1, cls=TCLink )
|
||||
net.addLink( h2, s1 )
|
||||
net.start()
|
||||
|
||||
# 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*** Running iperf to test\n' )
|
||||
net.iperf()
|
||||
|
||||
info( '\n*** Configuring one intf with loss of 50%\n' )
|
||||
link1.intf1.config( loss=50 )
|
||||
info( '\n' )
|
||||
net.iperf( ( h1, h2 ), l4Type='UDP' )
|
||||
|
||||
info( '\n*** Configuring one intf with delay of 15ms\n' )
|
||||
link1.intf1.config( delay='15ms' )
|
||||
info( '\n*** Run a ping to confirm delay\n' )
|
||||
net.pingPairFull()
|
||||
|
||||
info( '\n*** Done testing\n' )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
intfOptions()
|
||||
+13
-6
@@ -8,15 +8,14 @@ from mininet.net import Mininet
|
||||
from mininet.link import TCIntf
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import custom
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import custom, quietRun
|
||||
from mininet.log import setLogLevel, info
|
||||
|
||||
|
||||
def testLinkLimit( net, bw ):
|
||||
"Run bandwidth limit test"
|
||||
print '*** Testing network %.2f Mbps bandwidth limit' % bw
|
||||
net.iperf( )
|
||||
|
||||
info( '*** Testing network %.2f Mbps bandwidth limit\n' % bw )
|
||||
net.iperf()
|
||||
|
||||
def limit( bw=10, cpu=.1 ):
|
||||
"""Example/test of link and CPU bandwidth limits
|
||||
@@ -25,7 +24,15 @@ def limit( bw=10, cpu=.1 ):
|
||||
intf = custom( TCIntf, bw=bw )
|
||||
myTopo = TreeTopo( depth=1, fanout=2 )
|
||||
for sched in 'rt', 'cfs':
|
||||
print '*** Testing with', sched, 'bandwidth limiting'
|
||||
info( '*** Testing with', sched, 'bandwidth limiting\n' )
|
||||
if sched == 'rt':
|
||||
release = quietRun( 'uname -r' ).strip('\r\n')
|
||||
output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s'
|
||||
% release )
|
||||
if output == '# CONFIG_RT_GROUP_SCHED is not set\n':
|
||||
info( '*** RT Scheduler is not enabled in your kernel. '
|
||||
'Skipping this test\n' )
|
||||
continue
|
||||
host = custom( CPULimitedHost, sched=sched, cpu=cpu )
|
||||
net = Mininet( topo=myTopo, intf=intf, host=host )
|
||||
net.start()
|
||||
|
||||
@@ -24,10 +24,12 @@ of switches, this example demonstrates:
|
||||
"""
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch
|
||||
from mininet.node import UserSwitch, OVSKernelSwitch, Controller
|
||||
from mininet.topo import Topo
|
||||
from mininet.log import lg
|
||||
from mininet.util import irange
|
||||
from mininet.util import irange, quietRun
|
||||
from mininet.link import TCLink
|
||||
from functools import partial
|
||||
|
||||
import sys
|
||||
flush = sys.stdout.flush
|
||||
@@ -70,13 +72,24 @@ def linearBandwidthTest( lengths ):
|
||||
switches = { 'reference user': UserSwitch,
|
||||
'Open vSwitch kernel': OVSKernelSwitch }
|
||||
|
||||
# UserSwitch is horribly slow with recent kernels.
|
||||
# We can reinstate it once its performance is fixed
|
||||
del switches[ 'reference user' ]
|
||||
|
||||
topo = LinearTestTopo( hostCount )
|
||||
|
||||
# Select TCP Reno
|
||||
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 ]
|
||||
results[ datapath ] = []
|
||||
net = Mininet( topo=topo, switch=Switch )
|
||||
link = partial( TCLink, delay='1ms' )
|
||||
net = Mininet( topo=topo, switch=Switch,
|
||||
controller=Controller, waitConnected=True,
|
||||
link=link )
|
||||
net.start()
|
||||
print "*** testing basic connectivity"
|
||||
for n in lengths:
|
||||
@@ -84,8 +97,11 @@ def linearBandwidthTest( lengths ):
|
||||
print "*** testing bandwidth"
|
||||
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 ] )
|
||||
bandwidth = net.iperf( [ src, dst ], seconds=10 )
|
||||
print bandwidth
|
||||
flush()
|
||||
results[ datapath ] += [ ( n, bandwidth ) ]
|
||||
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
linuxrouter.py: Example network with Linux IP router
|
||||
|
||||
This example converts a Node into a router using IP forwarding
|
||||
already built into Linux.
|
||||
|
||||
The example topology creates a router and three IP subnets:
|
||||
|
||||
- 192.168.1.0/24 (r0-eth1, IP: 192.168.1.1)
|
||||
- 172.16.0.0/12 (r0-eth2, IP: 172.16.0.1)
|
||||
- 10.0.0.0/8 (r0-eth3, IP: 10.0.0.1)
|
||||
|
||||
Each subnet consists of a single host connected to
|
||||
a single switch:
|
||||
|
||||
r0-eth1 - s1-eth1 - h1-eth0 (IP: 192.168.1.100)
|
||||
r0-eth2 - s2-eth1 - h2-eth0 (IP: 172.16.0.100)
|
||||
r0-eth3 - s3-eth1 - h3-eth0 (IP: 10.0.0.100)
|
||||
|
||||
The example relies on default routing entries that are
|
||||
automatically created for each router interface, as well
|
||||
as 'defaultRoute' parameters for the host interfaces.
|
||||
|
||||
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."
|
||||
|
||||
def config( self, **params ):
|
||||
super( LinuxRouter, self).config( **params )
|
||||
# Enable forwarding on the router
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=1' )
|
||||
|
||||
def terminate( self ):
|
||||
self.cmd( 'sysctl net.ipv4.ip_forward=0' )
|
||||
super( LinuxRouter, self ).terminate()
|
||||
|
||||
|
||||
class NetworkTopo( Topo ):
|
||||
"A LinuxRouter connecting three IP subnets"
|
||||
|
||||
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' ]
|
||||
|
||||
self.addLink( s1, router, intfName2='r0-eth1',
|
||||
params2={ 'ip' : defaultIP } ) # for clarity
|
||||
self.addLink( s2, router, intfName2='r0-eth2',
|
||||
params2={ 'ip' : '172.16.0.1/12' } )
|
||||
self.addLink( s3, router, intfName2='r0-eth3',
|
||||
params2={ 'ip' : '10.0.0.1/8' } )
|
||||
|
||||
h1 = self.addHost( 'h1', ip='192.168.1.100/24',
|
||||
defaultRoute='via 192.168.1.1' )
|
||||
h2 = self.addHost( 'h2', ip='172.16.0.100/12',
|
||||
defaultRoute='via 172.16.0.1' )
|
||||
h3 = self.addHost( 'h3', ip='10.0.0.100/8',
|
||||
defaultRoute='via 10.0.0.1' )
|
||||
|
||||
for h, s in [ (h1, s1), (h2, s2), (h3, s3) ]:
|
||||
self.addLink( h, s )
|
||||
|
||||
|
||||
def run():
|
||||
"Test linux router"
|
||||
topo = NetworkTopo()
|
||||
net = Mininet( topo=topo ) # controller is used by s1-s3
|
||||
net.start()
|
||||
info( '*** Routing Table on Router:\n' )
|
||||
print net[ 'r0' ].cmd( 'route' )
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
run()
|
||||
+2967
-87
File diff suppressed because it is too large
Load Diff
Executable
+134
@@ -0,0 +1,134 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
Simple example of Mobility with Mininet
|
||||
(aka enough rope to hang yourself.)
|
||||
|
||||
We move a host from s1 to s2, s2 to s3, and then back to s1.
|
||||
|
||||
Gotchas:
|
||||
|
||||
The reference controller doesn't support mobility, so we need to
|
||||
manually flush the switch flow tables!
|
||||
|
||||
Good luck!
|
||||
|
||||
to-do:
|
||||
|
||||
- think about wifi/hub behavior
|
||||
- think about clearing last hop - why doesn't that work?
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
|
||||
class MobilitySwitch( OVSSwitch ):
|
||||
"Switch that can reattach and rename interfaces"
|
||||
|
||||
def delIntf( self, intf ):
|
||||
"Remove (and detach) an interface"
|
||||
port = self.ports[ intf ]
|
||||
del self.ports[ intf ]
|
||||
del self.intfs[ port ]
|
||||
del self.nameToIntf[ intf.name ]
|
||||
|
||||
def addIntf( self, intf, rename=False, **kwargs ):
|
||||
"Add (and reparent) an interface"
|
||||
OVSSwitch.addIntf( self, intf, **kwargs )
|
||||
intf.node = self
|
||||
if rename:
|
||||
self.renameIntf( intf )
|
||||
|
||||
def attach( self, intf ):
|
||||
"Attach an interface and set its port"
|
||||
port = self.ports[ intf ]
|
||||
if port:
|
||||
if self.isOldOVS():
|
||||
self.cmd( 'ovs-vsctl add-port', self, intf )
|
||||
else:
|
||||
self.cmd( 'ovs-vsctl add-port', self, intf,
|
||||
'-- set Interface', intf,
|
||||
'ofport_request=%s' % port )
|
||||
self.validatePort( intf )
|
||||
|
||||
def validatePort( self, intf ):
|
||||
"Validate intf's OF port number"
|
||||
ofport = int( self.cmd( 'ovs-vsctl get Interface', intf,
|
||||
'ofport' ) )
|
||||
if ofport != self.ports[ intf ]:
|
||||
warn( 'WARNING: ofport for', intf, 'is actually', ofport,
|
||||
'\n' )
|
||||
|
||||
def renameIntf( self, intf, newname='' ):
|
||||
"Rename an interface (to its canonical name)"
|
||||
intf.ifconfig( 'down' )
|
||||
if not newname:
|
||||
newname = '%s-eth%d' % ( self.name, self.ports[ intf ] )
|
||||
intf.cmd( 'ip link set', intf, 'name', newname )
|
||||
del self.nameToIntf[ intf.name ]
|
||||
intf.name = newname
|
||||
self.nameToIntf[ intf.name ] = intf
|
||||
intf.ifconfig( 'up' )
|
||||
|
||||
def moveIntf( self, intf, switch, port=None, rename=True ):
|
||||
"Move one of our interfaces to another switch"
|
||||
self.detach( intf )
|
||||
self.delIntf( intf )
|
||||
switch.addIntf( intf, port=port, rename=rename )
|
||||
switch.attach( intf )
|
||||
|
||||
|
||||
def printConnections( switches ):
|
||||
"Compactly print connected nodes to each switch"
|
||||
for sw in switches:
|
||||
output( '%s: ' % sw )
|
||||
for intf in sw.intfList():
|
||||
link = intf.link
|
||||
if link:
|
||||
intf1, intf2 = link.intf1, link.intf2
|
||||
remote = intf1 if intf1.node != sw else intf2
|
||||
output( '%s(%s) ' % ( remote.node, sw.ports[ intf ] ) )
|
||||
output( '\n' )
|
||||
|
||||
|
||||
def moveHost( host, oldSwitch, newSwitch, newPort=None ):
|
||||
"Move a host from old switch to new switch"
|
||||
hintf, sintf = host.connectionsTo( oldSwitch )[ 0 ]
|
||||
oldSwitch.moveIntf( sintf, newSwitch, port=newPort )
|
||||
return hintf, sintf
|
||||
|
||||
|
||||
def mobilityTest():
|
||||
"A simple test of mobility"
|
||||
print '* Simple mobility test'
|
||||
net = Mininet( topo=LinearTopo( 3 ), switch=MobilitySwitch )
|
||||
print '* Starting network:'
|
||||
net.start()
|
||||
printConnections( net.switches )
|
||||
print '* Testing network'
|
||||
net.pingAll()
|
||||
print '* Identifying switch interface for h1'
|
||||
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
|
||||
hintf, sintf = moveHost( h1, old, new, newPort=port )
|
||||
print '*', hintf, 'is now connected to', sintf
|
||||
print '* Clearing out old flows'
|
||||
for sw in net.switches:
|
||||
sw.dpctl( 'del-flows' )
|
||||
print '* New network:'
|
||||
printConnections( net.switches )
|
||||
print '* Testing connectivity:'
|
||||
net.pingAll()
|
||||
old = new
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
mobilityTest()
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
This is a simple example that demonstrates multiple links
|
||||
between nodes.
|
||||
"""
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.net import Mininet
|
||||
from mininet.topo import Topo
|
||||
|
||||
def runMultiLink():
|
||||
"Create and run multiple link network"
|
||||
topo = simpleMultiLinkTopo( n=2 )
|
||||
net = Mininet( topo=topo )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
class simpleMultiLinkTopo( Topo ):
|
||||
"Simple topology with multiple links"
|
||||
|
||||
def __init__( self, n, **kwargs ):
|
||||
Topo.__init__( self, **kwargs )
|
||||
|
||||
h1, h2 = self.addHost( 'h1' ), self.addHost( 'h2' )
|
||||
s1 = self.addSwitch( 's1' )
|
||||
|
||||
for _ in range( n ):
|
||||
self.addLink( s1, h1 )
|
||||
self.addLink( s1, h2 )
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
runMultiLink()
|
||||
+3
-93
@@ -2,11 +2,6 @@
|
||||
|
||||
"""
|
||||
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
|
||||
@@ -14,99 +9,14 @@ from mininet.log import lg
|
||||
from mininet.node import Node
|
||||
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 )
|
||||
# Add NAT connectivity
|
||||
net.addNAT().configDefault()
|
||||
net.start()
|
||||
print "*** Hosts are running and should have internet connectivity"
|
||||
print "*** Type 'exit' or control-D to shut down network"
|
||||
CLI( net )
|
||||
# Shut down NAT
|
||||
stopNAT( rootnode )
|
||||
net.stop()
|
||||
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
natnet.py: Example network with NATs
|
||||
|
||||
|
||||
h0
|
||||
|
|
||||
s0
|
||||
|
|
||||
----------------
|
||||
| |
|
||||
nat1 nat2
|
||||
| |
|
||||
s1 s2
|
||||
| |
|
||||
h1 h2
|
||||
|
||||
"""
|
||||
|
||||
from mininet.topo import Topo
|
||||
from mininet.net import Mininet
|
||||
from mininet.nodelib import NAT
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.cli import CLI
|
||||
from mininet.util import irange
|
||||
|
||||
class InternetTopo(Topo):
|
||||
"Single switch connected to n hosts."
|
||||
def __init__(self, n=2, **opts):
|
||||
Topo.__init__(self, **opts)
|
||||
|
||||
# set up inet switch
|
||||
inetSwitch = self.addSwitch('s0')
|
||||
# add inet host
|
||||
inetHost = self.addHost('h0')
|
||||
self.addLink(inetSwitch, inetHost)
|
||||
|
||||
# add local nets
|
||||
for i in irange(1, n):
|
||||
inetIntf = 'nat%d-eth0' % i
|
||||
localIntf = 'nat%d-eth1' % i
|
||||
localIP = '192.168.%d.1' % i
|
||||
localSubnet = '192.168.%d.0/24' % i
|
||||
natParams = { 'ip' : '%s/24' % localIP }
|
||||
# add NAT to topology
|
||||
nat = self.addNode('nat%d' % i, cls=NAT, subnet=localSubnet,
|
||||
inetIntf=inetIntf, localIntf=localIntf)
|
||||
switch = self.addSwitch('s%d' % i)
|
||||
# connect NAT to inet and local switches
|
||||
self.addLink(nat, inetSwitch, intfName1=inetIntf)
|
||||
self.addLink(nat, switch, intfName1=localIntf, params1=natParams)
|
||||
# add host and connect to local switch
|
||||
host = self.addHost('h%d' % i,
|
||||
ip='192.168.%d.100/24' % i,
|
||||
defaultRoute='via %s' % localIP)
|
||||
self.addLink(host, switch)
|
||||
|
||||
def run():
|
||||
"Create network and run the CLI"
|
||||
topo = InternetTopo()
|
||||
net = Mininet(topo=topo)
|
||||
net.start()
|
||||
CLI(net)
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel('info')
|
||||
run()
|
||||
Executable
+79
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
Create a network with 5 hosts, numbered 1-4 and 9.
|
||||
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
|
||||
|
||||
def validatePort( switch, intf ):
|
||||
"Validate intf's OF port number"
|
||||
ofport = int( switch.cmd( 'ovs-vsctl get Interface', intf,
|
||||
'ofport' ) )
|
||||
if ofport != switch.ports[ intf ]:
|
||||
warn( 'WARNING: ofport for', intf, 'is actually', ofport, '\n' )
|
||||
return 0
|
||||
else:
|
||||
return 1
|
||||
|
||||
def testPortNumbering():
|
||||
|
||||
"""Test port numbering:
|
||||
Create a network with 5 hosts (using Mininet's
|
||||
mid-level API) and check that implicit and
|
||||
explicit port numbering works as expected."""
|
||||
|
||||
net = Mininet( controller=Controller )
|
||||
|
||||
info( '*** Adding controller\n' )
|
||||
net.addController( 'c0' )
|
||||
|
||||
info( '*** Adding hosts\n' )
|
||||
h1 = net.addHost( 'h1', ip='10.0.0.1' )
|
||||
h2 = net.addHost( 'h2', ip='10.0.0.2' )
|
||||
h3 = net.addHost( 'h3', ip='10.0.0.3' )
|
||||
h4 = net.addHost( 'h4', ip='10.0.0.4' )
|
||||
h5 = net.addHost( 'h5', ip='10.0.0.5' )
|
||||
|
||||
info( '*** Adding switch\n' )
|
||||
s1 = net.addSwitch( 's1' )
|
||||
|
||||
info( '*** Creating links\n' )
|
||||
# host 1-4 connect to ports 1-4 on the switch
|
||||
net.addLink( h1, s1 )
|
||||
net.addLink( h2, s1 )
|
||||
net.addLink( h3, s1 )
|
||||
net.addLink( h4, s1 )
|
||||
# specify a different port to connect host 5 to on the switch.
|
||||
net.addLink( h5, s1, port1=1, port2= 9)
|
||||
|
||||
info( '*** Starting network\n' )
|
||||
net.start()
|
||||
|
||||
# print the interfaces and their port numbers
|
||||
info( '\n*** printing and validating the ports '
|
||||
'running on each interface\n' )
|
||||
for intfs in s1.intfList():
|
||||
if not intfs.name == "lo":
|
||||
info( intfs, ': ', s1.ports[intfs],
|
||||
'\n' )
|
||||
info( 'Validating that', intfs,
|
||||
'is actually on port', s1.ports[intfs], '... ' )
|
||||
if validatePort( s1, intfs ):
|
||||
info( 'Validated.\n' )
|
||||
print '\n'
|
||||
|
||||
# test the network with pingall
|
||||
net.pingAll()
|
||||
print '\n'
|
||||
|
||||
info( '*** Stopping network' )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
testPortNumbering()
|
||||
@@ -31,17 +31,16 @@ class SingleSwitchTopo(Topo):
|
||||
|
||||
def perfTest():
|
||||
"Create network and run simple performance test"
|
||||
topo = SingleSwitchTopo(n=4)
|
||||
net = Mininet(topo=topo,
|
||||
host=CPULimitedHost, link=TCLink)
|
||||
topo = SingleSwitchTopo( n=4 )
|
||||
net = Mininet( topo=topo,
|
||||
host=CPULimitedHost, link=TCLink,
|
||||
autoStaticArp=True )
|
||||
net.start()
|
||||
print "Dumping host connections"
|
||||
dumpNodeConnections(net.hosts)
|
||||
print "Testing network connectivity"
|
||||
net.pingAll()
|
||||
print "Testing bandwidth between h1 and h4"
|
||||
h1, h4 = net.getNodeByName('h1', 'h4')
|
||||
net.iperf((h1, h4))
|
||||
net.iperf( ( h1, h4 ), l4Type='UDP' )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
+8
-4
@@ -23,7 +23,7 @@ from mininet.cli import CLI
|
||||
from mininet.log import lg
|
||||
from mininet.node import Node
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.link import Link
|
||||
from mininet.util import waitListening
|
||||
|
||||
def TreeNet( depth=1, fanout=2, **kwargs ):
|
||||
"Convenience function for creating tree networks."
|
||||
@@ -38,7 +38,7 @@ def connectToRootNS( network, switch, ip, routes ):
|
||||
routes: host networks to route to"""
|
||||
# Create a node in root namespace and link to switch 0
|
||||
root = Node( 'root', inNamespace=False )
|
||||
intf = Link( root, switch ).intf1
|
||||
intf = network.addLink( root, switch ).intf1
|
||||
root.setIP( ip, intf=intf )
|
||||
# Start network that now includes link to root namespace
|
||||
network.start()
|
||||
@@ -59,6 +59,10 @@ 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"
|
||||
for server in network.hosts:
|
||||
waitListening( server=server, port=22, timeout=5 )
|
||||
|
||||
print
|
||||
print "*** Hosts are running sshd at the following addresses:"
|
||||
print
|
||||
@@ -76,6 +80,6 @@ if __name__ == '__main__':
|
||||
net = TreeNet( depth=1, fanout=4 )
|
||||
# get sshd args from the command line or use default args
|
||||
# useDNS=no -u0 to avoid reverse DNS lookup timeout
|
||||
opts = ' '.join( sys.argv[ 1: ] ) if len( sys.argv ) > 1 else (
|
||||
argvopts = ' '.join( sys.argv[ 1: ] ) if len( sys.argv ) > 1 else (
|
||||
'-D -o UseDNS=no -u0' )
|
||||
sshd( net, opts=opts )
|
||||
sshd( net, opts=argvopts )
|
||||
|
||||
+13
-1
@@ -12,6 +12,18 @@ import sys
|
||||
from mininet.util import ensureRoot
|
||||
from mininet.clean import cleanup
|
||||
|
||||
class MininetTestResult( unittest.TextTestResult ):
|
||||
def addFailure( self, test, err ):
|
||||
super( MininetTestResult, self ).addFailure( test, err )
|
||||
cleanup()
|
||||
def addError( self,test, err ):
|
||||
super( MininetTestResult, self ).addError( test, err )
|
||||
cleanup()
|
||||
|
||||
class MininetTestRunner( unittest.TextTestRunner ):
|
||||
def _makeResult( self ):
|
||||
return MininetTestResult( self.stream, self.descriptions, self.verbosity )
|
||||
|
||||
def runTests( testDir, verbosity=1 ):
|
||||
"discover and run all tests in testDir"
|
||||
# ensure root and cleanup before starting tests
|
||||
@@ -20,7 +32,7 @@ def runTests( testDir, verbosity=1 ):
|
||||
# discover all tests in testDir
|
||||
testSuite = unittest.defaultTestLoader.discover( testDir )
|
||||
# run tests
|
||||
unittest.TextTestRunner( verbosity=verbosity ).run( testSuite )
|
||||
MininetTestRunner( verbosity=verbosity ).run( testSuite )
|
||||
|
||||
if __name__ == '__main__':
|
||||
# get the directory containing example tests
|
||||
|
||||
@@ -6,21 +6,18 @@ Tests for baresshd.py
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from time import sleep
|
||||
from mininet.clean import cleanup, sh
|
||||
|
||||
class testBareSSHD( unittest.TestCase ):
|
||||
|
||||
opts = [ '\(yes/no\)\?', 'Welcome to h1', 'refused', pexpect.EOF, pexpect.TIMEOUT ]
|
||||
opts = [ 'Welcome to h1', pexpect.EOF, pexpect.TIMEOUT ]
|
||||
|
||||
def connected( self ):
|
||||
"Log into ssh server, check banner, then exit"
|
||||
p = pexpect.spawn( 'ssh 10.0.0.1 -i /tmp/ssh/test_rsa exit' )
|
||||
p = pexpect.spawn( 'ssh 10.0.0.1 -o StrictHostKeyChecking=no -i /tmp/ssh/test_rsa exit' )
|
||||
while True:
|
||||
index = p.expect( self.opts )
|
||||
if index == 0:
|
||||
p.sendline( 'yes' )
|
||||
elif index == 1:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -37,18 +34,23 @@ class testBareSSHD( unittest.TestCase ):
|
||||
cmd = ( 'python -m mininet.examples.baresshd '
|
||||
'-o AuthorizedKeysFile=/tmp/ssh/authorized_keys '
|
||||
'-o StrictModes=no' )
|
||||
sh( cmd )
|
||||
p = pexpect.spawn( cmd )
|
||||
runOpts = [ 'You may now ssh into h1 at 10.0.0.1',
|
||||
'after 5 seconds, h1 is not listening on port 22',
|
||||
pexpect.EOF, pexpect.TIMEOUT ]
|
||||
while True:
|
||||
index = p.expect( runOpts )
|
||||
if index == 0:
|
||||
break
|
||||
else:
|
||||
self.tearDown()
|
||||
self.fail( 'sshd failed to start in host h1' )
|
||||
|
||||
def testSSH( self ):
|
||||
"Simple test to verify that we can ssh into h1"
|
||||
result = False
|
||||
# try to connect up to 3 times; sshd can take a while to start
|
||||
for _ in range( 3 ):
|
||||
result = self.connected()
|
||||
if result:
|
||||
break
|
||||
else:
|
||||
sleep( 1 )
|
||||
result = self.connected()
|
||||
self.assertTrue( result )
|
||||
|
||||
def tearDown( self ):
|
||||
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
'''
|
||||
A simple sanity check test for cluster edition
|
||||
'''
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
|
||||
class clusterSanityCheck( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
def testClusterPingAll( self ):
|
||||
p = pexpect.spawn( 'python -m mininet.examples.clusterSanity' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'pingall' )
|
||||
p.expect ( '(\d+)% dropped' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
self.assertEqual( percent, 0 )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2,6 +2,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
|
||||
|
||||
"""
|
||||
|
||||
import unittest
|
||||
@@ -16,18 +27,20 @@ class testCPU( unittest.TestCase ):
|
||||
def testCPU( self ):
|
||||
"Verify that CPU utilization is monotonically decreasing for each scheduler"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.cpu' )
|
||||
opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)', pexpect.EOF ]
|
||||
# matches each line from results( shown above )
|
||||
opts = [ '([a-z]+)\t([\d\.]+)%\t([\d\.]+)',
|
||||
pexpect.EOF ]
|
||||
scheds = []
|
||||
while True:
|
||||
index = p.expect( opts, timeout=600 )
|
||||
if index == 0:
|
||||
sched = p.match.group( 1 )
|
||||
sched = p.match.group( 1 )
|
||||
cpu = float( p.match.group( 2 ) )
|
||||
bw = float( p.match.group( 3 ) )
|
||||
if sched not in scheds:
|
||||
scheds.append( sched )
|
||||
previous_bw = 10 ** 4 # 10 GB/s
|
||||
self.assertTrue( bw < previous_bw )
|
||||
else:
|
||||
self.assertTrue( bw < previous_bw )
|
||||
previous_bw = bw
|
||||
else:
|
||||
break
|
||||
|
||||
@@ -19,7 +19,7 @@ class testEmptyNet( unittest.TestCase ):
|
||||
p.sendline( 'pingall' )
|
||||
p.expect ( '(\d+)% dropped' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
self.assertEqual( percent, 0 )
|
||||
self.assertEqual( percent, 0 )
|
||||
p.expect( self.prompt )
|
||||
# iperf test
|
||||
p.sendline( 'iperf' )
|
||||
|
||||
@@ -5,12 +5,14 @@ Test for hwintf.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
import re
|
||||
|
||||
import pexpect
|
||||
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Node
|
||||
from mininet.link import Link, Intf
|
||||
from mininet.link import Link
|
||||
|
||||
|
||||
class testHwintf( unittest.TestCase ):
|
||||
|
||||
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test for intfOptions.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
import sys
|
||||
|
||||
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
|
||||
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",
|
||||
pexpect.EOF ]
|
||||
while True:
|
||||
index = p.expect( opts, timeout=600 )
|
||||
if index == 0:
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertGreaterEqual( bw, float( 5 * tolerance ) )
|
||||
self.assertLessEqual( bw, float( 5 + 5 * ( 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 ) )
|
||||
elif index == 2:
|
||||
delay = float( p.match.group( 6 ) )
|
||||
self.assertGreaterEqual( delay, 15 * tolerance )
|
||||
self.assertLessEqual( delay, 15 + 15 * ( 1 - tolerance ) )
|
||||
else:
|
||||
break
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -14,8 +14,8 @@ class testLimit( unittest.TestCase ):
|
||||
def testLimit( self ):
|
||||
"Verify that CPU limits are within a 2% tolerance of limit for each scheduler"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.limit' )
|
||||
opts = [ '\*\*\* Testing network ([\d\.]+) Mbps',
|
||||
'\*\*\* Results: \[([\d\., ]+)\]',
|
||||
opts = [ '\*\*\* Testing network ([\d\.]+) Mbps',
|
||||
'\*\*\* Results: \[([\d\., ]+)\]',
|
||||
pexpect.EOF ]
|
||||
count = 0
|
||||
bw = 0
|
||||
|
||||
@@ -15,13 +15,12 @@ class testLinearBandwidth( unittest.TestCase ):
|
||||
"Verify that bandwidth is monotonically decreasing as # of hops increases"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.linearbandwidth' )
|
||||
count = 0
|
||||
opts = [ '\*\*\* Linear network results',
|
||||
'(\d+)\s+([\d\.]+) (.bits)',
|
||||
opts = [ '\*\*\* Linear network results',
|
||||
'(\d+)\s+([\d\.]+) (.bits)',
|
||||
pexpect.EOF ]
|
||||
while True:
|
||||
index = p.expect( opts, timeout=600 )
|
||||
if index == 0:
|
||||
previous_bw = 10 ** 10 # 10 Gbits
|
||||
count += 1
|
||||
elif index == 1:
|
||||
n = int( p.match.group( 1 ) )
|
||||
@@ -33,11 +32,17 @@ class testLinearBandwidth( unittest.TestCase ):
|
||||
bw *= 10 ** 6
|
||||
elif unit[ 0 ] == 'G':
|
||||
bw *= 10 ** 9
|
||||
self.assertTrue( bw < previous_bw )
|
||||
previous_bw = bw
|
||||
# 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' %
|
||||
( bw, n, previous_bw, previous_n ) )
|
||||
self.assertTrue( bw < previous_bw, info )
|
||||
previous_bw, previous_n = bw, n
|
||||
else:
|
||||
break
|
||||
|
||||
# verify that we received results from at least one switch
|
||||
self.assertTrue( count > 0 )
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test for linuxrouter.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import quietRun
|
||||
|
||||
class testLinuxRouter( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
def testPingall( self ):
|
||||
"Test connectivity between hosts"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'pingall' )
|
||||
p.expect ( '(\d+)% dropped' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( percent, 0 )
|
||||
|
||||
def testRouterPing( self ):
|
||||
"Test connectivity from h1 to router"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 ping -c 1 r0' )
|
||||
p.expect ( '(\d+)% packet loss' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( percent, 0 )
|
||||
|
||||
def testTTL( self ):
|
||||
"Verify that the TTL is decremented"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.linuxrouter' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'h1 ping -c 1 h2' )
|
||||
p.expect ( 'ttl=(\d+)' )
|
||||
ttl = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( ttl, 63 ) # 64 - 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test for mobility.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
from subprocess import check_output
|
||||
|
||||
class testMobility( unittest.TestCase ):
|
||||
|
||||
def testMobility( self ):
|
||||
"Run the example and verify its 4 ping results"
|
||||
cmd = 'python -m mininet.examples.mobility 2>&1'
|
||||
grep = ' | grep -c " 0% dropped" '
|
||||
result = check_output( cmd + grep, shell=True )
|
||||
assert int( result ) == 4
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Executable
+55
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
'''
|
||||
Test for multiple links between nodes
|
||||
validates mininet interfaces against systems interfaces
|
||||
'''
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
|
||||
class testMultiLink( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
def testMultiLink(self):
|
||||
p = pexpect.spawn( 'python -m mininet.examples.multilink' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'intfs' )
|
||||
p.expect( 's(\d): lo' )
|
||||
intfsOutput = p.before
|
||||
# parse interfaces from mininet intfs, and store them in a list
|
||||
hostToIntfs = intfsOutput.split( '\r\n' )[ 1:3 ]
|
||||
intfList = []
|
||||
for hostToIntf in hostToIntfs:
|
||||
intfList += [ intf for intf in
|
||||
hostToIntf.split()[1].split(',') ]
|
||||
|
||||
# get interfaces from system by running ifconfig on every host
|
||||
sysIntfList = []
|
||||
opts = [ 'h(\d)-eth(\d)', self.prompt ]
|
||||
p.expect( self.prompt )
|
||||
|
||||
p.sendline( 'h1 ifconfig' )
|
||||
while True:
|
||||
p.expect( opts )
|
||||
if p.after == self.prompt:
|
||||
break
|
||||
sysIntfList.append( p.after )
|
||||
|
||||
p.sendline( 'h2 ifconfig' )
|
||||
while True:
|
||||
p.expect( opts )
|
||||
if p.after == self.prompt:
|
||||
break
|
||||
sysIntfList.append( p.after )
|
||||
|
||||
failMsg = ( 'The systems interfaces and mininet interfaces\n'
|
||||
'are not the same' )
|
||||
|
||||
self.assertEqual( sysIntfList, intfList, msg=failMsg )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -11,7 +11,7 @@ from collections import defaultdict
|
||||
class testMultiPing( unittest.TestCase ):
|
||||
|
||||
def testMultiPing( self ):
|
||||
"""Verify that each target is pinged at least once, and
|
||||
"""Verify that each target is pinged at least once, and
|
||||
that pings to 'real' targets are successful and unknown targets fail"""
|
||||
p = pexpect.spawn( 'python -m mininet.examples.multiping' )
|
||||
opts = [ "Host (h\d+) \(([\d.]+)\) will be pinging ips: ([\d\. ]+)",
|
||||
|
||||
@@ -14,7 +14,7 @@ class testNAT( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
@unittest.skipIf( '0 received' in quietRun( 'ping -c 1 %s' % destIP ),
|
||||
@unittest.skipIf( '0 received' in quietRun( 'ping -c 1 %s' % destIP ),
|
||||
'Destination IP is not reachable' )
|
||||
def testNAT( self ):
|
||||
"Attempt to ping an IP on the Internet and verify 0% packet loss"
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test for natnet.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from mininet.util import quietRun
|
||||
|
||||
class testNATNet( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
def setUp( self ):
|
||||
self.net = pexpect.spawn( 'python -m mininet.examples.natnet' )
|
||||
self.net.expect( self.prompt )
|
||||
|
||||
def testPublicPing( self ):
|
||||
"Attempt to ping the public server (h0) from h1 and h2"
|
||||
self.net.sendline( 'h1 ping -c 1 h0' )
|
||||
self.net.expect ( '(\d+)% packet loss' )
|
||||
percent = int( self.net.match.group( 1 ) ) if self.net.match else -1
|
||||
self.assertEqual( percent, 0 )
|
||||
self.net.expect( self.prompt )
|
||||
|
||||
self.net.sendline( 'h2 ping -c 1 h0' )
|
||||
self.net.expect ( '(\d+)% packet loss' )
|
||||
percent = int( self.net.match.group( 1 ) ) if self.net.match else -1
|
||||
self.assertEqual( percent, 0 )
|
||||
self.net.expect( self.prompt )
|
||||
|
||||
def testPrivatePing( self ):
|
||||
"Attempt to ping h1 and h2 from public server"
|
||||
self.net.sendline( 'h0 ping -c 1 -t 1 h1' )
|
||||
result = self.net.expect ( [ 'unreachable', 'loss' ] )
|
||||
self.assertEqual( result, 0 )
|
||||
self.net.expect( self.prompt )
|
||||
|
||||
self.net.sendline( 'h0 ping -c 1 -t 1 h2' )
|
||||
result = self.net.expect ( [ 'unreachable', 'loss' ] )
|
||||
self.assertEqual( result, 0 )
|
||||
self.net.expect( self.prompt )
|
||||
|
||||
def testPrivateToPrivatePing( self ):
|
||||
"Attempt to ping from NAT'ed host h1 to NAT'ed host h2"
|
||||
self.net.sendline( 'h1 ping -c 1 -t 1 h2' )
|
||||
result = self.net.expect ( [ '[Uu]nreachable', 'loss' ] )
|
||||
self.assertEqual( result, 0 )
|
||||
self.net.expect( self.prompt )
|
||||
|
||||
def tearDown( self ):
|
||||
self.net.sendline( 'exit' )
|
||||
self.net.wait()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test for numberedports.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from collections import defaultdict
|
||||
from mininet.node import OVSSwitch
|
||||
|
||||
class testNumberedports( unittest.TestCase ):
|
||||
|
||||
@unittest.skipIf( OVSSwitch.setup() or OVSSwitch.isOldOVS(), "old version of OVS" )
|
||||
def testConsistency( self ):
|
||||
"""verify consistency between mininet and ovs ports"""
|
||||
p = pexpect.spawn( 'python -m mininet.examples.numberedports' )
|
||||
opts = [ 'Validating that s1-eth\d is actually on port \d ... Validated.',
|
||||
'Validating that s1-eth\d is actually on port \d ... WARNING',
|
||||
pexpect.EOF ]
|
||||
correct_ports = True
|
||||
count = 0
|
||||
while True:
|
||||
index = p.expect( opts )
|
||||
if index == 0:
|
||||
count += 1
|
||||
elif index == 1:
|
||||
correct_ports = False
|
||||
elif index == 2:
|
||||
self.assertNotEqual( 0, count )
|
||||
break
|
||||
self.assertTrue( correct_ports )
|
||||
|
||||
def testNumbering( self ):
|
||||
"""verify that all of the port numbers are printed correctly and consistent with their interface"""
|
||||
p = pexpect.spawn( 'python -m mininet.examples.numberedports' )
|
||||
opts = [ 's1-eth(\d+) : (\d+)',
|
||||
pexpect.EOF ]
|
||||
count_intfs = 0
|
||||
while True:
|
||||
index = p.expect( opts )
|
||||
if index == 0:
|
||||
count_intfs += 1
|
||||
intfport = p.match.group( 1 )
|
||||
ofport = p.match.group( 2 )
|
||||
self.assertEqual( intfport, ofport )
|
||||
elif index == 1:
|
||||
break
|
||||
self.assertNotEqual( 0, count_intfs )
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -6,12 +6,8 @@ Test for simpleperf.py
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
import re
|
||||
import sys
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.link import TCLink
|
||||
|
||||
from mininet.examples.simpleperf import SingleSwitchTopo
|
||||
|
||||
@@ -19,35 +15,20 @@ class testSimplePerf( unittest.TestCase ):
|
||||
|
||||
@unittest.skipIf( '-quick' in sys.argv, 'long test' )
|
||||
def testE2E( self ):
|
||||
"Run the example and verify ping and iperf results"
|
||||
"Run the example and verify iperf results"
|
||||
BW = 10
|
||||
TOLERANCE = .8
|
||||
expectedBw = BW * TOLERANCE
|
||||
p = pexpect.spawn( 'python -m mininet.examples.simpleperf' )
|
||||
# check ping results
|
||||
p.expect( "Results: (\d+)% dropped", timeout=120 )
|
||||
loss = int( p.match.group( 1 ) )
|
||||
self.assertTrue( loss > 0 and loss < 100 )
|
||||
# check iperf results
|
||||
p.expect( "Results: \['([\d\.]+) .bits/sec", timeout=480 )
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertTrue( bw > 0 )
|
||||
p.expect( "Results: \['10M', '([\d\.]+) .bits/sec", timeout=480 )
|
||||
measuredBw = float( p.match.group( 1 ) )
|
||||
lowerBound = expectedBw * TOLERANCE
|
||||
upperBound = expectedBw + expectedBw * ( 1 - TOLERANCE )
|
||||
self.assertGreaterEqual( measuredBw, lowerBound )
|
||||
self.assertLessEqual( measuredBw, upperBound )
|
||||
p.wait()
|
||||
|
||||
def testTopo( self ):
|
||||
"""Import SingleSwitchTopo from example and test connectivity between two hosts
|
||||
Note: this test may fail very rarely because it is non-deterministic
|
||||
i.e. links are configured with 10% packet loss, but if we get unlucky and
|
||||
none or all of the packets are dropped, the test will fail"""
|
||||
topo = SingleSwitchTopo( n=4 )
|
||||
net = Mininet( topo=topo, host=CPULimitedHost, link=TCLink )
|
||||
net.start()
|
||||
h1, h4 = net.get( 'h1', 'h4' )
|
||||
# have h1 ping h4 ten times
|
||||
expectStr = '(\d+) packets transmitted, (\d+) received, (\d+)% packet loss'
|
||||
output = h1.cmd( 'ping -c 10 %s' % h4.IP() )
|
||||
m = re.search( expectStr, output )
|
||||
loss = int( m.group( 3 ) )
|
||||
net.stop()
|
||||
self.assertTrue( loss > 0 and loss < 100 )
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
|
||||
@@ -6,7 +6,6 @@ Test for sshd.py
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
from time import sleep
|
||||
from mininet.clean import sh
|
||||
|
||||
class testSSHD( unittest.TestCase ):
|
||||
@@ -15,7 +14,7 @@ class testSSHD( unittest.TestCase ):
|
||||
|
||||
def connected( self, ip ):
|
||||
"Log into ssh server, check banner, then exit"
|
||||
# Note: this test will fail if "Welcome" is not in the sshd banner
|
||||
# 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 )
|
||||
while True:
|
||||
@@ -27,7 +26,7 @@ class testSSHD( unittest.TestCase ):
|
||||
return False
|
||||
elif index == 2:
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
p.wait()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Test for vlanhost.py
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import pexpect
|
||||
import sys
|
||||
from mininet.util import quietRun
|
||||
|
||||
class testVLANHost( unittest.TestCase ):
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
@unittest.skipIf( '-quick' in sys.argv, 'long test' )
|
||||
def testVLANTopo( self ):
|
||||
"Test connectivity (or lack thereof) between hosts in VLANTopo"
|
||||
p = pexpect.spawn( 'python -m mininet.examples.vlanhost' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'pingall 1' ) #ping timeout=1
|
||||
p.expect( '(\d+)% dropped', timeout=30 ) # there should be 24 failed pings
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( percent, 80 )
|
||||
|
||||
def testSpecificVLAN( self ):
|
||||
"Test connectivity between hosts on a specific VLAN"
|
||||
vlan = 1001
|
||||
p = pexpect.spawn( 'python -m mininet.examples.vlanhost %d' % vlan )
|
||||
p.expect( self.prompt )
|
||||
|
||||
p.sendline( 'h1 ping -c 1 h2' )
|
||||
p.expect ( '(\d+)% packet loss' )
|
||||
percent = int( p.match.group( 1 ) ) if p.match else -1
|
||||
p.expect( self.prompt )
|
||||
|
||||
p.sendline( 'h1 ifconfig' )
|
||||
i = p.expect( ['h1-eth0.%d' % vlan, pexpect.TIMEOUT ], timeout=2 )
|
||||
p.expect( self.prompt )
|
||||
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
self.assertEqual( percent, 0 ) # no packet loss on ping
|
||||
self.assertEqual( i, 0 ) # check vlan intf is present
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -9,10 +9,10 @@ and running sysctl -p. Check util/sysctl_addon.
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.node import OVSKernelSwitch
|
||||
from mininet.node import OVSSwitch
|
||||
from mininet.topolib import TreeNet
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
network = TreeNet( depth=2, fanout=32, switch=OVSKernelSwitch )
|
||||
network = TreeNet( depth=2, fanout=32, switch=OVSSwitch )
|
||||
network.run( CLI, network )
|
||||
|
||||
Executable
+124
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
vlanhost.py: Host subclass that uses a VLAN tag for the default interface.
|
||||
|
||||
Dependencies:
|
||||
This class depends on the "vlan" package
|
||||
$ sudo apt-get install vlan
|
||||
|
||||
Usage (example uses VLAN ID=1000):
|
||||
From the command line:
|
||||
sudo mn --custom vlanhost.py --host vlan,vlan=1000
|
||||
|
||||
From a script (see exampleUsage function below):
|
||||
from functools import partial
|
||||
from vlanhost import VLANHost
|
||||
|
||||
....
|
||||
|
||||
host = partial( VLANHost, vlan=1000 )
|
||||
net = Mininet( host=host, ... )
|
||||
|
||||
Directly running this script:
|
||||
sudo python vlanhost.py 1000
|
||||
|
||||
"""
|
||||
|
||||
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"
|
||||
|
||||
def config( self, vlan=100, **params ):
|
||||
"""Configure VLANHost according to (optional) parameters:
|
||||
vlan: VLAN ID for default interface"""
|
||||
|
||||
r = super( VLANHost, self ).config( **params )
|
||||
|
||||
intf = self.defaultIntf()
|
||||
# remove IP from default, "physical" interface
|
||||
self.cmd( 'ifconfig %s inet 0' % intf )
|
||||
# create VLAN interface
|
||||
self.cmd( 'vconfig add %s %d' % ( intf, vlan ) )
|
||||
# assign the host's IP to the VLAN interface
|
||||
self.cmd( 'ifconfig %s.%d inet %s' % ( intf, vlan, params['ip'] ) )
|
||||
# update the intf name and host's intf map
|
||||
newName = '%s.%d' % ( intf, vlan )
|
||||
# update the (Mininet) interface to refer to VLAN interface name
|
||||
intf.name = newName
|
||||
# add VLAN interface to host's name to intf map
|
||||
self.nameToIntf[ newName ] = intf
|
||||
|
||||
return r
|
||||
|
||||
hosts = { 'vlan': VLANHost }
|
||||
|
||||
|
||||
def exampleAllHosts( vlan ):
|
||||
"""Simple example of how VLANHost can be used in a script"""
|
||||
# This is where the magic happens...
|
||||
host = partial( VLANHost, vlan=vlan )
|
||||
# vlan (type: int): VLAN ID to be used by all hosts
|
||||
|
||||
# Start a basic network using our VLANHost
|
||||
topo = SingleSwitchTopo( k=2 )
|
||||
net = Mininet( host=host, topo=topo )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
# pylint: disable=arguments-differ
|
||||
|
||||
class VLANStarTopo( Topo ):
|
||||
"""Example topology that uses host in multiple VLANs
|
||||
|
||||
The topology has a single switch. There are k VLANs with
|
||||
n hosts in each, all connected to the single switch. There
|
||||
are also n hosts that are not in any VLAN, also connected to
|
||||
the switch."""
|
||||
|
||||
def build( self, k=2, n=2, vlanBase=100 ):
|
||||
s1 = self.addSwitch( 's1' )
|
||||
for i in range( k ):
|
||||
vlan = vlanBase + i
|
||||
for j in range(n):
|
||||
name = 'h%d-%d' % ( j+1, vlan )
|
||||
h = self.addHost( name, cls=VLANHost, vlan=vlan )
|
||||
self.addLink( h, s1 )
|
||||
for j in range( n ):
|
||||
h = self.addHost( 'h%d' % (j+1) )
|
||||
self.addLink( h, s1 )
|
||||
|
||||
|
||||
def exampleCustomTags():
|
||||
"""Simple example that exercises VLANStarTopo"""
|
||||
|
||||
net = Mininet( topo=VLANStarTopo() )
|
||||
net.start()
|
||||
CLI( net )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.cli import CLI
|
||||
from mininet.topo import SingleSwitchTopo
|
||||
from mininet.log import setLogLevel
|
||||
|
||||
setLogLevel( 'info' )
|
||||
|
||||
if not quietRun( 'which vconfig' ):
|
||||
error( "Cannot find command 'vconfig'\nThe package",
|
||||
"'vlan' is required in Ubuntu or Debian,",
|
||||
"or 'vconfig' in Fedora\n" )
|
||||
exit()
|
||||
|
||||
if len( sys.argv ) >= 2:
|
||||
exampleAllHosts( vlan=int( sys.argv[ 1 ] ) )
|
||||
else:
|
||||
exampleCustomTags()
|
||||
+95
-36
@@ -10,58 +10,117 @@ It may also get rid of 'false positives', but hopefully
|
||||
nothing irreplaceable!
|
||||
"""
|
||||
|
||||
from subprocess import Popen, PIPE
|
||||
from subprocess import ( Popen, PIPE, check_output as co,
|
||||
CalledProcessError )
|
||||
import time
|
||||
|
||||
from mininet.log import info
|
||||
from mininet.term import cleanUpScreens
|
||||
|
||||
|
||||
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 ]
|
||||
|
||||
def cleanup():
|
||||
"""Clean up junk which might be left over from old runs;
|
||||
do fast stuff before slow dp and link removal!"""
|
||||
def killprocs( pattern ):
|
||||
"Reliably terminate processes matching a pattern (including args)"
|
||||
sh( 'pkill -9 -f %s' % pattern )
|
||||
# Make sure they are gone
|
||||
while True:
|
||||
try:
|
||||
pids = co( [ 'pgrep', '-f', pattern ] )
|
||||
except CalledProcessError:
|
||||
pids = ''
|
||||
if pids:
|
||||
sh( 'pkill -9 -f %s' % pattern )
|
||||
time.sleep( .5 )
|
||||
else:
|
||||
break
|
||||
|
||||
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'
|
||||
# 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.
|
||||
# Send SIGTERM first to give processes a chance to shutdown cleanly.
|
||||
sh( 'killall ' + zombies + ' 2> /dev/null' )
|
||||
time.sleep(1)
|
||||
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
|
||||
class Cleanup( object ):
|
||||
"Wrapper for cleanup()"
|
||||
|
||||
# And kill off sudo mnexec
|
||||
sh( 'pkill -9 -f "sudo mnexec"')
|
||||
callbacks = []
|
||||
|
||||
info( "*** Removing junk from /tmp\n" )
|
||||
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
||||
@classmethod
|
||||
def cleanup( cls):
|
||||
"""Clean up junk which might be left over from old runs;
|
||||
do fast stuff before slow dp and link removal!"""
|
||||
|
||||
info( "*** Removing old X11 tunnels\n" )
|
||||
cleanUpScreens()
|
||||
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'
|
||||
# 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.
|
||||
# Send SIGTERM first to give processes a chance to shutdown cleanly.
|
||||
sh( 'killall ' + zombies + ' 2> /dev/null' )
|
||||
time.sleep( 1 )
|
||||
sh( 'killall -9 ' + zombies + ' 2> /dev/null' )
|
||||
|
||||
info( "*** Removing excess kernel datapaths\n" )
|
||||
dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'" ).split( '\n' )
|
||||
for dp in dps:
|
||||
if dp != '':
|
||||
sh( 'dpctl deldp ' + dp )
|
||||
# And kill off sudo mnexec
|
||||
sh( 'pkill -9 -f "sudo mnexec"')
|
||||
|
||||
info( "*** Removing OVS datapaths" )
|
||||
dps = sh("ovs-vsctl --timeout=1 list-br").split( '\n' )
|
||||
for dp in dps:
|
||||
if dp:
|
||||
info( "*** Removing junk from /tmp\n" )
|
||||
sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' )
|
||||
|
||||
info( "*** Removing old X11 tunnels\n" )
|
||||
cleanUpScreens()
|
||||
|
||||
info( "*** Removing excess kernel datapaths\n" )
|
||||
dps = sh( "ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'"
|
||||
).splitlines()
|
||||
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:
|
||||
sh( "ovs-vsctl " + " -- ".join( "--if-exists del-br " + dp
|
||||
for dp in dps if dp ) )
|
||||
# And in case the above didn't work...
|
||||
dps = sh( "ovs-vsctl --timeout=1 list-br" ).strip().splitlines()
|
||||
for dp in dps:
|
||||
sh( 'ovs-vsctl del-br ' + dp )
|
||||
|
||||
info( "*** Removing all links of the pattern foo-ethX\n" )
|
||||
links = sh( r"ip link show | egrep -o '(\w+-eth\w+)'" ).split( '\n' )
|
||||
for link in links:
|
||||
if link != '':
|
||||
sh( "ip link del " + link )
|
||||
info( "*** Removing all links of the pattern foo-ethX\n" )
|
||||
links = sh( "ip link show | "
|
||||
"egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'"
|
||||
).splitlines()
|
||||
# Delete blocks of links
|
||||
n = 1000 # chunk size
|
||||
for i in xrange( 0, len( links ), n ):
|
||||
cmd = ';'.join( 'ip link del %s' % link
|
||||
for link in links[ i : i + n ] )
|
||||
sh( '( %s ) 2> /dev/null' % cmd )
|
||||
|
||||
info( "*** Cleanup complete.\n" )
|
||||
if 'tap9' in sh( 'ip link show' ):
|
||||
info( "*** Removing tap9 - assuming it's from cluster edition\n" )
|
||||
sh( 'ip link del tap9' )
|
||||
|
||||
info( "*** Killing stale mininet node processes\n" )
|
||||
killprocs( 'mininet:' )
|
||||
|
||||
info( "*** Shutting down stale tunnels\n" )
|
||||
killprocs( 'Tunnel=Ethernet' )
|
||||
killprocs( '.ssh/mn')
|
||||
sh( 'rm -f ~/.ssh/mn/*' )
|
||||
|
||||
# Call any additional cleanup code if necessary
|
||||
for callback in cls.callbacks:
|
||||
callback()
|
||||
|
||||
info( "*** Cleanup complete.\n" )
|
||||
|
||||
@classmethod
|
||||
def addCleanupCallback( cls, callback ):
|
||||
"Add cleanup callback"
|
||||
if callback not in cls.callbacks:
|
||||
cls.callbacks.append( callback )
|
||||
|
||||
|
||||
cleanup = Cleanup.cleanup
|
||||
addCleanupCallback = Cleanup.addCleanupCallback
|
||||
|
||||
+117
-31
@@ -31,10 +31,13 @@ from os import isatty
|
||||
from select import poll, POLLIN
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
import atexit
|
||||
|
||||
from mininet.log import info, output, error
|
||||
from mininet.term import makeTerms, runX11
|
||||
from mininet.util import quietRun, isShellBuiltin, dumpNodeConnections
|
||||
from mininet.util import ( quietRun, dumpNodeConnections,
|
||||
dumpPorts )
|
||||
|
||||
class CLI( Cmd ):
|
||||
"Simple command-line interface to talk to nodes."
|
||||
@@ -42,6 +45,10 @@ class CLI( Cmd ):
|
||||
prompt = 'mininet> '
|
||||
|
||||
def __init__( self, mininet, stdin=sys.stdin, script=None ):
|
||||
"""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 }
|
||||
@@ -52,22 +59,55 @@ class CLI( Cmd ):
|
||||
self.inputFile = script
|
||||
Cmd.__init__( self )
|
||||
info( '*** Starting CLI:\n' )
|
||||
|
||||
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:
|
||||
from readline import read_history_file, write_history_file
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
history_path = os.path.expanduser( '~/.mininet_history' )
|
||||
if os.path.isfile( history_path ):
|
||||
read_history_file( history_path )
|
||||
atexit.register( lambda: write_history_file( history_path ) )
|
||||
|
||||
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.monitor()
|
||||
node.waitOutput()
|
||||
if self.isatty():
|
||||
quietRun( 'stty sane' )
|
||||
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."
|
||||
@@ -78,11 +118,6 @@ class CLI( Cmd ):
|
||||
self.locals.update( self.mn )
|
||||
return self.locals
|
||||
|
||||
# Disable pylint "Unused argument: 'arg's'" messages, as well as
|
||||
# "method could be a function" warning, since each CLI function
|
||||
# must have the same interface
|
||||
# pylint: disable-msg=R0201
|
||||
|
||||
helpStr = (
|
||||
'You may also send a command to a node using:\n'
|
||||
' <node> command {args}\n'
|
||||
@@ -113,16 +148,22 @@ class CLI( Cmd ):
|
||||
nodes = ' '.join( sorted( self.mn ) )
|
||||
output( 'available nodes are: \n%s\n' % nodes )
|
||||
|
||||
def do_ports( self, _line ):
|
||||
"display ports and interfaces for each switch"
|
||||
dumpPorts( self.mn.switches )
|
||||
|
||||
def do_net( self, _line ):
|
||||
"List network connections."
|
||||
dumpNodeConnections( self.mn.values() )
|
||||
|
||||
def do_sh( self, line ):
|
||||
"Run an external shell command"
|
||||
"""Run an external shell command
|
||||
Usage: sh [cmd args]"""
|
||||
assert self # satisfy pylint and allow override
|
||||
call( line, shell=True )
|
||||
|
||||
# do_py() and do_px() need to catch any exception during eval()/exec()
|
||||
# pylint: disable-msg=W0703
|
||||
# pylint: disable=broad-except
|
||||
|
||||
def do_py( self, line ):
|
||||
"""Evaluate a Python expression.
|
||||
@@ -139,7 +180,7 @@ class CLI( Cmd ):
|
||||
output( str( e ) + '\n' )
|
||||
|
||||
# We are in fact using the exec() pseudo-function
|
||||
# pylint: disable-msg=W0122
|
||||
# pylint: disable=exec-used
|
||||
|
||||
def do_px( self, line ):
|
||||
"""Execute a Python statement.
|
||||
@@ -149,18 +190,18 @@ class CLI( Cmd ):
|
||||
except Exception, e:
|
||||
output( str( e ) + '\n' )
|
||||
|
||||
# pylint: enable-msg=W0703,W0122
|
||||
# pylint: enable=broad-except,exec-used
|
||||
|
||||
def do_pingall( self, _line ):
|
||||
def do_pingall( self, line ):
|
||||
"Ping between all hosts."
|
||||
self.mn.pingAll()
|
||||
self.mn.pingAll( line )
|
||||
|
||||
def do_pingpair( self, _line ):
|
||||
"Ping between first two hosts, useful for testing."
|
||||
self.mn.pingPair()
|
||||
|
||||
def do_pingallfull( self, _line ):
|
||||
"Ping between first two hosts, returns all ping results."
|
||||
"Ping between all hosts, returns all ping results."
|
||||
self.mn.pingAllFull()
|
||||
|
||||
def do_pingpairfull( self, _line ):
|
||||
@@ -168,7 +209,8 @@ class CLI( Cmd ):
|
||||
self.mn.pingPairFull()
|
||||
|
||||
def do_iperf( self, line ):
|
||||
"Simple iperf TCP test between two (optionally specified) hosts."
|
||||
"""Simple iperf TCP test between two (optionally specified) hosts.
|
||||
Usage: iperf node1 node2"""
|
||||
args = line.split()
|
||||
if not args:
|
||||
self.mn.iperf()
|
||||
@@ -187,7 +229,8 @@ class CLI( Cmd ):
|
||||
error( 'invalid number of args: iperf src dst\n' )
|
||||
|
||||
def do_iperfudp( self, line ):
|
||||
"Simple iperf TCP test between two (optionally specified) hosts."
|
||||
"""Simple iperf UDP test between two (optionally specified) hosts.
|
||||
Usage: iperfudp bw node1 node2"""
|
||||
args = line.split()
|
||||
if not args:
|
||||
self.mn.iperf( l4Type='UDP' )
|
||||
@@ -219,7 +262,8 @@ class CLI( Cmd ):
|
||||
output( '%s\n' % repr( node ) )
|
||||
|
||||
def do_link( self, line ):
|
||||
"Bring link(s) between two nodes up or down."
|
||||
"""Bring link(s) between two nodes up or down.
|
||||
Usage: link node1 node2 [up/down]"""
|
||||
args = line.split()
|
||||
if len(args) != 3:
|
||||
error( 'invalid number of args: link end1 end2 [up down]\n' )
|
||||
@@ -229,7 +273,8 @@ class CLI( Cmd ):
|
||||
self.mn.configLinkStatus( *args )
|
||||
|
||||
def do_xterm( self, line, term='xterm' ):
|
||||
"Spawn xterm(s) for the given node(s)."
|
||||
"""Spawn xterm(s) for the given node(s).
|
||||
Usage: xterm node1 node2 ..."""
|
||||
args = line.split()
|
||||
if not args:
|
||||
error( 'usage: %s node1 node2 ...\n' % term )
|
||||
@@ -243,7 +288,8 @@ class CLI( Cmd ):
|
||||
|
||||
def do_x( self, line ):
|
||||
"""Create an X11 tunnel to the given node,
|
||||
optionally starting a client."""
|
||||
optionally starting a client.
|
||||
Usage: x node [cmd args]"""
|
||||
args = line.split()
|
||||
if not args:
|
||||
error( 'usage: x node [cmd args]...\n' )
|
||||
@@ -253,11 +299,13 @@ class CLI( Cmd ):
|
||||
self.mn.terms += runX11( node, cmd )
|
||||
|
||||
def do_gterm( self, line ):
|
||||
"Spawn gnome-terminal(s) for the given node(s)."
|
||||
"""Spawn gnome-terminal(s) for the given node(s).
|
||||
Usage: gterm node1 node2 ..."""
|
||||
self.do_xterm( line, term='gterm' )
|
||||
|
||||
def do_exit( self, _line ):
|
||||
"Exit"
|
||||
assert self # satisfy pylint and allow override
|
||||
return 'exited by user command'
|
||||
|
||||
def do_quit( self, line ):
|
||||
@@ -274,7 +322,8 @@ class CLI( Cmd ):
|
||||
return isatty( self.stdin.fileno() )
|
||||
|
||||
def do_noecho( self, line ):
|
||||
"Run an interactive command with echoing turned off."
|
||||
"""Run an interactive command with echoing turned off.
|
||||
Usage: noecho [cmd args]"""
|
||||
if self.isatty():
|
||||
quietRun( 'stty -echo' )
|
||||
self.default( line )
|
||||
@@ -282,7 +331,8 @@ class CLI( Cmd ):
|
||||
quietRun( 'stty echo' )
|
||||
|
||||
def do_source( self, line ):
|
||||
"Read commands from an input file."
|
||||
"""Read commands from an input file.
|
||||
Usage: source <file>"""
|
||||
args = line.split()
|
||||
if len(args) != 1:
|
||||
error( 'usage: source <file>\n' )
|
||||
@@ -297,10 +347,12 @@ class CLI( Cmd ):
|
||||
break
|
||||
except IOError:
|
||||
error( 'error reading file %s\n' % args[ 0 ] )
|
||||
self.inputFile.close()
|
||||
self.inputFile = None
|
||||
|
||||
def do_dpctl( self, line ):
|
||||
"Run dpctl (or ovs-ofctl) command on all switches."
|
||||
"""Run dpctl (or ovs-ofctl) command on all switches.
|
||||
Usage: dpctl command [arg1] [arg2] ..."""
|
||||
args = line.split()
|
||||
if len(args) < 1:
|
||||
error( 'usage: dpctl command [arg1] [arg2] ...\n' )
|
||||
@@ -316,6 +368,33 @@ class CLI( Cmd ):
|
||||
elapsed = time.time() - start
|
||||
self.stdout.write("*** Elapsed time: %0.6f secs\n" % elapsed)
|
||||
|
||||
def do_links( self, _line ):
|
||||
"Report on links"
|
||||
for link in self.mn.links:
|
||||
print link, link.status()
|
||||
|
||||
def do_switch( self, line ):
|
||||
"Starts or stops a switch"
|
||||
args = line.split()
|
||||
if len(args) != 2:
|
||||
error( 'invalid number of args: switch <switch name>'
|
||||
'{start, stop}\n' )
|
||||
return
|
||||
sw = args[ 0 ]
|
||||
command = args[ 1 ]
|
||||
if sw not in self.mn or self.mn.get( sw ) not in self.mn.switches:
|
||||
error( 'invalid switch: %s\n' % args[ 1 ] )
|
||||
else:
|
||||
sw = args[ 0 ]
|
||||
command = args[ 1 ]
|
||||
if command == 'start':
|
||||
self.mn.get( sw ).start( self.mn.controllers )
|
||||
elif command == 'stop':
|
||||
self.mn.get( sw ).stop( deleteIntfs=False )
|
||||
else:
|
||||
error( 'invalid command: '
|
||||
'switch <switch name> {start, stop}\n' )
|
||||
|
||||
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.
|
||||
@@ -337,16 +416,13 @@ class CLI( Cmd ):
|
||||
for arg in rest ]
|
||||
rest = ' '.join( rest )
|
||||
# Run cmd on node:
|
||||
builtin = isShellBuiltin( first )
|
||||
node.sendCmd( rest, printPid=( not builtin ) )
|
||||
node.sendCmd( rest )
|
||||
self.waitForNode( node )
|
||||
else:
|
||||
error( '*** Unknown command: %s\n' % line )
|
||||
|
||||
# pylint: enable-msg=R0201
|
||||
|
||||
def waitForNode( self, node ):
|
||||
"Wait for a node to finish, and print its output."
|
||||
"Wait for a node to finish, and print its output."
|
||||
# Pollers
|
||||
nodePoller = poll()
|
||||
nodePoller.register( node.stdout )
|
||||
@@ -364,7 +440,7 @@ class CLI( Cmd ):
|
||||
if False and self.inputFile:
|
||||
key = self.inputFile.read( 1 )
|
||||
if key is not '':
|
||||
node.write(key)
|
||||
node.write( key )
|
||||
else:
|
||||
self.inputFile = None
|
||||
if isReadable( self.inPoller ):
|
||||
@@ -376,8 +452,18 @@ class CLI( Cmd ):
|
||||
if not node.waiting:
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
# There is an at least one race condition here, since
|
||||
# it's possible to interrupt ourselves after we've
|
||||
# read data but before it has been printed.
|
||||
node.sendInt()
|
||||
|
||||
def precmd( self, line ):
|
||||
"allow for comments in the cli"
|
||||
if '#' in line:
|
||||
line = line.split( '#' )[ 0 ]
|
||||
return line
|
||||
|
||||
|
||||
# Helper functions
|
||||
|
||||
def isReadable( poller ):
|
||||
|
||||
+183
-49
@@ -25,14 +25,16 @@ Link: basic link class for creating veth pairs
|
||||
"""
|
||||
|
||||
from mininet.log import info, error, debug
|
||||
from mininet.util import makeIntfPair, quietRun
|
||||
from mininet.util import makeIntfPair
|
||||
import mininet.node
|
||||
import re
|
||||
|
||||
class Intf( object ):
|
||||
|
||||
"Basic interface object that can configure itself."
|
||||
|
||||
def __init__( self, name, node=None, port=None, link=None, **params ):
|
||||
def __init__( self, name, node=None, port=None, link=None,
|
||||
mac=None, **params ):
|
||||
"""name: interface name (e.g. h1-eth0)
|
||||
node: owning node (where this intf most likely lives)
|
||||
link: parent link if we're part of a link
|
||||
@@ -40,9 +42,19 @@ class Intf( object ):
|
||||
self.node = node
|
||||
self.name = name
|
||||
self.link = link
|
||||
self.mac, self.ip, self.prefixLen = None, None, None
|
||||
self.mac = mac
|
||||
self.ip, self.prefixLen = None, None
|
||||
|
||||
# if interface is lo, we know the ip is 127.0.0.1.
|
||||
# This saves an ifconfig command per node
|
||||
if self.name == 'lo':
|
||||
self.ip = '127.0.0.1'
|
||||
# Add to node (and move ourselves if necessary )
|
||||
node.addIntf( self, port=port )
|
||||
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 )
|
||||
@@ -63,6 +75,9 @@ class Intf( object ):
|
||||
self.ip, self.prefixLen = ipstr.split( '/' )
|
||||
return self.ifconfig( ipstr, 'up' )
|
||||
else:
|
||||
if prefixLen is None:
|
||||
raise Exception( 'No prefix length set for IP address %s'
|
||||
% ( ipstr, ) )
|
||||
self.ip, self.prefixLen = ipstr, prefixLen
|
||||
return self.ifconfig( '%s/%s' % ( ipstr, prefixLen ) )
|
||||
|
||||
@@ -79,7 +94,10 @@ class Intf( object ):
|
||||
|
||||
def updateIP( self ):
|
||||
"Return updated IP address based on ifconfig"
|
||||
ifconfig = self.ifconfig()
|
||||
# use pexec instead of node.cmd so that we dont read
|
||||
# backgrounded output from the cli.
|
||||
ifconfig, _err, _exitCode = self.node.pexec(
|
||||
'ifconfig %s' % self.name )
|
||||
ips = self._ipMatchRegex.findall( ifconfig )
|
||||
self.ip = ips[ 0 ] if ips else None
|
||||
return self.ip
|
||||
@@ -91,6 +109,19 @@ class Intf( object ):
|
||||
self.mac = macs[ 0 ] if macs else None
|
||||
return self.mac
|
||||
|
||||
# Instead of updating ip and mac separately,
|
||||
# use one ifconfig call to do it simultaneously.
|
||||
# This saves an ifconfig command, which improves performance.
|
||||
|
||||
def updateAddr( self ):
|
||||
"Return IP address and MAC address based on ifconfig."
|
||||
ifconfig = self.ifconfig()
|
||||
ips = self._ipMatchRegex.findall( ifconfig )
|
||||
macs = self._macMatchRegex.findall( ifconfig )
|
||||
self.ip = ips[ 0 ] if ips else None
|
||||
self.mac = macs[ 0 ] if macs else None
|
||||
return self.ip, self.mac
|
||||
|
||||
def IP( self ):
|
||||
"Return IP address"
|
||||
return self.ip
|
||||
@@ -102,8 +133,15 @@ class Intf( object ):
|
||||
def isUp( self, setUp=False ):
|
||||
"Return whether interface is up"
|
||||
if setUp:
|
||||
self.ifconfig( 'up' )
|
||||
return "UP" in self.ifconfig()
|
||||
cmdOutput = self.ifconfig( 'up' )
|
||||
# no output indicates success
|
||||
if cmdOutput:
|
||||
error( "Error setting %s up: %s " % ( self.name, cmdOutput ) )
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return "UP" in self.ifconfig()
|
||||
|
||||
def rename( self, newname ):
|
||||
"Rename interface"
|
||||
@@ -129,9 +167,9 @@ class Intf( object ):
|
||||
f = getattr( self, method, None )
|
||||
if not f or value is None:
|
||||
return
|
||||
if type( value ) is list:
|
||||
if isinstance( value, list ):
|
||||
result = f( *value )
|
||||
elif type( value ) is dict:
|
||||
elif isinstance( value, dict ):
|
||||
result = f( **value )
|
||||
else:
|
||||
result = f( value )
|
||||
@@ -154,16 +192,23 @@ class Intf( object ):
|
||||
self.setParam( r, 'setIP', ip=ip )
|
||||
self.setParam( r, 'isUp', up=up )
|
||||
self.setParam( r, 'ifconfig', ifconfig=ifconfig )
|
||||
self.updateIP()
|
||||
self.updateMAC()
|
||||
return r
|
||||
|
||||
def delete( self ):
|
||||
"Delete interface"
|
||||
self.cmd( 'ip link del ' + self.name )
|
||||
if self.node.inNamespace:
|
||||
# Link may have been dumped into root NS
|
||||
quietRun( 'ip link del ' + self.name )
|
||||
# We used to do this, but it slows us down:
|
||||
# if self.node.inNamespace:
|
||||
# Link may have been dumped into root NS
|
||||
# quietRun( 'ip link del ' + self.name )
|
||||
|
||||
def status( self ):
|
||||
"Return intf status as a string"
|
||||
links, _err, _result = self.node.pexec( 'ip link show' )
|
||||
if self.name in links:
|
||||
return "OK"
|
||||
else:
|
||||
return "MISSING"
|
||||
|
||||
def __repr__( self ):
|
||||
return '<%s %s>' % ( self.__class__.__name__, self.name )
|
||||
@@ -177,15 +222,19 @@ class TCIntf( Intf ):
|
||||
Allows specification of bandwidth limits (various methods)
|
||||
as well as delay, loss and max queue length"""
|
||||
|
||||
# The parameters we use seem to work reasonably up to 1 Gb/sec
|
||||
# For higher data rates, we will probably need to change them.
|
||||
bwParamMax = 1000
|
||||
|
||||
def bwCmds( self, bw=None, speedup=0, use_hfsc=False, use_tbf=False,
|
||||
latency_ms=None, enable_ecn=False, enable_red=False ):
|
||||
"Return tc commands to set bandwidth"
|
||||
|
||||
cmds, parent = [], ' root '
|
||||
|
||||
if bw and ( bw < 0 or bw > 1000 ):
|
||||
error( 'Bandwidth', bw, 'is outside range 0..1000 Mbps\n' )
|
||||
|
||||
if bw and ( bw < 0 or bw > self.bwParamMax ):
|
||||
error( 'Bandwidth limit', bw, 'is outside supported range 0..%d'
|
||||
% self.bwParamMax, '- ignoring\n' )
|
||||
elif bw is not None:
|
||||
# BL: this seems a bit brittle...
|
||||
if ( speedup > 0 and
|
||||
@@ -279,7 +328,11 @@ class TCIntf( Intf ):
|
||||
return
|
||||
|
||||
# Clear existing configuration
|
||||
cmds = [ '%s qdisc del dev %s root' ]
|
||||
tcoutput = self.tc( '%s qdisc show dev %s' )
|
||||
if "priomap" not in tcoutput:
|
||||
cmds = [ '%s qdisc del dev %s root' ]
|
||||
else:
|
||||
cmds = []
|
||||
|
||||
# Bandwidth limits via various methods
|
||||
bwcmds, parent = self.bwCmds( bw=bw, speedup=speedup,
|
||||
@@ -291,8 +344,9 @@ class TCIntf( Intf ):
|
||||
|
||||
# Delay/jitter/loss/max_queue_size using netem
|
||||
delaycmds, parent = self.delayCmds( delay=delay, jitter=jitter,
|
||||
loss=loss, max_queue_size=max_queue_size,
|
||||
parent=parent )
|
||||
loss=loss,
|
||||
max_queue_size=max_queue_size,
|
||||
parent=parent )
|
||||
cmds += delaycmds
|
||||
|
||||
# Ugly but functional: display configuration info
|
||||
@@ -307,6 +361,9 @@ class TCIntf( Intf ):
|
||||
# Execute all the commands in our node
|
||||
debug("at map stage w/cmds: %s\n" % cmds)
|
||||
tcoutputs = [ self.tc(cmd) for cmd in cmds ]
|
||||
for output in tcoutputs:
|
||||
if output != '':
|
||||
error( "*** Error: %s" % output )
|
||||
debug( "cmds:", cmds, '\n' )
|
||||
debug( "outputs:", tcoutputs, '\n' )
|
||||
result[ 'tcoutputs'] = tcoutputs
|
||||
@@ -320,10 +377,11 @@ class Link( object ):
|
||||
"""A basic link is just a veth pair.
|
||||
Other types of links could be tunnels, link emulators, etc.."""
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
def __init__( self, node1, node2, port1=None, port2=None,
|
||||
intfName1=None, intfName2=None,
|
||||
intfName1=None, intfName2=None, addr1=None, addr2=None,
|
||||
intf=Intf, cls1=None, cls2=None, params1=None,
|
||||
params2=None ):
|
||||
params2=None, fast=True ):
|
||||
"""Create veth link to another node, making two new interfaces.
|
||||
node1: first node
|
||||
node2: second node
|
||||
@@ -336,65 +394,141 @@ class Link( object ):
|
||||
params1: parameters for interface 1
|
||||
params2: parameters for interface 2"""
|
||||
# This is a bit awkward; it seems that having everything in
|
||||
# params would be more orthogonal, but being able to specify
|
||||
# in-line arguments is more convenient!
|
||||
if port1 is None:
|
||||
port1 = node1.newPort()
|
||||
if port2 is None:
|
||||
port2 = node2.newPort()
|
||||
# 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 )
|
||||
if port1 is not None:
|
||||
params1[ 'port' ] = port1
|
||||
if port2 is not None:
|
||||
params2[ 'port' ] = port2
|
||||
if 'port' not in params1:
|
||||
params1[ 'port' ] = node1.newPort()
|
||||
if 'port' not in params2:
|
||||
params2[ 'port' ] = node2.newPort()
|
||||
if not intfName1:
|
||||
intfName1 = self.intfName( node1, port1 )
|
||||
intfName1 = self.intfName( node1, params1[ 'port' ] )
|
||||
if not intfName2:
|
||||
intfName2 = self.intfName( node2, port2 )
|
||||
intfName2 = self.intfName( node2, params2[ 'port' ] )
|
||||
|
||||
self.makeIntfPair( intfName1, intfName2 )
|
||||
self.fast = fast
|
||||
if fast:
|
||||
params1.setdefault( 'moveIntfFn', self._ignore )
|
||||
params2.setdefault( 'moveIntfFn', self._ignore )
|
||||
self.makeIntfPair( intfName1, intfName2, addr1, addr2,
|
||||
node1, node2, deleteIntfs=False )
|
||||
else:
|
||||
self.makeIntfPair( intfName1, intfName2, addr1, addr2 )
|
||||
|
||||
if not cls1:
|
||||
cls1 = intf
|
||||
if not cls2:
|
||||
cls2 = intf
|
||||
if not params1:
|
||||
params1 = {}
|
||||
if not params2:
|
||||
params2 = {}
|
||||
|
||||
intf1 = cls1( name=intfName1, node=node1, port=port1,
|
||||
link=self, **params1 )
|
||||
intf2 = cls2( name=intfName2, node=node2, port=port2,
|
||||
link=self, **params2 )
|
||||
intf1 = cls1( name=intfName1, node=node1,
|
||||
link=self, mac=addr1, **params1 )
|
||||
intf2 = cls2( name=intfName2, node=node2,
|
||||
link=self, mac=addr2, **params2 )
|
||||
|
||||
# All we are is dust in the wind, and our two interfaces
|
||||
self.intf1, self.intf2 = intf1, intf2
|
||||
# pylint: enable=too-many-branches
|
||||
|
||||
@classmethod
|
||||
def intfName( cls, node, n ):
|
||||
@staticmethod
|
||||
def _ignore( *args, **kwargs ):
|
||||
"Ignore any arguments"
|
||||
pass
|
||||
|
||||
def intfName( self, node, n ):
|
||||
"Construct a canonical interface name node-ethN for interface n."
|
||||
# Leave this as an instance method for now
|
||||
assert self
|
||||
return node.name + '-eth' + repr( n )
|
||||
|
||||
@classmethod
|
||||
def makeIntfPair( cls, intf1, intf2 ):
|
||||
def makeIntfPair( cls, intfname1, intfname2, addr1=None, addr2=None,
|
||||
node1=None, node2=None, deleteIntfs=True ):
|
||||
"""Create pair of interfaces
|
||||
intf1: name of interface 1
|
||||
intf2: name of interface 2
|
||||
(override this class method [and possibly delete()]
|
||||
intfname1: name for interface 1
|
||||
intfname2: name for interface 2
|
||||
addr1: MAC address for interface 1 (optional)
|
||||
addr2: MAC address for interface 2 (optional)
|
||||
node1: home node for interface 1 (optional)
|
||||
node2: home node for interface 2 (optional)
|
||||
(override this method [and possibly delete()]
|
||||
to change link type)"""
|
||||
makeIntfPair( intf1, intf2 )
|
||||
# Leave this as a class method for now
|
||||
assert cls
|
||||
return makeIntfPair( intfname1, intfname2, addr1, addr2, node1, node2,
|
||||
deleteIntfs=deleteIntfs )
|
||||
|
||||
def delete( self ):
|
||||
"Delete this link"
|
||||
self.intf1.delete()
|
||||
self.intf2.delete()
|
||||
# We only need to delete one side, though this doesn't seem to
|
||||
# cost us much and might help subclasses.
|
||||
# self.intf2.delete()
|
||||
|
||||
def stop( self ):
|
||||
"Override to stop and clean up link as needed"
|
||||
self.delete()
|
||||
|
||||
def status( self ):
|
||||
"Return link status as a string"
|
||||
return "(%s %s)" % ( self.intf1.status(), self.intf2.status() )
|
||||
|
||||
def __str__( self ):
|
||||
return '%s<->%s' % ( self.intf1, self.intf2 )
|
||||
|
||||
|
||||
class OVSIntf( Intf ):
|
||||
"Patch interface on an OVSSwitch"
|
||||
|
||||
def ifconfig( self, *args ):
|
||||
cmd = ' '.join( args )
|
||||
if cmd == 'up':
|
||||
# OVSIntf is always up
|
||||
return
|
||||
else:
|
||||
raise Exception( 'OVSIntf cannot do ifconfig ' + cmd )
|
||||
|
||||
|
||||
class OVSLink( Link ):
|
||||
"""Link that makes patch links between OVSSwitches
|
||||
Warning: in testing we have found that no more
|
||||
than ~64 OVS patch links should be used in row."""
|
||||
|
||||
def __init__( self, node1, node2, **kwargs ):
|
||||
"See Link.__init__() for options"
|
||||
self.isPatchLink = False
|
||||
if ( isinstance( node1, mininet.node.OVSSwitch ) and
|
||||
isinstance( node2, mininet.node.OVSSwitch ) ):
|
||||
self.isPatchLink = True
|
||||
kwargs.update( cls1=OVSIntf, cls2=OVSIntf )
|
||||
Link.__init__( self, node1, node2, **kwargs )
|
||||
|
||||
def makeIntfPair( self, *args, **kwargs ):
|
||||
"Usually delegated to OVSSwitch"
|
||||
if self.isPatchLink:
|
||||
return None, None
|
||||
else:
|
||||
return Link.makeIntfPair( *args, **kwargs )
|
||||
|
||||
|
||||
class TCLink( Link ):
|
||||
"Link with symmetric TC interfaces configured via opts"
|
||||
def __init__( self, node1, node2, port1=None, port2=None,
|
||||
intfName1=None, intfName2=None, **params ):
|
||||
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)
|
||||
params2=params )
|
||||
|
||||
+4
-4
@@ -69,7 +69,7 @@ class Singleton( type ):
|
||||
def __call__( cls, *args, **kw ):
|
||||
if cls.instance is None:
|
||||
cls.instance = super( Singleton, cls ).__call__( *args, **kw )
|
||||
return cls.instance
|
||||
return cls.instance
|
||||
|
||||
|
||||
class MininetLogger( Logger, object ):
|
||||
@@ -124,8 +124,8 @@ class MininetLogger( Logger, object ):
|
||||
self.setLevel( level )
|
||||
self.handlers[ 0 ].setLevel( level )
|
||||
|
||||
# pylint: disable-msg=E0202
|
||||
# "An attribute inherited from mininet.log hide this method"
|
||||
# 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()
|
||||
@@ -142,7 +142,7 @@ class MininetLogger( Logger, object ):
|
||||
if self.isEnabledFor( OUTPUT ):
|
||||
self._log( OUTPUT, msg, args, kwargs )
|
||||
|
||||
# pylint: enable-msg=E0202
|
||||
# pylint: enable=method-hidden
|
||||
|
||||
lg = MininetLogger()
|
||||
|
||||
|
||||
@@ -28,9 +28,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 type( subtract ) is str:
|
||||
if isinstance( subtract, basestring ):
|
||||
subtract = [ subtract ]
|
||||
if type( add ) is str:
|
||||
if isinstance( add, basestring ):
|
||||
add = [ add ]
|
||||
for mod in subtract:
|
||||
if mod in lsmod():
|
||||
|
||||
+226
-97
@@ -90,29 +90,35 @@ import os
|
||||
import re
|
||||
import select
|
||||
import signal
|
||||
import random
|
||||
|
||||
from time import sleep
|
||||
from itertools import chain
|
||||
from itertools import chain, groupby
|
||||
from math import ceil
|
||||
|
||||
from mininet.cli import CLI
|
||||
from mininet.log import info, error, debug, output
|
||||
from mininet.node import Host, OVSKernelSwitch, Controller
|
||||
from mininet.log import info, error, debug, output, warn
|
||||
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
|
||||
from mininet.util import macColonHex, ipStr, ipParse, netParse, ipAdd
|
||||
from mininet.util import ( quietRun, fixLimits, numCores, ensureRoot,
|
||||
macColonHex, ipStr, ipParse, netParse, ipAdd,
|
||||
waitListening )
|
||||
from mininet.term import cleanUpScreens, makeTerms
|
||||
|
||||
# Mininet version: should be consistent with README and LICENSE
|
||||
VERSION = "2.1.0+"
|
||||
VERSION = "2.2.1"
|
||||
|
||||
class Mininet( object ):
|
||||
"Network emulation with hosts spawned in network namespaces."
|
||||
|
||||
def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host,
|
||||
controller=Controller, link=Link, intf=Intf,
|
||||
controller=DefaultController, link=Link, intf=Intf,
|
||||
build=True, xterms=False, cleanup=False, ipBase='10.0.0.0/8',
|
||||
inNamespace=False,
|
||||
autoSetMacs=False, autoStaticArp=False, autoPinCpus=False,
|
||||
listenPort=None ):
|
||||
listenPort=None, waitConnected=False ):
|
||||
"""Create Mininet object.
|
||||
topo: Topo (topology) object or None
|
||||
switch: default Switch class
|
||||
@@ -148,10 +154,12 @@ class Mininet( object ):
|
||||
self.numCores = numCores()
|
||||
self.nextCore = 0 # next core for pinning hosts to CPUs
|
||||
self.listenPort = listenPort
|
||||
self.waitConn = waitConnected
|
||||
|
||||
self.hosts = []
|
||||
self.switches = []
|
||||
self.controllers = []
|
||||
self.links = []
|
||||
|
||||
self.nameToNode = {} # name to Node (Host/Switch) objects
|
||||
|
||||
@@ -163,6 +171,36 @@ class Mininet( object ):
|
||||
if topo and build:
|
||||
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
|
||||
delay: seconds to sleep per iteration
|
||||
returns: True if all switches are connected"""
|
||||
info( '*** Waiting for switches to connect\n' )
|
||||
time = 0
|
||||
remaining = list( self.switches )
|
||||
while True:
|
||||
for switch in tuple( remaining ):
|
||||
if switch.connected():
|
||||
info( '%s ' % switch )
|
||||
remaining.remove( switch )
|
||||
if not remaining:
|
||||
info( '\n' )
|
||||
return True
|
||||
if time > timeout and timeout is not None:
|
||||
break
|
||||
sleep( delay )
|
||||
time += delay
|
||||
warn( 'Timed out after %d seconds\n' % time )
|
||||
for switch in remaining:
|
||||
if not switch.connected():
|
||||
warn( 'Warning: %s is not connected to a controller\n'
|
||||
% switch.name )
|
||||
else:
|
||||
remaining.remove( switch )
|
||||
return not remaining
|
||||
|
||||
def addHost( self, name, cls=None, **params ):
|
||||
"""Add host.
|
||||
name: name of host to add
|
||||
@@ -175,7 +213,7 @@ class Mininet( object ):
|
||||
prefixLen=self.prefixLen ) +
|
||||
'/%s' % self.prefixLen }
|
||||
if self.autoSetMacs:
|
||||
defaults[ 'mac'] = macColonHex( self.nextIP )
|
||||
defaults[ 'mac' ] = macColonHex( self.nextIP )
|
||||
if self.autoPinCpus:
|
||||
defaults[ 'cores' ] = self.nextCore
|
||||
self.nextCore = ( self.nextCore + 1 ) % self.numCores
|
||||
@@ -213,12 +251,12 @@ class Mininet( object ):
|
||||
if not controller:
|
||||
controller = self.controller
|
||||
# Construct new controller if one is not given
|
||||
if isinstance(name, Controller):
|
||||
if isinstance( name, Controller ):
|
||||
controller_new = name
|
||||
# Pylint thinks controller is a str()
|
||||
# pylint: disable=E1103
|
||||
# pylint: disable=maybe-no-member
|
||||
name = controller_new.name
|
||||
# pylint: enable=E1103
|
||||
# pylint: enable=maybe-no-member
|
||||
else:
|
||||
controller_new = controller( name, **params )
|
||||
# Add new controller to net
|
||||
@@ -227,6 +265,30 @@ class Mininet( object ):
|
||||
self.nameToNode[ name ] = controller_new
|
||||
return controller_new
|
||||
|
||||
def addNAT( self, name='nat0', connect=True, inNamespace=False,
|
||||
**params):
|
||||
"""Add a NAT to the Mininet network
|
||||
name: name of NAT node
|
||||
connect: switch to connect to | True (s1) | None
|
||||
inNamespace: create in a network namespace
|
||||
params: other NAT node params, notably:
|
||||
ip: used as default gateway address"""
|
||||
nat = self.addHost( name, cls=NAT, inNamespace=inNamespace,
|
||||
subnet=self.ipBase, **params )
|
||||
# find first switch and create link
|
||||
if connect:
|
||||
if not isinstance( connect, Node ):
|
||||
# Use first switch if not specified
|
||||
connect = self.switches[ 0 ]
|
||||
# Connect the nat to the switch
|
||||
self.addLink( nat, self.switches[ 0 ] )
|
||||
# Set the default route on hosts
|
||||
natIP = nat.params[ 'ip' ].split('/')[ 0 ]
|
||||
for host in self.hosts:
|
||||
if host.inNamespace:
|
||||
host.setDefaultRoute( 'via %s' % natIP )
|
||||
return nat
|
||||
|
||||
# BL: We now have four ways to look up nodes
|
||||
# This may (should?) be cleaned up in the future.
|
||||
def getNodeByName( self, *args ):
|
||||
@@ -270,21 +332,40 @@ class Mininet( object ):
|
||||
"return (key,value) tuple list for every node in net"
|
||||
return zip( self.keys(), self.values() )
|
||||
|
||||
@staticmethod
|
||||
def randMac():
|
||||
"Return a random, non-multicast MAC address"
|
||||
return macColonHex( random.randint(1, 2**48 - 1) & 0xfeffffffffff |
|
||||
0x020000000000 )
|
||||
|
||||
def addLink( self, node1, node2, port1=None, port2=None,
|
||||
cls=None, **params ):
|
||||
""""Add a link from node1 to node2
|
||||
node1: source node
|
||||
node2: dest node
|
||||
port1: source port
|
||||
port2: dest port
|
||||
node1: source node (or name)
|
||||
node2: dest node (or name)
|
||||
port1: source port (optional)
|
||||
port2: dest port (optional)
|
||||
cls: link class (optional)
|
||||
params: additional link params (optional)
|
||||
returns: link object"""
|
||||
defaults = { 'port1': port1,
|
||||
'port2': port2,
|
||||
'intf': self.intf }
|
||||
defaults.update( params )
|
||||
if not cls:
|
||||
cls = self.link
|
||||
return cls( node1, node2, **defaults )
|
||||
# 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 ]
|
||||
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() )
|
||||
cls = self.link if cls is None else cls
|
||||
link = cls( node1, node2, **options )
|
||||
self.links.append( link )
|
||||
return link
|
||||
|
||||
def configHosts( self ):
|
||||
"Configure a set of hosts."
|
||||
@@ -302,7 +383,6 @@ class Mininet( object ):
|
||||
# quietRun( 'renice +18 -p ' + repr( host.pid ) )
|
||||
# This may not be the right place to do this, but
|
||||
# it needs to be done somewhere.
|
||||
host.cmd( 'ifconfig lo up' )
|
||||
info( '\n' )
|
||||
|
||||
def buildFromTopo( self, topo=None ):
|
||||
@@ -321,10 +401,14 @@ class Mininet( object ):
|
||||
# Add a default controller
|
||||
info( '*** Adding controller\n' )
|
||||
classes = self.controller
|
||||
if type( classes ) is not list:
|
||||
if not isinstance( classes, list ):
|
||||
classes = [ classes ]
|
||||
for i, cls in enumerate( classes ):
|
||||
self.addController( 'c%d' % i, cls )
|
||||
# Allow Controller objects because nobody understands partial()
|
||||
if isinstance( cls, Controller ):
|
||||
self.addController( cls )
|
||||
else:
|
||||
self.addController( 'c%d' % i, cls )
|
||||
|
||||
info( '*** Adding hosts:\n' )
|
||||
for hostName in topo.hosts():
|
||||
@@ -333,16 +417,19 @@ class Mininet( object ):
|
||||
|
||||
info( '\n*** Adding switches:\n' )
|
||||
for switchName in topo.switches():
|
||||
self.addSwitch( switchName, **topo.nodeInfo( switchName) )
|
||||
# A bit ugly: add batch parameter if appropriate
|
||||
params = topo.nodeInfo( switchName)
|
||||
cls = params.get( 'cls', self.switch )
|
||||
if hasattr( cls, 'batchStartup' ):
|
||||
params.setdefault( 'batch', True )
|
||||
self.addSwitch( switchName, **params )
|
||||
info( switchName + ' ' )
|
||||
|
||||
info( '\n*** Adding links:\n' )
|
||||
for srcName, dstName in topo.links(sort=True):
|
||||
src, dst = self.nameToNode[ srcName ], self.nameToNode[ dstName ]
|
||||
params = topo.linkInfo( srcName, dstName )
|
||||
srcPort, dstPort = topo.port( srcName, dstName )
|
||||
self.addLink( src, dst, srcPort, dstPort, **params )
|
||||
info( '(%s, %s) ' % ( src.name, dst.name ) )
|
||||
for srcName, dstName, params in topo.links(
|
||||
sort=True, withInfo=True ):
|
||||
self.addLink( **params )
|
||||
info( '(%s, %s) ' % ( srcName, dstName ) )
|
||||
|
||||
info( '\n' )
|
||||
|
||||
@@ -355,7 +442,7 @@ class Mininet( object ):
|
||||
"Build mininet."
|
||||
if self.topo:
|
||||
self.buildFromTopo( self.topo )
|
||||
if ( self.inNamespace ):
|
||||
if self.inNamespace:
|
||||
self.configureControlNetwork()
|
||||
info( '*** Configuring hosts\n' )
|
||||
self.configHosts()
|
||||
@@ -395,32 +482,57 @@ class Mininet( object ):
|
||||
self.build()
|
||||
info( '*** Starting controller\n' )
|
||||
for controller in self.controllers:
|
||||
info( controller.name + ' ')
|
||||
controller.start()
|
||||
info( '\n' )
|
||||
info( '*** Starting %s switches\n' % len( self.switches ) )
|
||||
for switch in self.switches:
|
||||
info( switch.name + ' ')
|
||||
switch.start( self.controllers )
|
||||
started = {}
|
||||
for swclass, switches in groupby(
|
||||
sorted( self.switches, key=type ), 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()
|
||||
|
||||
def stop( self ):
|
||||
"Stop the controller(s), switches and hosts"
|
||||
info( '*** Stopping %i controllers\n' % len( self.controllers ) )
|
||||
for controller in self.controllers:
|
||||
info( controller.name + ' ' )
|
||||
controller.stop()
|
||||
info( '\n' )
|
||||
if self.terms:
|
||||
info( '*** Stopping %i terms\n' % len( self.terms ) )
|
||||
self.stopXterms()
|
||||
info( '*** Stopping %i links\n' % len( self.links ) )
|
||||
for link in self.links:
|
||||
info( '.' )
|
||||
link.stop()
|
||||
info( '\n' )
|
||||
info( '*** Stopping %i switches\n' % len( self.switches ) )
|
||||
stopped = {}
|
||||
for swclass, switches in groupby(
|
||||
sorted( self.switches, key=type ), type ):
|
||||
switches = tuple( switches )
|
||||
if hasattr( swclass, 'batchShutdown' ):
|
||||
success = swclass.batchShutdown( switches )
|
||||
stopped.update( { s: s for s in success } )
|
||||
for switch in self.switches:
|
||||
info( switch.name + ' ' )
|
||||
switch.stop()
|
||||
if switch not in stopped:
|
||||
switch.stop()
|
||||
switch.terminate()
|
||||
info( '\n' )
|
||||
info( '*** Stopping %i hosts\n' % len( self.hosts ) )
|
||||
for host in self.hosts:
|
||||
info( host.name + ' ' )
|
||||
host.terminate()
|
||||
info( '\n' )
|
||||
info( '*** Stopping %i controllers\n' % len( self.controllers ) )
|
||||
for controller in self.controllers:
|
||||
info( controller.name + ' ' )
|
||||
controller.stop()
|
||||
info( '\n*** Done\n' )
|
||||
|
||||
def run( self, test, *args, **kwargs ):
|
||||
@@ -440,13 +552,13 @@ class Mininet( object ):
|
||||
if hosts is None:
|
||||
hosts = self.hosts
|
||||
poller = select.poll()
|
||||
Node = hosts[ 0 ] # so we can call class method fdToNode
|
||||
h1 = hosts[ 0 ] # so we can call class method fdToNode
|
||||
for host in hosts:
|
||||
poller.register( host.stdout )
|
||||
while True:
|
||||
ready = poller.poll( timeoutms )
|
||||
for fd, event in ready:
|
||||
host = Node.fdToNode( fd )
|
||||
host = h1.fdToNode( fd )
|
||||
if event & select.POLLIN:
|
||||
line = host.readline()
|
||||
if line is not None:
|
||||
@@ -463,13 +575,13 @@ class Mininet( object ):
|
||||
"Parse ping output and return packets sent, received."
|
||||
# Check for downed link
|
||||
if 'connect: Network is unreachable' in pingOutput:
|
||||
return (1, 0)
|
||||
return 1, 0
|
||||
r = r'(\d+) packets transmitted, (\d+) received'
|
||||
m = re.search( r, pingOutput )
|
||||
if m is None:
|
||||
error( '*** Error: could not parse ping output: %s\n' %
|
||||
pingOutput )
|
||||
return (1, 0)
|
||||
return 1, 0
|
||||
sent, received = int( m.group( 1 ) ), int( m.group( 2 ) )
|
||||
return sent, received
|
||||
|
||||
@@ -492,8 +604,12 @@ class Mininet( object ):
|
||||
opts = ''
|
||||
if timeout:
|
||||
opts = '-W %s' % timeout
|
||||
result = node.cmd( 'ping -c1 %s %s' % (opts, dest.IP()) )
|
||||
sent, received = self._parsePing( result )
|
||||
if dest.intfs:
|
||||
result = node.cmd( 'ping -c1 %s %s' %
|
||||
(opts, dest.IP()) )
|
||||
sent, received = self._parsePing( result )
|
||||
else:
|
||||
sent, received = 0, 0
|
||||
packets += sent
|
||||
if received > sent:
|
||||
error( '*** Error: received too many packets' )
|
||||
@@ -504,7 +620,7 @@ class Mininet( object ):
|
||||
output( ( '%s ' % dest.name ) if received else 'X ' )
|
||||
output( '\n' )
|
||||
if packets > 0:
|
||||
ploss = 100 * lost / packets
|
||||
ploss = 100.0 * lost / packets
|
||||
received = packets - lost
|
||||
output( "*** Results: %i%% dropped (%d/%d received)\n" %
|
||||
( ploss, received, packets ) )
|
||||
@@ -533,6 +649,8 @@ class Mininet( object ):
|
||||
r += r'(\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+) ms'
|
||||
m = re.search( r, pingOutput )
|
||||
if m is None:
|
||||
if received == 0:
|
||||
return errorTuple
|
||||
error( '*** Error: could not parse ping output: %s\n' %
|
||||
pingOutput )
|
||||
return errorTuple
|
||||
@@ -575,10 +693,10 @@ class Mininet( object ):
|
||||
(rttmin, rttavg, rttmax, rttdev) )
|
||||
return all_outputs
|
||||
|
||||
def pingAll( self ):
|
||||
def pingAll( self, timeout=None ):
|
||||
"""Ping between all hosts.
|
||||
returns: ploss packet loss percentage"""
|
||||
return self.ping()
|
||||
return self.ping( timeout=timeout )
|
||||
|
||||
def pingPair( self ):
|
||||
"""Ping between first two hosts, useful for testing.
|
||||
@@ -613,43 +731,44 @@ class Mininet( object ):
|
||||
|
||||
# XXX This should be cleaned up
|
||||
|
||||
def iperf( self, hosts=None, l4Type='TCP', udpBw='10M' ):
|
||||
def iperf( self, hosts=None, l4Type='TCP', udpBw='10M', fmt=None,
|
||||
seconds=5, port=5001):
|
||||
"""Run iperf between two hosts.
|
||||
hosts: list of hosts; if None, uses opposite hosts
|
||||
hosts: list of hosts; if None, uses first and last hosts
|
||||
l4Type: string, one of [ TCP, UDP ]
|
||||
returns: results two-element array of server and client speeds"""
|
||||
if not quietRun( 'which telnet' ):
|
||||
error( 'Cannot find telnet in $PATH - required for iperf test' )
|
||||
return
|
||||
if not hosts:
|
||||
hosts = [ self.hosts[ 0 ], self.hosts[ -1 ] ]
|
||||
else:
|
||||
assert len( hosts ) == 2
|
||||
udpBw: bandwidth target for UDP test
|
||||
fmt: iperf format argument if any
|
||||
seconds: iperf time to transmit
|
||||
port: iperf port
|
||||
returns: two-element array of [ server, client ] speeds
|
||||
note: send() is buffered, so client rate can be much higher than
|
||||
the actual transmission rate; on an unloaded system, server
|
||||
rate should be much closer to the actual receive rate"""
|
||||
hosts = hosts or [ self.hosts[ 0 ], self.hosts[ -1 ] ]
|
||||
assert len( hosts ) == 2
|
||||
client, server = hosts
|
||||
output( '*** Iperf: testing ' + l4Type + ' bandwidth between ' )
|
||||
output( "%s and %s\n" % ( client.name, server.name ) )
|
||||
output( '*** Iperf: testing', l4Type, 'bandwidth between',
|
||||
client, 'and', server, '\n' )
|
||||
server.cmd( 'killall -9 iperf' )
|
||||
iperfArgs = 'iperf '
|
||||
iperfArgs = 'iperf -p %d ' % port
|
||||
bwArgs = ''
|
||||
if l4Type == 'UDP':
|
||||
iperfArgs += '-u '
|
||||
bwArgs = '-b ' + udpBw + ' '
|
||||
elif l4Type != 'TCP':
|
||||
raise Exception( 'Unexpected l4 type: %s' % l4Type )
|
||||
server.sendCmd( iperfArgs + '-s', printPid=True )
|
||||
servout = ''
|
||||
while server.lastPid is None:
|
||||
servout += server.monitor()
|
||||
if fmt:
|
||||
iperfArgs += '-f %s ' % fmt
|
||||
server.sendCmd( iperfArgs + '-s' )
|
||||
if l4Type == 'TCP':
|
||||
while 'Connected' not in client.cmd(
|
||||
'sh -c "echo A | telnet -e A %s 5001"' % server.IP()):
|
||||
output('waiting for iperf to start up...')
|
||||
sleep(.5)
|
||||
cliout = client.cmd( iperfArgs + '-t 5 -c ' + server.IP() + ' ' +
|
||||
bwArgs )
|
||||
if not waitListening( client, server.IP(), 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 )
|
||||
server.sendInt()
|
||||
servout += server.waitOutput()
|
||||
servout = server.waitOutput()
|
||||
debug( 'Server output: %s\n' % servout )
|
||||
result = [ self._parseIperf( servout ), self._parseIperf( cliout ) ]
|
||||
if l4Type == 'UDP':
|
||||
@@ -660,36 +779,46 @@ class Mininet( object ):
|
||||
def runCpuLimitTest( self, cpu, duration=5 ):
|
||||
"""run CPU limit test with 'while true' processes.
|
||||
cpu: desired CPU fraction of each host
|
||||
duration: test duration in seconds
|
||||
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)
|
||||
info( '*** Testing CPU %.0f%% bandwidth limit\n' % pct )
|
||||
hosts = self.hosts
|
||||
cores = int( quietRun( 'nproc' ) )
|
||||
# number of processes to run a while loop on per host
|
||||
num_procs = int( ceil( cores * cpu ) )
|
||||
pids = {}
|
||||
for h in hosts:
|
||||
h.cmd( 'while true; do a=1; done &' )
|
||||
pids = [h.cmd( 'echo $!' ).strip() for h in hosts]
|
||||
pids_str = ",".join(["%s" % pid for pid in pids])
|
||||
cmd = 'ps -p %s -o pid,%%cpu,args' % pids_str
|
||||
# It's a shame that this is what pylint prefers
|
||||
outputs = []
|
||||
pids[ h ] = []
|
||||
for _core in range( num_procs ):
|
||||
h.cmd( 'while true; do a=1; done &' )
|
||||
pids[ h ].append( h.cmd( 'echo $!' ).strip() )
|
||||
outputs = {}
|
||||
time = {}
|
||||
# get the initial cpu time for each host
|
||||
for host in hosts:
|
||||
outputs[ host ] = []
|
||||
with open( '/sys/fs/cgroup/cpuacct/%s/cpuacct.usage' %
|
||||
host, 'r' ) as f:
|
||||
time[ host ] = float( f.read() )
|
||||
for _ in range( duration ):
|
||||
sleep( 1 )
|
||||
outputs.append( quietRun( cmd ).strip() )
|
||||
for h in hosts:
|
||||
h.cmd( 'kill %1' )
|
||||
for host in hosts:
|
||||
with open( '/sys/fs/cgroup/cpuacct/%s/cpuacct.usage' %
|
||||
host, 'r' ) as f:
|
||||
readTime = float( f.read() )
|
||||
outputs[ host ].append( ( ( readTime - time[ host ] )
|
||||
/ 1000000000 ) / cores * 100 )
|
||||
time[ host ] = readTime
|
||||
for h, pids in pids.items():
|
||||
for pid in pids:
|
||||
h.cmd( 'kill -9 %s' % pid )
|
||||
cpu_fractions = []
|
||||
for test_output in outputs:
|
||||
# Split by line. Ignore first line, which looks like this:
|
||||
# PID %CPU COMMAND\n
|
||||
for line in test_output.split('\n')[1:]:
|
||||
r = r'\d+\s*(\d+\.\d+)'
|
||||
m = re.search( r, line )
|
||||
if m is None:
|
||||
error( '*** Error: could not extract CPU fraction: %s\n' %
|
||||
line )
|
||||
return None
|
||||
cpu_fractions.append( float( m.group( 1 ) ) )
|
||||
for _host, outputs in outputs.items():
|
||||
for pct in outputs:
|
||||
cpu_fractions.append( pct )
|
||||
output( '*** Results: %s\n' % cpu_fractions )
|
||||
return cpu_fractions
|
||||
|
||||
@@ -705,9 +834,9 @@ class Mininet( object ):
|
||||
elif dst not in self.nameToNode:
|
||||
error( 'dst not in network: %s\n' % dst )
|
||||
else:
|
||||
if type( src ) is str:
|
||||
if isinstance( src, basestring ):
|
||||
src = self.nameToNode[ src ]
|
||||
if type( dst ) is str:
|
||||
if isinstance( dst, basestring ):
|
||||
dst = self.nameToNode[ dst ]
|
||||
connections = src.connectionsTo( dst )
|
||||
if len( connections ) == 0:
|
||||
|
||||
+545
-248
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,144 @@
|
||||
"""
|
||||
Node Library for Mininet
|
||||
|
||||
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)"
|
||||
|
||||
nextPrio = 100 # next bridge priority for spanning tree
|
||||
|
||||
def __init__( self, name, stp=False, prio=None, **kwargs ):
|
||||
"""stp: use spanning tree protocol? (default False)
|
||||
prio: optional explicit bridge priority for STP"""
|
||||
self.stp = stp
|
||||
if prio:
|
||||
self.prio = prio
|
||||
else:
|
||||
self.prio = LinuxBridge.nextPrio
|
||||
LinuxBridge.nextPrio += 1
|
||||
Switch.__init__( self, name, **kwargs )
|
||||
|
||||
def connected( self ):
|
||||
"Are we forwarding yet?"
|
||||
if self.stp:
|
||||
return 'forwarding' in self.cmd( 'brctl showstp', self )
|
||||
else:
|
||||
return True
|
||||
|
||||
def start( self, _controllers ):
|
||||
"Start Linux bridge"
|
||||
self.cmd( 'ifconfig', self, 'down' )
|
||||
self.cmd( 'brctl delbr', self )
|
||||
self.cmd( 'brctl addbr', self )
|
||||
if self.stp:
|
||||
self.cmd( 'brctl setbridgeprio', self.prio )
|
||||
self.cmd( 'brctl stp', self, 'on' )
|
||||
for i in self.intfList():
|
||||
if self.name in i.name:
|
||||
self.cmd( 'brctl addif', self, i )
|
||||
self.cmd( 'ifconfig', self, 'up' )
|
||||
|
||||
def stop( self, deleteIntfs=True ):
|
||||
"""Stop Linux bridge
|
||||
deleteIntfs: delete interfaces? (True)"""
|
||||
self.cmd( 'ifconfig', self, 'down' )
|
||||
self.cmd( 'brctl delbr', self )
|
||||
super( LinuxBridge, self ).stop( deleteIntfs )
|
||||
|
||||
def dpctl( self, *args ):
|
||||
"Run brctl command"
|
||||
return self.cmd( 'brctl', *args )
|
||||
|
||||
@classmethod
|
||||
def setup( cls ):
|
||||
"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, subnet='10.0/8',
|
||||
localIntf=None, flush=False, **params):
|
||||
"""Start NAT/forwarding between Mininet and external network
|
||||
subnet: Mininet subnet (default 10.0/8)
|
||||
flush: flush iptables before installing NAT rules"""
|
||||
super( NAT, self ).__init__( name, **params )
|
||||
|
||||
self.subnet = subnet
|
||||
self.localIntf = localIntf
|
||||
self.flush = flush
|
||||
self.forwardState = self.cmd( 'sysctl -n net.ipv4.ip_forward' ).strip()
|
||||
|
||||
def config( self, **params ):
|
||||
"""Configure the NAT and iptables"""
|
||||
super( NAT, self).config( **params )
|
||||
|
||||
if not self.localIntf:
|
||||
self.localIntf = self.defaultIntf()
|
||||
|
||||
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' )
|
||||
|
||||
# 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',
|
||||
'-o', self.localIntf, '-d', self.subnet,'-j ACCEPT' )
|
||||
self.cmd( 'iptables -t nat -A POSTROUTING',
|
||||
'-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 terminate( self ):
|
||||
"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()
|
||||
+5
-4
@@ -32,16 +32,16 @@ def tunnelX11( node, display=None):
|
||||
port = 6000 + int( float( screen ) )
|
||||
connection = r'TCP\:%s\:%s' % ( host, port )
|
||||
cmd = [ "socat", "TCP-LISTEN:%d,fork,reuseaddr" % port,
|
||||
"EXEC:'mnexec -a 1 socat STDIO %s'" % connection ]
|
||||
"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
|
||||
term: 'xterm' or 'gterm'
|
||||
returns: two Popen objects, tunnel and terminal"""
|
||||
title += ': ' + node.name
|
||||
title = '"%s: %s"' % ( title, node.name )
|
||||
if not node.inNamespace:
|
||||
title += ' (root)'
|
||||
cmds = {
|
||||
@@ -54,7 +54,8 @@ def makeTerm( node, title='Node', term='xterm', display=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 ):
|
||||
|
||||
@@ -6,7 +6,7 @@ Run all mininet core tests
|
||||
-quick : skip tests that take more than ~30 seconds
|
||||
"""
|
||||
|
||||
import unittest
|
||||
from unittest import defaultTestLoader, TextTestRunner
|
||||
import os
|
||||
import sys
|
||||
from mininet.util import ensureRoot
|
||||
@@ -19,13 +19,13 @@ def runTests( testDir, verbosity=1 ):
|
||||
ensureRoot()
|
||||
cleanup()
|
||||
# discover all tests in testDir
|
||||
testSuite = unittest.defaultTestLoader.discover( testDir )
|
||||
testSuite = defaultTestLoader.discover( testDir )
|
||||
# run tests
|
||||
unittest.TextTestRunner( verbosity=verbosity ).run( testSuite )
|
||||
TextTestRunner( verbosity=verbosity ).run( testSuite )
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
# get the directory containing example tests
|
||||
testDir = os.path.dirname( os.path.realpath( __file__ ) )
|
||||
verbosity = 2 if '-v' in sys.argv else 1
|
||||
runTests( testDir, verbosity )
|
||||
thisdir = os.path.dirname( os.path.realpath( __file__ ) )
|
||||
vlevel = 2 if '-v' in sys.argv else 1
|
||||
runTests( testDir=thisdir, verbosity=vlevel )
|
||||
|
||||
+137
-26
@@ -4,6 +4,7 @@
|
||||
Test creation and pings for topologies with link and/or CPU options."""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
from mininet.net import Mininet
|
||||
@@ -13,6 +14,7 @@ from mininet.link import TCLink
|
||||
from mininet.topo import Topo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import quietRun
|
||||
from mininet.clean import cleanup
|
||||
|
||||
# Number of hosts for each test
|
||||
N = 2
|
||||
@@ -38,23 +40,55 @@ class testOptionsTopoCommon( object ):
|
||||
"""Verify ability to create networks with host and link options
|
||||
(common code)."""
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
switchClass = None # overridden in subclasses
|
||||
|
||||
def runOptionsTopoTest( self, n, hopts=None, lopts=None ):
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
"Clean up if necessary"
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
def runOptionsTopoTest( self, n, msg, hopts=None, lopts=None ):
|
||||
"Generic topology-with-options test runner."
|
||||
mn = Mininet( topo=SingleSwitchOptionsTopo( n=n, hopts=hopts,
|
||||
lopts=lopts ),
|
||||
host=CPULimitedHost, link=TCLink,
|
||||
switch=self.switchClass )
|
||||
switch=self.switchClass, waitConnected=True )
|
||||
dropped = mn.run( mn.ping )
|
||||
self.assertEqual( dropped, 0 )
|
||||
hoptsStr = ', '.join( '%s: %s' % ( opt, value )
|
||||
for opt, value in hopts.items() )
|
||||
loptsStr = ', '.join( '%s: %s' % ( opt, value )
|
||||
for opt, value in lopts.items() )
|
||||
msg += ( '%s%% of pings were dropped during mininet.ping().\n'
|
||||
'Topo = SingleSwitchTopo, %s hosts\n'
|
||||
'hopts = %s\n'
|
||||
'lopts = %s\n'
|
||||
'host = CPULimitedHost\n'
|
||||
'link = TCLink\n'
|
||||
'Switch = %s\n'
|
||||
% ( dropped, n, hoptsStr, loptsStr, self.switchClass ) )
|
||||
|
||||
def assertWithinTolerance(self, measured, expected, tolerance_frac):
|
||||
self.assertEqual( dropped, 0, msg=msg )
|
||||
|
||||
def assertWithinTolerance( self, measured, expected, tolerance_frac, msg ):
|
||||
"""Check that a given value is within a tolerance of expected
|
||||
tolerance_frac: less-than-1.0 value; 0.8 would yield 20% tolerance.
|
||||
"""
|
||||
self.assertTrue( float(measured) >= float(expected) * tolerance_frac )
|
||||
self.assertTrue( float(measured) >= float(expected) * tolerance_frac )
|
||||
upperBound = ( float( expected ) + ( 1 - tolerance_frac ) *
|
||||
float( expected ) )
|
||||
lowerBound = float( expected ) * tolerance_frac
|
||||
info = ( 'measured value is out of bounds\n'
|
||||
'expected value: %s\n'
|
||||
'measured value: %s\n'
|
||||
'failure tolerance: %s\n'
|
||||
'upper bound: %s\n'
|
||||
'lower bound: %s\n'
|
||||
% ( expected, measured, tolerance_frac,
|
||||
upperBound, lowerBound ) )
|
||||
msg += info
|
||||
|
||||
self.assertGreaterEqual( float( measured ), lowerBound, msg=msg )
|
||||
self.assertLessEqual( float( measured ), upperBound, msg=msg )
|
||||
|
||||
def testCPULimits( self ):
|
||||
"Verify topology creation with CPU limits set for both schedulers."
|
||||
@@ -64,46 +98,102 @@ class testOptionsTopoCommon( object ):
|
||||
#self.runOptionsTopoTest( N, hopts=hopts )
|
||||
|
||||
mn = Mininet( SingleSwitchOptionsTopo( n=N, hopts=hopts ),
|
||||
host=CPULimitedHost, switch=self.switchClass )
|
||||
host=CPULimitedHost, switch=self.switchClass,
|
||||
waitConnected=True )
|
||||
mn.start()
|
||||
results = mn.runCpuLimitTest( cpu=CPU_FRACTION )
|
||||
mn.stop()
|
||||
for cpu in results:
|
||||
self.assertWithinTolerance( cpu, CPU_FRACTION, CPU_TOLERANCE )
|
||||
hostUsage = '\n'.join( 'h%s: %s' %
|
||||
( n + 1,
|
||||
results[ (n - 1) * 5 : (n * 5) - 1 ] )
|
||||
for n in range( N ) )
|
||||
hoptsStr = ', '.join( '%s: %s' % ( opt, value )
|
||||
for opt, value in hopts.items() )
|
||||
msg = ( '\nTesting cpu limited to %d%% of cpu per host\n'
|
||||
'cpu usage percent per host:\n%s\n'
|
||||
'Topo = SingleSwitchTopo, %s hosts\n'
|
||||
'hopts = %s\n'
|
||||
'host = CPULimitedHost\n'
|
||||
'Switch = %s\n'
|
||||
% ( CPU_FRACTION * 100, hostUsage, N, hoptsStr,
|
||||
self.switchClass ) )
|
||||
for pct in results:
|
||||
#divide cpu by 100 to convert from percentage to fraction
|
||||
self.assertWithinTolerance( pct/100, CPU_FRACTION,
|
||||
CPU_TOLERANCE, msg )
|
||||
|
||||
def testLinkBandwidth( self ):
|
||||
"Verify that link bandwidths are accurate within a bound."
|
||||
if self.switchClass is UserSwitch:
|
||||
self.skipTest( 'UserSwitch has very poor performance -'
|
||||
' skipping for now' )
|
||||
BW = 5 # Mbps
|
||||
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.
|
||||
mn = Mininet( SingleSwitchOptionsTopo( n=N, lopts=lopts ),
|
||||
link=TCLink, switch=self.switchClass )
|
||||
bw_strs = mn.run( mn.iperf )
|
||||
for bw_str in bw_strs:
|
||||
bw = float( bw_str.split(' ')[0] )
|
||||
self.assertWithinTolerance( bw, BW, BW_TOLERANCE )
|
||||
link=TCLink, switch=self.switchClass,
|
||||
waitConnected=True )
|
||||
bw_strs = mn.run( mn.iperf, fmt='m' )
|
||||
loptsStr = ', '.join( '%s: %s' % ( opt, value )
|
||||
for opt, value in lopts.items() )
|
||||
msg = ( '\nTesting link bandwidth limited to %d Mbps per link\n'
|
||||
'iperf results[ client, server ]: %s\n'
|
||||
'Topo = SingleSwitchTopo, %s hosts\n'
|
||||
'Link = TCLink\n'
|
||||
'lopts = %s\n'
|
||||
'host = default\n'
|
||||
'switch = %s\n'
|
||||
% ( BW, bw_strs, N, loptsStr, self.switchClass ) )
|
||||
|
||||
# On the client side, iperf doesn't wait for ACKs - it simply
|
||||
# reports how long it took to fill up the TCP send buffer.
|
||||
# As long as the kernel doesn't wait a long time before
|
||||
# delivering bytes to the iperf server, its reported data rate
|
||||
# should be close to the actual receive rate.
|
||||
serverRate, _clientRate = bw_strs
|
||||
bw = float( serverRate.split(' ')[0] )
|
||||
self.assertWithinTolerance( bw, BW, BW_TOLERANCE, msg )
|
||||
|
||||
def testLinkDelay( self ):
|
||||
"Verify that link delays are accurate within a bound."
|
||||
DELAY_MS = 15
|
||||
DELAY_TOLERANCE = 0.8 # Delay fraction below which test should fail
|
||||
REPS = 3
|
||||
lopts = { 'delay': '%sms' % DELAY_MS, 'use_htb': True }
|
||||
mn = Mininet( SingleSwitchOptionsTopo( n=N, lopts=lopts ),
|
||||
link=TCLink, switch=self.switchClass )
|
||||
ping_delays = mn.run( mn.pingFull )
|
||||
link=TCLink, switch=self.switchClass, autoStaticArp=True,
|
||||
waitConnected=True )
|
||||
mn.start()
|
||||
for _ in range( REPS ):
|
||||
ping_delays = mn.pingFull()
|
||||
mn.stop()
|
||||
test_outputs = ping_delays[0]
|
||||
# Ignore unused variables below
|
||||
# pylint: disable-msg=W0612
|
||||
# pylint: disable=W0612
|
||||
node, dest, ping_outputs = test_outputs
|
||||
sent, received, rttmin, rttavg, rttmax, rttdev = ping_outputs
|
||||
self.assertEqual( sent, received )
|
||||
# pylint: enable-msg=W0612
|
||||
pingFailMsg = 'sent %s pings, only received %s' % ( sent, received )
|
||||
self.assertEqual( sent, received, msg=pingFailMsg )
|
||||
# pylint: enable=W0612
|
||||
loptsStr = ', '.join( '%s: %s' % ( opt, value )
|
||||
for opt, value in lopts.items() )
|
||||
msg = ( '\nTesting Link Delay of %s ms\n'
|
||||
'ping results across 4 links:\n'
|
||||
'(Sent, Received, rttmin, rttavg, rttmax, rttdev)\n'
|
||||
'%s\n'
|
||||
'Topo = SingleSwitchTopo, %s hosts\n'
|
||||
'Link = TCLink\n'
|
||||
'lopts = %s\n'
|
||||
'host = default'
|
||||
'switch = %s\n'
|
||||
% ( DELAY_MS, ping_outputs, N, loptsStr, self.switchClass ) )
|
||||
|
||||
for rttval in [rttmin, rttavg, rttmax]:
|
||||
# Multiply delay by 4 to cover there & back on two links
|
||||
self.assertWithinTolerance( rttval, DELAY_MS * 4.0,
|
||||
DELAY_TOLERANCE)
|
||||
DELAY_TOLERANCE, msg )
|
||||
|
||||
def testLinkLoss( self ):
|
||||
"Verify that we see packet drops with a high configured loss rate."
|
||||
@@ -112,7 +202,8 @@ class testOptionsTopoCommon( object ):
|
||||
lopts = { 'loss': LOSS_PERCENT, 'use_htb': True }
|
||||
mn = Mininet( topo=SingleSwitchOptionsTopo( n=N, lopts=lopts ),
|
||||
host=CPULimitedHost, link=TCLink,
|
||||
switch=self.switchClass )
|
||||
switch=self.switchClass,
|
||||
waitConnected=True )
|
||||
# Drops are probabilistic, but the chance of no dropped packets is
|
||||
# 1 in 100 million with 4 hops for a link w/99% loss.
|
||||
dropped_total = 0
|
||||
@@ -120,36 +211,56 @@ class testOptionsTopoCommon( object ):
|
||||
for _ in range(REPS):
|
||||
dropped_total += mn.ping(timeout='1')
|
||||
mn.stop()
|
||||
self.assertTrue(dropped_total > 0)
|
||||
|
||||
loptsStr = ', '.join( '%s: %s' % ( opt, value )
|
||||
for opt, value in lopts.items() )
|
||||
msg = ( '\nTesting packet loss with %d%% loss rate\n'
|
||||
'number of dropped pings during mininet.ping(): %s\n'
|
||||
'expected number of dropped packets: 1\n'
|
||||
'Topo = SingleSwitchTopo, %s hosts\n'
|
||||
'Link = TCLink\n'
|
||||
'lopts = %s\n'
|
||||
'host = default\n'
|
||||
'switch = %s\n'
|
||||
% ( LOSS_PERCENT, dropped_total, N, loptsStr,
|
||||
self.switchClass ) )
|
||||
|
||||
self.assertGreater( dropped_total, 0, msg )
|
||||
|
||||
def testMostOptions( self ):
|
||||
"Verify topology creation with most link options and CPU limits."
|
||||
lopts = { 'bw': 10, 'delay': '5ms', 'use_htb': True }
|
||||
hopts = { 'cpu': 0.5 / N }
|
||||
self.runOptionsTopoTest( N, hopts=hopts, lopts=lopts )
|
||||
msg = '\nTesting many cpu and link options\n'
|
||||
self.runOptionsTopoTest( N, msg, hopts=hopts, lopts=lopts )
|
||||
|
||||
# pylint: enable=E1101
|
||||
|
||||
class testOptionsTopoOVSKernel( testOptionsTopoCommon, unittest.TestCase ):
|
||||
"""Verify ability to create networks with host and link options
|
||||
(OVS kernel switch)."""
|
||||
longMessage = True
|
||||
switchClass = OVSSwitch
|
||||
|
||||
@unittest.skip( 'Skipping OVS user switch test for now' )
|
||||
class testOptionsTopoOVSUser( testOptionsTopoCommon, unittest.TestCase ):
|
||||
"""Verify ability to create networks with host and link options
|
||||
(OVS user switch)."""
|
||||
longMessage = True
|
||||
switchClass = partial( OVSSwitch, datapath='user' )
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ivs-ctl' ), 'IVS is not installed' )
|
||||
class testOptionsTopoIVS( testOptionsTopoCommon, unittest.TestCase ):
|
||||
"Verify ability to create networks with host and link options (IVS)."
|
||||
longMessage = True
|
||||
switchClass = IVSSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
|
||||
'Reference user switch is not installed' )
|
||||
'Reference user switch is not installed' )
|
||||
class testOptionsTopoUserspace( testOptionsTopoCommon, unittest.TestCase ):
|
||||
"Verify ability to create networks with host and link options (UserSwitch)."
|
||||
"""Verify ability to create networks with host and link options
|
||||
(UserSwitch)."""
|
||||
longMessage = True
|
||||
switchClass = UserSwitch
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
Test creation and all-pairs ping for each included mininet topo type."""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
from functools import partial
|
||||
|
||||
from mininet.net import Mininet
|
||||
@@ -12,6 +13,7 @@ from mininet.node import UserSwitch, OVSSwitch, IVSSwitch
|
||||
from mininet.topo import SingleSwitchTopo, LinearTopo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import quietRun
|
||||
from mininet.clean import cleanup
|
||||
|
||||
# Tell pylint not to complain about calls to other class
|
||||
# pylint: disable=E1101
|
||||
@@ -19,18 +21,25 @@ from mininet.util import quietRun
|
||||
class testSingleSwitchCommon( object ):
|
||||
"Test ping with single switch topology (common code)."
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
switchClass = None # overridden in subclasses
|
||||
|
||||
@staticmethod
|
||||
def tearDown():
|
||||
"Clean up if necessary"
|
||||
if sys.exc_info != ( None, None, None ):
|
||||
cleanup()
|
||||
|
||||
def testMinimal( self ):
|
||||
"Ping test on minimal topology"
|
||||
mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller )
|
||||
mn = Mininet( SingleSwitchTopo(), self.switchClass, Host, Controller,
|
||||
waitConnected=True )
|
||||
dropped = mn.run( mn.ping )
|
||||
self.assertEqual( dropped, 0 )
|
||||
|
||||
def testSingle5( self ):
|
||||
"Ping test on 5-host single-switch topology"
|
||||
mn = Mininet( SingleSwitchTopo( k=5 ), self.switchClass, Host,
|
||||
Controller )
|
||||
Controller, waitConnected=True )
|
||||
dropped = mn.run( mn.ping )
|
||||
self.assertEqual( dropped, 0 )
|
||||
|
||||
@@ -50,7 +59,7 @@ class testSingleSwitchIVS( testSingleSwitchCommon, unittest.TestCase ):
|
||||
switchClass = IVSSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
|
||||
'Reference user switch is not installed' )
|
||||
'Reference user switch is not installed' )
|
||||
class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
|
||||
"Test ping with single switch topology (Userspace switch)."
|
||||
switchClass = UserSwitch
|
||||
@@ -62,11 +71,12 @@ class testSingleSwitchUserspace( testSingleSwitchCommon, unittest.TestCase ):
|
||||
class testLinearCommon( object ):
|
||||
"Test all-pairs ping with LinearNet (common code)."
|
||||
|
||||
switchClass = None # overridden in subclasses
|
||||
switchClass = None # overridden in subclasses
|
||||
|
||||
def testLinear5( self ):
|
||||
"Ping test on a 5-switch topology"
|
||||
mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host, Controller )
|
||||
mn = Mininet( LinearTopo( k=5 ), self.switchClass, Host,
|
||||
Controller, waitConnected=True )
|
||||
dropped = mn.run( mn.ping )
|
||||
self.assertEqual( dropped, 0 )
|
||||
|
||||
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Package: mininet
|
||||
Regression tests for switch dpid assignment."""
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.node import Host, Controller
|
||||
from mininet.node import ( UserSwitch, OVSSwitch, IVSSwitch )
|
||||
from mininet.topo import Topo
|
||||
from mininet.log import setLogLevel
|
||||
from mininet.util import quietRun
|
||||
from mininet.clean import cleanup
|
||||
|
||||
|
||||
class TestSwitchDpidAssignmentOVS( unittest.TestCase ):
|
||||
"Verify Switch dpid assignment."
|
||||
|
||||
switchClass = OVSSwitch # overridden in subclasses
|
||||
|
||||
def tearDown( self ):
|
||||
"Clean up if necessary"
|
||||
# satisfy pylint
|
||||
assert self
|
||||
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' )
|
||||
self.assertEqual( switch.defaultDpid(), switch.dpid )
|
||||
|
||||
def dpidFrom( self, num ):
|
||||
"Compute default dpid from number"
|
||||
fmt = ( '%0' + str( self.switchClass.dpidLen ) + 'x' )
|
||||
return fmt % num
|
||||
|
||||
def testActualDpidAssignment( self ):
|
||||
"""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 )
|
||||
self.assertEqual( switch.dpid, dpid )
|
||||
|
||||
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
|
||||
exception message."""
|
||||
with self.assertRaises( Exception ) as raises_cm:
|
||||
Mininet( Topo(), self.switchClass,
|
||||
Host, Controller ).addSwitch( 'A' )
|
||||
self.assertEqual(raises_cm.exception.message, 'Unable to derive '
|
||||
'default datapath ID - please either specify a dpid '
|
||||
'or use a canonical switch name such as s23.')
|
||||
|
||||
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' )
|
||||
|
||||
self.assertEqual( switch.dpid, self.dpidFrom( 123 ) )
|
||||
|
||||
class OVSUser( OVSSwitch):
|
||||
"OVS User Switch convenience class"
|
||||
def __init__( self, *args, **kwargs ):
|
||||
kwargs.update( datapath='user' )
|
||||
OVSSwitch.__init__( self, *args, **kwargs )
|
||||
|
||||
class testSwitchOVSUser( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignnment of OVS User Switch."
|
||||
switchClass = OVSUser
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ivs-ctl' ),
|
||||
'IVS switch is not installed' )
|
||||
class testSwitchIVS( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignment of IVS switch."
|
||||
switchClass = IVSSwitch
|
||||
|
||||
@unittest.skipUnless( quietRun( 'which ofprotocol' ),
|
||||
'Reference user switch is not installed' )
|
||||
class testSwitchUserspace( TestSwitchDpidAssignmentOVS ):
|
||||
"Test dpid assignment of Userspace switch."
|
||||
switchClass = UserSwitch
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'warning' )
|
||||
unittest.main()
|
||||
@@ -9,9 +9,21 @@ TODO: missing xterm test
|
||||
import unittest
|
||||
import pexpect
|
||||
import os
|
||||
import re
|
||||
from mininet.util import quietRun
|
||||
from distutils.version import StrictVersion
|
||||
|
||||
def tsharkVersion():
|
||||
"Return tshark version"
|
||||
versionStr = quietRun( 'tshark -v' )
|
||||
versionMatch = re.findall( r'TShark \d+.\d+.\d+', versionStr )[0]
|
||||
return versionMatch.split()[ 1 ]
|
||||
|
||||
# pylint doesn't understand pexpect.match, unfortunately!
|
||||
# pylint:disable=maybe-no-member
|
||||
|
||||
class testWalkthrough( unittest.TestCase ):
|
||||
"Test Mininet walkthrough"
|
||||
|
||||
prompt = 'mininet>'
|
||||
|
||||
@@ -24,11 +36,16 @@ class testWalkthrough( unittest.TestCase ):
|
||||
|
||||
def testWireshark( self ):
|
||||
"Use tshark to test the of dissector"
|
||||
tshark = pexpect.spawn( 'tshark -i lo -R of' )
|
||||
tshark.expect( 'Capturing on lo' )
|
||||
# Satisfy pylint
|
||||
assert self
|
||||
if StrictVersion( tsharkVersion() ) < StrictVersion( '1.12.0' ):
|
||||
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'" ] )
|
||||
mn = pexpect.spawn( 'mn --test pingall' )
|
||||
mn.expect( '0% dropped' )
|
||||
tshark.expect( 'OFP 74 Hello' )
|
||||
tshark.expect( [ '74 Hello', '74 of_hello', '74 Type: OFPT_HELLO' ] )
|
||||
tshark.sendintr()
|
||||
|
||||
def testBasic( self ):
|
||||
@@ -41,7 +58,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
self.assertEqual( index, 0, 'No output for "help" command')
|
||||
# nodes command
|
||||
p.sendline( 'nodes' )
|
||||
p.expect( '([chs]\d ?){4}' )
|
||||
p.expect( r'([chs]\d ?){4}' )
|
||||
nodes = p.match.group( 0 ).split()
|
||||
self.assertEqual( len( nodes ), 4, 'No nodes in "nodes" command')
|
||||
p.expect( self.prompt )
|
||||
@@ -57,14 +74,15 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p.expect( self.prompt )
|
||||
# dump command
|
||||
p.sendline( 'dump' )
|
||||
expected = [ '<\w+ (%s)' % n for n in nodes ]
|
||||
expected = [ r'<\w+ (%s)' % n for n in nodes ]
|
||||
actual = []
|
||||
for _ in nodes:
|
||||
index = p.expect( expected )
|
||||
node = p.match.group( 1 )
|
||||
actual.append( node )
|
||||
p.expect( '\n' )
|
||||
self.assertEqual( actual.sort(), nodes.sort(), '"nodes" and "dump" differ' )
|
||||
self.assertEqual( actual.sort(), nodes.sort(),
|
||||
'"nodes" and "dump" differ' )
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'exit' )
|
||||
p.wait()
|
||||
@@ -101,11 +119,11 @@ class testWalkthrough( unittest.TestCase ):
|
||||
break
|
||||
self.assertEqual( ifcount, 3, 'Missing interfaces on s1')
|
||||
# h1 ps
|
||||
p.sendline( 'h1 ps -a' )
|
||||
p.sendline( "h1 ps -a | egrep -v 'ps|grep'" )
|
||||
p.expect( self.prompt )
|
||||
h1Output = p.before
|
||||
# s1 ps
|
||||
p.sendline( 's1 ps -a' )
|
||||
p.sendline( "s1 ps -a | egrep -v 'ps|grep'" )
|
||||
p.expect( self.prompt )
|
||||
s1Output = p.before
|
||||
# strip command from ps output
|
||||
@@ -151,7 +169,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p.expect( pexpect.EOF )
|
||||
# test iperf
|
||||
p = pexpect.spawn( 'mn --test iperf' )
|
||||
p.expect( "Results: \['([\d\.]+) .bits/sec'," )
|
||||
p.expect( r"Results: \['([\d\.]+) .bits/sec'," )
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertTrue( bw > 0 )
|
||||
p.expect( pexpect.EOF )
|
||||
@@ -160,7 +178,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
"Test pingall on single,3 and linear,4 topos"
|
||||
# testing single,3
|
||||
p = pexpect.spawn( 'mn --test pingall --topo single,3' )
|
||||
p.expect( '(\d+)/(\d+) received')
|
||||
p.expect( r'(\d+)/(\d+) received')
|
||||
received = int( p.match.group( 1 ) )
|
||||
sent = int( p.match.group( 2 ) )
|
||||
self.assertEqual( sent, 6, 'Wrong number of pings sent in single,3' )
|
||||
@@ -168,7 +186,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p.expect( pexpect.EOF )
|
||||
# testing linear,4
|
||||
p = pexpect.spawn( 'mn --test pingall --topo linear,4' )
|
||||
p.expect( '(\d+)/(\d+) received')
|
||||
p.expect( r'(\d+)/(\d+) received')
|
||||
received = int( p.match.group( 1 ) )
|
||||
sent = int( p.match.group( 2 ) )
|
||||
self.assertEqual( sent, 12, 'Wrong number of pings sent in linear,4' )
|
||||
@@ -181,14 +199,15 @@ class testWalkthrough( unittest.TestCase ):
|
||||
# test bw
|
||||
p.expect( self.prompt )
|
||||
p.sendline( 'iperf' )
|
||||
p.expect( "Results: \['([\d\.]+) Mbits/sec'," )
|
||||
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')
|
||||
p.expect( self.prompt )
|
||||
# test delay
|
||||
p.sendline( 'h1 ping -c 4 h2' )
|
||||
p.expect( 'rtt min/avg/max/mdev = ([\d\.]+)/([\d\.]+)/([\d\.]+)/([\d\.]+) ms' )
|
||||
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' )
|
||||
@@ -208,14 +227,17 @@ class testWalkthrough( unittest.TestCase ):
|
||||
p = pexpect.spawn( 'mn -v debug --test none' )
|
||||
p.expect( pexpect.EOF )
|
||||
lines = p.before.split( '\n' )
|
||||
self.assertTrue( len( lines ) > 100, "Debug output is too short" )
|
||||
self.assertTrue( len( lines ) > 70, "Debug output is too short" )
|
||||
|
||||
def testCustomTopo( self ):
|
||||
"Start Mininet using a custom topo, then run pingall"
|
||||
# Satisfy pylint
|
||||
assert self
|
||||
custom = os.path.dirname( os.path.realpath( __file__ ) )
|
||||
custom = os.path.join( custom, '../../custom/topo-2sw-2host.py' )
|
||||
custom = os.path.normpath( custom )
|
||||
p = pexpect.spawn( 'mn --custom %s --topo mytopo --test pingall' % custom )
|
||||
p = pexpect.spawn(
|
||||
'mn --custom %s --topo mytopo --test pingall' % custom )
|
||||
p.expect( '0% dropped' )
|
||||
p.expect( pexpect.EOF )
|
||||
|
||||
@@ -233,7 +255,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
switches = [ 'user', 'ovsk' ]
|
||||
for sw in switches:
|
||||
p = pexpect.spawn( 'mn --switch %s --test iperf' % sw )
|
||||
p.expect( "Results: \['([\d\.]+) .bits/sec'," )
|
||||
p.expect( r"Results: \['([\d\.]+) .bits/sec'," )
|
||||
bw = float( p.match.group( 1 ) )
|
||||
self.assertTrue( bw > 0 )
|
||||
p.expect( pexpect.EOF )
|
||||
@@ -241,7 +263,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
def testBenchmark( self ):
|
||||
"Run benchmark and verify that it takes less than 2 seconds"
|
||||
p = pexpect.spawn( 'mn --test none' )
|
||||
p.expect( 'completed in ([\d\.]+) seconds' )
|
||||
p.expect( r'completed in ([\d\.]+) seconds' )
|
||||
time = float( p.match.group( 1 ) )
|
||||
self.assertTrue( time < 2, 'Benchmark takes more than 2 seconds' )
|
||||
|
||||
@@ -265,7 +287,7 @@ class testWalkthrough( unittest.TestCase ):
|
||||
self.assertEqual( ifcount, 2, 'Missing interfaces on s1' )
|
||||
# verify that all hosts a reachable
|
||||
p.sendline( 'pingall' )
|
||||
p.expect( '(\d+)% dropped' )
|
||||
p.expect( r'(\d+)% dropped' )
|
||||
dropped = int( p.match.group( 1 ) )
|
||||
self.assertEqual( dropped, 0, 'pingall failed')
|
||||
p.expect( self.prompt )
|
||||
@@ -317,15 +339,20 @@ class testWalkthrough( unittest.TestCase ):
|
||||
'Github is not reachable; cannot download Pox' )
|
||||
def testRemoteController( self ):
|
||||
"Test Mininet using Pox controller"
|
||||
# Satisfy pylint
|
||||
assert self
|
||||
if not os.path.exists( '/tmp/pox' ):
|
||||
p = pexpect.spawn( 'git clone https://github.com/noxrepo/pox.git /tmp/pox' )
|
||||
p = pexpect.spawn(
|
||||
'git clone https://github.com/noxrepo/pox.git /tmp/pox' )
|
||||
p.expect( pexpect.EOF )
|
||||
pox = pexpect.spawn( '/tmp/pox/pox.py forwarding.l2_learning' )
|
||||
net = pexpect.spawn( 'mn --controller=remote,ip=127.0.0.1,port=6633 --test pingall' )
|
||||
net = pexpect.spawn(
|
||||
'mn --controller=remote,ip=127.0.0.1,port=6633 --test pingall' )
|
||||
net.expect( '0% dropped' )
|
||||
net.expect( pexpect.EOF )
|
||||
pox.sendintr()
|
||||
pox.wait()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
+245
-160
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
'''@package topo
|
||||
"""@package topo
|
||||
|
||||
Network topology creation.
|
||||
|
||||
@@ -9,261 +9,346 @@ This package includes code to represent network topologies.
|
||||
|
||||
A Topo object can be a topology database for NOX, can represent a physical
|
||||
setup for testing, and can even be emulated with the Mininet package.
|
||||
'''
|
||||
"""
|
||||
|
||||
from mininet.util import irange, natural, naturalSeq
|
||||
|
||||
class MultiGraph( object ):
|
||||
"Utility class to track nodes and edges - replaces networkx.Graph"
|
||||
"Utility class to track nodes and edges - replaces networkx.MultiGraph"
|
||||
|
||||
def __init__( self ):
|
||||
self.data = {}
|
||||
self.node = {}
|
||||
self.edge = {}
|
||||
|
||||
def add_node( self, node ):
|
||||
"Add node to graph"
|
||||
self.data.setdefault( node, [] )
|
||||
def add_node( self, node, attr_dict=None, **attrs):
|
||||
"""Add node to graph
|
||||
attr_dict: attribute dict (optional)
|
||||
attrs: more attributes (optional)
|
||||
warning: updates attr_dict with attrs"""
|
||||
attr_dict = {} if attr_dict is None else attr_dict
|
||||
attr_dict.update( attrs )
|
||||
self.node[ node ] = attr_dict
|
||||
|
||||
def add_edge( self, src, dest ):
|
||||
"Add edge to graph"
|
||||
src, dest = sorted( ( src, dest ) )
|
||||
self.add_node( src )
|
||||
self.add_node( dest )
|
||||
self.data[ src ].append( dest )
|
||||
def add_edge( self, src, dst, key=None, attr_dict=None, **attrs ):
|
||||
"""Add edge to graph
|
||||
key: optional key
|
||||
attr_dict: optional attribute dict
|
||||
attrs: more attributes
|
||||
warning: udpates attr_dict with attrs"""
|
||||
attr_dict = {} if attr_dict is None else attr_dict
|
||||
attr_dict.update( attrs )
|
||||
self.node.setdefault( src, {} )
|
||||
self.node.setdefault( dst, {} )
|
||||
self.edge.setdefault( src, {} )
|
||||
self.edge.setdefault( dst, {} )
|
||||
self.edge[ src ].setdefault( dst, {} )
|
||||
entry = self.edge[ dst ][ src ] = self.edge[ src ][ dst ]
|
||||
# If no key, pick next ordinal number
|
||||
if key is None:
|
||||
keys = [ k for k in entry.keys() if isinstance( k, int ) ]
|
||||
key = max( [ 0 ] + keys ) + 1
|
||||
entry[ key ] = attr_dict
|
||||
return key
|
||||
|
||||
def nodes( self ):
|
||||
"Return list of graph nodes"
|
||||
return self.data.keys()
|
||||
def nodes( self, data=False):
|
||||
"""Return list of graph nodes
|
||||
data: return list of ( node, attrs)"""
|
||||
return self.node.items() if data else self.node.keys()
|
||||
|
||||
def edges( self ):
|
||||
def edges_iter( self, data=False, keys=False ):
|
||||
"Iterator: return graph edges"
|
||||
for src in self.data.keys():
|
||||
for dest in self.data[ src ]:
|
||||
yield ( src, dest )
|
||||
for src, entry in self.edge.iteritems():
|
||||
for dst, keys in entry.iteritems():
|
||||
if src > dst:
|
||||
# Skip duplicate edges
|
||||
continue
|
||||
for k, attrs in keys.iteritems():
|
||||
if data:
|
||||
if keys:
|
||||
yield( src, dst, k, attrs )
|
||||
else:
|
||||
yield( src, dst, attrs )
|
||||
else:
|
||||
if keys:
|
||||
yield( src, dst, k )
|
||||
else:
|
||||
yield( src, dst )
|
||||
|
||||
def edges( self, data=False, keys=False ):
|
||||
"Return list of graph edges"
|
||||
return list( self.edges_iter( data=data, keys=keys ) )
|
||||
|
||||
def __getitem__( self, node ):
|
||||
"Return link dict for the given node"
|
||||
return self.data[node]
|
||||
"Return link dict for given src node"
|
||||
return self.edge[ node ]
|
||||
|
||||
def __len__( self ):
|
||||
"Return the number of nodes"
|
||||
return len( self.node )
|
||||
|
||||
def convertTo( self, cls, data=False, keys=False ):
|
||||
"""Convert to a new object of networkx.MultiGraph-like class cls
|
||||
data: include node and edge data
|
||||
keys: include edge keys as well as edge data"""
|
||||
g = cls()
|
||||
g.add_nodes_from( self.nodes( data=data ) )
|
||||
g.add_edges_from( self.edges( data=( data or keys ), keys=keys ) )
|
||||
return g
|
||||
|
||||
|
||||
class Topo(object):
|
||||
class Topo( object ):
|
||||
"Data center network representation for structured multi-trees."
|
||||
|
||||
def __init__(self, hopts=None, sopts=None, lopts=None):
|
||||
"""Topo object:
|
||||
def __init__( self, *args, **params ):
|
||||
"""Topo object.
|
||||
Optional named parameters:
|
||||
hinfo: default host options
|
||||
sopts: default switch options
|
||||
lopts: default link options"""
|
||||
lopts: default link options
|
||||
calls build()"""
|
||||
self.g = MultiGraph()
|
||||
self.node_info = {}
|
||||
self.link_info = {} # (src, dst) tuples hash to EdgeInfo objects
|
||||
self.hopts = {} if hopts is None else hopts
|
||||
self.sopts = {} if sopts is None else sopts
|
||||
self.lopts = {} if lopts is None else lopts
|
||||
self.ports = {} # ports[src][dst] is port on src that connects to dst
|
||||
self.hopts = params.pop( 'hopts', {} )
|
||||
self.sopts = params.pop( 'sopts', {} )
|
||||
self.lopts = params.pop( 'lopts', {} )
|
||||
# ports[src][dst][sport] is port on dst that connects to src
|
||||
self.ports = {}
|
||||
self.build( *args, **params )
|
||||
|
||||
def addNode(self, name, **opts):
|
||||
def build( self, *args, **params ):
|
||||
"Override this method to build your topology."
|
||||
pass
|
||||
|
||||
def addNode( self, name, **opts ):
|
||||
"""Add Node to graph.
|
||||
name: name
|
||||
opts: node options
|
||||
returns: node name"""
|
||||
self.g.add_node(name)
|
||||
self.node_info[name] = opts
|
||||
self.g.add_node( name, **opts )
|
||||
return name
|
||||
|
||||
def addHost(self, name, **opts):
|
||||
def addHost( self, name, **opts ):
|
||||
"""Convenience method: Add host to graph.
|
||||
name: host name
|
||||
opts: host options
|
||||
returns: host name"""
|
||||
if not opts and self.hopts:
|
||||
opts = self.hopts
|
||||
return self.addNode(name, **opts)
|
||||
return self.addNode( name, **opts )
|
||||
|
||||
def addSwitch(self, name, **opts):
|
||||
def addSwitch( self, name, **opts ):
|
||||
"""Convenience method: Add switch to graph.
|
||||
name: switch name
|
||||
opts: switch options
|
||||
returns: switch name"""
|
||||
if not opts and self.sopts:
|
||||
opts = self.sopts
|
||||
result = self.addNode(name, isSwitch=True, **opts)
|
||||
result = self.addNode( name, isSwitch=True, **opts )
|
||||
return result
|
||||
|
||||
def addLink(self, node1, node2, port1=None, port2=None,
|
||||
**opts):
|
||||
def addLink( self, node1, node2, port1=None, port2=None,
|
||||
key=None, **opts ):
|
||||
"""node1, node2: nodes to link together
|
||||
port1, port2: ports (optional)
|
||||
opts: link options (optional)
|
||||
returns: link info key"""
|
||||
if not opts and self.lopts:
|
||||
opts = self.lopts
|
||||
self.addPort(node1, node2, port1, port2)
|
||||
key = tuple(self.sorted([node1, node2]))
|
||||
self.link_info[key] = opts
|
||||
self.g.add_edge(*key)
|
||||
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
|
||||
|
||||
def addPort(self, src, dst, sport=None, dport=None):
|
||||
'''Generate port mapping for new edge.
|
||||
@param src source switch name
|
||||
@param dst destination switch name
|
||||
'''
|
||||
self.ports.setdefault(src, {})
|
||||
self.ports.setdefault(dst, {})
|
||||
# New port: number of outlinks + base
|
||||
src_base = 1 if self.isSwitch(src) else 0
|
||||
dst_base = 1 if self.isSwitch(dst) else 0
|
||||
if sport is None:
|
||||
sport = len(self.ports[src]) + src_base
|
||||
if dport is None:
|
||||
dport = len(self.ports[dst]) + dst_base
|
||||
self.ports[src][dst] = sport
|
||||
self.ports[dst][src] = dport
|
||||
|
||||
def nodes(self, sort=True):
|
||||
def nodes( self, sort=True ):
|
||||
"Return nodes in graph"
|
||||
if sort:
|
||||
return self.sorted( self.g.nodes() )
|
||||
else:
|
||||
return self.g.nodes()
|
||||
|
||||
def isSwitch(self, n):
|
||||
'''Returns true if node is a switch.'''
|
||||
info = self.node_info[n]
|
||||
return info and info.get('isSwitch', False)
|
||||
def isSwitch( self, n ):
|
||||
"Returns true if node is a switch."
|
||||
return self.g.node[ n ].get( 'isSwitch', False )
|
||||
|
||||
def switches(self, sort=True):
|
||||
'''Return switches.
|
||||
sort: sort switches alphabetically
|
||||
@return dpids list of dpids
|
||||
'''
|
||||
return [n for n in self.nodes(sort) if self.isSwitch(n)]
|
||||
def switches( self, sort=True ):
|
||||
"""Return switches.
|
||||
sort: sort switches alphabetically
|
||||
returns: dpids list of dpids"""
|
||||
return [ n for n in self.nodes( sort ) if self.isSwitch( n ) ]
|
||||
|
||||
def hosts(self, sort=True):
|
||||
'''Return hosts.
|
||||
sort: sort hosts alphabetically
|
||||
@return dpids list of dpids
|
||||
'''
|
||||
return [n for n in self.nodes(sort) if not self.isSwitch(n)]
|
||||
def hosts( self, sort=True ):
|
||||
"""Return hosts.
|
||||
sort: sort hosts alphabetically
|
||||
returns: list of hosts"""
|
||||
return [ n for n in self.nodes( sort ) if not self.isSwitch( n ) ]
|
||||
|
||||
def links(self, sort=True):
|
||||
'''Return links.
|
||||
sort: sort links alphabetically
|
||||
@return links list of name pairs
|
||||
'''
|
||||
def iterLinks( self, withKeys=False, withInfo=False ):
|
||||
"""Return links (iterator)
|
||||
withKeys: return link keys
|
||||
withInfo: return link info
|
||||
returns: list of ( src, dst [,key, info ] )"""
|
||||
for _src, _dst, key, info in self.g.edges_iter( data=True, keys=True ):
|
||||
node1, node2 = info[ 'node1' ], info[ 'node2' ]
|
||||
if withKeys:
|
||||
if withInfo:
|
||||
yield( node1, node2, key, info )
|
||||
else:
|
||||
yield( node1, node2, key )
|
||||
else:
|
||||
if withInfo:
|
||||
yield( node1, node2, info )
|
||||
else:
|
||||
yield( node1, node2 )
|
||||
|
||||
def links( self, sort=False, withKeys=False, withInfo=False ):
|
||||
"""Return links
|
||||
sort: sort links alphabetically, preserving (src, dst) order
|
||||
withKeys: return link keys
|
||||
withInfo: return link info
|
||||
returns: list of ( src, dst [,key, info ] )"""
|
||||
links = list( self.iterLinks( withKeys, withInfo ) )
|
||||
if not sort:
|
||||
return self.g.edges()
|
||||
else:
|
||||
links = [tuple(self.sorted(e)) for e in self.g.edges()]
|
||||
return sorted( links, key=naturalSeq )
|
||||
return links
|
||||
# Ignore info when sorting
|
||||
tupleSize = 3 if withKeys else 2
|
||||
return sorted( links, key=( lambda l: naturalSeq( l[ :tupleSize ] ) ) )
|
||||
|
||||
def port(self, src, dst):
|
||||
'''Get port number.
|
||||
# This legacy port management mechanism is clunky and will probably
|
||||
# be removed at some point.
|
||||
|
||||
@param src source switch name
|
||||
@param dst destination switch name
|
||||
@return tuple (src_port, dst_port):
|
||||
src_port: port on source switch leading to the destination switch
|
||||
dst_port: port on destination switch leading to the source switch
|
||||
'''
|
||||
if src in self.ports and dst in self.ports[src]:
|
||||
assert dst in self.ports and src in self.ports[dst]
|
||||
return (self.ports[src][dst], self.ports[dst][src])
|
||||
def addPort( self, src, dst, sport=None, dport=None ):
|
||||
"""Generate port mapping for new edge.
|
||||
src: source switch name
|
||||
dst: destination switch name"""
|
||||
# Initialize if necessary
|
||||
ports = self.ports
|
||||
ports.setdefault( src, {} )
|
||||
ports.setdefault( dst, {} )
|
||||
# New port: number of outlinks + base
|
||||
if sport is None:
|
||||
src_base = 1 if self.isSwitch( src ) else 0
|
||||
sport = len( ports[ src ] ) + src_base
|
||||
if dport is None:
|
||||
dst_base = 1 if self.isSwitch( dst ) else 0
|
||||
dport = len( ports[ dst ] ) + dst_base
|
||||
ports[ src ][ sport ] = ( dst, dport )
|
||||
ports[ dst ][ dport ] = ( src, sport )
|
||||
return sport, dport
|
||||
|
||||
def linkInfo( self, src, dst ):
|
||||
"Return link metadata"
|
||||
src, dst = self.sorted([src, dst])
|
||||
return self.link_info[(src, dst)]
|
||||
def port( self, src, dst ):
|
||||
"""Get port numbers.
|
||||
src: source switch name
|
||||
dst: destination switch name
|
||||
sport: optional source port (otherwise use lowest src port)
|
||||
returns: tuple (sport, dport), where
|
||||
sport = port on source switch leading to the destination switch
|
||||
dport = port on destination switch leading to the source switch
|
||||
Note that you can also look up ports using linkInfo()"""
|
||||
# A bit ugly and slow vs. single-link implementation ;-(
|
||||
ports = [ ( sport, entry[ 1 ] )
|
||||
for sport, entry in self.ports[ src ].items()
|
||||
if entry[ 0 ] == dst ]
|
||||
return ports if len( ports ) != 1 else ports[ 0 ]
|
||||
|
||||
def setlinkInfo( self, src, dst, info ):
|
||||
"Set link metadata"
|
||||
src, dst = self.sorted([src, dst])
|
||||
self.link_info[(src, dst)] = info
|
||||
def _linkEntry( self, src, dst, key=None ):
|
||||
"Helper function: return link entry and key"
|
||||
entry = self.g[ src ][ dst ]
|
||||
if key is None:
|
||||
key = min( entry )
|
||||
return entry, key
|
||||
|
||||
def linkInfo( self, src, dst, key=None ):
|
||||
"Return link metadata dict"
|
||||
entry, key = self._linkEntry( src, dst, key )
|
||||
return entry[ key ]
|
||||
|
||||
def setlinkInfo( self, src, dst, info, key=None ):
|
||||
"Set link metadata dict"
|
||||
entry, key = self._linkEntry( src, dst, key )
|
||||
entry[ key ] = info
|
||||
|
||||
def nodeInfo( self, name ):
|
||||
"Return metadata (dict) for node"
|
||||
info = self.node_info[ name ]
|
||||
return info if info is not None else {}
|
||||
return self.g.node[ name ]
|
||||
|
||||
def setNodeInfo( self, name, info ):
|
||||
"Set metadata (dict) for node"
|
||||
self.node_info[ name ] = info
|
||||
self.g.node[ name ] = info
|
||||
|
||||
def convertTo( self, cls, data=True, keys=True ):
|
||||
"""Convert to a new object of networkx.MultiGraph-like class cls
|
||||
data: include node and edge data (default True)
|
||||
keys: include edge keys as well as edge data (default True)"""
|
||||
return self.g.convertTo( cls, data=data, keys=keys )
|
||||
|
||||
@staticmethod
|
||||
def sorted( items ):
|
||||
"Items sorted in natural (i.e. alphabetical) order"
|
||||
return sorted(items, key=natural)
|
||||
return sorted( items, key=natural )
|
||||
|
||||
class SingleSwitchTopo(Topo):
|
||||
'''Single switch connected to k hosts.'''
|
||||
|
||||
def __init__(self, k=2, **opts):
|
||||
'''Init.
|
||||
# Our idiom defines additional parameters in build(param...)
|
||||
# pylint: disable=arguments-differ
|
||||
|
||||
@param k number of hosts
|
||||
@param enable_all enables all nodes and switches?
|
||||
'''
|
||||
super(SingleSwitchTopo, self).__init__(**opts)
|
||||
class SingleSwitchTopo( Topo ):
|
||||
"Single switch connected to k hosts."
|
||||
|
||||
def build( self, k=2, **_opts ):
|
||||
"k: number of hosts"
|
||||
self.k = k
|
||||
|
||||
switch = self.addSwitch('s1')
|
||||
for h in irange(1, k):
|
||||
host = self.addHost('h%s' % h)
|
||||
self.addLink(host, switch)
|
||||
switch = self.addSwitch( 's1' )
|
||||
for h in irange( 1, k ):
|
||||
host = self.addHost( 'h%s' % h )
|
||||
self.addLink( host, switch )
|
||||
|
||||
|
||||
class SingleSwitchReversedTopo(Topo):
|
||||
'''Single switch connected to k hosts, with reversed ports.
|
||||
class SingleSwitchReversedTopo( Topo ):
|
||||
"""Single switch connected to k hosts, with reversed ports.
|
||||
The lowest-numbered host is connected to the highest-numbered port.
|
||||
Useful to verify that Mininet properly handles custom port
|
||||
numberings."""
|
||||
|
||||
The lowest-numbered host is connected to the highest-numbered port.
|
||||
|
||||
Useful to verify that Mininet properly handles custom port numberings.
|
||||
'''
|
||||
def __init__(self, k=2, **opts):
|
||||
'''Init.
|
||||
|
||||
@param k number of hosts
|
||||
@param enable_all enables all nodes and switches?
|
||||
'''
|
||||
super(SingleSwitchReversedTopo, self).__init__(**opts)
|
||||
def build( self, k=2 ):
|
||||
"k: number of hosts"
|
||||
self.k = k
|
||||
switch = self.addSwitch('s1')
|
||||
for h in irange(1, k):
|
||||
host = self.addHost('h%s' % h)
|
||||
self.addLink(host, switch,
|
||||
port1=0, port2=(k - h + 1))
|
||||
switch = self.addSwitch( 's1' )
|
||||
for h in irange( 1, k ):
|
||||
host = self.addHost( 'h%s' % h )
|
||||
self.addLink( host, switch,
|
||||
port1=0, port2=( k - h + 1 ) )
|
||||
|
||||
class LinearTopo(Topo):
|
||||
|
||||
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."
|
||||
|
||||
def __init__(self, k=2, n=1, **opts):
|
||||
"""Init.
|
||||
k: number of switches
|
||||
n: number of hosts per switch
|
||||
hconf: host configuration options
|
||||
lconf: link configuration options"""
|
||||
|
||||
super(LinearTopo, self).__init__(**opts)
|
||||
|
||||
def build( self, k=2, n=1, **_opts):
|
||||
"""k: number of switches
|
||||
n: number of hosts per switch"""
|
||||
self.k = k
|
||||
self.n = n
|
||||
|
||||
if n == 1:
|
||||
genHostName = lambda i, j: 'h%s' % i
|
||||
else:
|
||||
genHostName = lambda i, j: 'h%ss%d' % (j, i)
|
||||
|
||||
genHostName = lambda i, j: 'h%ss%d' % ( j, i )
|
||||
|
||||
lastSwitch = None
|
||||
for i in irange(1, k):
|
||||
for i in irange( 1, k ):
|
||||
# Add switch
|
||||
switch = self.addSwitch('s%s' % i)
|
||||
switch = self.addSwitch( 's%s' % i )
|
||||
# Add hosts to switch
|
||||
for j in irange(1, n):
|
||||
host = self.addHost(genHostName(i, j))
|
||||
self.addLink(host, switch)
|
||||
for j in irange( 1, n ):
|
||||
host = self.addHost( genHostName( i, j ) )
|
||||
self.addLink( host, switch )
|
||||
# Connect switch to previous
|
||||
if lastSwitch:
|
||||
self.addLink(switch, lastSwitch)
|
||||
self.addLink( switch, lastSwitch )
|
||||
lastSwitch = switch
|
||||
|
||||
# pylint: enable=arguments-differ
|
||||
|
||||
+47
-2
@@ -3,11 +3,13 @@
|
||||
from mininet.topo import Topo
|
||||
from mininet.net import Mininet
|
||||
|
||||
# The build() method is expected to do this:
|
||||
# pylint: disable=arguments-differ
|
||||
|
||||
class TreeTopo( Topo ):
|
||||
"Topology for a tree network with a given depth and fanout."
|
||||
|
||||
def __init__( self, depth=1, fanout=2 ):
|
||||
super( TreeTopo, self ).__init__()
|
||||
def build( self, depth=1, fanout=2 ):
|
||||
# Numbering: h1..N, s1..M
|
||||
self.hostNum = 1
|
||||
self.switchNum = 1
|
||||
@@ -34,3 +36,46 @@ def TreeNet( depth=1, fanout=2, **kwargs ):
|
||||
"Convenience function for creating tree networks."
|
||||
topo = TreeTopo( depth, fanout )
|
||||
return Mininet( topo, **kwargs )
|
||||
|
||||
|
||||
class TorusTopo( Topo ):
|
||||
"""2-D Torus topology
|
||||
WARNING: this topology has LOOPS and WILL NOT WORK
|
||||
with the default controller or any Ethernet bridge
|
||||
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, 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:
|
||||
genHostName = lambda loc, k: 'h%s' % ( loc )
|
||||
else:
|
||||
genHostName = lambda loc, k: 'h%sx%d' % ( loc, k )
|
||||
|
||||
hosts, switches, dpid = {}, {}, 0
|
||||
# Create and wire interior
|
||||
for i in range( 0, x ):
|
||||
for j in range( 0, y ):
|
||||
loc = '%dx%d' % ( i + 1, j + 1 )
|
||||
# dpid cannot be zero for OVS
|
||||
dpid = ( i + 1 ) * 256 + ( j + 1 )
|
||||
switch = switches[ i, j ] = self.addSwitch(
|
||||
'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 ):
|
||||
sw1 = switches[ i, j ]
|
||||
sw2 = switches[ i, ( j + 1 ) % y ]
|
||||
sw3 = switches[ ( i + 1 ) % x, j ]
|
||||
self.addLink( sw1, sw2 )
|
||||
self.addLink( sw1, sw3 )
|
||||
|
||||
# pylint: enable=arguments-differ
|
||||
|
||||
+170
-69
@@ -10,6 +10,7 @@ import re
|
||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||
from os import O_NONBLOCK
|
||||
import os
|
||||
from functools import partial
|
||||
|
||||
# Command execution support
|
||||
|
||||
@@ -24,7 +25,7 @@ def checkRun( cmd ):
|
||||
return check_call( cmd.split( ' ' ) )
|
||||
|
||||
# pylint doesn't understand explicit type checking
|
||||
# pylint: disable-msg=E1103
|
||||
# pylint: disable=maybe-no-member
|
||||
|
||||
def oldQuietRun( *cmd ):
|
||||
"""Run a command, routing stderr to stdout, and return the output.
|
||||
@@ -55,18 +56,13 @@ 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
|
||||
def errRun( *cmd, **kwargs ):
|
||||
"""Run a command and return stdout, stderr and return code
|
||||
cmd: string or list of command and args
|
||||
stderr: STDOUT to merge stderr with stdout
|
||||
shell: run command using shell
|
||||
echo: monitor output to console"""
|
||||
# Allow passing in a list or a string
|
||||
if len( cmd ) == 1:
|
||||
cmd = cmd[ 0 ]
|
||||
if isinstance( cmd, str ):
|
||||
cmd = cmd.split( ' ' )
|
||||
cmd = [ str( arg ) for arg in cmd ]
|
||||
# By default we separate stderr, don't run in a shell, and don't echo
|
||||
stderr = kwargs.get( 'stderr', PIPE )
|
||||
shell = kwargs.get( 'shell', False )
|
||||
@@ -74,6 +70,15 @@ def errRun( *cmd, **kwargs ):
|
||||
if echo:
|
||||
# cmd goes to stderr, output goes to stdout
|
||||
info( cmd, '\n' )
|
||||
if len( cmd ) == 1:
|
||||
cmd = cmd[ 0 ]
|
||||
# Allow passing in a list or a string
|
||||
if isinstance( cmd, str ) 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' )
|
||||
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
|
||||
@@ -88,21 +93,31 @@ def errRun( *cmd, **kwargs ):
|
||||
errDone = False
|
||||
while not outDone or not errDone:
|
||||
readable = poller.poll()
|
||||
for fd, _event in readable:
|
||||
for fd, event in readable:
|
||||
f = fdtofile[ fd ]
|
||||
data = f.read( 1024 )
|
||||
if echo:
|
||||
output( data )
|
||||
if f == popen.stdout:
|
||||
out += data
|
||||
if data == '':
|
||||
if event & POLLIN:
|
||||
data = f.read( 1024 )
|
||||
if echo:
|
||||
output( data )
|
||||
if f == popen.stdout:
|
||||
out += data
|
||||
if data == '':
|
||||
outDone = True
|
||||
elif f == popen.stderr:
|
||||
err += data
|
||||
if data == '':
|
||||
errDone = True
|
||||
else: # POLLHUP or something unexpected
|
||||
if f == popen.stdout:
|
||||
outDone = True
|
||||
elif f == popen.stderr:
|
||||
err += data
|
||||
if data == '':
|
||||
elif f == popen.stderr:
|
||||
errDone = True
|
||||
poller.unregister( fd )
|
||||
|
||||
returncode = popen.wait()
|
||||
debug( out, err, returncode )
|
||||
return out, err, returncode
|
||||
# pylint: enable=too-many-branches
|
||||
|
||||
def errFail( *cmd, **kwargs ):
|
||||
"Run a command using errRun and raise exception on nonzero exit"
|
||||
@@ -116,8 +131,7 @@ def quietRun( cmd, **kwargs ):
|
||||
"Run a command and return merged stdout and stderr"
|
||||
return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ]
|
||||
|
||||
# pylint: enable-msg=E1103
|
||||
# pylint: disable-msg=E1101
|
||||
# pylint: enable=maybe-no-member
|
||||
|
||||
def isShellBuiltin( cmd ):
|
||||
"Return True if cmd is a bash builtin."
|
||||
@@ -130,8 +144,6 @@ def isShellBuiltin( cmd ):
|
||||
|
||||
isShellBuiltin.builtIns = None
|
||||
|
||||
# pylint: enable-msg=E1101
|
||||
|
||||
# Interface management
|
||||
#
|
||||
# Interfaces are managed as strings which are simply the
|
||||
@@ -145,17 +157,41 @@ isShellBuiltin.builtIns = None
|
||||
# live in the root namespace and thus do not have to be
|
||||
# explicitly moved.
|
||||
|
||||
def makeIntfPair( intf1, intf2 ):
|
||||
"""Make a veth pair connecting intf1 and intf2.
|
||||
intf1: string, interface
|
||||
intf2: string, interface
|
||||
returns: success boolean"""
|
||||
# Delete any old interfaces with the same names
|
||||
quietRun( 'ip link del ' + intf1 )
|
||||
quietRun( 'ip link del ' + intf2 )
|
||||
def makeIntfPair( intf1, intf2, addr1=None, addr2=None, node1=None, node2=None,
|
||||
deleteIntfs=True, runCmd=None ):
|
||||
"""Make a veth pair connnecting new interfaces intf1 and intf2
|
||||
intf1: name for interface 1
|
||||
intf2: name for interface 2
|
||||
addr1: MAC address for interface 1 (optional)
|
||||
addr2: MAC address for interface 2 (optional)
|
||||
node1: home node for interface 1 (optional)
|
||||
node2: home node for interface 2 (optional)
|
||||
deleteIntfs: delete intfs before creating them
|
||||
runCmd: function to run shell commands (quietRun)
|
||||
raises Exception on failure"""
|
||||
if not runCmd:
|
||||
runCmd = quietRun if not node1 else node1.cmd
|
||||
runCmd2 = quietRun if not node2 else node2.cmd
|
||||
if deleteIntfs:
|
||||
# Delete any old interfaces with the same names
|
||||
runCmd( 'ip link del ' + intf1 )
|
||||
runCmd2( 'ip link del ' + intf2 )
|
||||
# Create new pair
|
||||
cmd = 'ip link add name ' + intf1 + ' type veth peer name ' + intf2
|
||||
return quietRun( cmd )
|
||||
netns = 1 if not node2 else node2.pid
|
||||
if addr1 is None and addr2 is None:
|
||||
cmdOutput = runCmd( 'ip link add name %s '
|
||||
'type veth peer name %s '
|
||||
'netns %s' % ( intf1, intf2, netns ) )
|
||||
else:
|
||||
cmdOutput = runCmd( 'ip link add name %s '
|
||||
'address %s '
|
||||
'type veth peer name %s '
|
||||
'address %s '
|
||||
'netns %s' %
|
||||
( intf1, addr1, intf2, addr2, netns ) )
|
||||
if cmdOutput:
|
||||
raise Exception( "Error creating interface pair (%s,%s): %s " %
|
||||
( intf1, intf2, cmdOutput ) )
|
||||
|
||||
def retry( retries, delaySecs, fn, *args, **keywords ):
|
||||
"""Try something several times before giving up.
|
||||
@@ -171,35 +207,32 @@ def retry( retries, delaySecs, fn, *args, **keywords ):
|
||||
error( "*** gave up after %i retries\n" % tries )
|
||||
exit( 1 )
|
||||
|
||||
def moveIntfNoRetry( intf, dstNode, srcNode=None, printError=False ):
|
||||
def moveIntfNoRetry( intf, dstNode, printError=False ):
|
||||
"""Move interface to node, without retrying.
|
||||
intf: string, interface
|
||||
dstNode: destination Node
|
||||
srcNode: source Node or None (default) for root ns
|
||||
printError: if true, print error"""
|
||||
intf = str( intf )
|
||||
cmd = 'ip link set %s netns %s' % ( intf, dstNode.pid )
|
||||
if srcNode:
|
||||
srcNode.cmd( cmd )
|
||||
else:
|
||||
quietRun( cmd )
|
||||
links = dstNode.cmd( 'ip link show' )
|
||||
if not ( ' %s:' % intf ) in links:
|
||||
cmdOutput = quietRun( cmd )
|
||||
# If ip link set does not produce any output, then we can assume
|
||||
# that the link has been moved successfully.
|
||||
if cmdOutput:
|
||||
if printError:
|
||||
error( '*** Error: moveIntf: ' + intf +
|
||||
' not successfully moved to ' + dstNode.name + '\n' )
|
||||
' not successfully moved to ' + dstNode.name + ':\n',
|
||||
cmdOutput )
|
||||
return False
|
||||
return True
|
||||
|
||||
def moveIntf( intf, dstNode, srcNode=None, printError=False,
|
||||
retries=3, delaySecs=0.001 ):
|
||||
def moveIntf( intf, dstNode, printError=True,
|
||||
retries=3, delaySecs=0.001 ):
|
||||
"""Move interface to node, retrying on failure.
|
||||
intf: string, interface
|
||||
dstNode: destination Node
|
||||
srcNode: source Node or None (default) for root ns
|
||||
printError: if true, print error"""
|
||||
retry( retries, delaySecs, moveIntfNoRetry, intf, dstNode,
|
||||
srcNode=srcNode, printError=printError )
|
||||
printError=printError )
|
||||
|
||||
# Support for dumping network
|
||||
|
||||
@@ -227,6 +260,15 @@ def dumpNetConnections( net ):
|
||||
nodes = net.controllers + net.switches + net.hosts
|
||||
dumpNodeConnections( nodes )
|
||||
|
||||
def dumpPorts( switches ):
|
||||
"dump interface to openflow port mappings for each switch"
|
||||
for switch in switches:
|
||||
output( '%s ' % switch.name )
|
||||
for intf in switch.intfList():
|
||||
port = switch.ports[ intf ]
|
||||
output( '%s:%d ' % ( intf, port ) )
|
||||
output( '\n' )
|
||||
|
||||
# IP and Mac address formatting and parsing
|
||||
|
||||
def _colonHex( val, bytecount ):
|
||||
@@ -269,7 +311,7 @@ def ipAdd( i, prefixLen=8, ipBaseNum=0x0a000000 ):
|
||||
ipBaseNum: option base IP address as int
|
||||
returns IP address as string"""
|
||||
imax = 0xffffffff >> prefixLen
|
||||
assert i <= imax
|
||||
assert i <= imax, 'Not enough IP addresses in the subnet'
|
||||
mask = 0xffffffff ^ imax
|
||||
ipnum = ( ipBaseNum & mask ) + i
|
||||
return ipStr( ipnum )
|
||||
@@ -277,6 +319,8 @@ def ipAdd( i, prefixLen=8, ipBaseNum=0x0a000000 ):
|
||||
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 )
|
||||
return ipNum( *args )
|
||||
|
||||
def netParse( ipstr ):
|
||||
@@ -286,6 +330,10 @@ def netParse( ipstr ):
|
||||
if '/' in ipstr:
|
||||
ip, pf = ipstr.split( '/' )
|
||||
prefixLen = int( pf )
|
||||
#if no prefix is specified, set the prefix to 24
|
||||
else:
|
||||
ip = ipstr
|
||||
prefixLen = 24
|
||||
return ipParse( ip ), prefixLen
|
||||
|
||||
def checkInt( s ):
|
||||
@@ -363,7 +411,7 @@ def sysctlTestAndSet( name, limit ):
|
||||
#read limit
|
||||
with open( name, 'r' ) as readFile:
|
||||
oldLimit = readFile.readline()
|
||||
if type( limit ) is int:
|
||||
if isinstance( limit, int ):
|
||||
#compare integer limits before overriding
|
||||
if int( oldLimit ) < limit:
|
||||
with open( name, 'w' ) as writeFile:
|
||||
@@ -402,9 +450,12 @@ def fixLimits():
|
||||
sysctlTestAndSet( 'net.ipv4.route.max_size', 32768 )
|
||||
#Increase number of PTYs for nodes
|
||||
sysctlTestAndSet( 'kernel.pty.max', 20000 )
|
||||
except:
|
||||
# pylint: disable=broad-except
|
||||
except Exception:
|
||||
warn( "*** Error setting resource limits. "
|
||||
"Mininet's performance may be affected.\n" )
|
||||
# pylint: enable=broad-except
|
||||
|
||||
|
||||
def mountCgroups():
|
||||
"Make sure cgroups file system is mounted"
|
||||
@@ -423,7 +474,7 @@ def natural( text ):
|
||||
def num( s ):
|
||||
"Convert text segment to int if necessary"
|
||||
return int( s ) if s.isdigit() else s
|
||||
return [ num( s ) for s in re.split( r'(\d+)', text ) ]
|
||||
return [ num( s ) for s in re.split( r'(\d+)', str( text ) ) ]
|
||||
|
||||
def naturalSeq( t ):
|
||||
"Natural sort key function for sequences"
|
||||
@@ -472,31 +523,54 @@ 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
|
||||
|
||||
def customized( name, *args, **params ):
|
||||
"Customized constructor, useful for Node, Link, and other classes"
|
||||
params = params.copy()
|
||||
params.update( kwargs )
|
||||
if not newargs:
|
||||
return constructor( name, *args, **params )
|
||||
if args:
|
||||
warn( 'warning: %s replacing %s with %s\n' % (
|
||||
constructor, args, newargs ) )
|
||||
return constructor( name, *newargs, **params )
|
||||
return specialClass( cls, append=args, defaults=kwargs )
|
||||
|
||||
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"""
|
||||
|
||||
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 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__, defaults )
|
||||
return CustomClass
|
||||
|
||||
customized.__name__ = 'customConstructor(%s)' % argStr
|
||||
return customized
|
||||
|
||||
def buildTopo( topos, topoStr ):
|
||||
"""Create topology from string with format (object, arg1, arg2,...).
|
||||
@@ -516,3 +590,30 @@ def ensureRoot():
|
||||
print "*** Mininet must run as root."
|
||||
exit( 1 )
|
||||
return
|
||||
|
||||
def waitListening( client=None, server='127.0.0.1', port=80, timeout=None ):
|
||||
"""Wait until server is listening on port.
|
||||
returns True if server is listening"""
|
||||
runCmd = ( client.cmd if client else
|
||||
partial( quietRun, shell=True ) )
|
||||
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()
|
||||
cmd = ( 'echo A | telnet -e A %s %s' % ( serverIP, port ) )
|
||||
time = 0
|
||||
result = runCmd( cmd )
|
||||
while 'Connected' not in result:
|
||||
if 'No route' in result:
|
||||
rtable = runCmd( 'route' )
|
||||
error( 'no route to %s:\n%s' % ( server, rtable ) )
|
||||
return False
|
||||
if timeout and time >= timeout:
|
||||
error( 'could not connect to %s on port %d\n' % ( server, port ) )
|
||||
return False
|
||||
debug( 'waiting for', server, 'to listen on port', port, '\n' )
|
||||
info( '.' )
|
||||
sleep( .5 )
|
||||
time += .5
|
||||
result = runCmd( cmd )
|
||||
return True
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
* - closing all file descriptors except stdin/out/error
|
||||
* - detaching from a controlling tty using setsid
|
||||
* - running in a network namespace
|
||||
* - running in network and mount namespaces
|
||||
* - printing out the pid of a process so we can identify it later
|
||||
* - attaching to a namespace and cgroup
|
||||
* - setting RT scheduling
|
||||
@@ -23,21 +23,22 @@
|
||||
#include <stdlib.h>
|
||||
#include <sched.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#if !defined(VERSION)
|
||||
#define VERSION "(devel)"
|
||||
#endif
|
||||
|
||||
void usage(char *name)
|
||||
void usage(char *name)
|
||||
{
|
||||
printf("Execution utility for Mininet\n\n"
|
||||
"Usage: %s [-cdnp] [-a pid] [-g group] [-r rtprio] cmd args...\n\n"
|
||||
"Options:\n"
|
||||
" -c: close all file descriptors except stdin/out/error\n"
|
||||
" -d: detach from tty by calling setsid()\n"
|
||||
" -n: run in new network namespace\n"
|
||||
" -n: run in new network and mount namespaces\n"
|
||||
" -p: print ^A + pid\n"
|
||||
" -a pid: attach to pid's network namespace\n"
|
||||
" -a pid: attach to pid's network and mount namespaces\n"
|
||||
" -g group: add to cgroup\n"
|
||||
" -r rtprio: run with SCHED_RR (usually requires -g)\n"
|
||||
" -v: print version\n",
|
||||
@@ -98,6 +99,8 @@ int main(int argc, char *argv[])
|
||||
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) {
|
||||
@@ -122,11 +125,16 @@ int main(int argc, char *argv[])
|
||||
setsid();
|
||||
break;
|
||||
case 'n':
|
||||
/* run in network namespace */
|
||||
if (unshare(CLONE_NEWNET) == -1) {
|
||||
/* run in network and mount namespaces */
|
||||
if (unshare(CLONE_NEWNET|CLONE_NEWNS) == -1) {
|
||||
perror("unshare");
|
||||
return 1;
|
||||
}
|
||||
/* mount sysfs to pick up the new network namespace */
|
||||
if (mount("sysfs", "/sys", "sysfs", MS_MGC_VAL, NULL) == -1) {
|
||||
perror("mount");
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
/* print pid */
|
||||
@@ -134,9 +142,9 @@ int main(int argc, char *argv[])
|
||||
fflush(stdout);
|
||||
break;
|
||||
case 'a':
|
||||
/* Attach to pid's network namespace */
|
||||
/* Attach to pid's network namespace and mount namespace */
|
||||
pid = atoi(optarg);
|
||||
sprintf(path, "/proc/%d/ns/net", pid );
|
||||
sprintf(path, "/proc/%d/ns/net", pid);
|
||||
nsid = open(path, O_RDONLY);
|
||||
if (nsid < 0) {
|
||||
perror(path);
|
||||
@@ -146,6 +154,22 @@ int main(int argc, char *argv[])
|
||||
perror("setns");
|
||||
return 1;
|
||||
}
|
||||
/* Plan A: call setns() to attach to mount namespace */
|
||||
sprintf(path, "/proc/%d/ns/mnt", pid);
|
||||
nsid = open(path, O_RDONLY);
|
||||
if (nsid < 0 || setns(nsid, 0) != 0) {
|
||||
/* Plan B: chroot/chdir into pid's root file system */
|
||||
sprintf(path, "/proc/%d/root", pid);
|
||||
if (chroot(path) < 0) {
|
||||
perror(path);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* chdir to correct working directory */
|
||||
if (chdir(cwd) != 0) {
|
||||
perror(cwd);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
/* Attach to cgroup */
|
||||
@@ -167,7 +191,7 @@ int main(int argc, char *argv[])
|
||||
exit(0);
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
@@ -175,7 +199,7 @@ int main(int argc, char *argv[])
|
||||
perror(argv[optind]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
usage(argv[0]);
|
||||
|
||||
return 0;
|
||||
|
||||
Executable
+182
@@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Mininet ssh authentication script for cluster edition
|
||||
# This script will create a single key pair, which is then
|
||||
# propagated throughout the entire cluster.
|
||||
# There are two options for setup; temporary setup
|
||||
# persistent setup. If no options are specified, and the script
|
||||
# is only given ip addresses or host names, it will default to
|
||||
# the temporary setup. An ssh directory is then created in
|
||||
# /tmp/mn/ssh on each node, and mounted with the keys over the
|
||||
# user's ssh directory. This setup can easily be torn down by running
|
||||
# clustersetup with the -c option.
|
||||
# If the -p option is used, the setup will be persistent. In this
|
||||
# case, the key pair will be be distributed directly to each node's
|
||||
# ssh directory, but will be called cluster_key. An option to
|
||||
# specify this key for use will be added to the config file in each
|
||||
# user's ssh directory.
|
||||
|
||||
|
||||
set -e
|
||||
num_options=0
|
||||
persistent=false
|
||||
showHelp=false
|
||||
clean=false
|
||||
declare -a hosts=()
|
||||
user=$(whoami)
|
||||
SSHDIR=/tmp/mn/ssh
|
||||
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
|
||||
$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
|
||||
$USERDIR directory
|
||||
-c: method to clean up a temporary ssh setup.
|
||||
Any hosts taken as arguments will be cleaned
|
||||
"
|
||||
|
||||
persistentSetup() {
|
||||
echo "***creating key pair"
|
||||
ssh-keygen -t rsa -C "Cluster_Edition_Key" -f $USERDIR/cluster_key -N '' &> /dev/null
|
||||
cat $USERDIR/cluster_key.pub >> $USERDIR/authorized_keys
|
||||
echo "***configuring ssh"
|
||||
echo "IdentityFile $USERDIR/cluster_key" >> $USERDIR/config
|
||||
echo "IdentityFile $USERDIR/id_rsa" >> $USERDIR/config
|
||||
|
||||
for host in $hosts; do
|
||||
echo "***copying public key to $host"
|
||||
ssh-copy-id -i $USERDIR/cluster_key.pub $user@$host &> /dev/null
|
||||
echo "***copying key pair to remote host"
|
||||
scp $USERDIR/cluster_key $user@$host:$USERDIR
|
||||
scp $USERDIR/cluster_key.pub $user@$host:$USERDIR
|
||||
echo "***configuring remote host"
|
||||
ssh -o ForwardAgent=yes $user@$host "
|
||||
echo 'IdentityFile $USERDIR/cluster_key' >> $USERDIR/config
|
||||
echo 'IdentityFile $USERDIR/id_rsa' >> $USERDIR/config"
|
||||
done
|
||||
|
||||
for host in $hosts; do
|
||||
echo "***copying known_hosts to $host"
|
||||
scp $USERDIR/known_hosts $user@$host:$USERDIR/cluster_known_hosts
|
||||
ssh $user@$host "
|
||||
cat $USERDIR/cluster_known_hosts >> $USERDIR/known_hosts
|
||||
rm $USERDIR/cluster_known_hosts"
|
||||
done
|
||||
}
|
||||
|
||||
tempSetup() {
|
||||
|
||||
echo "***creating temporary ssh directory"
|
||||
mkdir -p $SSHDIR
|
||||
echo "***creating key pair"
|
||||
ssh-keygen -t rsa -C "Cluster_Edition_Key" -f $SSHDIR/id_rsa -N '' &> /dev/null
|
||||
|
||||
echo "***mounting temporary ssh directory"
|
||||
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 $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
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
|
||||
for host in $hosts; do
|
||||
echo "***cleaning up $host"
|
||||
ssh $user@$host "sudo umount $USERDIR
|
||||
sudo rm -rf $SSHDIR"
|
||||
done
|
||||
|
||||
echo "**unmounting local directories"
|
||||
sudo umount $USERDIR
|
||||
echo "***removing temporary ssh directory"
|
||||
sudo rm -rf $SSHDIR
|
||||
echo "done!"
|
||||
|
||||
}
|
||||
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "ERROR: No Arguments"
|
||||
echo "$usage"
|
||||
exit
|
||||
else
|
||||
while getopts 'hpc' OPTION
|
||||
do
|
||||
((num_options+=1))
|
||||
case $OPTION in
|
||||
h) showHelp=true;;
|
||||
p) persistent=true;;
|
||||
c) clean=true;;
|
||||
?) showHelp=true;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
fi
|
||||
|
||||
if [ "$num_options" -gt 1 ]; then
|
||||
echo "ERROR: Too Many Options"
|
||||
echo "$usage"
|
||||
exit
|
||||
fi
|
||||
|
||||
if $showHelp; then
|
||||
echo "$usage"
|
||||
exit
|
||||
fi
|
||||
|
||||
for i in "$@"; do
|
||||
output=$(getent ahostsv4 "$i")
|
||||
if [ -z "$output" ]; then
|
||||
echo '***WARNING: could not find hostname "$i"'
|
||||
echo ""
|
||||
else
|
||||
hosts+="$i "
|
||||
fi
|
||||
done
|
||||
|
||||
if $clean; then
|
||||
cleanup
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "***authenticating to:"
|
||||
for host in $hosts; do
|
||||
echo "$host"
|
||||
done
|
||||
|
||||
echo
|
||||
|
||||
if $persistent; then
|
||||
echo '***Setting up persistent SSH configuration between all nodes'
|
||||
persistentSetup
|
||||
echo $'\n*** Sucessfully set up ssh throughout the cluster!'
|
||||
|
||||
else
|
||||
echo '*** Setting up temporary SSH configuration between all nodes'
|
||||
tempSetup
|
||||
echo $'\n***Finished temporary setup. When you are done with your cluster'
|
||||
echo $' session, tear down the SSH connections with'
|
||||
echo $' ./clustersetup.sh -c '$hosts''
|
||||
fi
|
||||
|
||||
echo
|
||||
+3
-3
@@ -30,7 +30,7 @@ def fixParam( line ):
|
||||
def fixReturns( line ):
|
||||
"Change returns: foo to @return foo"
|
||||
return re.sub( 'returns:', r'@returns', line )
|
||||
|
||||
|
||||
def fixLine( line ):
|
||||
global comment
|
||||
match = spaces.match( line )
|
||||
@@ -69,7 +69,7 @@ def funTest():
|
||||
).splitlines( True )
|
||||
|
||||
fixLines( testFun )
|
||||
|
||||
|
||||
def fixLines( lines, fid ):
|
||||
for line in lines:
|
||||
os.write( fid, fixLine( line ) )
|
||||
@@ -86,4 +86,4 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+211
-195
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Mininet install script for Ubuntu (and Debian Lenny)
|
||||
# Mininet install script for Ubuntu (and Debian Wheezy+)
|
||||
# Brandon Heller (brandonh@stanford.edu)
|
||||
|
||||
# Fail on error
|
||||
@@ -63,28 +63,28 @@ echo "Detected Linux distribution: $DIST $RELEASE $CODENAME $ARCH"
|
||||
|
||||
# Kernel params
|
||||
|
||||
if [ "$DIST" = "Ubuntu" ]; then
|
||||
if [ "$RELEASE" = "10.04" ]; then
|
||||
KERNEL_NAME='3.0.0-15-generic'
|
||||
else
|
||||
KERNEL_NAME=`uname -r`
|
||||
fi
|
||||
KERNEL_HEADERS=linux-headers-${KERNEL_NAME}
|
||||
elif [ "$DIST" = "Debian" ] && [ "$ARCH" = "i386" ] && [ "$CODENAME" = "lenny" ]; then
|
||||
KERNEL_NAME=2.6.33.1-mininet
|
||||
KERNEL_HEADERS=linux-headers-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
|
||||
KERNEL_IMAGE=linux-image-${KERNEL_NAME}_${KERNEL_NAME}-10.00.Custom_i386.deb
|
||||
elif [ "$DIST" = "Fedora" ]; then
|
||||
KERNEL_NAME=`uname -r`
|
||||
KERNEL_HEADERS=kernel-headers-${KERNEL_NAME}
|
||||
else
|
||||
echo "Install.sh currently only supports Ubuntu, Debian Lenny i386 and Fedora."
|
||||
KERNEL_NAME=`uname -r`
|
||||
KERNEL_HEADERS=kernel-headers-${KERNEL_NAME}
|
||||
|
||||
if ! echo $DIST | egrep 'Ubuntu|Debian|Fedora'; then
|
||||
echo "Install.sh currently only supports Ubuntu, Debian and Fedora."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# More distribution info
|
||||
DIST_LC=`echo $DIST | tr [A-Z] [a-z]` # as lower case
|
||||
|
||||
|
||||
# Determine whether version $1 >= version $2
|
||||
# usage: if version_ge 1.20 1.2.3; then echo "true!"; fi
|
||||
function version_ge {
|
||||
# sort -V sorts by *version number*
|
||||
latest=`printf "$1\n$2" | sort -V | tail -1`
|
||||
# If $1 is latest version, then $1 >= $2
|
||||
[ "$1" == "$latest" ]
|
||||
}
|
||||
|
||||
|
||||
# Kernel Deb pkg to be removed:
|
||||
KERNEL_IMAGE_OLD=linux-image-2.6.26-33-generic
|
||||
|
||||
@@ -96,42 +96,15 @@ OVS_BUILDSUFFIX=-ignore # was -2
|
||||
OVS_PACKAGE_NAME=ovs-$OVS_RELEASE-core-$DIST_LC-$RELEASE-$ARCH$OVS_BUILDSUFFIX.tar
|
||||
OVS_TAG=v$OVS_RELEASE
|
||||
|
||||
IVS_TAG=v0.3
|
||||
|
||||
# Command-line versions overrides that simplify custom VM creation
|
||||
# To use, pass in the vars on the cmd line before install.sh, e.g.
|
||||
# WS_DISSECTOR_REV=pre-ws-1.10.0 install.sh -w
|
||||
WS_DISSECTOR_REV=${WS_DISSECTOR_REV:-""}
|
||||
OF13_SWITCH_REV=${OF13_SWITCH_REV:-""}
|
||||
|
||||
|
||||
function kernel {
|
||||
echo "Install Mininet-compatible kernel if necessary"
|
||||
sudo apt-get update
|
||||
if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" = "10.04" ]; then
|
||||
$install linux-image-$KERNEL_NAME
|
||||
elif [ "$DIST" = "Debian" ]; then
|
||||
# The easy approach: download pre-built linux-image and linux-headers packages:
|
||||
wget -c $KERNEL_LOC/$KERNEL_HEADERS
|
||||
wget -c $KERNEL_LOC/$KERNEL_IMAGE
|
||||
|
||||
# Install custom linux headers and image:
|
||||
$pkginst $KERNEL_IMAGE $KERNEL_HEADERS
|
||||
|
||||
# The next two steps are to work around a bug in newer versions of
|
||||
# kernel-package, which fails to add initrd images with the latest kernels.
|
||||
# See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=525032
|
||||
# Generate initrd image if the .deb didn't install it:
|
||||
if ! test -e /boot/initrd.img-${KERNEL_NAME}; then
|
||||
sudo update-initramfs -c -k ${KERNEL_NAME}
|
||||
fi
|
||||
|
||||
# Ensure /boot/grub/menu.lst boots with initrd image:
|
||||
sudo update-grub
|
||||
|
||||
# The default should be the new kernel. Otherwise, you may need to modify
|
||||
# /boot/grub/menu.lst to set the default to the entry corresponding to the
|
||||
# kernel you just installed.
|
||||
if ! $install linux-image-$KERNEL_NAME; then
|
||||
echo "Could not install linux-image-$KERNEL_NAME"
|
||||
echo "Skipping - assuming installed kernel is OK."
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -170,16 +143,18 @@ function mn_deps {
|
||||
function mn_dev {
|
||||
echo "Installing Mininet developer dependencies"
|
||||
$install doxygen doxypy texlive-fonts-recommended
|
||||
if ! $install doxygen-latex; then
|
||||
echo "doxygen-latex not needed"
|
||||
fi
|
||||
}
|
||||
|
||||
# The following will cause a full OF install, covering:
|
||||
# -user switch
|
||||
# The instructions below are an abbreviated version from
|
||||
# http://www.openflowswitch.org/wk/index.php/Debian_Install
|
||||
# ... modified to use Debian Lenny rather than unstable.
|
||||
function of {
|
||||
echo "Installing OpenFlow reference implementation..."
|
||||
cd $BUILD_DIR/
|
||||
cd $BUILD_DIR
|
||||
$install autoconf automake libtool make gcc
|
||||
if [ "$DIST" = "Fedora" ]; then
|
||||
$install git pkgconfig glibc-devel
|
||||
@@ -217,17 +192,24 @@ function of13 {
|
||||
fi
|
||||
|
||||
# Install netbee
|
||||
NBEESRC="nbeesrc-jan-10-2013"
|
||||
if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 14.04; then
|
||||
NBEESRC="nbeesrc-feb-24-2015"
|
||||
NBEEDIR="netbee"
|
||||
else
|
||||
NBEESRC="nbeesrc-jan-10-2013"
|
||||
NBEEDIR="nbeesrc-jan-10-2013"
|
||||
fi
|
||||
|
||||
NBEEURL=${NBEEURL:-http://www.nbee.org/download/}
|
||||
wget -nc ${NBEEURL}${NBEESRC}.zip
|
||||
unzip ${NBEESRC}.zip
|
||||
cd ${NBEESRC}/src
|
||||
cd ${NBEEDIR}/src
|
||||
cmake .
|
||||
make
|
||||
cd $BUILD_DIR/
|
||||
sudo cp ${NBEESRC}/bin/libn*.so /usr/local/lib
|
||||
sudo cp ${NBEEDIR}/bin/libn*.so /usr/local/lib
|
||||
sudo ldconfig
|
||||
sudo cp -R ${NBEESRC}/include/ /usr/
|
||||
sudo cp -R ${NBEEDIR}/include/ /usr/
|
||||
|
||||
# Resume the install:
|
||||
cd $BUILD_DIR/ofsoftswitch13
|
||||
@@ -238,173 +220,156 @@ function of13 {
|
||||
cd $BUILD_DIR
|
||||
}
|
||||
|
||||
function wireshark_version_check {
|
||||
# Check Wireshark version
|
||||
WS=$(which wireshark)
|
||||
WS_VER_PATCH=(1 10) # targetting wireshark 1.10.0
|
||||
WS_VER=($($WS --version | sed 's/[a-z ]*\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1 \2 \3/'))
|
||||
if [ "${WS_VER[0]}" -lt "${WS_VER_PATCH[0]}" ] ||
|
||||
[[ "${WS_VER[0]}" -le "${WS_VER_PATCH[0]}" && "${WS_VER[1]}" -lt "${WS_VER_PATCH[1]}" ]]
|
||||
then
|
||||
# pre-1.10.0 wireshark
|
||||
echo "Setting revision: pre-ws-1.10.0"
|
||||
WS_DISSECTOR_REV="pre-ws-1.10.0"
|
||||
fi
|
||||
}
|
||||
|
||||
function wireshark {
|
||||
echo "Installing Wireshark dissector..."
|
||||
|
||||
if [ "$DIST" = "Fedora" ]; then
|
||||
# Just install Fedora's wireshark RPMS
|
||||
# Fedora's wirehark >= 1.10.2-2 includes an OF dissector
|
||||
# (it has been backported from the future Wireshark 1.12 code base)
|
||||
$install wireshark wireshark-gnome
|
||||
return
|
||||
fi
|
||||
|
||||
$install wireshark tshark libgtk2.0-dev
|
||||
|
||||
if [ "$DIST" = "Ubuntu" ] && [ "$RELEASE" != "10.04" ]; then
|
||||
# Install newer version
|
||||
$install scons mercurial libglib2.0-dev
|
||||
$install libwiretap-dev libwireshark-dev
|
||||
cd $BUILD_DIR
|
||||
hg clone https://bitbucket.org/barnstorm/of-dissector
|
||||
if [[ -z "$WS_DISSECTOR_REV" ]]; then
|
||||
wireshark_version_check
|
||||
function install_wireshark {
|
||||
if ! which wireshark; then
|
||||
echo "Installing Wireshark"
|
||||
if [ "$DIST" = "Fedora" ]; then
|
||||
$install wireshark wireshark-gnome
|
||||
else
|
||||
$install wireshark tshark
|
||||
fi
|
||||
cd of-dissector
|
||||
if [[ -n "$WS_DISSECTOR_REV" ]]; then
|
||||
hg checkout ${WS_DISSECTOR_REV}
|
||||
fi
|
||||
# Build dissector
|
||||
cd src
|
||||
export WIRESHARK=/usr/include/wireshark
|
||||
scons
|
||||
# libwireshark0/ on 11.04; libwireshark1/ on later
|
||||
WSDIR=`find /usr/lib -type d -name 'libwireshark*' | head -1`
|
||||
WSPLUGDIR=$WSDIR/plugins/
|
||||
sudo cp openflow.so $WSPLUGDIR
|
||||
echo "Copied openflow plugin to $WSPLUGDIR"
|
||||
else
|
||||
# Install older version from reference source
|
||||
cd $BUILD_DIR/openflow/utilities/wireshark_dissectors/openflow
|
||||
make
|
||||
sudo make install
|
||||
fi
|
||||
|
||||
# Copy coloring rules: OF is white-on-blue:
|
||||
echo "Optionally installing wireshark color filters"
|
||||
mkdir -p $HOME/.wireshark
|
||||
cp $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
|
||||
cp -n $MININET_DIR/mininet/util/colorfilters $HOME/.wireshark
|
||||
|
||||
echo "Checking Wireshark version"
|
||||
WSVER=`wireshark -v | egrep -o '[0-9\.]+' | head -1`
|
||||
if version_ge $WSVER 1.12; then
|
||||
echo "Wireshark version $WSVER >= 1.12 - returning"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Cloning LoxiGen and building openflow.lua dissector"
|
||||
cd $BUILD_DIR
|
||||
git clone https://github.com/floodlight/loxigen.git
|
||||
cd loxigen
|
||||
make wireshark
|
||||
|
||||
# Copy into plugin directory
|
||||
# libwireshark0/ on 11.04; libwireshark1/ on later
|
||||
WSDIR=`find /usr/lib -type d -name 'libwireshark*' | head -1`
|
||||
WSPLUGDIR=$WSDIR/plugins/
|
||||
PLUGIN=loxi_output/wireshark/openflow.lua
|
||||
sudo cp $PLUGIN $WSPLUGDIR
|
||||
echo "Copied openflow plugin $PLUGIN to $WSPLUGDIR"
|
||||
|
||||
cd $BUILD_DIR
|
||||
}
|
||||
|
||||
|
||||
# Install Open vSwitch specific version Ubuntu package
|
||||
function ubuntuOvs {
|
||||
echo "Creating and Installing Open vSwitch packages..."
|
||||
|
||||
OVS_SRC=$BUILD_DIR/openvswitch
|
||||
OVS_TARBALL_LOC=http://openvswitch.org/releases
|
||||
|
||||
if ! echo "$DIST" | egrep "Ubuntu|Debian" > /dev/null; then
|
||||
echo "OS must be Ubuntu or Debian"
|
||||
$cd BUILD_DIR
|
||||
return
|
||||
fi
|
||||
if [ "$DIST" = "Ubuntu" ] && ! version_ge $RELEASE 12.04; then
|
||||
echo "Ubuntu version must be >= 12.04"
|
||||
cd $BUILD_DIR
|
||||
return
|
||||
fi
|
||||
if [ "$DIST" = "Debian" ] && ! version_ge $RELEASE 7.0; then
|
||||
echo "Debian version must be >= 7.0"
|
||||
cd $BUILD_DIR
|
||||
return
|
||||
fi
|
||||
|
||||
rm -rf $OVS_SRC
|
||||
mkdir -p $OVS_SRC
|
||||
cd $OVS_SRC
|
||||
|
||||
if wget $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz 2> /dev/null; then
|
||||
tar xzf openvswitch-$OVS_RELEASE.tar.gz
|
||||
else
|
||||
echo "Failed to find OVS at $OVS_TARBALL_LOC/openvswitch-$OVS_RELEASE.tar.gz"
|
||||
cd $BUILD_DIR
|
||||
return
|
||||
fi
|
||||
|
||||
# Remove any old packages
|
||||
$remove openvswitch-common openvswitch-datapath-dkms openvswitch-controller \
|
||||
openvswitch-pki openvswitch-switch
|
||||
|
||||
# Get build deps
|
||||
$install build-essential fakeroot debhelper autoconf automake libssl-dev \
|
||||
pkg-config bzip2 openssl python-all procps python-qt4 \
|
||||
python-zopeinterface python-twisted-conch dkms
|
||||
|
||||
# Build OVS
|
||||
cd $BUILD_DIR/openvswitch/openvswitch-$OVS_RELEASE
|
||||
DEB_BUILD_OPTIONS='parallel=2 nocheck' fakeroot debian/rules binary
|
||||
cd ..
|
||||
$pkginst openvswitch-common_$OVS_RELEASE*.deb openvswitch-datapath-dkms_$OVS_RELEASE*.deb \
|
||||
openvswitch-pki_$OVS_RELEASE*.deb openvswitch-switch_$OVS_RELEASE*.deb
|
||||
if $pkginst openvswitch-controller_$OVS_RELEASE*.deb; then
|
||||
echo "Ignoring error installing openvswitch-controller"
|
||||
fi
|
||||
|
||||
modinfo openvswitch
|
||||
sudo ovs-vsctl show
|
||||
# Switch can run on its own, but
|
||||
# Mininet should control the controller
|
||||
# This appears to only be an issue on Ubuntu/Debian
|
||||
if sudo service openvswitch-controller stop; then
|
||||
echo "Stopped running controller"
|
||||
fi
|
||||
if [ -e /etc/init.d/openvswitch-controller ]; then
|
||||
sudo update-rc.d openvswitch-controller disable
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Install Open vSwitch
|
||||
# Instructions derived from OVS INSTALL, INSTALL.OpenFlow and README files.
|
||||
|
||||
function ovs {
|
||||
echo "Installing Open vSwitch..."
|
||||
|
||||
if [ "$DIST" = "Fedora" ]; then
|
||||
# Just install Fedora's openvswitch RPMS
|
||||
if [ "$DIST" == "Fedora" ]; then
|
||||
$install openvswitch openvswitch-controller
|
||||
return
|
||||
fi
|
||||
|
||||
OVS_SRC=$BUILD_DIR/openvswitch
|
||||
OVS_BUILD=$OVS_SRC/build-$KERNEL_NAME
|
||||
OVS_KMODS=($OVS_BUILD/datapath/linux/{openvswitch_mod.ko,brcompat_mod.ko})
|
||||
|
||||
# Required for module build/dkms install
|
||||
$install $KERNEL_HEADERS
|
||||
|
||||
ovspresent=0
|
||||
|
||||
# First see if we have packages
|
||||
# XXX wget -c seems to fail from github/amazon s3
|
||||
cd /tmp
|
||||
if wget $OVS_PACKAGE_LOC/$OVS_PACKAGE_NAME 2> /dev/null; then
|
||||
$install patch dkms fakeroot python-argparse
|
||||
tar xf $OVS_PACKAGE_NAME
|
||||
orig=`tar tf $OVS_PACKAGE_NAME`
|
||||
# Now install packages in reasonable dependency order
|
||||
order='dkms common pki openvswitch-switch brcompat controller'
|
||||
pkgs=""
|
||||
for p in $order; do
|
||||
pkg=`echo "$orig" | grep $p`
|
||||
# Annoyingly, things seem to be missing without this flag
|
||||
$pkginst --force-confmiss $pkg
|
||||
done
|
||||
ovspresent=1
|
||||
fi
|
||||
|
||||
# Otherwise try distribution's OVS packages
|
||||
if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 11.10` = 1 ]; then
|
||||
if [ "$DIST" = "Ubuntu" ] && ! version_ge $RELEASE 14.04; then
|
||||
# Older Ubuntu versions need openvswitch-datapath/-dkms
|
||||
# Manually installing openvswitch-datapath may be necessary
|
||||
# for manually built kernel .debs using Debian's defective kernel
|
||||
# packaging, which doesn't yield usable headers.
|
||||
if ! dpkg --get-selections | grep openvswitch-datapath; then
|
||||
# If you've already installed a datapath, assume you
|
||||
# know what you're doing and don't need dkms datapath.
|
||||
# Otherwise, install it.
|
||||
$install openvswitch-datapath-dkms
|
||||
fi
|
||||
if $install openvswitch-switch openvswitch-controller; then
|
||||
echo "Ignoring error installing openvswitch-controller"
|
||||
fi
|
||||
ovspresent=1
|
||||
fi
|
||||
|
||||
# Switch can run on its own, but
|
||||
# Mininet should control the controller
|
||||
if [ -e /etc/init.d/openvswitch-controller ]; then
|
||||
$install openvswitch-switch
|
||||
if $install openvswitch-controller; then
|
||||
# Switch can run on its own, but
|
||||
# Mininet should control the controller
|
||||
# This appears to only be an issue on Ubuntu/Debian
|
||||
if sudo service openvswitch-controller stop; then
|
||||
echo "Stopped running controller"
|
||||
fi
|
||||
sudo update-rc.d openvswitch-controller disable
|
||||
fi
|
||||
|
||||
if [ $ovspresent = 1 ]; then
|
||||
echo "Done (hopefully) installing packages"
|
||||
cd $BUILD_DIR
|
||||
return
|
||||
fi
|
||||
|
||||
# Otherwise attempt to install from source
|
||||
|
||||
$install pkg-config gcc make python-dev libssl-dev libtool
|
||||
|
||||
if [ "$DIST" = "Debian" ]; then
|
||||
if [ "$CODENAME" = "lenny" ]; then
|
||||
$install git-core
|
||||
# Install Autoconf 2.63+ backport from Debian Backports repo:
|
||||
# Instructions from http://backports.org/dokuwiki/doku.php?id=instructions
|
||||
sudo su -c "echo 'deb http://www.backports.org/debian lenny-backports main contrib non-free' >> /etc/apt/sources.list"
|
||||
sudo apt-get update
|
||||
sudo apt-get -y --force-yes install debian-backports-keyring
|
||||
sudo apt-get -y --force-yes -t lenny-backports install autoconf
|
||||
if [ -e /etc/init.d/openvswitch-controller ]; then
|
||||
sudo update-rc.d openvswitch-controller disable
|
||||
fi
|
||||
else
|
||||
$install git
|
||||
echo "Attempting to install openvswitch-testcontroller"
|
||||
if ! $install openvswitch-testcontroller; then
|
||||
echo "Failed - skipping openvswitch-testcontroller"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install OVS from release
|
||||
cd $BUILD_DIR/
|
||||
git clone git://openvswitch.org/openvswitch $OVS_SRC
|
||||
cd $OVS_SRC
|
||||
git checkout $OVS_TAG
|
||||
./boot.sh
|
||||
BUILDDIR=/lib/modules/${KERNEL_NAME}/build
|
||||
if [ ! -e $BUILDDIR ]; then
|
||||
echo "Creating build sdirectory $BUILDDIR"
|
||||
sudo mkdir -p $BUILDDIR
|
||||
fi
|
||||
opts="--with-linux=$BUILDDIR"
|
||||
mkdir -p $OVS_BUILD
|
||||
cd $OVS_BUILD
|
||||
../configure $opts
|
||||
make
|
||||
sudo make install
|
||||
|
||||
modprobe
|
||||
}
|
||||
|
||||
function remove_ovs {
|
||||
@@ -438,12 +403,44 @@ function ivs {
|
||||
|
||||
# Install IVS from source
|
||||
cd $BUILD_DIR
|
||||
git clone git://github.com/floodlight/ivs $IVS_SRC -b $IVS_TAG --recursive
|
||||
git clone git://github.com/floodlight/ivs $IVS_SRC --recursive
|
||||
cd $IVS_SRC
|
||||
make
|
||||
sudo make install
|
||||
}
|
||||
|
||||
# Install RYU
|
||||
function ryu {
|
||||
echo "Installing RYU..."
|
||||
|
||||
# install Ryu dependencies"
|
||||
$install autoconf automake g++ libtool python make
|
||||
if [ "$DIST" = "Ubuntu" ]; then
|
||||
$install libxml2 libxslt-dev python-pip python-dev
|
||||
sudo pip install gevent
|
||||
elif [ "$DIST" = "Debian" ]; then
|
||||
$install libxml2 libxslt-dev python-pip python-dev
|
||||
sudo pip install gevent
|
||||
fi
|
||||
|
||||
# if needed, update python-six
|
||||
SIX_VER=`pip show six | grep Version | awk '{print $2}'`
|
||||
if version_ge 1.7.0 $SIX_VER; then
|
||||
echo "Installing python-six version 1.7.0..."
|
||||
sudo pip install -I six==1.7.0
|
||||
fi
|
||||
# fetch RYU
|
||||
cd $BUILD_DIR/
|
||||
git clone git://github.com/osrg/ryu.git ryu
|
||||
cd ryu
|
||||
|
||||
# install ryu
|
||||
sudo python ./setup.py install
|
||||
|
||||
# Add symbolic link to /usr/bin
|
||||
sudo ln -s ./bin/ryu-manager /usr/local/bin/ryu-manager
|
||||
}
|
||||
|
||||
# Install NOX with tutorial files
|
||||
function nox {
|
||||
echo "Installing NOX w/tutorial files..."
|
||||
@@ -472,7 +469,7 @@ function nox {
|
||||
# Apply patches
|
||||
git checkout -b tutorial-destiny
|
||||
git am $MININET_DIR/mininet/util/nox-patches/*tutorial-port-nox-destiny*.patch
|
||||
if [ "$DIST" = "Ubuntu" ] && [ `expr $RELEASE '>=' 12.04` = 1 ]; then
|
||||
if [ "$DIST" = "Ubuntu" ] && version_ge $RELEASE 12.04; then
|
||||
git am $MININET_DIR/mininet/util/nox-patches/*nox-ubuntu12-hacks.patch
|
||||
fi
|
||||
|
||||
@@ -580,9 +577,9 @@ function vm_other {
|
||||
# BLACKLIST=/etc/modprobe.d/blacklist
|
||||
#fi
|
||||
#sudo sh -c "echo 'blacklist net-pf-10\nblacklist ipv6' >> $BLACKLIST"
|
||||
|
||||
echo "Disabling IPv6"
|
||||
# Disable IPv6
|
||||
if ! grep 'disable IPv6' /etc/sysctl.conf; then
|
||||
if ! grep 'disable_ipv6' /etc/sysctl.conf; then
|
||||
echo 'Disabling IPv6'
|
||||
echo '
|
||||
# Mininet: disable IPv6
|
||||
@@ -590,6 +587,13 @@ net.ipv6.conf.all.disable_ipv6 = 1
|
||||
net.ipv6.conf.default.disable_ipv6 = 1
|
||||
net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
|
||||
fi
|
||||
# Since the above doesn't disable neighbor discovery, also do this:
|
||||
if ! grep 'ipv6.disable' /etc/default/grub; then
|
||||
sudo sed -i -e \
|
||||
's/GRUB_CMDLINE_LINUX_DEFAULT="/GRUB_CMDLINE_LINUX_DEFAULT="ipv6.disable=1 /' \
|
||||
/etc/default/grub
|
||||
sudo update-grub
|
||||
fi
|
||||
# Disabling IPv6 breaks X11 forwarding via ssh
|
||||
line='AddressFamily inet'
|
||||
file='/etc/ssh/sshd_config'
|
||||
@@ -611,6 +615,13 @@ net.ipv6.conf.lo.disable_ipv6 = 1' | sudo tee -a /etc/sysctl.conf > /dev/null
|
||||
# Install NTP
|
||||
$install ntp
|
||||
|
||||
# Install vconfig for VLAN example
|
||||
if [ "$DIST" = "Fedora" ]; then
|
||||
$install vconfig
|
||||
else
|
||||
$install vlan
|
||||
fi
|
||||
|
||||
# Set git to colorize everything.
|
||||
git config --global color.diff auto
|
||||
git config --global color.status auto
|
||||
@@ -660,7 +671,7 @@ function all {
|
||||
# Skip mn_dev (doxypy/texlive/fonts/etc.) because it's huge
|
||||
# mn_dev
|
||||
of
|
||||
wireshark
|
||||
install_wireshark
|
||||
ovs
|
||||
# We may add ivs once it's more mature
|
||||
# ivs
|
||||
@@ -706,7 +717,7 @@ function vm_clean {
|
||||
}
|
||||
|
||||
function usage {
|
||||
printf '\nUsage: %s [-abcdfhikmnprtvwx03]\n\n' $(basename $0) >&2
|
||||
printf '\nUsage: %s [-abcdfhikmnprtvVwxy03]\n\n' $(basename $0) >&2
|
||||
|
||||
printf 'This install script attempts to install useful packages\n' >&2
|
||||
printf 'for Mininet. It should (hopefully) work on Ubuntu 11.10+\n' >&2
|
||||
@@ -731,7 +742,9 @@ function usage {
|
||||
printf -- ' -s <dir>: place dependency (S)ource/build trees in <dir>\n' >&2
|
||||
printf -- ' -t: complete o(T)her Mininet VM setup tasks\n' >&2
|
||||
printf -- ' -v: install Open (V)switch\n' >&2
|
||||
printf -- ' -V <version>: install a particular version of Open (V)switch on Ubuntu\n' >&2
|
||||
printf -- ' -w: install OpenFlow (W)ireshark dissector\n' >&2
|
||||
printf -- ' -y: install R(y)u Controller\n' >&2
|
||||
printf -- ' -x: install NO(X) Classic OpenFlow controller\n' >&2
|
||||
printf -- ' -0: (default) -0[fx] installs OpenFlow 1.0 versions\n' >&2
|
||||
printf -- ' -3: -3[fx] installs OpenFlow 1.3 versions\n' >&2
|
||||
@@ -744,7 +757,7 @@ if [ $# -eq 0 ]
|
||||
then
|
||||
all
|
||||
else
|
||||
while getopts 'abcdefhikmnprs:tvwx03' OPTION
|
||||
while getopts 'abcdefhikmnprs:tvV:wxy03' OPTION
|
||||
do
|
||||
case $OPTION in
|
||||
a) all;;
|
||||
@@ -769,12 +782,15 @@ else
|
||||
echo "Dependency installation directory: $BUILD_DIR";;
|
||||
t) vm_other;;
|
||||
v) ovs;;
|
||||
w) wireshark;;
|
||||
V) OVS_RELEASE=$OPTARG;
|
||||
ubuntuOvs;;
|
||||
w) install_wireshark;;
|
||||
x) case $OF_VERSION in
|
||||
1.0) nox;;
|
||||
1.3) nox13;;
|
||||
*) echo "Invalid OpenFlow version $OF_VERSION";;
|
||||
esac;;
|
||||
y) ryu;;
|
||||
0) OF_VERSION=1.0;;
|
||||
3) OF_VERSION=1.3;;
|
||||
?) usage;;
|
||||
|
||||
@@ -9,7 +9,7 @@ else
|
||||
host=$1
|
||||
fi
|
||||
|
||||
pid=`ps ax | grep "mininet:$host$" | grep bash | awk '{print $1};'`
|
||||
pid=`ps ax | grep "mininet:$host$" | grep bash | grep -v mnexec | awk '{print $1};'`
|
||||
|
||||
if echo $pid | grep -q ' '; then
|
||||
echo "Error: found multiple mininet:$host processes"
|
||||
@@ -40,5 +40,5 @@ if [ -d $rootdir -a -x $rootdir/bin/bash ]; then
|
||||
cmd="chroot $rootdir /bin/bash -c $cmd"
|
||||
fi
|
||||
|
||||
cmd="exec sudo mnexec -a $pid $cg $cmd"
|
||||
cmd="exec sudo mnexec $cg -a $pid $cmd"
|
||||
eval $cmd
|
||||
|
||||
@@ -8,7 +8,7 @@ version = 'Mininet ' + co( 'PYTHONPATH=. bin/mn --version', shell=True )
|
||||
version = version.strip()
|
||||
|
||||
# Find all Mininet path references
|
||||
lines = co( "grep -or 'Mininet \w\+\.\w\+\.\w\+[+]*' *", shell=True )
|
||||
lines = co( "egrep -or 'Mininet [0-9\.\+]+\w*' *", shell=True )
|
||||
|
||||
error = False
|
||||
|
||||
|
||||
+198
-70
@@ -52,7 +52,8 @@ LogToConsole = False # VM output to console rather than log file
|
||||
SaveQCOW2 = False # Save QCOW2 image rather than deleting it
|
||||
NoKVM = False # Don't use kvm and use emulation instead
|
||||
Branch = None # Branch to update and check out before testing
|
||||
Zip = False # Archive .ovf and .vmdk into a .zip file
|
||||
Zip = False # Archive .ovf and .vmdk into a .zip file
|
||||
Forward = [] # VM port forwarding options (-redir)
|
||||
|
||||
VMImageDir = os.environ[ 'HOME' ] + '/vm-images'
|
||||
|
||||
@@ -61,10 +62,10 @@ Prompt = '\$ ' # Shell prompt that pexpect will wait for
|
||||
isoURLs = {
|
||||
'precise32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/12.04/'
|
||||
'ubuntu-12.04.3-server-i386.iso',
|
||||
'ubuntu-12.04.5-server-i386.iso',
|
||||
'precise64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/12.04/'
|
||||
'ubuntu-12.04.3-server-amd64.iso',
|
||||
'ubuntu-12.04.5-server-amd64.iso',
|
||||
'quantal32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/12.10/'
|
||||
'ubuntu-12.10-server-i386.iso',
|
||||
@@ -83,6 +84,18 @@ isoURLs = {
|
||||
'saucy64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/13.10/'
|
||||
'ubuntu-13.10-server-amd64.iso',
|
||||
'trusty32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/14.04/'
|
||||
'ubuntu-14.04-server-i386.iso',
|
||||
'trusty64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/14.04/'
|
||||
'ubuntu-14.04-server-amd64.iso',
|
||||
'utopic32server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/14.10/'
|
||||
'ubuntu-14.10-server-i386.iso',
|
||||
'utopic64server':
|
||||
'http://mirrors.kernel.org/ubuntu-releases/14.10/'
|
||||
'ubuntu-14.10-server-amd64.iso',
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +104,18 @@ def OSVersion( flavor ):
|
||||
urlbase = path.basename( isoURLs.get( flavor, 'unknown' ) )
|
||||
return path.splitext( urlbase )[ 0 ]
|
||||
|
||||
def OVFOSNameID( flavor ):
|
||||
"Return OVF-specified ( OS Name, ID ) for flavor"
|
||||
version = OSVersion( flavor )
|
||||
arch = archFor( flavor )
|
||||
if 'ubuntu' in version:
|
||||
map = { 'i386': ( 'Ubuntu', 93 ),
|
||||
'x86_64': ( 'Ubuntu 64-bit', 94 ) }
|
||||
else:
|
||||
map = { 'i386': ( 'Linux', 36 ),
|
||||
'x86_64': ( 'Linux 64-bit', 101 ) }
|
||||
osname, osid = map[ arch ]
|
||||
return osname, osid
|
||||
|
||||
LogStartTime = time()
|
||||
LogFile = None
|
||||
@@ -137,10 +162,10 @@ def srun( cmd, **kwargs ):
|
||||
def depend():
|
||||
"Install package dependencies"
|
||||
log( '* Installing package dependencies' )
|
||||
run( 'sudo apt-get -y update' )
|
||||
run( 'sudo apt-get install -y'
|
||||
run( 'sudo apt-get -qy update' )
|
||||
run( 'sudo apt-get -qy install'
|
||||
' kvm cloud-utils genisoimage qemu-kvm qemu-utils'
|
||||
' e2fsprogs dnsmasq'
|
||||
' e2fsprogs dnsmasq curl'
|
||||
' python-setuptools mtools zip' )
|
||||
run( 'sudo easy_install pexpect' )
|
||||
|
||||
@@ -168,7 +193,10 @@ def findiso( flavor ):
|
||||
if not path.exists( iso ) or ( stat( iso )[ ST_MODE ] & 0777 != 0444 ):
|
||||
log( '* Retrieving', url )
|
||||
run( 'curl -C - -o %s %s' % ( iso, url ) )
|
||||
if 'ISO' not in run( 'file ' + iso ):
|
||||
# Make sure the file header/type is something reasonable like
|
||||
# 'ISO' or 'x86 boot sector', and not random html or text
|
||||
result = run( 'file ' + iso )
|
||||
if 'ISO' not in result and 'boot' not in result:
|
||||
os.remove( iso )
|
||||
raise Exception( 'findiso: could not download iso from ' + url )
|
||||
# Write-protect iso, signaling it is complete
|
||||
@@ -214,7 +242,7 @@ def extractKernel( image, flavor, imageDir=VMImageDir ):
|
||||
# Assume kernel is in partition 1/boot/vmlinuz*generic for now
|
||||
part = nbd + 'p1'
|
||||
mnt = mkdtemp()
|
||||
srun( 'mount -o ro %s %s' % ( part, mnt ) )
|
||||
srun( 'mount -o ro,noload %s %s' % ( part, mnt ) )
|
||||
kernsrc = glob( '%s/boot/vmlinuz*generic' % mnt )[ 0 ]
|
||||
initrdsrc = glob( '%s/boot/initrd*generic' % mnt )[ 0 ]
|
||||
srun( 'cp %s %s' % ( initrdsrc, initrd ) )
|
||||
@@ -295,7 +323,7 @@ zerombr yes
|
||||
clearpart --all --initlabel
|
||||
#Automatic partitioning
|
||||
autopart
|
||||
#System authorization infomation
|
||||
#System authorization information
|
||||
auth --useshadow --enablemd5
|
||||
#Firewall configuration
|
||||
firewall --disabled
|
||||
@@ -305,9 +333,11 @@ skipx
|
||||
|
||||
# Tell the Ubuntu/Debian installer to stop asking stupid questions
|
||||
|
||||
PreseedText = """
|
||||
d-i mirror/country string manual
|
||||
d-i mirror/http/hostname string mirrors.kernel.org
|
||||
PreseedText = ( """
|
||||
"""
|
||||
#d-i mirror/country string manual
|
||||
#d-i mirror/http/hostname string mirrors.kernel.org
|
||||
"""
|
||||
d-i mirror/http/directory string /ubuntu
|
||||
d-i mirror/http/proxy string
|
||||
d-i partman/confirm_write_new_label boolean true
|
||||
@@ -317,7 +347,7 @@ d-i partman/confirm_nooverwrite boolean true
|
||||
d-i user-setup/allow-password-weak boolean true
|
||||
d-i finish-install/reboot_in_progress note
|
||||
d-i debian-installer/exit/poweroff boolean true
|
||||
"""
|
||||
""" )
|
||||
|
||||
def makeKickstartFloppy():
|
||||
"Create and return kickstart floppy, kickstart, preseed"
|
||||
@@ -414,7 +444,12 @@ def boot( cow, kernel, initrd, logfile, memory=1024 ):
|
||||
returns: pexpect object to qemu process"""
|
||||
# pexpect might not be installed until after depend() is called
|
||||
global pexpect
|
||||
import pexpect
|
||||
if not pexpect:
|
||||
import pexpect
|
||||
class Spawn( pexpect.spawn ):
|
||||
"Subprocess is sudo, so we have to sudo kill it"
|
||||
def close( self, force=False ):
|
||||
srun( 'kill %d' % self.pid )
|
||||
arch = archFor( kernel )
|
||||
log( '* Detected kernel architecture', arch )
|
||||
if NoKVM:
|
||||
@@ -432,29 +467,46 @@ def boot( cow, kernel, initrd, logfile, memory=1024 ):
|
||||
'-initrd', initrd,
|
||||
'-drive file=%s,if=virtio' % cow,
|
||||
'-append "root=/dev/vda1 init=/sbin/init console=ttyS0" ' ]
|
||||
if Forward:
|
||||
cmd += sum( [ [ '-redir', f ] for f in Forward ], [] )
|
||||
cmd = ' '.join( cmd )
|
||||
log( '* BOOTING VM FROM', cow )
|
||||
log( cmd )
|
||||
vm = pexpect.spawn( cmd, timeout=TIMEOUT, logfile=logfile )
|
||||
vm = Spawn( cmd, timeout=TIMEOUT, logfile=logfile )
|
||||
return vm
|
||||
|
||||
|
||||
def login( vm ):
|
||||
def login( vm, user='mininet', password='mininet' ):
|
||||
"Log in to vm (pexpect object)"
|
||||
log( '* Waiting for login prompt' )
|
||||
vm.expect( 'login: ' )
|
||||
log( '* Logging in' )
|
||||
vm.sendline( 'mininet' )
|
||||
vm.sendline( user )
|
||||
log( '* Waiting for password prompt' )
|
||||
vm.expect( 'Password: ' )
|
||||
log( '* Sending password' )
|
||||
vm.sendline( 'mininet' )
|
||||
vm.sendline( password )
|
||||
log( '* Waiting for login...' )
|
||||
|
||||
|
||||
def removeNtpd( vm, prompt=Prompt, ntpPackage='ntp' ):
|
||||
"Remove ntpd and set clock immediately"
|
||||
log( '* Removing ntpd' )
|
||||
vm.sendline( 'sudo -n apt-get -qy remove ' + ntpPackage )
|
||||
vm.expect( prompt )
|
||||
# Try to make sure that it isn't still running
|
||||
vm.sendline( 'sudo -n pkill ntpd' )
|
||||
vm.expect( prompt )
|
||||
log( '* Getting seconds since epoch from this server' )
|
||||
# Note r'date +%s' specifies a format for 'date', not python!
|
||||
seconds = int( run( r'date +%s' ) )
|
||||
log( '* Setting VM clock' )
|
||||
vm.sendline( 'sudo -n date -s @%d' % seconds )
|
||||
|
||||
|
||||
def sanityTest( vm ):
|
||||
"Run Mininet sanity test (pingall) in vm"
|
||||
vm.sendline( 'sudo mn --test pingall' )
|
||||
vm.sendline( 'sudo -n mn --test pingall' )
|
||||
if vm.expect( [ ' 0% dropped', pexpect.TIMEOUT ], timeout=45 ) == 0:
|
||||
log( '* Sanity check OK' )
|
||||
else:
|
||||
@@ -466,9 +518,9 @@ def sanityTest( vm ):
|
||||
def coreTest( vm, prompt=Prompt ):
|
||||
"Run core tests (make test) in VM"
|
||||
log( '* Making sure cgroups are mounted' )
|
||||
vm.sendline( 'sudo service cgroup-lite restart' )
|
||||
vm.sendline( 'sudo -n service cgroup-lite restart' )
|
||||
vm.expect( prompt )
|
||||
vm.sendline( 'sudo cgroups-mount' )
|
||||
vm.sendline( 'sudo -n cgroups-mount' )
|
||||
vm.expect( prompt )
|
||||
log( '* Running make test' )
|
||||
vm.sendline( 'cd ~/mininet; sudo make test' )
|
||||
@@ -477,39 +529,68 @@ def coreTest( vm, prompt=Prompt ):
|
||||
# know the time for each test, which means that this
|
||||
# script will have to change as we add more tests.
|
||||
for test in range( 0, 2 ):
|
||||
if vm.expect( [ 'OK', 'FAILED', pexpect.TIMEOUT ], timeout=180 ) == 0:
|
||||
if vm.expect( [ 'OK.*\r\n', 'FAILED.*\r\n', pexpect.TIMEOUT ], timeout=180 ) == 0:
|
||||
log( '* Test', test, 'OK' )
|
||||
else:
|
||||
log( '* Test', test, 'FAILED' )
|
||||
log( '* Test', test, 'output:' )
|
||||
log( vm.before )
|
||||
|
||||
|
||||
def installPexpect( vm, prompt=Prompt ):
|
||||
"install pexpect"
|
||||
vm.sendline( 'sudo -n apt-get -qy install python-pexpect' )
|
||||
vm.expect( prompt )
|
||||
|
||||
|
||||
def noneTest( vm, prompt=Prompt ):
|
||||
"This test does nothing"
|
||||
installPexpect( vm, prompt )
|
||||
vm.sendline( 'echo' )
|
||||
|
||||
|
||||
def examplesquickTest( vm, prompt=Prompt ):
|
||||
"Quick test of mininet examples"
|
||||
vm.sendline( 'sudo apt-get install python-pexpect' )
|
||||
vm.expect( prompt )
|
||||
vm.sendline( 'sudo python ~/mininet/examples/test/runner.py -v -quick' )
|
||||
installPexpect( vm, prompt )
|
||||
vm.sendline( 'sudo -n python ~/mininet/examples/test/runner.py -v -quick' )
|
||||
|
||||
|
||||
def examplesfullTest( vm, prompt=Prompt ):
|
||||
"Full (slow) test of mininet examples"
|
||||
vm.sendline( 'sudo apt-get install python-pexpect' )
|
||||
vm.expect( prompt )
|
||||
vm.sendline( 'sudo python ~/mininet/examples/test/runner.py -v' )
|
||||
installPexpect( vm, prompt )
|
||||
vm.sendline( 'sudo -n python ~/mininet/examples/test/runner.py -v' )
|
||||
|
||||
|
||||
def walkthroughTest( vm, prompt=Prompt ):
|
||||
"Test mininet walkthrough"
|
||||
vm.sendline( 'sudo apt-get install python-pexpect' )
|
||||
vm.expect( prompt )
|
||||
vm.sendline( 'sudo python ~/mininet/mininet/test/test_walkthrough.py -v' )
|
||||
installPexpect( vm, prompt )
|
||||
vm.sendline( 'sudo -n python ~/mininet/mininet/test/test_walkthrough.py -v' )
|
||||
|
||||
|
||||
def useTest( vm, prompt=Prompt ):
|
||||
"Use VM interactively - exit by pressing control-]"
|
||||
old = vm.logfile
|
||||
if old == stdout:
|
||||
# Avoid doubling every output character!
|
||||
log( '* Temporarily disabling logging to stdout' )
|
||||
vm.logfile = None
|
||||
log( '* Switching to interactive use - press control-] to exit' )
|
||||
vm.interact()
|
||||
if old == stdout:
|
||||
log( '* Restoring logging to stdout' )
|
||||
vm.logfile = stdout
|
||||
|
||||
|
||||
def checkOutBranch( vm, branch, prompt=Prompt ):
|
||||
vm.sendline( 'cd ~/mininet; git fetch; git pull --rebase; git checkout '
|
||||
+ branch )
|
||||
# This is a bit subtle; it will check out an existing branch (e.g. master)
|
||||
# if it exists; otherwise it will create a detached branch.
|
||||
# The branch will be rebased to its parent on origin.
|
||||
# This probably doesn't matter since we're running on a COW disk
|
||||
# anyway.
|
||||
vm.sendline( 'cd ~/mininet; git fetch --all; git checkout '
|
||||
+ branch + '; git pull --rebase origin ' + branch )
|
||||
vm.expect( prompt )
|
||||
vm.sendline( 'sudo make install' )
|
||||
vm.sendline( 'sudo -n make install' )
|
||||
|
||||
|
||||
def interact( vm, tests, pre='', post='', prompt=Prompt ):
|
||||
@@ -522,12 +603,16 @@ def interact( vm, tests, pre='', post='', prompt=Prompt ):
|
||||
log( '* Waiting for output' )
|
||||
vm.expect( prompt )
|
||||
log( '* Fetching Mininet VM install script' )
|
||||
branch = Branch if Branch else 'master'
|
||||
vm.sendline( 'wget '
|
||||
'https://raw.github.com/mininet/mininet/master/util/vm/'
|
||||
'install-mininet-vm.sh' )
|
||||
'https://raw.github.com/mininet/mininet/%s/util/vm/'
|
||||
'install-mininet-vm.sh' % branch )
|
||||
vm.expect( prompt )
|
||||
log( '* Running VM install script' )
|
||||
vm.sendline( 'bash install-mininet-vm.sh' )
|
||||
installcmd = 'bash -v install-mininet-vm.sh'
|
||||
if Branch:
|
||||
installcmd += ' ' + Branch
|
||||
vm.sendline( installcmd )
|
||||
vm.expect ( 'password for mininet: ' )
|
||||
vm.sendline( 'mininet' )
|
||||
log( '* Waiting for script to complete... ' )
|
||||
@@ -540,6 +625,13 @@ def interact( vm, tests, pre='', post='', prompt=Prompt ):
|
||||
log( '* Mininet version: ', version )
|
||||
log( '* Testing Mininet' )
|
||||
runTests( vm, tests=tests, pre=pre, post=post )
|
||||
# Ubuntu adds this because we install via a serial console,
|
||||
# but we want the VM to boot via the VM console. Otherwise
|
||||
# we get the message 'error: terminal "serial" not found'
|
||||
log( '* Disabling serial console' )
|
||||
vm.sendline( "sudo sed -i -e 's/^GRUB_TERMINAL=serial/#GRUB_TERMINAL=serial/' "
|
||||
"/etc/default/grub; sudo update-grub" )
|
||||
vm.expect( prompt )
|
||||
log( '* Shutting down' )
|
||||
vm.sendline( 'sync; sudo shutdown -h now' )
|
||||
log( '* Waiting for EOF/shutdown' )
|
||||
@@ -576,13 +668,13 @@ OVFTemplate = """<?xml version="1.0"?>
|
||||
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<References>
|
||||
<File ovf:href="%s" ovf:id="file1" ovf:size="%d"/>
|
||||
<File ovf:href="%(diskname)s" ovf:id="file1" ovf:size="%(filesize)d"/>
|
||||
</References>
|
||||
<DiskSection>
|
||||
<Info>Virtual disk information</Info>
|
||||
<Disk ovf:capacity="%d" ovf:capacityAllocationUnits="byte"
|
||||
<Disk ovf:capacity="%(disksize)d" ovf:capacityAllocationUnits="byte"
|
||||
ovf:diskId="vmdisk1" ovf:fileRef="file1"
|
||||
ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html"/>
|
||||
ovf:format="http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized"/>
|
||||
</DiskSection>
|
||||
<NetworkSection>
|
||||
<Info>The list of logical networks</Info>
|
||||
@@ -590,26 +682,30 @@ OVFTemplate = """<?xml version="1.0"?>
|
||||
<Description>The nat network</Description>
|
||||
</Network>
|
||||
</NetworkSection>
|
||||
<VirtualSystem ovf:id="Mininet-VM">
|
||||
<Info>A Mininet Virtual Machine (%s)</Info>
|
||||
<Name>mininet-vm</Name>
|
||||
<VirtualSystem ovf:id="%(vmname)s">
|
||||
<Info>%(vminfo)s (%(name)s)</Info>
|
||||
<Name>%(vmname)s</Name>
|
||||
<OperatingSystemSection ovf:id="%(osid)d">
|
||||
<Info>The kind of installed guest operating system</Info>
|
||||
<Description>%(osname)s</Description>
|
||||
</OperatingSystemSection>
|
||||
<VirtualHardwareSection>
|
||||
<Info>Virtual hardware requirements</Info>
|
||||
<Item>
|
||||
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
|
||||
<rasd:Description>Number of Virtual CPUs</rasd:Description>
|
||||
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
|
||||
<rasd:ElementName>%(cpus)s virtual CPU(s)</rasd:ElementName>
|
||||
<rasd:InstanceID>1</rasd:InstanceID>
|
||||
<rasd:ResourceType>3</rasd:ResourceType>
|
||||
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
|
||||
<rasd:VirtualQuantity>%(cpus)s</rasd:VirtualQuantity>
|
||||
</Item>
|
||||
<Item>
|
||||
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
|
||||
<rasd:Description>Memory Size</rasd:Description>
|
||||
<rasd:ElementName>%dMB of memory</rasd:ElementName>
|
||||
<rasd:ElementName>%(mem)dMB of memory</rasd:ElementName>
|
||||
<rasd:InstanceID>2</rasd:InstanceID>
|
||||
<rasd:ResourceType>4</rasd:ResourceType>
|
||||
<rasd:VirtualQuantity>%d</rasd:VirtualQuantity>
|
||||
<rasd:VirtualQuantity>%(mem)d</rasd:VirtualQuantity>
|
||||
</Item>
|
||||
<Item>
|
||||
<rasd:Address>0</rasd:Address>
|
||||
@@ -652,16 +748,24 @@ OVFTemplate = """<?xml version="1.0"?>
|
||||
"""
|
||||
|
||||
|
||||
def generateOVF( name, diskname, disksize, mem=1024 ):
|
||||
def generateOVF( name, osname, osid, diskname, disksize, mem=1024, cpus=1,
|
||||
vmname='Mininet-VM', vminfo='A Mininet Virtual Machine' ):
|
||||
"""Generate (and return) OVF file "name.ovf"
|
||||
name: root name of OVF file to generate
|
||||
osname: OS name for OVF (Ubuntu | Ubuntu 64-bit)
|
||||
osid: OS ID for OVF (93 | 94 )
|
||||
diskname: name of disk file
|
||||
disksize: size of virtual disk in bytes
|
||||
mem: VM memory size in MB"""
|
||||
mem: VM memory size in MB
|
||||
cpus: # of virtual CPUs
|
||||
vmname: Name for VM (default name when importing)
|
||||
vmimfo: Brief description of VM for OVF"""
|
||||
ovf = name + '.ovf'
|
||||
filesize = stat( diskname )[ ST_SIZE ]
|
||||
# OVFTemplate uses the memory size twice in a row
|
||||
xmltext = OVFTemplate % ( diskname, filesize, disksize, name, mem, mem )
|
||||
params = dict( osname=osname, osid=osid, diskname=diskname,
|
||||
filesize=filesize, disksize=disksize, name=name,
|
||||
mem=mem, cpus=cpus, vmname=vmname, vminfo=vminfo )
|
||||
xmltext = OVFTemplate % params
|
||||
with open( ovf, 'w+' ) as f:
|
||||
f.write( xmltext )
|
||||
return ovf
|
||||
@@ -669,9 +773,12 @@ def generateOVF( name, diskname, disksize, mem=1024 ):
|
||||
|
||||
def qcow2size( qcow2 ):
|
||||
"Return virtual disk size (in bytes) of qcow2 image"
|
||||
output = check_output( [ 'file', qcow2 ] )
|
||||
assert 'QCOW' in output
|
||||
bytes = int( re.findall( '(\d+) bytes', output )[ 0 ] )
|
||||
output = check_output( [ 'qemu-img', 'info', qcow2 ] )
|
||||
try:
|
||||
assert 'format: qcow' in output
|
||||
bytes = int( re.findall( '(\d+) bytes', output )[ 0 ] )
|
||||
except:
|
||||
raise Exception( 'Could not determine size of %s' % qcow2 )
|
||||
return bytes
|
||||
|
||||
|
||||
@@ -688,6 +795,8 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
||||
date = strftime( '%y%m%d-%H-%M-%S', lstart)
|
||||
ovfdate = strftime( '%y%m%d', lstart )
|
||||
dir = 'mn-%s-%s' % ( flavor, date )
|
||||
if Branch:
|
||||
dir = 'mn-%s-%s-%s' % ( Branch, flavor, date )
|
||||
try:
|
||||
os.mkdir( dir )
|
||||
except:
|
||||
@@ -709,13 +818,16 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
||||
vm = boot( volume, kernel, initrd, logfile, memory=memory )
|
||||
version = interact( vm, tests=tests, pre=pre, post=post )
|
||||
size = qcow2size( volume )
|
||||
vmdk = convert( volume, basename='mininet-vm-' + archFor( flavor ) )
|
||||
arch = archFor( flavor )
|
||||
vmdk = convert( volume, basename='mininet-vm-' + arch )
|
||||
if not SaveQCOW2:
|
||||
log( '* Removing qcow2 volume', volume )
|
||||
os.remove( volume )
|
||||
log( '* Converted VM image stored as', abspath( vmdk ) )
|
||||
ovfname = 'mininet-%s-%s-%s' % ( version, ovfdate, OSVersion( flavor ) )
|
||||
ovf = generateOVF( diskname=vmdk, disksize=size, name=ovfname )
|
||||
osname, osid = OVFOSNameID( flavor )
|
||||
ovf = generateOVF( name=ovfname, osname=osname, osid=osid,
|
||||
diskname=vmdk, disksize=size )
|
||||
log( '* Generated OVF descriptor file', ovf )
|
||||
if Zip:
|
||||
log( '* Generating .zip file' )
|
||||
@@ -728,8 +840,17 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
||||
os.chdir( '..' )
|
||||
|
||||
|
||||
def runTests( vm, tests=None, pre='', post='', prompt=Prompt ):
|
||||
def runTests( vm, tests=None, pre='', post='', prompt=Prompt, uninstallNtpd=False ):
|
||||
"Run tests (list) in vm (pexpect object)"
|
||||
# We disable ntpd and set the time so that ntpd won't be
|
||||
# messing with the time during tests. Set to true for a COW
|
||||
# disk and False for a non-COW disk.
|
||||
if uninstallNtpd:
|
||||
removeNtpd( vm )
|
||||
vm.expect( prompt )
|
||||
if Branch:
|
||||
checkOutBranch( vm, branch=Branch )
|
||||
vm.expect( prompt )
|
||||
if not tests:
|
||||
tests = []
|
||||
if pre:
|
||||
@@ -760,8 +881,8 @@ def getMininetVersion( vm ):
|
||||
return version
|
||||
|
||||
|
||||
def bootAndRunTests( image, tests=None, pre='', post='', prompt=Prompt,
|
||||
memory=1024 ):
|
||||
def bootAndRun( image, prompt=Prompt, memory=1024, outputFile=None,
|
||||
runFunction=None, **runArgs ):
|
||||
"""Boot and test VM
|
||||
tests: list of tests to run
|
||||
pre: command line to run in VM before tests
|
||||
@@ -789,15 +910,16 @@ def bootAndRunTests( image, tests=None, pre='', post='', prompt=Prompt,
|
||||
login( vm )
|
||||
log( '* Waiting for prompt after login' )
|
||||
vm.expect( prompt )
|
||||
if Branch:
|
||||
checkOutBranch( vm, branch=Branch )
|
||||
vm.expect( prompt )
|
||||
runTests( vm, tests=tests, pre=pre, post=post )
|
||||
# runTests eats its last prompt, but maybe it shouldn't...
|
||||
# runFunction should begin with sendline and should eat its last prompt
|
||||
if runFunction:
|
||||
runFunction( vm, **runArgs )
|
||||
log( '* Shutting down' )
|
||||
vm.sendline( 'sudo shutdown -h now ' )
|
||||
vm.sendline( 'sudo -n shutdown -h now ' )
|
||||
log( '* Waiting for shutdown' )
|
||||
vm.wait()
|
||||
if outputFile:
|
||||
log( '* Saving temporary image to %s' % outputFile )
|
||||
convert( cow, outputFile )
|
||||
log( '* Removing temporary dir', tmpdir )
|
||||
srun( 'rm -rf ' + tmpdir )
|
||||
elapsed = time() - bootTestStart
|
||||
@@ -827,7 +949,7 @@ def testString():
|
||||
|
||||
def parseArgs():
|
||||
"Parse command line arguments and run"
|
||||
global LogToConsole, NoKVM, Branch, Zip, TIMEOUT
|
||||
global LogToConsole, NoKVM, Branch, Zip, TIMEOUT, Forward
|
||||
parser = argparse.ArgumentParser( description='Mininet VM build script',
|
||||
epilog=buildFlavorString() + ' ' +
|
||||
testString() )
|
||||
@@ -858,12 +980,15 @@ def parseArgs():
|
||||
parser.add_argument( '-p', '--post', metavar='cmd', default='',
|
||||
help='specify a command line to run after tests' )
|
||||
parser.add_argument( '-b', '--branch', metavar='branch',
|
||||
help='For an existing VM image, check out and install'
|
||||
' this branch before testing' )
|
||||
help='branch to install and/or check out and test' )
|
||||
parser.add_argument( 'flavor', nargs='*',
|
||||
help='VM flavor(s) to build (e.g. raring32server)' )
|
||||
parser.add_argument( '-z', '--zip', action='store_true',
|
||||
help='archive .ovf and .vmdk into .zip file' )
|
||||
parser.add_argument( '-o', '--out',
|
||||
help='output file for test image (vmdk)' )
|
||||
parser.add_argument( '-f', '--forward', default=[], action='append',
|
||||
help='forward VM ports to local server, e.g. tcp:5555::22' )
|
||||
args = parser.parse_args()
|
||||
if args.depend:
|
||||
depend()
|
||||
@@ -881,6 +1006,8 @@ def parseArgs():
|
||||
Zip = True
|
||||
if args.timeout:
|
||||
TIMEOUT = args.timeout
|
||||
if args.forward:
|
||||
Forward = args.forward
|
||||
if not args.test and not args.run and not args.post:
|
||||
args.test = [ 'sanity', 'core' ]
|
||||
for flavor in args.flavor:
|
||||
@@ -895,8 +1022,9 @@ def parseArgs():
|
||||
log( '* BUILD FAILED with exception: ', e )
|
||||
exit( 1 )
|
||||
for image in args.image:
|
||||
bootAndRunTests( image, tests=args.test, pre=args.run,
|
||||
post=args.post, memory=args.memory)
|
||||
bootAndRun( image, runFunction=runTests, tests=args.test, pre=args.run,
|
||||
post=args.post, memory=args.memory, outputFile=args.out,
|
||||
uninstallNtpd=True )
|
||||
if not ( args.depend or args.list or args.clean or args.flavor
|
||||
or args.image ):
|
||||
parser.print_help()
|
||||
|
||||
@@ -3,21 +3,25 @@
|
||||
# This script is intended to install Mininet into
|
||||
# a brand-new Ubuntu virtual machine,
|
||||
# to create a fully usable "tutorial" VM.
|
||||
#
|
||||
# optional argument: Mininet branch to install
|
||||
set -e
|
||||
echo `whoami` ALL=NOPASSWD: ALL | sudo tee -a /etc/sudoers > /dev/null
|
||||
echo "$(whoami) ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers > /dev/null
|
||||
sudo sed -i -e 's/Default/#Default/' /etc/sudoers
|
||||
echo mininet-vm | sudo tee /etc/hostname > /dev/null
|
||||
sudo sed -i -e 's/ubuntu/mininet-vm/g' /etc/hosts
|
||||
sudo hostname `cat /etc/hostname`
|
||||
sudo sed -i -e 's/quiet splash/text/' /etc/default/grub
|
||||
sudo sed -i -e 's/splash//' /etc/default/grub
|
||||
sudo sed -i -e 's/quiet/text/' /etc/default/grub
|
||||
sudo update-grub
|
||||
# 12.10 and earlier
|
||||
sudo sed -i -e 's/us.archive.ubuntu.com/mirrors.kernel.org/' \
|
||||
/etc/apt/sources.list
|
||||
# 13.04 and later
|
||||
sudo sed -i -e 's/\/archive.ubuntu.com/\/mirrors.kernel.org/' \
|
||||
/etc/apt/sources.list
|
||||
# Update from official archive
|
||||
sudo apt-get update
|
||||
# 12.10 and earlier
|
||||
#sudo sed -i -e 's/us.archive.ubuntu.com/mirrors.kernel.org/' \
|
||||
# /etc/apt/sources.list
|
||||
# 13.04 and later
|
||||
#sudo sed -i -e 's/\/archive.ubuntu.com/\/mirrors.kernel.org/' \
|
||||
# /etc/apt/sources.list
|
||||
# Clean up vmware easy install junk if present
|
||||
if [ -e /etc/issue.backup ]; then
|
||||
sudo mv /etc/issue.backup /etc/issue
|
||||
@@ -25,11 +29,18 @@ fi
|
||||
if [ -e /etc/rc.local.backup ]; then
|
||||
sudo mv /etc/rc.local.backup /etc/rc.local
|
||||
fi
|
||||
# Install Mininet
|
||||
# Fetch Mininet
|
||||
sudo apt-get -y install git-core openssh-server
|
||||
git clone git://github.com/mininet/mininet
|
||||
cd mininet
|
||||
cd
|
||||
# Optionally check out branch
|
||||
if [ "$1" != "" ]; then
|
||||
pushd mininet
|
||||
#git checkout -b $1 $1
|
||||
# TODO branch will in detached HEAD state if it is not master
|
||||
git checkout $1
|
||||
popd
|
||||
fi
|
||||
# Install Mininet
|
||||
time mininet/util/install.sh
|
||||
# Finalize VM
|
||||
time mininet/util/install.sh -tc
|
||||
@@ -38,4 +49,3 @@ time mininet/util/install.sh -tc
|
||||
# echo "export NOX_CORE_DIR=~/noxcore/build/src/" >> .bashrc
|
||||
#fi
|
||||
echo "Done preparing Mininet VM."
|
||||
|
||||
|
||||
Reference in New Issue
Block a user