Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mininet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olaf Bergmann
mininet
Commits
aa4dfda4
Commit
aa4dfda4
authored
10 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
adding documentation and test for linuxrouter.py
parent
8a987b9c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/README.md
+5
-0
5 additions, 0 deletions
examples/README.md
examples/linuxrouter.py
+26
-13
26 additions, 13 deletions
examples/linuxrouter.py
examples/test/test_linuxrouter.py
+52
-0
52 additions, 0 deletions
examples/test/test_linuxrouter.py
with
83 additions
and
13 deletions
examples/README.md
+
5
−
0
View file @
aa4dfda4
...
...
@@ -56,6 +56,11 @@ This example shows how to use link and CPU limits.
This example shows how to create a custom topology programatically
by subclassing Topo, and how to run a series of tests on it.
### linuxrouter.py:
This example shows how to create and configure a router in Mininet
that uses Linux IP forwarding.
#### miniedit.py:
This example demonstrates creating a network via a graphical editor.
...
...
This diff is collapsed.
Click to expand it.
examples/linuxrouter.py
+
26
−
13
View file @
aa4dfda4
...
...
@@ -3,6 +3,18 @@
"""
linuxrouter.py: Example network with Linux IP router
This example converts a Node into a router using IP forwarding
already built into Linux.
The topology contains a router with three IP subnets:
- 192.168.1.0/24 (interface IP: 192.168.1.1)
- 172.16.0.0/12 (interface IP: 172.16.0.1)
- 10.0.0.0/8 (interface IP: 10.0.0.1)
It also contains three hosts, one in each subnet:
- h1 (IP: 192.168.1.100)
- h2 (IP: 172.16.0.100)
- h3 (IP: 10.0.0.100)
"""
...
...
@@ -14,6 +26,7 @@
from
mininet.util
import
irange
class
Router
(
Node
):
"
A Node with IP forwarding enabled.
"
def
config
(
self
,
**
params
):
super
(
Router
,
self
).
config
(
**
params
)
...
...
@@ -25,25 +38,25 @@ def terminate( self ):
super
(
Router
,
self
).
terminate
()
class
NetworkTopo
(
Topo
):
def
__init__
(
self
,
n
=
2
,
h
=
1
,
**
opts
):
Topo
.
__init__
(
self
,
**
opts
)
class
NetworkTopo
(
Topo
):
"
A simple topology of a router with three subnets (one host in each).
"
router
=
self
.
addNode
(
'
r0
'
,
cls
=
Router
,
ip
=
'
192.168.1.1/24
'
)
h1
=
self
.
addHost
(
'
h1
'
,
ip
=
'
192.168.1.100/8
'
,
defaultRoute
=
'
via 192.168.1.1
'
)
h2
=
self
.
addHost
(
'
h2
'
,
ip
=
'
172.16.0.100/8
'
,
defaultRoute
=
'
via 172.16.0.1
'
)
h3
=
self
.
addHost
(
'
h3
'
,
ip
=
'
10.0.0.100/24
'
,
defaultRoute
=
'
via 10.0.0.1
'
)
self
.
addLink
(
h1
,
router
,
intfName2
=
'
r0-eth1
'
,
params2
=
{
'
ip
'
:
'
192.168.1.1/24
'
})
self
.
addLink
(
h2
,
router
,
intfName2
=
'
r0-eth2
'
,
params2
=
{
'
ip
'
:
'
172.16.0.1/24
'
})
self
.
addLink
(
h3
,
router
,
intfName2
=
'
r0-eth3
'
,
params2
=
{
'
ip
'
:
'
10.0.0.1/24
'
})
def
build
(
self
,
n
=
2
,
h
=
1
,
**
opts
):
router
=
self
.
addNode
(
'
r0
'
,
cls
=
Router
,
ip
=
'
192.168.1.1/24
'
)
h1
=
self
.
addHost
(
'
h1
'
,
ip
=
'
192.168.1.100/24
'
,
defaultRoute
=
'
via 192.168.1.1
'
)
h2
=
self
.
addHost
(
'
h2
'
,
ip
=
'
172.16.0.100/12
'
,
defaultRoute
=
'
via 172.16.0.1
'
)
h3
=
self
.
addHost
(
'
h3
'
,
ip
=
'
10.0.0.100/8
'
,
defaultRoute
=
'
via 10.0.0.1
'
)
self
.
addLink
(
h1
,
router
,
intfName2
=
'
r0-eth1
'
,
params2
=
{
'
ip
'
:
'
192.168.1.1/24
'
}
)
self
.
addLink
(
h2
,
router
,
intfName2
=
'
r0-eth2
'
,
params2
=
{
'
ip
'
:
'
172.16.0.1/12
'
}
)
self
.
addLink
(
h3
,
router
,
intfName2
=
'
r0-eth3
'
,
params2
=
{
'
ip
'
:
'
10.0.0.1/8
'
}
)
def
run
():
topo
=
NetworkTopo
()
net
=
Mininet
(
topo
=
topo
)
net
=
Mininet
(
topo
=
topo
,
controller
=
None
)
# no controller needed
net
.
start
()
CLI
(
net
)
CLI
(
net
)
net
.
stop
()
if
__name__
==
'
__main__
'
:
setLogLevel
(
'
info
'
)
setLogLevel
(
'
info
'
)
run
()
This diff is collapsed.
Click to expand it.
examples/test/test_linuxrouter.py
0 → 100644
+
52
−
0
View file @
aa4dfda4
#!/usr/bin/env python
"""
Test for linuxrouter.py
"""
import
unittest
import
pexpect
from
mininet.util
import
quietRun
class
testLinuxRouter
(
unittest
.
TestCase
):
prompt
=
'
mininet>
'
def
testPingall
(
self
):
"
Test connectivity between hosts
"
p
=
pexpect
.
spawn
(
'
python -m mininet.examples.linuxrouter
'
)
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
pingall
'
)
p
.
expect
(
'
(\d+)% dropped
'
)
percent
=
int
(
p
.
match
.
group
(
1
)
)
if
p
.
match
else
-
1
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
exit
'
)
p
.
wait
()
self
.
assertEqual
(
percent
,
0
)
def
testRouterPing
(
self
):
"
Test connectivity from h1 to router
"
p
=
pexpect
.
spawn
(
'
python -m mininet.examples.linuxrouter
'
)
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
h1 ping -c 1 r0
'
)
p
.
expect
(
'
(\d+)% packet loss
'
)
percent
=
int
(
p
.
match
.
group
(
1
)
)
if
p
.
match
else
-
1
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
exit
'
)
p
.
wait
()
self
.
assertEqual
(
percent
,
0
)
def
testTTL
(
self
):
"
Verify that the TTL is decremented
"
p
=
pexpect
.
spawn
(
'
python -m mininet.examples.linuxrouter
'
)
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
h1 ping -c 1 h2
'
)
p
.
expect
(
'
ttl=(\d+)
'
)
ttl
=
int
(
p
.
match
.
group
(
1
)
)
if
p
.
match
else
-
1
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
exit
'
)
p
.
wait
()
self
.
assertEqual
(
ttl
,
63
)
# 64 - 1
if
__name__
==
'
__main__
'
:
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment