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
d334c1cc
Commit
d334c1cc
authored
10 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
adding test for vlanhost.py and adding vlantopo example
parent
fe8358ad
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
+8
-3
8 additions, 3 deletions
examples/README.md
examples/test/test_vlanhost.py
+50
-0
50 additions, 0 deletions
examples/test/test_vlanhost.py
examples/vlanhost.py
+35
-5
35 additions, 5 deletions
examples/vlanhost.py
with
93 additions
and
8 deletions
examples/README.md
+
8
−
3
View file @
d334c1cc
...
...
@@ -79,6 +79,11 @@ This example shows how to connect a Mininet network to the Internet
using NAT. It also answers the eternal question "why can't I ping
`google.com`
?"
#### numberedports.py
This example verifies the mininet ofport numbers match up to the ovs port numbers.
It also verifies that the port numbers match up to the interface numbers
#### popen.py:
This example monitors a number of hosts using
`host.popen()`
and
...
...
@@ -118,7 +123,7 @@ memory and `sysctl` configuration (see `INSTALL`.)
This example creates a 64-host tree network, and attempts to check full
connectivity using
`ping`
, for different switch/datapath types.
#### numberedports.py
#### vlanhost.py:
An example of how to subclass Host to use a VLAN on its primary interface.
This example verifies the mininet ofport numbers match up to the ovs port numbers.
It also verifies that the port numbers match up to the interface numbers
This diff is collapsed.
Click to expand it.
examples/test/test_vlanhost.py
0 → 100644
+
50
−
0
View file @
d334c1cc
#!/usr/bin/env python
"""
Test for vlanhost.py
"""
import
unittest
import
pexpect
import
sys
from
mininet.util
import
quietRun
class
testVLANHost
(
unittest
.
TestCase
):
prompt
=
'
mininet>
'
@unittest.skipIf
(
'
-quick
'
in
sys
.
argv
,
'
long test
'
)
def
testVLANTopo
(
self
):
"
Test connectivity (or lack thereof) between hosts in VLANTopo
"
p
=
pexpect
.
spawn
(
'
python -m mininet.examples.vlanhost
'
)
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
pingall 1
'
)
#ping timeout=1
p
.
expect
(
'
(\d+)% dropped
'
,
timeout
=
30
)
# there should be 24 failed pings
percent
=
int
(
p
.
match
.
group
(
1
)
)
if
p
.
match
else
-
1
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
exit
'
)
p
.
wait
()
self
.
assertEqual
(
percent
,
80
)
def
testSpecificVLAN
(
self
):
"
Test connectivity between hosts on a specific VLAN
"
vlan
=
1001
p
=
pexpect
.
spawn
(
'
python -m mininet.examples.vlanhost %d
'
%
vlan
)
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
h1 ping -c 1 h2
'
)
p
.
expect
(
'
(\d+)% packet loss
'
)
percent
=
int
(
p
.
match
.
group
(
1
)
)
if
p
.
match
else
-
1
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
h1 ifconfig
'
)
i
=
p
.
expect
(
[
'
h1-eth0.%d
'
%
vlan
,
pexpect
.
TIMEOUT
],
timeout
=
2
)
p
.
expect
(
self
.
prompt
)
p
.
sendline
(
'
exit
'
)
p
.
wait
()
self
.
assertEqual
(
percent
,
0
)
# no packet loss on ping
self
.
assertEqual
(
i
,
0
)
# check vlan intf is present
if
__name__
==
'
__main__
'
:
unittest
.
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
examples/vlanhost.py
+
35
−
5
View file @
d334c1cc
#!/usr/bin/env python
"""
vlanhost.py: Host subclass that uses a VLAN tag for the default interface.
...
...
@@ -24,6 +25,7 @@
"""
from
mininet.node
import
Host
from
mininet.topo
import
Topo
class
VLANHost
(
Host
):
...
...
@@ -52,7 +54,7 @@ def config( self, vlan=100, **params ):
hosts
=
{
'
vlan
'
:
VLANHost
}
def
example
Usage
(
vlan
):
def
example
AllHosts
(
vlan
):
"""
Simple example of how VLANHost can be used in a script
"""
# This is where the magic happens...
host
=
partial
(
VLANHost
,
vlan
=
vlan
)
...
...
@@ -65,6 +67,30 @@ def exampleUsage( vlan ):
CLI
(
net
)
net
.
stop
()
class
VLANStarTopo
(
Topo
):
"""
Example topology that uses host in multiple VLANs
"""
def
build
(
self
,
k
=
2
,
n
=
2
,
vlanBase
=
100
):
s1
=
self
.
addSwitch
(
'
s1
'
)
for
i
in
range
(
k
):
vlan
=
vlanBase
+
i
for
j
in
range
(
n
):
name
=
'
h%d-%d
'
%
(
j
+
1
,
vlan
)
h
=
self
.
addHost
(
name
,
cls
=
VLANHost
,
vlan
=
vlan
)
self
.
addLink
(
h
,
s1
)
for
j
in
range
(
n
):
h
=
self
.
addHost
(
'
h%d
'
%
(
j
+
1
)
)
self
.
addLink
(
h
,
s1
)
def
exampleCustomTags
(
vlan
):
"""
Simple example that exercises VLANStarTopo
"""
net
=
Mininet
(
topo
=
VLANStarTopo
()
)
net
.
start
()
CLI
(
net
)
net
.
stop
()
if
__name__
==
'
__main__
'
:
import
sys
from
functools
import
partial
...
...
@@ -72,12 +98,16 @@ def exampleUsage( vlan ):
from
mininet.net
import
Mininet
from
mininet.cli
import
CLI
from
mininet.topo
import
SingleSwitchTopo
from
mininet.log
import
setLogLevel
setLogLevel
(
'
info
'
)
try
:
vlan
=
int
(
sys
.
argv
[
1
]
)
except
Exception
:
print
'
Usage: vlanhost.py <vlan id>
\n
'
print
'
Using VLAN ID=100...
'
vlan
=
100
vlan
=
None
exampleUsage
(
vlan
)
if
vlan
:
exampleAllHosts
(
vlan
)
else
:
exampleCustomTags
(
vlan
)
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