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
555d10de
Commit
555d10de
authored
11 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
adding internet / nat example
parent
3f2355a3
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/natnet.py
+69
-0
69 additions, 0 deletions
examples/natnet.py
with
69 additions
and
0 deletions
examples/natnet.py
0 → 100755
+
69
−
0
View file @
555d10de
#!/usr/bin/python
"""
natnet.py: Example network with NATs
h0
|
s0
|
----------------
| |
nat1 nat2
| |
s1 s2
| |
h1 h2
"""
from
mininet.topo
import
Topo
from
mininet.net
import
Mininet
from
mininet.node
import
NAT
from
mininet.log
import
setLogLevel
from
mininet.cli
import
CLI
from
mininet.util
import
irange
class
InternetTopo
(
Topo
):
"
Single switch connected to n hosts.
"
def
__init__
(
self
,
n
=
2
,
h
=
1
,
**
opts
):
Topo
.
__init__
(
self
,
**
opts
)
# set up inet switch
inetSwitch
=
self
.
addSwitch
(
'
s0
'
)
# add inet host
inetHost
=
self
.
addHost
(
'
h0
'
)
self
.
addLink
(
inetSwitch
,
inetHost
)
# add local nets
for
i
in
irange
(
1
,
n
):
inetIntf
=
'
nat%d-eth0
'
%
i
localIntf
=
'
nat%d-eth1
'
%
i
localIP
=
'
192.168.%d.1
'
%
i
localSubnet
=
'
192.168.%d.0/24
'
%
i
natParams
=
{
'
ip
'
:
'
%s/24
'
%
localIP
}
# add NAT to topology
nat
=
self
.
addNode
(
'
nat%d
'
%
i
,
cls
=
NAT
,
subnet
=
localSubnet
,
inetIntf
=
inetIntf
,
localIntf
=
localIntf
)
switch
=
self
.
addSwitch
(
'
s%d
'
%
i
)
# connect NAT to inet and local switches
self
.
addLink
(
nat
,
inetSwitch
,
intfName1
=
inetIntf
)
self
.
addLink
(
nat
,
switch
,
intfName1
=
localIntf
,
params1
=
natParams
)
# add host and connect to local switch
host
=
self
.
addHost
(
'
h%d
'
%
i
,
ip
=
'
192.168.%d.100/24
'
%
i
,
defaultRoute
=
'
via %s
'
%
localIP
)
self
.
addLink
(
host
,
switch
)
def
perfTest
():
"
Create network and run simple performance test
"
topo
=
InternetTopo
()
net
=
Mininet
(
topo
=
topo
)
net
.
start
()
CLI
(
net
)
net
.
stop
()
if
__name__
==
'
__main__
'
:
setLogLevel
(
'
info
'
)
perfTest
()
\ No newline at end of file
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