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
be1ed103
Commit
be1ed103
authored
10 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
adding vlanhost.py
parent
92075113
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/vlanhost.py
+83
-0
83 additions, 0 deletions
examples/vlanhost.py
with
83 additions
and
0 deletions
examples/vlanhost.py
0 → 100644
+
83
−
0
View file @
be1ed103
"""
vlanhost.py: Host subclass that uses a VLAN tag for the default interface.
Dependencies:
This class depends on the
"
vlan
"
package
$ sudo apt-get install vlan
Usage (example uses VLAN ID=1000):
From the command line:
sudo mn --custom vlanhost.py --host vlan,vlan=1000
From a script (see exampleUsage function below):
from functools import partial
from vlanhost import VLANHost
...
.
host = partial( VLANHost, vlan=1000 )
net = Mininet( host=host, ... )
Directly running this script:
sudo python vlanhost.py 1000
"""
from
mininet.node
import
Host
class
VLANHost
(
Host
):
def
config
(
self
,
vlan
=
100
,
**
params
):
"""
Configure VLANHost according to (optional) parameters:
vlan: VLAN ID for default interface
"""
r
=
super
(
Host
,
self
).
config
(
**
params
)
intf
=
self
.
defaultIntf
()
# remove IP from default, "physical" interface
self
.
cmd
(
'
ifconfig %s inet 0
'
%
intf
)
# create VLAN interface
self
.
cmd
(
'
vconfig add %s %d
'
%
(
intf
,
vlan
)
)
# assign the host's IP to the VLAN interface
self
.
cmd
(
'
ifconfig %s.%d inet %s
'
%
(
intf
,
vlan
,
params
[
'
ip
'
]
)
)
# update the intf name and host's intf map
newName
=
'
%s.%d
'
%
(
intf
,
vlan
)
# update the (Mininet) interface to refer to VLAN interface name
intf
.
name
=
newName
# add VLAN interface to host's name to intf map
self
.
nameToIntf
[
newName
]
=
intf
return
r
hosts
=
{
'
vlan
'
:
VLANHost
}
def
exampleUsage
(
vlan
):
"""
Simple example of how VLANHost can be used in a script
"""
# This is where the magic happens...
host
=
partial
(
VLANHost
,
vlan
=
vlan
)
# vlan (type: int): VLAN ID to be used by all hosts
# Start a basic network using our VLANHost
topo
=
SingleSwitchTopo
(
k
=
2
)
net
=
Mininet
(
host
=
host
,
topo
=
topo
)
net
.
start
()
CLI
(
net
)
net
.
stop
()
if
__name__
==
'
__main__
'
:
import
sys
from
functools
import
partial
from
mininet.net
import
Mininet
from
mininet.cli
import
CLI
from
mininet.topo
import
SingleSwitchTopo
try
:
vlan
=
int
(
sys
.
argv
[
1
]
)
except
Exception
:
print
'
Usage: vlanhost.py <vlan id>
\n
'
print
'
Using VLAN ID=100...
'
vlan
=
100
exampleUsage
(
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