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
2c76ab71
Commit
2c76ab71
authored
10 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
linuxrouter.py: changing name, printing routing table, and some more documentation
parent
aa4dfda4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/linuxrouter.py
+11
-5
11 additions, 5 deletions
examples/linuxrouter.py
with
11 additions
and
5 deletions
examples/linuxrouter.py
+
11
−
5
View file @
2c76ab71
...
...
@@ -16,33 +16,37 @@
- h2 (IP: 172.16.0.100)
- h3 (IP: 10.0.0.100)
Routing entries can be added to the routing tables of the
hosts or router using the
"
ip route add
"
or
"
route add
"
command.
See the man pages for more details.
"""
from
mininet.topo
import
Topo
from
mininet.net
import
Mininet
from
mininet.node
import
Node
from
mininet.log
import
setLogLevel
from
mininet.log
import
setLogLevel
,
info
from
mininet.cli
import
CLI
from
mininet.util
import
irange
class
Router
(
Node
):
class
Linux
Router
(
Node
):
"
A Node with IP forwarding enabled.
"
def
config
(
self
,
**
params
):
super
(
Router
,
self
).
config
(
**
params
)
super
(
Linux
Router
,
self
).
config
(
**
params
)
# Enable forwarding on the router
self
.
cmd
(
'
sysctl net.ipv4.ip_forward=1
'
)
def
terminate
(
self
):
self
.
cmd
(
'
sysctl net.ipv4.ip_forward=0
'
)
super
(
Router
,
self
).
terminate
()
super
(
Linux
Router
,
self
).
terminate
()
class
NetworkTopo
(
Topo
):
"
A simple topology of a router with three subnets (one host in each).
"
def
build
(
self
,
n
=
2
,
h
=
1
,
**
opts
):
router
=
self
.
addNode
(
'
r0
'
,
cls
=
Router
,
ip
=
'
192.168.1.1/24
'
)
router
=
self
.
addNode
(
'
r0
'
,
cls
=
Linux
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
'
)
...
...
@@ -54,6 +58,8 @@ def run():
topo
=
NetworkTopo
()
net
=
Mininet
(
topo
=
topo
,
controller
=
None
)
# no controller needed
net
.
start
()
info
(
'
*** Routing Table on Router
\n
'
)
print
net
[
'
r0
'
].
cmd
(
'
route
'
)
CLI
(
net
)
net
.
stop
()
...
...
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