├── .gitignore
├── LICENSE
├── README-zh.md
├── README.md
├── controller.py
├── dhcp.py
├── img
├── arch.png
├── dhcp_success.png
├── mininet_success.png
├── path_result.png
├── ping_result.png
└── topo_example.png
├── ofctl_utilis.py
├── project_demo_instructions.md
├── requirements.txt
└── tests
├── dhcp_test
└── test_network.py
└── switching_test
└── test_network.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # custom gitignore file for my projects
2 | sync.sh
3 |
4 | ### VisualStudioCode template
5 | .vscode/*
6 | !.vscode/settings.json
7 | !.vscode/tasks.json
8 | !.vscode/launch.json
9 | !.vscode/extensions.json
10 | !.vscode/*.code-snippets
11 |
12 | # Local History for Visual Studio Code
13 | .history/
14 |
15 | # Built Visual Studio Code Extensions
16 | *.vsix
17 |
18 | ### JetBrains template
19 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
20 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
21 |
22 | # User-specific stuff
23 | .idea/**/workspace.xml
24 | .idea/**/tasks.xml
25 | .idea/**/usage.statistics.xml
26 | .idea/**/dictionaries
27 | .idea/**/shelf
28 |
29 | # AWS User-specific
30 | .idea/**/aws.xml
31 |
32 | # Generated files
33 | .idea/**/contentModel.xml
34 |
35 | # Sensitive or high-churn files
36 | .idea/**/dataSources/
37 | .idea/**/dataSources.ids
38 | .idea/**/dataSources.local.xml
39 | .idea/**/sqlDataSources.xml
40 | .idea/**/dynamic.xml
41 | .idea/**/uiDesigner.xml
42 | .idea/**/dbnavigator.xml
43 |
44 | # Gradle
45 | .idea/**/gradle.xml
46 | .idea/**/libraries
47 |
48 | # Gradle and Maven with auto-import
49 | # When using Gradle or Maven with auto-import, you should exclude module files,
50 | # since they will be recreated, and may cause churn. Uncomment if using
51 | # auto-import.
52 | .idea
53 |
54 | # CMake
55 | cmake-build-*/
56 |
57 | # Mongo Explorer plugin
58 | .idea/**/mongoSettings.xml
59 |
60 | # File-based project format
61 | *.iws
62 |
63 | # IntelliJ
64 | out/
65 |
66 | # mpeltonen/sbt-idea plugin
67 | .idea_modules/
68 |
69 | # JIRA plugin
70 | atlassian-ide-plugin.xml
71 |
72 | # Cursive Clojure plugin
73 | .idea/replstate.xml
74 |
75 | # SonarLint plugin
76 | .idea/sonarlint/
77 |
78 | # Crashlytics plugin (for Android Studio and IntelliJ)
79 | com_crashlytics_export_strings.xml
80 | crashlytics.properties
81 | crashlytics-build.properties
82 | fabric.properties
83 |
84 | # Editor-based Rest Client
85 | .idea/httpRequests
86 |
87 | # Android studio 3.1+ serialized cache file
88 | .idea/caches/build_file_checksums.ser
89 |
90 | ### macOS template
91 | # General
92 | .DS_Store
93 | .AppleDouble
94 | .LSOverride
95 |
96 | # Icon must end with two \r
97 | Icon
98 |
99 | # Thumbnails
100 | ._*
101 |
102 | # Files that might appear in the root of a volume
103 | .DocumentRevisions-V100
104 | .fseventsd
105 | .Spotlight-V100
106 | .TemporaryItems
107 | .Trashes
108 | .VolumeIcon.icns
109 | .com.apple.timemachine.donotpresent
110 |
111 | # Directories potentially created on remote AFP share
112 | .AppleDB
113 | .AppleDesktop
114 | Network Trash Folder
115 | Temporary Items
116 | .apdisk
117 |
118 | ### Python template
119 | # Byte-compiled / optimized / DLL files
120 | __pycache__/
121 | *.py[cod]
122 | *$py.class
123 |
124 | # C extensions
125 | *.so
126 |
127 | # Distribution / packaging
128 | .Python
129 | build/
130 | develop-eggs/
131 | dist/
132 | downloads/
133 | eggs/
134 | .eggs/
135 | lib/
136 | lib64/
137 | parts/
138 | sdist/
139 | var/
140 | wheels/
141 | share/python-wheels/
142 | *.egg-info/
143 | .installed.cfg
144 | *.egg
145 | MANIFEST
146 |
147 | # PyInstaller
148 | # Usually these files are written by a python script from a template
149 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
150 | *.manifest
151 | *.spec
152 |
153 | # Installer logs
154 | pip-log.txt
155 | pip-delete-this-directory.txt
156 |
157 | # Unit test / coverage reports
158 | htmlcov/
159 | .tox/
160 | .nox/
161 | .coverage
162 | .coverage.*
163 | .cache
164 | nosetests.xml
165 | coverage.xml
166 | *.cover
167 | *.py,cover
168 | .hypothesis/
169 | .pytest_cache/
170 | cover/
171 |
172 | # Translations
173 | *.mo
174 | *.pot
175 |
176 | # Django stuff:
177 | *.log
178 | local_settings.py
179 | db.sqlite3
180 | db.sqlite3-journal
181 |
182 | # Flask stuff:
183 | instance/
184 | .webassets-cache
185 |
186 | # Scrapy stuff:
187 | .scrapy
188 |
189 | # Sphinx documentation
190 | docs/_build/
191 |
192 | # PyBuilder
193 | .pybuilder/
194 | target/
195 |
196 | # Jupyter Notebook
197 | .ipynb_checkpoints
198 |
199 | # IPython
200 | profile_default/
201 | ipython_config.py
202 |
203 | # pyenv
204 | # For a library or package, you might want to ignore these files since the code is
205 | # intended to run in multiple environments; otherwise, check them in:
206 | # .python-version
207 |
208 | # pipenv
209 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
210 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
211 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
212 | # install all needed dependencies.
213 | #Pipfile.lock
214 |
215 | # poetry
216 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
217 | # This is especially recommended for binary packages to ensure reproducibility, and is more
218 | # commonly ignored for libraries.
219 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
220 | #poetry.lock
221 |
222 | # pdm
223 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
224 | #pdm.lock
225 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
226 | # in version control.
227 | # https://pdm.fming.dev/#use-with-ide
228 | .pdm.toml
229 |
230 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
231 | __pypackages__/
232 |
233 | # Celery stuff
234 | celerybeat-schedule
235 | celerybeat.pid
236 |
237 | # SageMath parsed files
238 | *.sage.py
239 |
240 | # Environments
241 | .env
242 | .venv
243 | env/
244 | venv/
245 | ENV/
246 | env.bak/
247 | venv.bak/
248 |
249 | # Spyder project settings
250 | .spyderproject
251 | .spyproject
252 |
253 | # Rope project settings
254 | .ropeproject
255 |
256 | # mkdocs documentation
257 | /site
258 |
259 | # mypy
260 | .mypy_cache/
261 | .dmypy.json
262 | dmypy.json
263 |
264 | # Pyre type checker
265 | .pyre/
266 |
267 | # pytype static type analyzer
268 | .pytype/
269 |
270 | # Cython debug symbols
271 | cython_debug/
272 |
273 | # PyCharm
274 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
275 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
276 | # and can be added to the global gitignore or merged into this file. For a more nuclear
277 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
278 | #.idea/
279 |
280 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README-zh.md:
--------------------------------------------------------------------------------
1 | # CS305 2023 Spring Project
2 |
3 | **请仔细阅读本文档!** 我们非常努力地使本文档尽可能清晰,并尽可能涵盖我们在测试中遇到的所有问题。然而,我们仍然可能在本文档中遗漏重要的细节。如果有什么不清楚的地方,你应该在这个仓库中提交Issues,或者立即联系老师和SA,而不是猜测你需要做什么。
4 | ## 背景描述
5 | **SDN**: SDN是一种新型的网络范式。正如你在本课程中所学到的,网络被分为控制平面和数据平面。控制平面是一组协议和配置,用于设置转发相关的设备(主机、交换机和路由器),以便它们能够转发数据包。例如,这包括ARP解析、DNS、DHCP、生成树协议、NAT,以及所有的路由协议。SDN最重要的特点就是控制平面和数据平面的分离。将控制逻辑集中在一个中心化的控制器中,由控制器对网络流量进行控制和管理。传统网络则将控制逻辑分布在各个网络设备中。而我们在Project中需要编写的就是一个中心化的控制器。
6 | 为了构建SDN的开发环境,我们需要使用以下两个组件。
7 |
8 | **Mininet**: Mininet是一个广泛使用的网络仿真器,它可以在Linux主机上创建任意的虚拟网络环境。为了教学或软件验证的方便,开发者们通常使用Mininet构建虚拟的网络拓扑。开发者可以随意在网络中添加虚拟主机、虚拟交换机等网络资源并对自己的SDN控制器进行测试。
9 |
10 | **Ryu**: Ryu是一个用于构建SDN控制器的开源框架。当我们通过mininet构建好虚拟SDN网络之后,我们利用Ryu来编写并部署SDN控制器。Ryu控制器可以与mininet中的虚拟交换机进行通信,从而控制虚拟网络的行为。下图展示出了Ryu和Mininet的架构。Ryu通过监控switch中的网络流量来做出相应动作(例如如何forward),而Mininet负责实际的网络流量的传输。
11 |
12 |
13 |
14 |
15 |
16 | 在这个project中,我们编写一个支持两种主要功能的Ryu controller:
17 | - 作为简易的DHCP服务器
18 | - 实现最短路Switching算法
19 |
20 | **注意:** 我们将使用mininet构建不同结构的网络拓扑来测试你所编写的Ryu controller。因此,你需要确保你的代码在使用自定的网络拓扑结构的情况下也能正常工作。
21 |
22 | ## 环境搭建
23 | 环境搭建主要分为两个步骤,首先是Mininet的安装,其次是安装我们提供的实验框架(包含Ryu)。
24 |
25 | ### 安装Mininet
26 | Mininet需要在Linux环境中运行。我们强烈建议在个人电脑上安装虚拟机,并在虚拟机中安装Mininet。
27 | #### Windows和其他amd64结构用户配置指南
28 | 1. 安装VMware或者VirtualBox
29 | 2. 直接下载Mininet官方配置好Mininet组件的的Ubuntu镜像[mininet-2.3.0-210211-ubuntu-20.04.1](https://github.com/mininet/mininet/releases/download/2.3.0/mininet-2.3.0-210211-ubuntu-20.04.1-legacy-server-amd64-ovf.zip)
30 | 3. 下载完成后解压双击ovf即可自动呼叫VMware等虚拟机软件引导创建
31 | 4. 创建完成后启动虚拟机,输入用户名`mininet`和密码`mininet`即可登录
32 | 你也可以参考这篇指南中安装虚拟机的部分。
33 |
34 | #### macOS ARM用户配置指南
35 | 如果您使用的是M1或者其他苹果芯片,请务必按照以下步骤配置:
36 | 1. 安装VMware Fusion或者Parallel Desktop
37 | 2. 安装Ubuntu 20.04.01 ARM版本(和芯片架构保持一致,建议搜索macOS m1安装Ubuntu Server 20.04)
38 | 3. 配置虚拟机并运行
39 | 4. 在虚拟机中安装Mininet
40 | ```
41 | sudo apt-get update
42 | sudo apt-get install mininet
43 | ```
44 | 5. 在虚拟机中安装python,pip和git
45 | ```
46 | sudo apt-get install python3 python3-pip git
47 | ```
48 | #### 检查Mininet是否安装成功
49 | 在虚拟机中打开你的终端(命令行),输入如下命令,检测Mininet是否配置成功。
50 | ```
51 | sudo mn --test pingall
52 | ```
53 | 当你看见类似的输出则证明Mininet的环境配置完成。
54 |
55 |
56 |
57 |
58 |
59 | **Mininet必须在root身份下执行。务必保证使用的时候使用了sudo或直接在root身份下运行**
60 |
61 | #### 安装实验框架
62 | 由于Ubuntu默认的Python版本过高,因此我们需要使用miniconda安装Python3.8的环境。
63 | 如果你是windows下的AMD 64Ubuntu用户,你可以直接使用以下指令安装miniconda。
64 | ```
65 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
66 | sh Miniconda3-latest-Linux-x86_64.sh -b -p ${HOME}/software/miniconda3
67 | echo "export PATH=${HOME}/software/miniconda3/bin:\$PATH" >> ~/.bashrc
68 | source ~/.bashrc
69 | conda init bash
70 | source ~/.bashrc
71 | conda create -n cs305 python=3.8
72 | conda activate cs305
73 | python --version
74 | ```
75 |
76 | 如果你是macos下的ARM Ubuntu用户,你可以直接使用以下指令安装miniconda。
77 | ```
78 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh
79 | sh Miniconda3-latest-Linux-aarch64.sh -b -p ${HOME}/software/miniconda3
80 | echo "export PATH=${HOME}/software/miniconda3/bin:\$PATH" >> ~/.bashrc
81 | source ~/.bashrc
82 | conda init bash
83 | source ~/.bashrc
84 | conda create -n cs305 python=3.8
85 | conda activate cs305
86 | python --version
87 | ```
88 | 安装完Python环境后你需要安装本次Project的实验框架。
89 |
90 | 本次Project仓库位于[CS305-2023Spring-Project](https://github.com/SUSTech-HPCLab/CS305-2023Spring-Project)。
91 | 你可以下载Zip文件或者clone这个仓库。
92 | 下载好源代码之后通过如下指令安装Python包依赖。
93 | ```
94 | conda activate cs305
95 | git clone https://github.com/SUSTech-HPCLab/CS305-2023Spring-Project.git
96 | cd CS305-2023Spring-Project
97 | pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
98 |
99 | # Check if Ryu is installed successfully
100 | ryu-manager --version
101 | # If you see the version information of ryu-manager, the installation is successful.
102 | ```
103 |
104 | **你需要检查系统中是否安装了 `arping`。在你的ubuntu terminal中输入arping。如果command not found, 你需要输入`sudo apt-get install arping `来安装arping**
105 |
106 | ## 任务描述
107 | 本次Project的基础部分包含两个部分:一个是简易的DHCP server。另一个是实现最短路switching算法。为了简化实验,我们对网络拓扑结构进行了如下的限制。
108 | - Mininet中只包含L2交换机和Host(主机)。这意味着我们的网络是一个大型局域子网。无需考虑多子网的情况。
109 | - Mininet中一个Host只会和一个交换机相连。
110 | ### 简易DHCP Server
111 | DHCP: Dynamic Host Configuration Protocol,中文为动态主机设置协议。主要目的是满足内部网或网络服务供应商自动分配IP地址给用户的需求。
112 |
113 | 尽管Mininet在默认情况下会自动地给每一个host分配一个ip。我们会在测试脚本中关闭mininet的ip初始化。你可以参考DHCP的协议标准[RFC 2131](https://www.rfc-editor.org/rfc/rfc2131)来实现一个功能丰富完备DHCP server。无论如何,你只需要做到:
114 |
115 | - **在host加入子网时,你设计的controller能够识别到dhcp packet并分配一个合法的IP地址给host**
116 |
117 | 在下个章节我们会介绍如何完成这个任务以及如何测试自己是否成功实现了DHCP server。
118 |
119 | ### 最短路Switching
120 | 你的任务是建立一个全局最短路径交换表,并在交换机上安装转发规则以实现这些路径。你将根据控制器controller收集的全局拓扑信息,在控制器上建立这个表。**以达到任意两个host之间的数据传输路径为最短路径。**
121 |
122 | 与传统的L2(Layer-2)交换机或L3(Layer-3)路由器不同,SDN交换机没有专门的MAC学习表(MAC-learning)或路由表。相反,SDN交换机使用一个更通用的流表结构,可以取代这些和其他结构。流表中的每个条目或规则都包含一组匹配标准(基于以太网、IP、TCP、UDP和其他标头的字段),选择特定的数据包,并包含对每个匹配规则的数据包应采取的一系列行动(action)。
123 | 你设计的Switching模块应该做到:首先匹配目标MAC地址(dest MAC), 根据匹配规则执行对应的Action,能够让数据包从正确的端口发送出去以到达目的地。
124 |
125 | **如果你对action,flowtable等名词感觉陌生,请参考课程slides,教科书或查阅Ryu的文档和Openflow协议的相关信息。**
126 |
127 | 匹配规则的作用与传统路由表中的目的地和掩码字段相同,而action的作用与传统路由表中的接口(interface)字段相同,都表明了数据包该发到哪里去。需要注意的是你的拓扑结构不受限于树状结构,因为你收集到了全部交换机的信息,循环不应该是一个问题。事实上,你必须测试你的switching能不能在有环路的拓扑结构上有效。
128 | 为了计算最短路径,你应该使用Bellman-Ford算法或Djikstra算法来计算从每任意两个host之间的最短路径。确定了从host A到达host B的最短路径后,控制器必须向路径中的每个交换机安装流量表中的规则和相应的动作。当拓扑结构发生变化时,你应该更新受影响的路径规则。
129 | ## 实现与测试
130 | 在这个章节中,我们将结合实验框架代码给大家介绍实现上述功能的思路。并告诉大家如何进行测试。
131 | ### 实验框架
132 | 我们提供了一些初始文件来帮助你们快速开始开发功能。项目的结构如下所示
133 | ```
134 | ├── controller.py # The main file of the controller
135 | ├── dhcp.py # Implement DHCP server here
136 | ├── ofctl_utilis.py # Don't need to modify this file, it provides useful functions for building and sending packets
137 | ├── requirements.txt
138 | └── tests
139 | ├── dhcp_test
140 | │ └── test_network.py
141 | └── switching_test
142 | └── test_network.py
143 | ```
144 |
145 | - controller.py:这个文件是项目的入口,你应该在这个文件中实现监控SDN网络中网络组件的增添,删除以及经过交换机的数据包流量。并根据收集到的信息触发DHCP功能或最短路switching功能
146 | - dhcp.py: DHCP的实现细节应该在这个文件中被呈现。controller.py 通过调用dhcp.py的相关函数触发dhcp功能。
147 | - tests: 为测试dhcp和switching功能编写的用于构建mininet网络的脚本。
148 | ### 实现简易DHCP
149 | #### 过程描述
150 | 在SDN中实现简易的DHCP包括了如下过程:
151 | 1. Host在加入网络时广播发送DHCP DISCOVER packet
152 | 2. Controller接收到DHCP DISCOVER packet后,选择一个空闲IP,构建DHCP OFFER packet发送回Host
153 | 3. Host在收到OFFER packet后,广播DHCP REQUEST信息。确认所选择的DHCP server配置。
154 | 4. Controller收到DHCP REQUEST信息后,构建DHCP ACK packet并发送回Host。
155 |
156 | **其中第一步和第三步由已经在测试脚本中实现了,你需要关注第二和第四步的实现。**
157 |
158 | #### 接收DHCP协议包
159 | 在`controller.py`文件中我们提供了接收DHCP协议包的相关代码。这个函数会在数据包进入switch时被调用。`Datapath`在这里是接收到数据包的switch。`inPort`是数据包传入的端口。如果这个数据包可以被dhcp协议解析,我们调用`DHCPServer.handle_dhcp`函数进行处理。如果不能被dhcp解析,你应该进行判断是否是别的协议包,并针对不同的协议作出不同的处理。
160 | ```
161 | @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
162 | def packet_in_handler(self, ev):
163 | try:
164 | msg = ev.msg
165 | datapath = msg.datapath # switch
166 | pkt = packet.Packet(data=msg.data)
167 | pkt_dhcp = pkt.get_protocols(dhcp.dhcp)
168 | inPort = msg.in_port
169 | if not pkt_dhcp:
170 | # TODO: handle other protocols like ARP
171 | pass
172 | else:
173 | DHCPServer.handle_dhcp(datapath, inPort, pkt)
174 | return
175 | except Exception as e:
176 | self.logger.error(e)
177 | ```
178 | #### 构建DHCP协议包
179 | 你需要在`dhcp.py`文件中的`handle_dhcp`函数中分辨接收的DHCP数据包类型。根据传入的数据包类型决定发送DHCP OFFER packet还是DHCP ACK packet。在选择合法IP时,你需要结合`dhcp.py`文件中的`Config`类中规定的 `start_ip`,`end_ip`,`netmask`这三个属性。这三个属性的共同决定了子网的大小——你可以分配的IP的数量。详情可以查看dhcp.py文件中的注释。
180 | #### 测试DHCP功能
181 | 假设在project的目录中,首先在一个terminal中执行如下命令
182 | ```
183 | ryu-manager --observe-links controller.py
184 | ```
185 | 新建另一个terminal,在新的terminal中执行如下命令
186 | ```
187 | cd ./tests/dhcp_test/
188 | sudo env "PATH=$PATH" python test_network.py # share the PATN env with sudo user
189 | ```
190 | 我们在dhcp.py文件的默认设置是从192.168.1.2开始分配IP。我们在执行test_network.py的terminal中输入`h1 ifconfig`和`h2 ifconfig`指令即可查看是否为这两台host分配好IP。只要出现了下图的内容,我们就认为基础的简易DHCP功能实现完成了。
191 |
192 |
193 |
194 |
195 | ### 实现最短路Switching
196 |
197 | 我们可以利用SDN架构,在没有广播的情况下进行最短路径switching,具体如下:
198 |
199 | - 当一个交换机被添加或删除以及交换机之间的链接被建立或删除时,网络拓扑结构将发生变化,这意味着最短路径也将发生变化。相应地,你应该更新受影响的交换机上的流表,以确保数据包总是沿着交换机之间的最短路径传输。为了实现这个功能,你可能需要创建一个抽象的数据结构来计算交换机之间的距离。
200 | - 像普通的网络架构一样,当主机想发送一个数据包时,它会查询它的路由表,以确定目的地是否在同一个子网中(无需考虑这种情况,我们的Project中只有一个子网)。这意味着主机将把数据包作为一个以太网帧发送到IP目的地,目的地的MAC地址(而不是网关或路由器的MAC地址而是下一跳的交换器的MAC地址)。如果主机不知道目的地的MAC地址,它会发出一个ARP请求
201 | - 当交换机收到ARP请求时,它将把请求作为PacketIn消息发送给controller,而不是广播它
202 | - controller将收到PacketIn消息,并查找目标主机的MAC地址,然后生成一个响应(在PacketOut消息内),供交换机发回给发送方主机。
203 | - 收到响应后,主机将发送IP数据包到目的地的MAC地址。
204 | - 在指向目的地的路径上的每个交换机上,数据包将在目的地MAC地址上匹配,并在正确的端口上转发。
205 |
206 | 为了让controller知道每台主机的MAC地址,我们必须建立一个协议,让主机告知控制器其地址。对于这项任务,我们要求主机在连接时发送一个不请自来的ARP回复(也称为 "无偿ARP",或arping),以告诉网络它的MAC和IP地址--我们已经配置Mininet在启动模拟网络时自动这样做(你可以在tests/switching_test/test_network.py中查看)。
207 | 最后,由于我们没有广播ARP消息,所有的ARP请求将被发送到控制器。当你收到一个ARP请求时,你应该产生一个适当的响应,以便主机可以填充它的ARP表。
208 |
209 |
210 | #### 测试最短路Switching
211 | 我们在`tests/switching_test/test_network.py`中提供了一个测试网络。它的网络拓扑如下。
212 |
213 |
214 |
215 |
216 |
217 | 在`test_network.py`中构建了一个三角网络。它首先会在网络中添加host, switch, link, 你需要利用OpenFlow协议监控这些事件,当这些事件发生时,你需要在控制器中进行相应的处理来实现最短路switching。当所有的组件(host,switch,link)初始化完毕后,我们在每一个host上执行`arping`命令。你需要识别这些`arping` packet并告知host如何确定目的地MAC。在这个测试中,你可以使用mininet cli中的指令`pingall`来检测网络的连通性。
218 | 在这个网络中,h1到h2的最短路是h1->s1->s2->h2。h1到h3的最短路是h1->s1->s3->h3。任意两个host之间的数据传输所经过的switch数量应该不超过两个。
219 |
220 | 在project的目录中,首先在一个terminal中执行如下命令
221 | ```
222 | ryu-manager --observe-links controller.py
223 | ```
224 | 新建另一个terminal,在新的terminal中执行如下命令
225 | ```
226 | cd ./tests/switching_test/
227 | sudo env "PATH=$PATH" python test_network.py
228 | ```
229 | 大约两秒之后,你会发现你在第二个terminal中进入了mininet cli。
230 | **你应该在这里输入`pingall` command来测试你的网络的连通性。** **为了方便助教检查你们的代码,请在controller中实现展示最短路径的功能**。下图是一个展示最短路径的例子。它在`pingall`指令之后在第一个terminal中展示出了任意两个host之间的路径及其长度。这里的distance为3,指的是h1->s1->s3->h3的路径长度为3(3条边)。
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 | 你在第二个terminal中会看到下图的结果。这表明没有丢包出现,网络是连通的。
239 |
240 |
241 |
242 |
243 |
244 | ## 评分
245 | 你需要在第16周的实验课上演示你的项目。展示完你的项目后,你需要提交:
246 |
247 | - `report.pdf` - 请清楚地说明你的项目的架构,并描述你所做的实施细节。如果需要,请添加截图或代码。你需要提供一个复杂的测试样例来证明你的程序的鲁棒性。
248 | - `src.zip` - 一个名为src的目录,包含你的源代码。
249 |
250 | 下面是暂定的评分规则:
251 | - Environment setup: 10 pts
252 | - DHCP: 30 pts
253 | - Shortest path switching: 50 pts
254 | - Report: 10 pts
255 | - Bonus: Up to 20 pts
256 |
257 |
258 |
259 | ### Bonus
260 |
261 | 你也许可以实现以下部分功能来获取Bonus分数。我们实现功能的完成度和难度来决定Bonus分数。你不需要完成下面所有的功能。
262 |
263 |
264 | - 实现DHCP租约时长的功能。
265 | - 根据RFC协议设计,确保DHCP不会重复分配IP。
266 | - 实现不同的路由算法。
267 | - 利用Ryu实现更多的功能比如DNS, 防火墙和NAT。
268 | - 使用Mininet研究更多你在计算机网络课程中学到的网络功能,如TCP行为、TCP Reno与TCP Tahoe的比较、[Bufferbloat](https://en.wikipedia.org/wiki/Bufferbloat)问题。
269 | - 更多你感兴趣的。请先和老师讨论你的想法。
270 |
271 | 请注意,你需要详细解释你做了什么,如何测试额外的功能,以及你在报告中发现了什么,以获得bonus分。你还需要设法如何在第16周的演示中很好地展示你的bonus功能。
272 | ## Hints
273 |
274 | ### 同步代码
275 | 你可以使用Visual Studio Code Remote extension通过SSH在虚拟机中编写代码
276 |
277 | ### 有用的Mininet Command
278 | 我们建议每次构建新的网络拓扑时,重启你的controller和mininet。你可能需要使用
279 | ```
280 | sudo mn -c
281 | ```
282 | 来清理之前配置的网络。
283 |
284 | 以下是一些可能可以提供帮助的指令
285 | ```
286 | MN> arping h1 # 从h1发送一个arping,产生一个ARP请求,识别h1的MAC和IP地址。触发一个EventHostAdd事件
287 | MN> arping_all # 从所有主机发送一个arping。这个命令会在测试脚本中自动运行。你也可以自己重新运行它--如果你想重启控制器而不重启mininet,这非常有用
288 | MN> h1 ping h2 -c 1 # 从h1向h2发送一个单一的ping包
289 | MN> pingall # Ping所有的主机
290 | MN> net # 查看当前的网络拓扑结构
291 | MN> dpctl dump-flows # 展示所有交换机的流量表
292 | ```
293 |
294 | ### 如何添加Forwarding Rule
295 |
296 | 你可以阅读`ofctl_utils.py`的源码来了解更多细节。以下是一个简单的例子向你展示如何在switch中添加一个forwarding rule。
297 | ```
298 | # Using function provided by ofctl_utils.py
299 | from ofctl_utils import OfCtl, VLANID_NONE
300 |
301 | def add_forwarding_rule(self, datapath, dl_dst, port):
302 | ofctl = OfCtl.factory(datapath, self.logger)
303 | actions = [datapath.ofproto_parser.OFPActionOutput(port)]
304 |
305 | ofctl.set_flow(cookie=0, priority=0,
306 | dl_type=ether_types.ETH_TYPE_IP,
307 | dl_vlan=VLANID_NONE,
308 | dl_dst=dl_dst,
309 | actions=actions)
310 | ```
311 |
312 | ### 有用的文档
313 | 1. Ryu's API documentation https://ryu.readthedocs.io/en/latest/index.html
314 | 2. Mininet's document https://github.com/mininet/mininet/wiki/Documentation
315 | 3. Mininet source code https://github.com/mininet/mininet
316 | 4. Openflow quick start https://homepages.dcc.ufmg.br/~mmvieira/cc/OpenFlow%20Tutorial%20-%20OpenFlow%20Wiki.htm
317 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CS305-2023Spring-Project
2 |
3 | **UPDATES: Please read the project demo instruction at [Demo Insrtuction](https://github.com/SUSTech-HPCLab/CS305-2023Spring-Project/blob/main/project_demo_instructions.md).**
4 |
5 | **Please read this project specification carefully and keep track of the updates!!!**
6 |
7 | **IMPORTANT NOTE**: We try our best to make this specification as clear as possible and cover all the problems we met during our testing. However, it is not uncommon that we could still miss important details in this specification. If there is anything unclear, you should submit issues in this repository or contact the instructors and SAs immediately, rather than guessing what you are required to do.
8 |
9 | ## Introduction
10 | **SDN**: Software-defined networking (SDN) is a new network paradigm. A network can be divided into control and data planes. The control plane is a set of protocols and configurations used to set up forwarding-related devices (hosts, switches, and routers) so that they can forward packets properly. This includes ARP resolution, DNS, DHCP, spanning tree protocol, NAT, and all routing protocols, many of which are covered in our CS305 course. The most important feature of SDN is the separation of the control plane and the data plane. By centralizing the control logic in a centralized controller, the controller can control and manage network traffic in a **programmable** manner. In contrast, traditional networks distribute control logic across network devices. In this project, we will write a centralized controller. To build a local SDN development environment, we use the following two software tools.
11 |
12 | **Mininet**: Mininet is a widely-used network emulator which enables creating arbitrary virtual network environments on a Linux host. For teaching or software verification purposes, developers often use Mininet to build virtual network topologies. Developers can emulate networks with virtual hosts, virtual switches, and other network components and test their SDN controllers.
13 |
14 | **Ryu**: Ryu is an open-source framework for building SDN controllers. After we build a virtual SDN network using Mininet, we use Ryu to write and deploy the SDN controller. A Ryu controller can communicate with the virtual switches in Mininet to control the behaviors of the virtual network. The figure below shows the overall architecture of Ryu and Mininet. Ryu monitors network traffic in switches to take corresponding actions (such as how to forward), while Mininet is responsible for the actual transmission of network traffic.
15 |
16 |
17 |
18 |
19 | In this project, we will write a Ryu controller to support two main functions:
20 |
21 | - Serve as a simple DHCP server
22 | - Implement the shortest path switching algorithm
23 |
24 | **NOTE:** We will use Mininet to build different network topologies to test the correctness of the Ryu controller you write. You are thus required to ensure your code works properly using customized network topologies.
25 |
26 | ## Environment Setup
27 | The environment setup consists of two main steps. First, install Mininet, and second, install the experimental framework we provide (including Ryu).
28 |
29 | ### Install Mininet
30 | Mininet needs to run in a Linux environment. We strongly recommend installing a virtual machine on a personal computer and then installing Mininet in the virtual machine.
31 |
32 | #### Windows and Other amd64 Users' Configuration Guide
33 | 1. Install VMware or VirtualBox.
34 | 2. Download the official Ubuntu image with mininet [mininet-2.3.0-210211-ubuntu-20.04.1](https://github.com/mininet/mininet/releases/download/2.3.0/mininet-2.3.0-210211-ubuntu-20.04.1-legacy-server-amd64-ovf.zip).
35 | 3. After downloading the image, unzip and double-click on the ovf file to automatically call the VMware or other virtual machine software to create it.
36 | 4. login to the virtual machine with the username `mininet` and paasword `mininet`.
37 | 5. You can also refer to the installation of the virtual machine in this [guide](https://naiv.fun/Dev/41.html).
38 | #### macOS ARM Users' Configuration Guide
39 | If you are using an M1 or other Apple chips, be sure to configure it as follows:
40 |
41 | 1. Install VMware Fusion or Parallel Desktop.
42 | 2. Install Ubuntu 20.04.01 ARM version (consistent with the chip architecture, it is recommended to search for macOS m1 installation of Ubuntu Server 20.04).
43 | 3. Configure the virtual machine and run it.
44 | 4. Install Mininet.
45 | ```
46 | sudo apt-get update
47 | sudo apt-get install mininet
48 | ```
49 | 5. Install Python, Pip and git
50 | ```
51 | sudo apt-get install python3 python3-pip git
52 | ```
53 |
54 | #### Check whether Mininet is installed correctly
55 | Open your terminal (command line) in the virtual machine and enter the following command to check if Mininet is configured correctly.
56 | ```
57 | sudo mn --test pingall
58 | ```
59 | If you see output similar to the following, it means that the Mininet environment is configured correctly.
60 |
61 |
62 |
63 |
64 |
65 | **Mininet must be executed as root. Be sure to use sudo or run it directly as root when using it.**
66 |
67 | #### Experiment Framework Installation
68 | Since Ubuntu's default Python version is too high, we need to install the Python 3.8 environment using miniconda.
69 | If you are an AMD64 Ubuntu user under windows, you can install miniconda directly using the following command.
70 | ```
71 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
72 | sh Miniconda3-latest-Linux-x86_64.sh -b -p ${HOME}/software/miniconda3
73 | echo "export PATH=${HOME}/software/miniconda3/bin:\$PATH" >> ~/.bashrc
74 | source ~/.bashrc
75 | conda init bash
76 | source ~/.bashrc
77 | conda create -n cs305 python=3.8
78 | conda activate cs305
79 | python --version
80 | ```
81 |
82 | If you are an ARM Ubuntu user under macos, you can install miniconda directly using the following command.
83 | ```
84 | wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh
85 | sh Miniconda3-latest-Linux-aarch64.sh -b -p ${HOME}/software/miniconda3
86 | echo "export PATH=${HOME}/software/miniconda3/bin:\$PATH" >> ~/.bashrc
87 | source ~/.bashrc
88 | conda init bash
89 | source ~/.bashrc
90 | conda create -n cs305 python=3.8
91 | conda activate cs305
92 | python --version
93 | ```
94 | After installing the Python environment you need to install the experimental framework for this Project.
95 |
96 | The project repository is located at [CS305-2023Spring-Project](https://github.com/SUSTech-HPCLab/CS305-2023Spring-Project). You can download the source code by downloading the ZIP file or cloning the repository. After downloading the source code, install the Python package dependencies with the following command.
97 | ```
98 | conda activate cs305
99 | git clone https://github.com/SUSTech-HPCLab/CS305-2023Spring-Project.git
100 | cd CS305-2023Spring-Project
101 | pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
102 |
103 |
104 | # Check if Ryu is installed successfully
105 | ryu-manager --version
106 | # If you see the version information of ryu-manager, the installation is successful.
107 | ```
108 |
109 | **You need to check if `arping` is installed in the VM. Enter `arping` in your Ubuntu terminal. If it shows "command not found," you need to enter `sudo apt-get install arping` to install arping.**
110 |
111 |
112 | ## Tasks
113 | The basic part of this project includes two parts: a simple DHCP server and implementation of the shortest path switching algorithm. To simplify the experiment, we have imposed the following restrictions on the network topology structure.
114 | - The Mininet only contains L2 switches and hosts. This means that our network is a large local subnet, and there is no need to consider multi-subnet scenarios.
115 | - Each host in Mininet is only connected to one switch.
116 |
117 | ### Simple DHCP Server
118 | DHCP, Dynamic Host Configuration Protocol, is mainly used for automatically assigning IP addresses to users in an internal network or network service provider.
119 |
120 | Although Mininet automatically assigns an IP address to each host by default, we will turn off the IP initialization of Mininet in the test script. You can refer to the DHCP protocol standard [RFC 2131](https://www.rfc-editor.org/rfc/rfc2131) to implement a feature-rich and complete DHCP server. In any case, you only need to:
121 |
122 | - **When the host joins the subnet, the controller you design can recognize the DHCP packet and assign a valid IP address to the host.**
123 |
124 | In the next section, we will introduce how to complete this task and how to test whether you have successfully implemented the DHCP server.
125 |
126 | ### Shortest Path Switching
127 | Your task is to establish a global shortest path switching table and install forwarding rules on the switches to implement these paths. You will build this table on the controller based on the global topology information collected by the controller. **The purpose is to achieve the shortest path between any two hosts.**
128 |
129 | Unlike traditional Layer-2 switches or Layer-3 routers, SDN switches do not have a dedicated MAC learning table (MAC-learning) or routing table. Instead, SDN switches use a more general *flow table* structure, which can replace these and other structures. Each entry or rule in the flow table contains a set of matching criteria (based on fields in Ethernet, IP, TCP, UDP, and other headers), selects specific packets, and contains a series of actions to be taken for each matching rule.
130 |
131 | Your switching module should match the destination MAC address and execute the corresponding action based on the matching rule to send the packet to the correct port to reach its destination.
132 |
133 | **If you are unfamiliar with the terms such as action and flow table, please refer to our slides, the course textbook, and the documentation of Ryu and the relevant information of the Openflow protocol.**
134 |
135 | The purpose of matching rules is the same as the destination and mask fields in traditional routing tables, while the purpose of actions is the same as the interface field in traditional routing tables, indicating where the packet should be sent. It should be noted that your topology is not limited to a tree structure, because you have collected information from all switches, and loops should not be a problem. In fact, you must test whether your switching is effective in topologies with loops.
136 |
137 | To calculate the shortest path, you should use the Bellman-Ford algorithm or Dijkstra's algorithm to calculate the shortest path between any two hosts. After determining the shortest path from host A to host B, the controller must install the rules and corresponding actions in the flow table to each switch in the path. When the topology changes, you should update the affected path rules.
138 |
139 | ## Implementation and Testing
140 | In this section, we will combine the experimental framework code to introduce the implementation ideas of the above functions and tell you how to test them.
141 | ### Experimental Framework
142 | We provide some basic starter programs to help you start with this project. The project structure is as follows.
143 | ```
144 | ├── controller.py # The main file of the controller
145 | ├── dhcp.py # Implement DHCP server here
146 | ├── ofctl_utilis.py # Don't need to modify this file, it provides useful functions for building and sending packets
147 | ├── requirements.txt
148 | └── tests
149 | ├── dhcp_test
150 | │ └── test_network.py
151 | └── switching_test
152 | └── test_network.py
153 | ```
154 |
155 | - `controller.py`: This file is the entry point of the project. You should implement monitoring of network components in the SDN network, addition and deletion, data flow through switches, and trigger DHCP or shortest path switching functions based on collected information.
156 | - `dhcp.py`: The implementation details of DHCP should be presented in this file. controller.py calls relevant functions in dhcp.py to trigger the DHCP function.
157 | - `tests`: Scripts for building mininet networks to test dhcp and switching functions.
158 | ### Implementing Simple DHCP
159 | Implementing simple DHCP in SDN includes the following steps:
160 | 1. When a host joins the network, it broadcasts a DHCP DISCOVER packet.
161 | 2. After the controller receives the DHCP DISCOVER packet, it selects a free IP and constructs a DHCP OFFER packet to send back to the host.
162 | 3. After the host receives the OFFER packet, it broadcasts the DHCP REQUEST information to confirm the DHCP server configuration it has selected.
163 | 4. After the controller receives the DHCP REQUEST information, it constructs a DHCP ACK packet and sends it back to the host.
164 |
165 | **The first and the third steps are implemented in the test script, and you should focus on implementing the second and fourth steps.**
166 |
167 | #### Receiving DHCP Protocol Packets
168 | In the `controller.py` file, we have provided relevant code for receiving DHCP protocol packets. This function is called when a packet enters the switch. `Datapath` here is the switch that receives the packet, and `inPort` is the port through which the packet enters. If this packet can be parsed by the DHCP protocol, we call the `DHCPServer.handle_dhcp` function to process it. If it cannot be parsed by DHCP, you should determine whether it is another protocol packet and make different treatments for different protocols.
169 | ```
170 | @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
171 | def packet_in_handler(self, ev):
172 | try:
173 | msg = ev.msg
174 | datapath = msg.datapath # switch
175 | pkt = packet.Packet(data=msg.data)
176 | pkt_dhcp = pkt.get_protocols(dhcp.dhcp)
177 | inPort = msg.in_port
178 | if not pkt_dhcp:
179 | # TODO: handle other protocols like ARP
180 | pass
181 | else:
182 | DHCPServer.handle_dhcp(datapath, inPort, pkt)
183 | return
184 | except Exception as e:
185 | self.logger.error(e)
186 | ```
187 |
188 | #### Building DHCP Protocol Packets
189 |
190 | You need to distinguish the received DHCP packet type in the `handle_dhcp` function in `dhcp.py`. Based on the received packet type, decide whether to send a DHCP OFFER packet or a DHCP ACK packet. When selecting a legal IP address, you need to combine the `start_ip`, `end_ip`, and `netmask` properties defined in the `Config` class in `dhcp.py`. These three properties together determine the size of the subnet—the number of IP addresses you can allocate. See the comments in `dhcp.py` for details.
191 |
192 | #### Testing DHCP Functionality
193 |
194 | Assuming that you are in the directory of the project, first execute the following command in a terminal:
195 |
196 | ```
197 | ryu-manager --observe-links controller.py
198 | ```
199 |
200 | Open another terminal, and execute the following command:
201 |
202 | ```
203 | cd ./tests/dhcp_test/
204 | sudo env "PATH=$PATH" python test_network.py # share the PATN env with sudo user
205 | ```
206 |
207 | We have set the default IP allocation to start from `192.168.1.2` in `dhcp.py`. You can check whether the two hosts have been assigned IP addresses by using command `h1 ifconfig` and `h2 ifconfig`.
208 | As long as the following result appears, we consider the basic simple DHCP function implementation is completed.
209 |
210 |
211 |
212 |
213 |
214 | #### Implementing The Shortest Path Switching
215 |
216 | We can leverage the centralized SDN architecture to perform the shortest path switching without broadcasts, as follows:
217 | ### Implementing Shortest Path Switching
218 |
219 | - When a switch is added or removed and a link between switches is established or removed, the network topology will change, which means the shortest path will also change. Correspondingly, you should update the flow table on the affected switch to ensure that data packets are always transmitted along the shortest path between switches. In order to implement this function you may need to create an abstract data structure to calculate the distance between switches.
220 |
221 | - As usual, when a host wants to send a packet, it consults its routing table to determine if the destination is in the same subnet (will always be true in this project). This means the host will send the packet to the IP destination as an Ethernet frame destined to the MAC address of the destination (as opposed to the MAC address of a gateway or router). If the host does not know the MAC address for the destination, it issues an ARP request
222 |
223 | - When a switch receives the ARP request, it will send the request to the controller as a PacketIn message, rather than broadcasting it
224 | - The controller will receive the PacketIn message and look up the MAC address of the destination host, then generate a response (inside a PacketOut message) for the switch to send back to the sender host
225 | - Upon receiving the response, the host will send the IP packet to the destination’s MAC address
226 | - At each switch along the path to the destination (as determined previously by your code), the packet will match on the destination MAC address and be forwarded on the correct port.
227 |
228 | In order for the controller to know the MAC address of each host, we must establish a protocol for hosts to inform the controller of its address. For this project, we require that hosts send an unsolicited ARP reply (also called a “gratuitous ARP”, or an arping) when connecting to tell the network its MAC and IP address—we have configured Mininet to do this automatically when starting the emulated network.
229 | Finally, since we are not broadcasting ARP messages, all ARP requests will be sent to the controller instead. When you receive an ARP request, you should generate an appropriate response so a host can populate its ARP table.
230 |
231 | #### Testing Shortest Path Switching
232 | We provide a test network in `tests/switching_test/test_network.py`. Its network topology is as follows.
233 |
234 |
235 |
236 |
237 |
238 | In `test_network.py`, a triangle network is constructed by adding hosts, switches, and links to the network. You need to monitor these events using the OpenFlow protocol and perform corresponding processing in the controller to achieve the shortest path switching. After all components (hosts, switches, links) are initialized, we execute the `arping` command on each host. You need to identify these `arping` packets and inform the hosts how to determine the destination MAC address. In this test, you can use the `pingall` command in the mininet CLI to test network connectivity.
239 | In this network, the shortest path from h1 to h2 is h1->s1->s2->h2, and the shortest path from h1 to h3 is h1->s1->s3->h3: the number of switches that data transmission between any two hosts passes through should not exceed two.
240 |
241 | In the project's directory, first execute the following command in one terminal:
242 | ```
243 | ryu-manager --observe-links controller.py
244 | ```
245 | In another terminal, execute the following command:
246 | ```
247 | cd ./tests/switching_test/
248 | sudo env "PATH=$PATH" python test_network.py # share the PATN env with sudo user
249 | ```
250 | After about two seconds, you will find that you have entered the mininet CLI in the second terminal.
251 | **You should enter the `pingall` command here to test the connectivity of your network.** **To facilitate checking on your code, please implement the function of displaying the shortest path in the controller.** The following figure shows an example of displaying the shortest path. After the `pingall` command, it displays the path and its length between any two hosts in the first terminal. Here, the distance is 3, which means that the path length from h1->s1->s3->h3 is 3 (3 edges).
252 |
253 |
254 |
255 |
256 |
257 | You will see the result in the following figure in the second terminal. This indicates that there is no packet loss and the network is connected.
258 |
259 |
260 |
261 |
262 |
263 | ## Grading and Submissions
264 |
265 | You will need to demonstrate your project on Week 16 during your lab section. After demonstrating your project, you are required to submit:
266 |
267 | - `report.pdf` — Please clearly illustrate the architecture of your project and describe the implementation details of what you've done. Add screenshots or codes if needed. You need to provide a complex testcase to demonstrate the robustness of your program.
268 | - `src.zip` — A directory named src containing your source code.
269 |
270 | Here is a TENTATIVE grading rule for your project:
271 |
272 | - Environment setup: 10 pts
273 | - DHCP: 30 pts
274 | - Shortest path switching: 50 pts
275 | - Report: 10 pts
276 | - Bonus: Up to 20 pts
277 |
278 | ### Bonus (Up to 20 points)
279 |
280 | You may implement some of the following features to get bonus points. We will decide your bonus points based on the completeness, complexity, and difficulty of your implemented functions. No need to implement all the features.
281 |
282 | - Implement the function of DHCP lease duration.
283 | - Design the DHCP function according to the RFC protocol to ensure that DHCP does not duplicate IP allocation.
284 | - Implement different routing algorithms.
285 | - Implement more functions using Ryu, such as DNS, firewall, and NAT.
286 | - Use Mininet to study more network features you have learned in the computer network course, such as TCP behaviors, TCP Reno versus TCP Tahoe, and [Bufferbloat](https://en.wikipedia.org/wiki/Bufferbloat) problem.
287 | - More that you can think of. Please discuss with the instructors first.
288 |
289 | Note that you need to provide a detailed explanation of what you do, how to test the extra functions, and what you discover in the report for the bonus points. You also need to think of a way to demonstrate your bonus functions during your Demo on Week 16.
290 |
291 | ## Hints
292 |
293 | **A Chinese version of this document is provided at [README-zh.md](https://github.com/SUSTech-HPCLab/CS305-2023Spring-Project/blob/main/README-zh.md)**.
294 |
295 | ### Synchronize Code
296 |
297 | You can use the Visual Studio Code Remote extension to write code in the virtual machine via SSH.
298 |
299 | ### Useful Mininet Command
300 | We recommend restarting your controller and Mininet every time you build a new network topology. You may need to use
301 | ```
302 | sudo mn -c
303 | ```
304 | to clean up previously configured networks.
305 |
306 | Here are some commands that may be helpful:
307 | ```
308 | MN> arping h1 # Send an arping from h1, generates an ARP request, identifies the MAC and IP address of h1. Triggers an EventHostAdd event
309 | MN> arping_all # Send an arping from all hosts. This command will be run automatically in the test script. You can also run it yourself -- useful if you want to restart the controller without restarting Mininet.
310 | MN> h1 ping h2 -c 1 # Send a single ping packet from h1 to h2
311 | MN> pingall # Ping all hosts
312 | MN> net # View the current network topology
313 | MN> dpctl dump-flows # Show flow tables for all switches
314 | ```
315 |
316 | ### How to add a forwarding rule
317 |
318 | You can read the code in `ofctl_utils.py` to learn more details.
319 | ```
320 | # Using function provided by ofctl_utils.py
321 | from ofctl_utils import OfCtl, VLANID_NONE
322 |
323 | def add_forwarding_rule(self, datapath, dl_dst, port):
324 | ofctl = OfCtl.factory(datapath, self.logger)
325 | actions = [datapath.ofproto_parser.OFPActionOutput(port)]
326 |
327 | ofctl.set_flow(cookie=0, priority=0,
328 | dl_type=ether_types.ETH_TYPE_IP,
329 | dl_vlan=VLANID_NONE,
330 | dl_dst=dl_dst,
331 | actions=actions)
332 | ```
333 |
334 |
335 | ### Useful Documents
336 | 1. Ryu's API documentation https://ryu.readthedocs.io/en/latest/index.html
337 | 2. Mininet's document https://github.com/mininet/mininet/wiki/Documentation
338 | 3. Mininet source code https://github.com/mininet/mininet
339 | 4. Openflow quick start https://homepages.dcc.ufmg.br/~mmvieira/cc/OpenFlow%20Tutorial%20-%20OpenFlow%20Wiki.htm
340 |
341 |
342 | ## Acknowledgments
343 | The project is modified based on an assignment from Prof. Aditya Akella for CS640 Computer Networks at the University of Wisconsin, Madison, and from Prof. Rodrigo Fonseca for CS168 Computer Networks at Brown university.
344 |
--------------------------------------------------------------------------------
/controller.py:
--------------------------------------------------------------------------------
1 | from ryu.base import app_manager
2 | from ryu.controller import ofp_event
3 | from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
4 | from ryu.controller.handler import set_ev_cls
5 | from ryu.topology import event, switches
6 | from ryu.ofproto import ofproto_v1_0
7 | from ryu.lib.packet import packet, ethernet, ether_types, arp
8 | from ryu.lib.packet import dhcp
9 | from ryu.lib.packet import ethernet
10 | from ryu.lib.packet import ipv4
11 | from ryu.lib.packet import packet
12 | from ryu.lib.packet import udp
13 | from dhcp import DHCPServer
14 |
15 | class ControllerApp(app_manager.RyuApp):
16 | OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
17 |
18 | def __init__(self, *args, **kwargs):
19 | super(ControllerApp, self).__init__(*args, **kwargs)
20 |
21 | @set_ev_cls(event.EventSwitchEnter)
22 | def handle_switch_add(self, ev):
23 | """
24 | Event handler indicating a switch has come online.
25 | """
26 |
27 | @set_ev_cls(event.EventSwitchLeave)
28 | def handle_switch_delete(self, ev):
29 | """
30 | Event handler indicating a switch has been removed
31 | """
32 |
33 |
34 | @set_ev_cls(event.EventHostAdd)
35 | def handle_host_add(self, ev):
36 | """
37 | Event handler indiciating a host has joined the network
38 | This handler is automatically triggered when a host sends an ARP response.
39 | """
40 | # TODO: Update network topology and flow rules
41 |
42 | @set_ev_cls(event.EventLinkAdd)
43 | def handle_link_add(self, ev):
44 | """
45 | Event handler indicating a link between two switches has been added
46 | """
47 | # TODO: Update network topology and flow rules
48 |
49 | @set_ev_cls(event.EventLinkDelete)
50 | def handle_link_delete(self, ev):
51 | """
52 | Event handler indicating when a link between two switches has been deleted
53 | """
54 | # TODO: Update network topology and flow rules
55 |
56 |
57 |
58 | @set_ev_cls(event.EventPortModify)
59 | def handle_port_modify(self, ev):
60 | """
61 | Event handler for when any switch port changes state.
62 | This includes links for hosts as well as links between switches.
63 | """
64 | # TODO: Update network topology and flow rules
65 |
66 |
67 |
68 | @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
69 | def packet_in_handler(self, ev):
70 | try:
71 | msg = ev.msg
72 | datapath = msg.datapath
73 | pkt = packet.Packet(data=msg.data)
74 | pkt_dhcp = pkt.get_protocols(dhcp.dhcp)
75 | inPort = msg.in_port
76 | if not pkt_dhcp:
77 | # TODO: handle other protocols like ARP
78 | pass
79 | else:
80 | DHCPServer.handle_dhcp(datapath, inPort, pkt)
81 | return
82 | except Exception as e:
83 | self.logger.error(e)
84 |
85 |
--------------------------------------------------------------------------------
/dhcp.py:
--------------------------------------------------------------------------------
1 | from ryu.lib import addrconv
2 | from ryu.lib.packet import packet
3 | from ryu.lib.packet import ethernet
4 | from ryu.lib.packet import ipv4
5 | from ryu.lib.packet import udp
6 | from ryu.lib.packet import dhcp
7 |
8 |
9 | class Config():
10 | controller_macAddr = '7e:49:b3:f0:f9:99' # don't modify, a dummy mac address for fill the mac enrty
11 | dns = '8.8.8.8' # don't modify, just for the dns entry
12 | start_ip = '192.168.1.2' # can be modified
13 | end_ip = '192.168.1.100' # can be modified
14 | netmask = '255.255.255.0' # can be modified
15 |
16 | # You may use above attributes to configure your DHCP server.
17 | # You can also add more attributes like "lease_time" to support bouns function.
18 |
19 |
20 | class DHCPServer():
21 | hardware_addr = Config.controller_macAddr
22 | start_ip = Config.start_ip
23 | end_ip = Config.end_ip
24 | netmask = Config.netmask
25 | dns = Config.dns
26 |
27 | @classmethod
28 | def assemble_ack(cls, pkt, datapath, port):
29 | # TODO: Generate DHCP ACK packet here
30 | return ack_pkt
31 |
32 | @classmethod
33 | def assemble_offer(cls, pkt, datapath):
34 | # TODO: Generate DHCP OFFER packet here
35 |
36 |
37 | @classmethod
38 | def handle_dhcp(cls, datapath, port, pkt):
39 | # TODO: Specify the type of received DHCP packet
40 | # You may choose a valid IP from IP pool and genereate DHCP OFFER packet
41 | # Or generate a DHCP ACK packet
42 | # Finally send the generated packet to the host by using _send_packet method
43 |
44 | @classmethod
45 | def _send_packet(cls, datapath, port, pkt):
46 | ofproto = datapath.ofproto
47 | parser = datapath.ofproto_parser
48 | if isinstance(pkt, str):
49 | pkt = pkt.encode()
50 | pkt.serialize()
51 | data = pkt.data
52 | actions = [parser.OFPActionOutput(port=port)]
53 | out = parser.OFPPacketOut(datapath=datapath,
54 | buffer_id=ofproto.OFP_NO_BUFFER,
55 | in_port=ofproto.OFPP_CONTROLLER,
56 | actions=actions,
57 | data=data)
58 | datapath.send_msg(out)
--------------------------------------------------------------------------------
/img/arch.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SUSTech-HPCLab/CS305-2023Spring-Project/a8097e2965d69c74208fe542ebbe6f3a996a067e/img/arch.png
--------------------------------------------------------------------------------
/img/dhcp_success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SUSTech-HPCLab/CS305-2023Spring-Project/a8097e2965d69c74208fe542ebbe6f3a996a067e/img/dhcp_success.png
--------------------------------------------------------------------------------
/img/mininet_success.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SUSTech-HPCLab/CS305-2023Spring-Project/a8097e2965d69c74208fe542ebbe6f3a996a067e/img/mininet_success.png
--------------------------------------------------------------------------------
/img/path_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SUSTech-HPCLab/CS305-2023Spring-Project/a8097e2965d69c74208fe542ebbe6f3a996a067e/img/path_result.png
--------------------------------------------------------------------------------
/img/ping_result.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SUSTech-HPCLab/CS305-2023Spring-Project/a8097e2965d69c74208fe542ebbe6f3a996a067e/img/ping_result.png
--------------------------------------------------------------------------------
/img/topo_example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SUSTech-HPCLab/CS305-2023Spring-Project/a8097e2965d69c74208fe542ebbe6f3a996a067e/img/topo_example.png
--------------------------------------------------------------------------------
/ofctl_utilis.py:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 | # implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 |
17 | import numbers
18 | import socket
19 | import struct
20 |
21 | from ryu.exception import OFPUnknownVersion
22 | from ryu.lib import dpid as dpid_lib
23 | from ryu.lib import hub
24 | from ryu.lib import mac as mac_lib
25 | from ryu.lib import addrconv
26 | from ryu.lib.packet import arp
27 | from ryu.lib.packet import ethernet
28 | from ryu.lib.packet import icmp
29 | from ryu.lib.packet import ipv4
30 | from ryu.lib.packet import packet
31 | from ryu.lib.packet import vlan
32 | from ryu.ofproto import ether
33 | from ryu.ofproto import inet
34 | from ryu.ofproto import ofproto_v1_0
35 | from ryu.ofproto import ofproto_v1_2
36 | from ryu.ofproto import ofproto_v1_3
37 |
38 | UINT16_MAX = 0xffff
39 | UINT32_MAX = 0xffffffff
40 | UINT64_MAX = 0xffffffffffffffff
41 |
42 | ETHERNET = ethernet.ethernet.__name__
43 | VLAN = vlan.vlan.__name__
44 | IPV4 = ipv4.ipv4.__name__
45 | ARP = arp.arp.__name__
46 | ICMP = icmp.icmp.__name__
47 |
48 | DEFAULT_TTL = 64
49 | OFP_REPLY_TIMER = 1.0
50 |
51 | MAX_SUSPENDPACKETS = 50 # Threshold of the packet suspends thread count.
52 |
53 | VLANID_NONE = 0
54 | VLANID_MIN = 2
55 | VLANID_MAX = 4094
56 |
57 |
58 | class OfCtl(object):
59 | """
60 | To use, create an OfCtl object by calling Ofctl.factory with a the datapath object returned by
61 | a switch event.
62 | """
63 | _OF_VERSIONS = {}
64 |
65 | @staticmethod
66 | def register_of_version(version):
67 | def _register_of_version(cls):
68 | OfCtl._OF_VERSIONS.setdefault(version, cls)
69 | return cls
70 | return _register_of_version
71 |
72 | @staticmethod
73 | def factory(dp, logger):
74 | """
75 | Create an OfCtl object
76 | Arguments:
77 | dp -- Switch datapath object
78 | logger -- RyuApp logger instance
79 | """
80 | of_version = dp.ofproto.OFP_VERSION
81 | if of_version in OfCtl._OF_VERSIONS:
82 | ofctl = OfCtl._OF_VERSIONS[of_version](dp, logger)
83 | else:
84 | raise OFPUnknownVersion(version=of_version)
85 |
86 | return ofctl
87 |
88 | def __init__(self, dp, logger):
89 | super(OfCtl, self).__init__()
90 | self.dp = dp
91 | self.sw_id = {'sw_id': dpid_lib.dpid_to_str(dp.id)}
92 | self.logger = logger
93 |
94 | def set_sw_config_for_ttl(self):
95 | # OpenFlow v1_2/1_3.
96 | pass
97 |
98 | def set_flow(self, cookie, priority, dl_type=0, dl_dst=0, dl_vlan=0,
99 | nw_src=0, src_mask=32, nw_dst=0, dst_mask=32,
100 | nw_proto=0, idle_timeout=0, actions=None):
101 | """
102 | Send a message to install a flow on this datapath
103 | The following arguments specify match criteria:
104 | cookie -- Opaque identifier to reference this rule
105 | priority -- Rule priority number
106 | dl_type -- EtherType
107 | dl_dst -- Ethernet destination address
108 | dl_vlan -- VLAN ID (default 0)
109 | nw_src -- IP source
110 | src_mask -- IP source mask (default /32)
111 | nw_dst -- IP destination
112 | dst_mask -- IP destination mask (default /32)
113 | nw_proto -- IP protocol value
114 | Other arguments:
115 | idle_timeout -- Idle timeout (default 0)
116 | actions -- List of actions to apply on match
117 | """
118 | # Abstract method
119 | raise NotImplementedError()
120 |
121 | def delete_flow(self, cookie=0, priority=0, match=None):
122 | """
123 | Delete a flow matching the following criteria
124 | Arguments:
125 | cookie -- Cookie referencing this flow or set of flows
126 | (default 0)
127 | priority -- Priority value for this flow (default 0)
128 | match -- Match criteria for deletion
129 | (defaults to all)
130 | NOTE: OpenFlow 1.0 does not support deletion based on
131 | the cookie value. Instead, match fields must be specified.
132 | """
133 |
134 | # Abstract method
135 | raise NotImplementedError()
136 |
137 | def send_arp(self, arp_opcode, vlan_id, dst_mac,
138 | sender_mac, sender_ip,
139 | target_ip, target_mac,
140 | src_port, output_port):
141 | """
142 | Generate an ARP packet and send it
143 | Arguments:
144 | arp_opcode -- Opcode for message
145 | vlan_id -- VLAN identifier, or VLANID_NONE
146 | dst_mac -- Destination to send the packet (not an ARP field)
147 | sender_mac -- Sender hardware address
148 | sender_ip -- Sender protocol address
149 | target_mac -- Target hardware address
150 | target_ip -- Target protocol address
151 | src_port -- Source port number for sending message (can be OFPP_CONTROLLER)
152 | output_port -- Outgoing port number to send message
153 | """
154 |
155 | if vlan_id != VLANID_NONE:
156 | ether_proto = ether.ETH_TYPE_8021Q
157 | pcp = 0
158 | cfi = 0
159 | vlan_ether = ether.ETH_TYPE_ARP
160 | v = vlan.vlan(pcp, cfi, vlan_id, vlan_ether)
161 | else:
162 | ether_proto = ether.ETH_TYPE_ARP
163 | hwtype = 1
164 | arp_proto = ether.ETH_TYPE_IP
165 | hlen = 6
166 | plen = 4
167 |
168 | pkt = packet.Packet()
169 | e = ethernet.ethernet(dst_mac, sender_mac, ether_proto)
170 | a = arp.arp(hwtype, arp_proto, hlen, plen, arp_opcode,
171 | sender_mac, sender_ip, target_mac, target_ip)
172 | pkt.add_protocol(e)
173 | if vlan_id != VLANID_NONE:
174 | pkt.add_protocol(v)
175 | pkt.add_protocol(a)
176 | pkt.serialize()
177 |
178 | # Send packet out
179 | self.send_packet_out(src_port, output_port, pkt.data, data_str=str(pkt))
180 |
181 | def send_icmp(self, in_port, protocol_list, vlan_id, icmp_type,
182 | icmp_code, icmp_data=None, msg_data=None, src_ip=None):
183 | # Generate ICMP reply packet
184 | csum = 0
185 | offset = ethernet.ethernet._MIN_LEN
186 |
187 | if vlan_id != VLANID_NONE:
188 | ether_proto = ether.ETH_TYPE_8021Q
189 | pcp = 0
190 | cfi = 0
191 | vlan_ether = ether.ETH_TYPE_IP
192 | v = vlan.vlan(pcp, cfi, vlan_id, vlan_ether)
193 | offset += vlan.vlan._MIN_LEN
194 | else:
195 | ether_proto = ether.ETH_TYPE_IP
196 |
197 | eth = protocol_list[ETHERNET]
198 | e = ethernet.ethernet(eth.src, eth.dst, ether_proto)
199 |
200 | ip = protocol_list[IPV4]
201 |
202 | if icmp_data is None and msg_data is not None:
203 | # RFC 4884 says that we should send "at least 128 octets"
204 | # if we are using the ICMP Extension Structure.
205 | # We're not using the extension structure, but let's send
206 | # up to 128 bytes of the original msg_data.
207 | #
208 | # RFC 4884 also states that the length field is interpreted in
209 | # 32 bit units, so the length calculated in bytes needs to first
210 | # be divided by 4, then increased by 1 if the modulus is non-zero.
211 | #
212 | # Finally, RFC 4884 says, if we're specifying the length, we MUST
213 | # zero pad to the next 32 bit boundary.
214 | end_of_data = offset + len(ip) + 128
215 | ip_datagram = bytearray()
216 | ip_datagram += msg_data[offset:end_of_data]
217 | data_len = int(len(ip_datagram) / 4)
218 | length_modulus = int(len(ip_datagram) % 4)
219 | if length_modulus:
220 | data_len += 1
221 | ip_datagram += bytearray([0] * (4 - length_modulus))
222 | if icmp_type == icmp.ICMP_DEST_UNREACH:
223 | icmp_data = icmp.dest_unreach(data_len=data_len,
224 | data=ip_datagram)
225 | elif icmp_type == icmp.ICMP_TIME_EXCEEDED:
226 | icmp_data = icmp.TimeExceeded(data_len=data_len,
227 | data=ip_datagram)
228 |
229 | ic = icmp.icmp(icmp_type, icmp_code, csum, data=icmp_data)
230 |
231 | if src_ip is None:
232 | src_ip = ip.dst
233 | ip_total_length = ip.header_length * 4 + ic._MIN_LEN
234 | if ic.data is not None:
235 | ip_total_length += ic.data._MIN_LEN
236 | if ic.data.data is not None:
237 | ip_total_length += + len(ic.data.data)
238 | i = ipv4.ipv4(ip.version, ip.header_length, ip.tos,
239 | ip_total_length, ip.identification, ip.flags,
240 | ip.offset, DEFAULT_TTL, inet.IPPROTO_ICMP, csum,
241 | src_ip, ip.src)
242 |
243 | pkt = packet.Packet()
244 | pkt.add_protocol(e)
245 | if vlan_id != VLANID_NONE:
246 | pkt.add_protocol(v)
247 | pkt.add_protocol(i)
248 | pkt.add_protocol(ic)
249 | pkt.serialize()
250 |
251 | # Send packet out
252 | self.send_packet_out(in_port, self.dp.ofproto.OFPP_IN_PORT,
253 | pkt.data, data_str=str(pkt))
254 |
255 | def send_packet_out(self, in_port, output, data, data_str=None):
256 | actions = [self.dp.ofproto_parser.OFPActionOutput(output, 0)]
257 | self.dp.send_packet_out(buffer_id=UINT32_MAX, in_port=in_port,
258 | actions=actions, data=data)
259 | # TODO: Packet library convert to string
260 | # if data_str is None:
261 | # data_str = str(packet.Packet(data))
262 | # self.logger.debug('Packet out = %s', data_str, extra=self.sw_id)
263 |
264 | def set_normal_flow(self, cookie, priority):
265 | out_port = self.dp.ofproto.OFPP_NORMAL
266 | actions = [self.dp.ofproto_parser.OFPActionOutput(out_port, 0)]
267 | self.set_flow(cookie, priority, actions=actions)
268 |
269 | def set_packetin_flow(self, cookie, priority, dl_type=0, dl_dst=0,
270 | dl_vlan=0, dst_ip=0, dst_mask=32, nw_proto=0):
271 | miss_send_len = UINT16_MAX
272 | actions = [self.dp.ofproto_parser.OFPActionOutput(
273 | self.dp.ofproto.OFPP_CONTROLLER, miss_send_len)]
274 | self.set_flow(cookie, priority, dl_type=dl_type, dl_dst=dl_dst,
275 | dl_vlan=dl_vlan, nw_dst=dst_ip, dst_mask=dst_mask,
276 | nw_proto=nw_proto, actions=actions)
277 |
278 | def send_stats_request(self, stats, waiters):
279 | self.dp.set_xid(stats)
280 | waiters_per_dp = waiters.setdefault(self.dp.id, {})
281 | event = hub.Event()
282 | msgs = []
283 | waiters_per_dp[stats.xid] = (event, msgs)
284 | self.dp.send_msg(stats)
285 |
286 | try:
287 | event.wait(timeout=OFP_REPLY_TIMER)
288 | except hub.Timeout:
289 | del waiters_per_dp[stats.xid]
290 |
291 | return msgs
292 |
293 |
294 | @OfCtl.register_of_version(ofproto_v1_0.OFP_VERSION)
295 | class OfCtl_v1_0(OfCtl):
296 |
297 | def __init__(self, dp, logger):
298 | super(OfCtl_v1_0, self).__init__(dp, logger)
299 |
300 | def get_packetin_inport(self, msg):
301 | return msg.in_port
302 |
303 | def get_all_flow(self, waiters):
304 | ofp = self.dp.ofproto
305 | ofp_parser = self.dp.ofproto_parser
306 |
307 | match = ofp_parser.OFPMatch(ofp.OFPFW_ALL, 0, 0, 0,
308 | 0, 0, 0, 0, 0, 0, 0, 0, 0)
309 | stats = ofp_parser.OFPFlowStatsRequest(self.dp, 0, match,
310 | 0xff, ofp.OFPP_NONE)
311 | return self.send_stats_request(stats, waiters)
312 |
313 | def set_flow(self, cookie, priority, dl_type=0, dl_dst=0, dl_vlan=0,
314 | nw_src=0, src_mask=32, nw_dst=0, dst_mask=32,
315 | nw_proto=0, idle_timeout=0, actions=None):
316 |
317 | ofp = self.dp.ofproto
318 | ofp_parser = self.dp.ofproto_parser
319 | cmd = ofp.OFPFC_ADD
320 |
321 | # Match
322 | wildcards = ofp.OFPFW_ALL
323 | if dl_type:
324 | wildcards &= ~ofp.OFPFW_DL_TYPE
325 | if dl_dst:
326 | wildcards &= ~ofp.OFPFW_DL_DST
327 | if dl_vlan:
328 | wildcards &= ~ofp.OFPFW_DL_VLAN
329 | if nw_src:
330 | v = (32 - src_mask) << ofp.OFPFW_NW_SRC_SHIFT | \
331 | ~ofp.OFPFW_NW_SRC_MASK
332 | wildcards &= v
333 | nw_src = ipv4_text_to_int(nw_src)
334 | if nw_dst:
335 | v = (32 - dst_mask) << ofp.OFPFW_NW_DST_SHIFT | \
336 | ~ofp.OFPFW_NW_DST_MASK
337 | wildcards &= v
338 | nw_dst = ipv4_text_to_int(nw_dst)
339 | if nw_proto:
340 | wildcards &= ~ofp.OFPFW_NW_PROTO
341 |
342 | match = ofp_parser.OFPMatch(wildcards, 0, 0, dl_dst, dl_vlan, 0,
343 | dl_type, 0, nw_proto,
344 | nw_src, nw_dst, 0, 0)
345 | actions = actions or []
346 |
347 | m = ofp_parser.OFPFlowMod(self.dp, match, cookie, cmd,
348 | idle_timeout=idle_timeout,
349 | priority=priority, actions=actions)
350 | self.dp.send_msg(m)
351 |
352 | def delete_flow(self, cookie=0, priority=0, match=None):
353 | cmd = self.dp.ofproto.OFPFC_DELETE
354 | actions = []
355 |
356 | ofp_parser = self.dp.ofproto_parser
357 |
358 | flow_mod = self.dp.ofproto_parser.OFPFlowMod(
359 | self.dp, match=match, cookie=cookie, command=cmd, priority=priority, actions=actions)
360 | self.dp.send_msg(flow_mod)
361 |
362 |
363 | class OfCtl_after_v1_2(OfCtl):
364 |
365 | def __init__(self, dp, logger):
366 | super(OfCtl_after_v1_2, self).__init__(dp, logger)
367 |
368 | def set_sw_config_for_ttl(self):
369 | pass
370 |
371 | def get_packetin_inport(self, msg):
372 | in_port = self.dp.ofproto.OFPP_ANY
373 | for match_field in msg.match.fields:
374 | if match_field.header == self.dp.ofproto.OXM_OF_IN_PORT:
375 | in_port = match_field.value
376 | break
377 | return in_port
378 |
379 | def get_all_flow(self, waiters):
380 | pass
381 |
382 | def set_flow(self, cookie, priority, dl_type=0, dl_dst=0, dl_vlan=0,
383 | nw_src=0, src_mask=32, nw_dst=0, dst_mask=32,
384 | nw_proto=0, idle_timeout=0, actions=None):
385 | ofp = self.dp.ofproto
386 | ofp_parser = self.dp.ofproto_parser
387 | cmd = ofp.OFPFC_ADD
388 |
389 | # Match
390 | match = ofp_parser.OFPMatch()
391 | if dl_type:
392 | match.set_dl_type(dl_type)
393 | if dl_dst:
394 | match.set_dl_dst(dl_dst)
395 | if dl_vlan:
396 | match.set_vlan_vid(dl_vlan)
397 | if nw_src:
398 | match.set_ipv4_src_masked(ipv4_text_to_int(nw_src),
399 | mask_ntob(src_mask))
400 | if nw_dst:
401 | match.set_ipv4_dst_masked(ipv4_text_to_int(nw_dst),
402 | mask_ntob(dst_mask))
403 | if nw_proto:
404 | if dl_type == ether.ETH_TYPE_IP:
405 | match.set_ip_proto(nw_proto)
406 | elif dl_type == ether.ETH_TYPE_ARP:
407 | match.set_arp_opcode(nw_proto)
408 |
409 | # Instructions
410 | actions = actions or []
411 | inst = [ofp_parser.OFPInstructionActions(ofp.OFPIT_APPLY_ACTIONS,
412 | actions)]
413 |
414 | m = ofp_parser.OFPFlowMod(self.dp, cookie, 0, 0, cmd, idle_timeout,
415 | 0, priority, UINT32_MAX, ofp.OFPP_ANY,
416 | ofp.OFPG_ANY, 0, match, inst)
417 | self.dp.send_msg(m)
418 |
419 | def set_routing_flow(self, cookie, priority, outport, dl_vlan=0,
420 | nw_src=0, src_mask=32, nw_dst=0, dst_mask=32,
421 | src_mac=0, dst_mac=0, idle_timeout=0, dec_ttl=False):
422 | ofp = self.dp.ofproto
423 | ofp_parser = self.dp.ofproto_parser
424 |
425 | dl_type = ether.ETH_TYPE_IP
426 |
427 | actions = []
428 | if dec_ttl:
429 | actions.append(ofp_parser.OFPActionDecNwTtl())
430 | if src_mac:
431 | actions.append(ofp_parser.OFPActionSetField(eth_src=src_mac))
432 | if dst_mac:
433 | actions.append(ofp_parser.OFPActionSetField(eth_dst=dst_mac))
434 | if outport is not None:
435 | actions.append(ofp_parser.OFPActionOutput(outport, 0))
436 |
437 | self.set_flow(cookie, priority, dl_type=dl_type, dl_vlan=dl_vlan,
438 | nw_src=nw_src, src_mask=src_mask,
439 | nw_dst=nw_dst, dst_mask=dst_mask,
440 | idle_timeout=idle_timeout, actions=actions)
441 |
442 | def delete_flow(self, cookie, priority=0, match=None):
443 | ofp = self.dp.ofproto
444 | ofp_parser = self.dp.ofproto_parser
445 |
446 | if match is None:
447 | match = ofp_parser.OFPMatch()
448 |
449 | cmd = ofp.OFPFC_DELETE
450 | cookie_mask = UINT64_MAX
451 | inst = []
452 |
453 | flow_mod = ofp_parser.OFPFlowMod(self.dp, cookie, cookie_mask, 0, cmd,
454 | 0, 0, 0, UINT32_MAX, ofp.OFPP_ANY,
455 | ofp.OFPG_ANY, 0, match, inst)
456 | self.dp.send_msg(flow_mod)
457 | self.logger.info('Delete flow [cookie=0x%x]', cookie, extra=self.sw_id)
458 |
459 |
460 | @OfCtl.register_of_version(ofproto_v1_2.OFP_VERSION)
461 | class OfCtl_v1_2(OfCtl_after_v1_2):
462 |
463 | def __init__(self, dp, logger):
464 | super(OfCtl_v1_2, self).__init__(dp, logger)
465 |
466 | def set_sw_config_for_ttl(self):
467 | flags = self.dp.ofproto.OFPC_INVALID_TTL_TO_CONTROLLER
468 | miss_send_len = UINT16_MAX
469 | m = self.dp.ofproto_parser.OFPSetConfig(self.dp, flags,
470 | miss_send_len)
471 | self.dp.send_msg(m)
472 | self.logger.info('Set SW config for TTL error packet in.',
473 | extra=self.sw_id)
474 |
475 | def get_all_flow(self, waiters):
476 | ofp = self.dp.ofproto
477 | ofp_parser = self.dp.ofproto_parser
478 |
479 | match = ofp_parser.OFPMatch()
480 | stats = ofp_parser.OFPFlowStatsRequest(self.dp, 0, ofp.OFPP_ANY,
481 | ofp.OFPG_ANY, 0, 0, match)
482 | return self.send_stats_request(stats, waiters)
483 |
484 |
485 | @OfCtl.register_of_version(ofproto_v1_3.OFP_VERSION)
486 | class OfCtl_v1_3(OfCtl_after_v1_2):
487 |
488 | def __init__(self, dp, logger):
489 | super(OfCtl_v1_3, self).__init__(dp, logger)
490 |
491 | def set_sw_config_for_ttl(self):
492 | packet_in_mask = (1 << self.dp.ofproto.OFPR_ACTION |
493 | 1 << self.dp.ofproto.OFPR_INVALID_TTL)
494 | port_status_mask = (1 << self.dp.ofproto.OFPPR_ADD |
495 | 1 << self.dp.ofproto.OFPPR_DELETE |
496 | 1 << self.dp.ofproto.OFPPR_MODIFY)
497 | flow_removed_mask = (1 << self.dp.ofproto.OFPRR_IDLE_TIMEOUT |
498 | 1 << self.dp.ofproto.OFPRR_HARD_TIMEOUT |
499 | 1 << self.dp.ofproto.OFPRR_DELETE)
500 | m = self.dp.ofproto_parser.OFPSetAsync(
501 | self.dp, [packet_in_mask, 0], [port_status_mask, 0],
502 | [flow_removed_mask, 0])
503 | self.dp.send_msg(m)
504 | self.logger.info('Set SW config for TTL error packet in.',
505 | extra=self.sw_id)
506 |
507 | def get_all_flow(self, waiters):
508 | ofp = self.dp.ofproto
509 | ofp_parser = self.dp.ofproto_parser
510 |
511 | match = ofp_parser.OFPMatch()
512 | stats = ofp_parser.OFPFlowStatsRequest(self.dp, 0, 0, ofp.OFPP_ANY,
513 | ofp.OFPG_ANY, 0, 0, match)
514 | return self.send_stats_request(stats, waiters)
515 |
516 |
517 | def ip_addr_aton(ip_str, err_msg=None):
518 | try:
519 | return addrconv.ipv4.bin_to_text(socket.inet_aton(ip_str))
520 | except (struct.error, socket.error) as e:
521 | if err_msg is not None:
522 | e.message = '%s %s' % (err_msg, e.message)
523 | raise ValueError(e.message)
524 |
525 |
526 | def ip_addr_ntoa(ip):
527 | return socket.inet_ntoa(addrconv.ipv4.text_to_bin(ip))
528 |
529 |
530 | def mask_ntob(mask, err_msg=None):
531 | try:
532 | return (UINT32_MAX << (32 - mask)) & UINT32_MAX
533 | except ValueError:
534 | msg = 'illegal netmask'
535 | if err_msg is not None:
536 | msg = '%s %s' % (err_msg, msg)
537 | raise ValueError(msg)
538 |
539 |
540 | def ipv4_apply_mask(address, prefix_len, err_msg=None):
541 | assert isinstance(address, str)
542 |
543 | address_int = ipv4_text_to_int(address)
544 | return ipv4_int_to_text(address_int & mask_ntob(prefix_len, err_msg))
545 |
546 |
547 | def ipv4_int_to_text(ip_int):
548 | assert isinstance(ip_int, numbers.Integral)
549 | return addrconv.ipv4.bin_to_text(struct.pack('!I', ip_int))
550 |
551 |
552 | def ipv4_text_to_int(ip_text):
553 | if ip_text == 0:
554 | return ip_text
555 | assert isinstance(ip_text, str)
556 | return struct.unpack('!I', addrconv.ipv4.text_to_bin(ip_text))[0]
557 |
558 |
559 | def nw_addr_aton(nw_addr, err_msg=None):
560 | ip_mask = nw_addr.split('/')
561 | default_route = ip_addr_aton(ip_mask[0], err_msg=err_msg)
562 | netmask = 32
563 | if len(ip_mask) == 2:
564 | try:
565 | netmask = int(ip_mask[1])
566 | except ValueError as e:
567 | if err_msg is not None:
568 | e.message = '%s %s' % (err_msg, e.message)
569 | raise ValueError(e.message)
570 | if netmask < 0:
571 | msg = 'illegal netmask'
572 | if err_msg is not None:
573 | msg = '%s %s' % (err_msg, msg)
574 | raise ValueError(msg)
575 | nw_addr = ipv4_apply_mask(default_route, netmask, err_msg)
576 | return nw_addr, netmask, default_route
--------------------------------------------------------------------------------
/project_demo_instructions.md:
--------------------------------------------------------------------------------
1 | # Project Demo Instructions
2 |
3 | You are required to demonstrate your project to the graders in Lab 16. We will definitely check (but not limited to) the following functions of your code. Please READ CAREFULLY and prepare test cases for the demo.
4 |
5 | Please remember to submit your code to Sakai IMMEDIATELY after the demonstration in the Lab 16.
6 |
7 | ## DHCP
8 |
9 | 1. Use the default config settings (i.e., `start_ip`, `end_ip`, `subnet mask`) and create a topo with a switch and one host (using Python script). Assign a valid IP address correctly to the host.
10 |
11 | 2. Use the default config settings (i.e., `start_ip`, `end_ip`, `subnet mask`) and create a topo with a switch and multiple hosts (using Python script). Assign valid IP addresses correctly to all the hosts.
12 |
13 | 3. Change the `start_ip`, `end_ip`, and `subnet mask`, and create a topo with a switch and multiple hosts (using Python script). Assign new valid IP addresses correctly to all the hosts.
14 |
15 | 4. Assume that the number of IP addresses between `start_ip` and `end_ip` is n. Create a topo with a switch and m hosts (using Python script), where m > n. In this case, the first n hosts are assigned valid IP addresses, and the remaining m-n hosts do not receive an IP address.
16 |
17 | ## Shortest path switching
18 |
19 | 1. Pass the basic test case (available in the GitHub repository) to ensure all hosts are reachable. Use `pingall` to check connectivity.
20 | - Upon each change in the network topology (e.g., add a switch, add a link, etc.), print the current topology structure and the shortest path (and length) between any two switches in the controller console (e.g., s1 to s2: s1 -> s3 -> s4 -> s2, 3 edges).
21 | - After the topology is established, use `pingall` to verify connectivity between all hosts.
22 |
23 | 2. Provide a complex test case
24 | - **You should provide a figure to show the inital topology of your own case. The content of this figure should be the visualization of a graph. Hosts and switches are the nodes of the graph, and the links are the edges.**
25 | - The test case should have more than 6 hosts, more than 6 switches, and more than 10 edges.
26 | - The test case should support initializing the topology (from Python script, similar to the basic test case) and dynamically changing the topology using the Mininet CLI.
27 | - The changes should cover the following topology modification operations: `handle_switch_add`, `handle_switch_delete`, `handle_host_add`, `handle_link_add`, `handle_link_delete`, `handle_port_modify`.
28 | - After each modification, print the current topology structure with a third-party library (e.g., networkx) and the shortest path (and length) between any two switches in the controller console (e.g., s1 to s2: s1 -> s3 -> s4 -> s2, 3 edges).
29 |
30 | ## Hints
31 |
32 | 1. Mininet commands that you may find useful:
33 | - `MN > switch s1 stop/start` (Stop/Start switch s1)
34 | - `MN > link h1 s1 down/up` (Bring down/Bring up the link between host h1 and switch s1)
35 | - `MN > sh ovs-ofctl mod-port s1 1 down` (Disable port 1 on switch s1 using OpenFlow)
36 | 2. `addHost` will not be tested at mininet cli. It will be triggered only at the initialization of the network topology. However, switch stop/start, link down/up and port on/off will be tested at mininet cli.
37 |
38 | 2. When creating hosts using Python script, please follow the basic test case in Github to create hosts without IPs. like `h1 = self.addHost('h1', ip='no ip defined/8')`
39 |
40 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | ryu==4.34
2 | mininet==2.3.0.dev6
3 | eventlet==0.29.1
4 |
--------------------------------------------------------------------------------
/tests/dhcp_test/test_network.py:
--------------------------------------------------------------------------------
1 | from mininet.cli import CLI
2 | from mininet.link import TCLink
3 | from mininet.log import setLogLevel
4 | from mininet.net import Mininet
5 | from mininet.node import RemoteController
6 | from mininet.topo import Topo
7 |
8 | def disable_ipv6(node):
9 | node.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
10 | node.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
11 | node.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")
12 |
13 |
14 | def ping(host, dst, count=1, timeout=1):
15 | return host.cmd('ping -c %s -W %s %s' % (count, timeout, dst))
16 |
17 | def send_arp(node, count=1):
18 | node.cmd('arping -c %s -A -I %s-eth0 %s' % (count, node.name, node.IP()))
19 |
20 | def send_dhcp(node):
21 | print('Sending DHCP request dhclient -v %s-eth0 '% (node.name))
22 | node.cmd('dhclient -v %s-eth0' % (node.name))
23 |
24 |
25 | def do_arp_all(net):
26 | for h in net.hosts:
27 | send_arp(h)
28 |
29 |
30 | class TestTopo(Topo):
31 | def __init__(self, **opts):
32 | Topo.__init__(self, **opts)
33 | h1 = self.addHost('h1', ip='no ip defined/8')
34 | h2 = self.addHost('h2', ip='no ip defined/8')
35 | # h1 = self.addHost('h1')
36 | # h2 = self.addHost('h2')
37 | s1 = self.addSwitch('s1')
38 | self.addLink(h1, s1)
39 | self.addLink(h2, s1)
40 |
41 | def run_mininet():
42 | topo = TestTopo()
43 | net = Mininet(topo=topo, autoSetMacs=True, controller=RemoteController)
44 | for h in net.hosts:
45 | disable_ipv6(h)
46 | for h in net.switches:
47 | disable_ipv6(h)
48 |
49 | net.start()
50 | for h in net.hosts:
51 | send_dhcp(h)
52 | CLI(net)
53 |
54 | net.stop()
55 |
56 | if __name__ == '__main__':
57 | setLogLevel('info')
58 | run_mininet()
59 |
--------------------------------------------------------------------------------
/tests/switching_test/test_network.py:
--------------------------------------------------------------------------------
1 | from mininet.cli import CLI
2 | from mininet.link import TCLink
3 | from mininet.log import setLogLevel
4 | from mininet.net import Mininet
5 | from mininet.node import RemoteController
6 | from mininet.topo import Topo
7 |
8 | def disable_ipv6(node):
9 | node.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1")
10 | node.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1")
11 | node.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1")
12 |
13 |
14 | def ping(host, dst, count=1, timeout=1):
15 | return host.cmd('ping -c %s -W %s %s' % (count, timeout, dst))
16 |
17 | def send_arp(node, count=1):
18 | node.cmd('arping -c %s -A -I %s-eth0 %s' % (count, node.name, node.IP()))
19 |
20 | def send_dhcp(node):
21 | print('Sending DHCP request dhclient -v %s-eth0 '% (node.name))
22 | node.cmd('dhclient -v %s-eth0' % (node.name))
23 |
24 |
25 | def do_arp_all(net):
26 | for h in net.hosts:
27 | send_arp(h)
28 |
29 | class TriangleTopo(Topo):
30 | def __init__(self, **opts):
31 | Topo.__init__(self, **opts)
32 | h1 = self.addHost('h1')
33 | h2 = self.addHost('h2')
34 | h3 = self.addHost('h3')
35 | s1 = self.addSwitch('s1')
36 | s2 = self.addSwitch('s2')
37 | s3 = self.addSwitch('s3')
38 | self.addLink(h1, s1)
39 | self.addLink(h2, s2)
40 | self.addLink(h3, s3)
41 | self.addLink(s1, s2)
42 | self.addLink(s2, s3)
43 | self.addLink(s3, s1)
44 |
45 |
46 | def run_mininet():
47 | import time
48 | topo = TriangleTopo()
49 | net = Mininet(topo=topo, autoSetMacs=True, controller=RemoteController)
50 | for h in net.hosts:
51 | disable_ipv6(h)
52 | for h in net.switches:
53 | disable_ipv6(h)
54 |
55 | net.start()
56 | time.sleep(1)
57 | do_arp_all(net)
58 | CLI(net)
59 |
60 | net.stop()
61 |
62 | if __name__ == '__main__':
63 | setLogLevel('info')
64 | run_mininet()
--------------------------------------------------------------------------------