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
82f483f5
Commit
82f483f5
authored
13 years ago
by
Bob Lantz
Browse files
Options
Downloads
Patches
Plain Diff
Add support for specifying host IP range with --ipbase.
parent
a49c85a6
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bin/mn
+4
-0
4 additions, 0 deletions
bin/mn
mininet/net.py
+8
-3
8 additions, 3 deletions
mininet/net.py
mininet/topo.py
+20
-11
20 additions, 11 deletions
mininet/topo.py
mininet/util.py
+14
-5
14 additions, 5 deletions
mininet/util.py
with
46 additions
and
19 deletions
bin/mn
+
4
−
0
View file @
82f483f5
...
@@ -192,6 +192,8 @@ class MininetRunner( object ):
...
@@ -192,6 +192,8 @@ class MininetRunner( object ):
help
=
'
|
'
.
join
(
TESTS
)
)
help
=
'
|
'
.
join
(
TESTS
)
)
opts
.
add_option
(
'
--xterms
'
,
'
-x
'
,
action
=
'
store_true
'
,
opts
.
add_option
(
'
--xterms
'
,
'
-x
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
spawn xterms for each node
'
)
default
=
False
,
help
=
'
spawn xterms for each node
'
)
opts
.
add_option
(
'
--ipbase
'
,
'
-i
'
,
type
=
'
string
'
,
default
=
'
10.0.0.0/8
'
,
help
=
'
base IP address for hosts
'
)
opts
.
add_option
(
'
--mac
'
,
action
=
'
store_true
'
,
opts
.
add_option
(
'
--mac
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
automatically set host MACs
'
)
default
=
False
,
help
=
'
automatically set host MACs
'
)
opts
.
add_option
(
'
--arp
'
,
action
=
'
store_true
'
,
opts
.
add_option
(
'
--arp
'
,
action
=
'
store_true
'
,
...
@@ -248,6 +250,7 @@ class MininetRunner( object ):
...
@@ -248,6 +250,7 @@ class MininetRunner( object ):
self
.
validate
(
self
.
options
)
self
.
validate
(
self
.
options
)
inNamespace
=
self
.
options
.
innamespace
inNamespace
=
self
.
options
.
innamespace
ipBase
=
self
.
options
.
ipbase
xterms
=
self
.
options
.
xterms
xterms
=
self
.
options
.
xterms
mac
=
self
.
options
.
mac
mac
=
self
.
options
.
mac
arp
=
self
.
options
.
arp
arp
=
self
.
options
.
arp
...
@@ -257,6 +260,7 @@ class MininetRunner( object ):
...
@@ -257,6 +260,7 @@ class MininetRunner( object ):
mn
=
Mininet
(
topo
=
topo
,
mn
=
Mininet
(
topo
=
topo
,
switch
=
switch
,
host
=
host
,
controller
=
controller
,
switch
=
switch
,
host
=
host
,
controller
=
controller
,
intf
=
intf
,
intf
=
intf
,
ipBase
=
ipBase
,
inNamespace
=
inNamespace
,
inNamespace
=
inNamespace
,
xterms
=
xterms
,
autoSetMacs
=
mac
,
xterms
=
xterms
,
autoSetMacs
=
mac
,
autoStaticArp
=
arp
,
listenPort
=
listenPort
)
autoStaticArp
=
arp
,
listenPort
=
listenPort
)
...
...
This diff is collapsed.
Click to expand it.
mininet/net.py
+
8
−
3
View file @
82f483f5
...
@@ -97,7 +97,7 @@
...
@@ -97,7 +97,7 @@
from
mininet.node
import
Host
,
OVSKernelSwitch
,
Controller
from
mininet.node
import
Host
,
OVSKernelSwitch
,
Controller
from
mininet.link
import
Link
from
mininet.link
import
Link
from
mininet.util
import
quietRun
,
fixLimits
from
mininet.util
import
quietRun
,
fixLimits
from
mininet.util
import
macColonHex
,
ipStr
,
ipParse
from
mininet.util
import
macColonHex
,
ipStr
,
ipParse
,
netParse
from
mininet.term
import
cleanUpScreens
,
makeTerms
from
mininet.term
import
cleanUpScreens
,
makeTerms
class
Mininet
(
object
):
class
Mininet
(
object
):
...
@@ -105,7 +105,7 @@ class Mininet( object ):
...
@@ -105,7 +105,7 @@ class Mininet( object ):
def
__init__
(
self
,
topo
=
None
,
switch
=
OVSKernelSwitch
,
host
=
Host
,
def
__init__
(
self
,
topo
=
None
,
switch
=
OVSKernelSwitch
,
host
=
Host
,
controller
=
Controller
,
link
=
Link
,
intf
=
None
,
controller
=
Controller
,
link
=
Link
,
intf
=
None
,
build
=
True
,
xterms
=
False
,
cleanup
=
False
,
build
=
True
,
xterms
=
False
,
cleanup
=
False
,
ipBase
=
'
10.0.0.0/8
'
,
inNamespace
=
False
,
inNamespace
=
False
,
autoSetMacs
=
False
,
autoStaticArp
=
False
,
listenPort
=
None
):
autoSetMacs
=
False
,
autoStaticArp
=
False
,
listenPort
=
None
):
"""
Create Mininet object.
"""
Create Mininet object.
...
@@ -130,6 +130,7 @@ def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host,
...
@@ -130,6 +130,7 @@ def __init__( self, topo=None, switch=OVSKernelSwitch, host=Host,
self
.
controller
=
controller
self
.
controller
=
controller
self
.
link
=
link
self
.
link
=
link
self
.
intf
=
intf
self
.
intf
=
intf
self
.
ipBase
=
ipBase
self
.
inNamespace
=
inNamespace
self
.
inNamespace
=
inNamespace
self
.
xterms
=
xterms
self
.
xterms
=
xterms
self
.
cleanup
=
cleanup
self
.
cleanup
=
cleanup
...
@@ -214,6 +215,8 @@ def buildFromTopo( self, topo=None ):
...
@@ -214,6 +215,8 @@ def buildFromTopo( self, topo=None ):
At the end of this function, everything should be connected
At the end of this function, everything should be connected
and up.
"""
and up.
"""
ipBaseNum
,
prefixLen
=
netParse
(
self
.
ipBase
)
if
not
topo
:
if
not
topo
:
topo
=
self
.
topo
()
topo
=
self
.
topo
()
...
@@ -222,7 +225,9 @@ def addNode( prefix, addMethod, nodeId ):
...
@@ -222,7 +225,9 @@ def addNode( prefix, addMethod, nodeId ):
name
=
prefix
+
topo
.
name
(
nodeId
)
name
=
prefix
+
topo
.
name
(
nodeId
)
ni
=
topo
.
nodeInfo
(
nodeId
)
ni
=
topo
.
nodeInfo
(
nodeId
)
# Default IP and MAC addresses
# Default IP and MAC addresses
defaults
=
{
'
ip
'
:
topo
.
ip
(
nodeId
)
}
defaults
=
{
'
ip
'
:
topo
.
ip
(
nodeId
,
ipBaseNum
=
ipBaseNum
,
prefixLen
=
prefixLen
)
}
if
self
.
autoSetMacs
:
if
self
.
autoSetMacs
:
defaults
[
'
mac
'
]
=
macColonHex
(
nodeId
)
defaults
[
'
mac
'
]
=
macColonHex
(
nodeId
)
defaults
.
update
(
ni
.
params
)
defaults
.
update
(
ni
.
params
)
...
...
This diff is collapsed.
Click to expand it.
mininet/topo.py
+
20
−
11
View file @
82f483f5
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
# from networkx.classes.graph import Graph
# from networkx.classes.graph import Graph
from
networkx
import
Graph
from
networkx
import
Graph
from
util
import
netParse
,
ipStr
class
NodeID
(
object
):
class
NodeID
(
object
):
'''
Topo node identifier.
'''
'''
Topo node identifier.
'''
...
@@ -42,15 +43,22 @@ def name_str(self):
...
@@ -42,15 +43,22 @@ def name_str(self):
'''
'''
return
str
(
self
.
dpid
)
return
str
(
self
.
dpid
)
def
ip_str
(
self
):
def
ip_str
(
self
,
ipBase
=
None
,
prefixLen
=
8
,
ipBaseNum
=
0x0a000000
):
'''
Name conversion.
'''
Name conversion.
ipBase: optional base IP address string
prefixLen: optional IP prefix length
ipBaseNum: option base IP address as int
@return ip ip as string
@return ip ip as string
'''
'''
hi
=
(
self
.
dpid
&
0xff0000
)
>>
16
if
ipBase
:
mid
=
(
self
.
dpid
&
0xff00
)
>>
8
ipnum
,
prefixLen
=
netParse
(
ipBase
)
lo
=
self
.
dpid
&
0xff
else
:
return
"
10.%i.%i.%i
"
%
(
hi
,
mid
,
lo
)
ipBaseNum
=
ipBaseNum
# Ugly but functional
assert
self
.
dpid
<
(
1
<<
(
32
-
prefixLen
)
)
mask
=
0xffffffff
^
(
(
1
<<
prefixLen
)
-
1
)
ipnum
=
self
.
dpid
+
(
ipBaseNum
&
mask
)
return
ipStr
(
ipnum
)
class
Node
(
object
):
class
Node
(
object
):
...
@@ -109,11 +117,12 @@ class Topo(object):
...
@@ -109,11 +117,12 @@ class Topo(object):
per-topo classes
per-topo classes
per-network classes
"""
per-network classes
"""
def
__init__
(
self
,
node
=
None
,
switch
=
None
,
link
=
None
):
def
__init__
(
self
,
node
=
None
,
switch
=
None
,
link
=
None
):
"""
Create Topo object.
"""
Create Topo object.
node: default node/host class (optional)
node: default node/host class (optional)
switch: default switch class (optional)
switch: default switch class (optional)
link: default link class (optional)
"""
link: default link class (optional)
ipBase: default IP address base (optional)
"""
self
.
g
=
Graph
()
self
.
g
=
Graph
()
self
.
node_info
=
{}
# dpids hash to Node objects
self
.
node_info
=
{}
# dpids hash to Node objects
self
.
edge_info
=
{}
# (src_dpid, dst_dpid) tuples hash to Edge objects
self
.
edge_info
=
{}
# (src_dpid, dst_dpid) tuples hash to Edge objects
...
@@ -342,13 +351,13 @@ def name(self, dpid):
...
@@ -342,13 +351,13 @@ def name(self, dpid):
'''
'''
return
self
.
id_gen
(
dpid
=
dpid
).
name_str
()
return
self
.
id_gen
(
dpid
=
dpid
).
name_str
()
def
ip
(
self
,
dpid
):
def
ip
(
self
,
dpid
,
**
params
):
'''
Get IP dotted-decimal string of node ID.
'''
Get IP dotted-decimal string of node ID.
@param dpid DPID of host or switch
@param dpid DPID of host or switch
@param params: params to pass to ip_str
@return ip_str
@return ip_str
'''
'''
return
self
.
id_gen
(
dpid
=
dpid
).
ip_str
()
return
self
.
id_gen
(
dpid
=
dpid
).
ip_str
(
**
params
)
def
nodeInfo
(
self
,
dpid
):
def
nodeInfo
(
self
,
dpid
):
"
Return metadata for node
"
"
Return metadata for node
"
...
...
This diff is collapsed.
Click to expand it.
mininet/util.py
+
14
−
5
View file @
82f483f5
...
@@ -204,19 +204,19 @@ def macColonHex( mac ):
...
@@ -204,19 +204,19 @@ def macColonHex( mac ):
returns: macStr MAC colon-hex string
"""
returns: macStr MAC colon-hex string
"""
return
_colonHex
(
mac
,
6
)
return
_colonHex
(
mac
,
6
)
def
ipStr
(
ip
):
def
ipStr
(
ip
,
defaultNet
=
10
):
"""
Generate IP address string from an unsigned int.
"""
Generate IP address string from an unsigned int.
ip: unsigned int of form w << 24 | x << 16 | y << 8 | z
ip: unsigned int of form w << 24 | x << 16 | y << 8 | z
returns: ip address string w.x.y.z, or 10.x.y.z if w==0
"""
returns: ip address string w.x.y.z, or 10.x.y.z if w==0
"""
w
=
(
ip
&
0xff000000
)
>>
24
w
=
(
ip
>>
24
)
&
0xff
w
=
10
if
w
==
0
else
w
w
=
10
if
w
==
0
else
w
x
=
(
ip
&
0xff0000
)
>>
16
x
=
(
ip
>>
16
)
&
0xff
y
=
(
ip
&
0xff00
)
>>
8
y
=
(
ip
>>
8
)
&
0xff
z
=
ip
&
0xff
z
=
ip
&
0xff
return
"
%i.%i.%i.%i
"
%
(
w
,
x
,
y
,
z
)
return
"
%i.%i.%i.%i
"
%
(
w
,
x
,
y
,
z
)
def
ipNum
(
w
,
x
,
y
,
z
):
def
ipNum
(
w
,
x
,
y
,
z
):
"""
Generate unsigned int from components ofIP address
"""
Generate unsigned int from components of
IP address
returns: w << 24 | x << 16 | y << 8 | z
"""
returns: w << 24 | x << 16 | y << 8 | z
"""
return
(
w
<<
24
)
|
(
x
<<
16
)
|
(
y
<<
8
)
|
z
return
(
w
<<
24
)
|
(
x
<<
16
)
|
(
y
<<
8
)
|
z
...
@@ -225,6 +225,15 @@ def ipParse( ip ):
...
@@ -225,6 +225,15 @@ def ipParse( ip ):
args
=
[
int
(
arg
)
for
arg
in
ip
.
split
(
'
.
'
)
]
args
=
[
int
(
arg
)
for
arg
in
ip
.
split
(
'
.
'
)
]
return
ipNum
(
*
args
)
return
ipNum
(
*
args
)
def
netParse
(
ipstr
):
"""
Parse an IP network specification, returning
address and prefix len as unsigned ints
"""
prefixLen
=
0
if
'
/
'
in
ipstr
:
ip
,
pf
=
ipstr
.
split
(
'
/
'
)
prefixLen
=
int
(
pf
)
return
ipParse
(
ip
),
prefixLen
def
checkInt
(
s
):
def
checkInt
(
s
):
"
Check if input string is an int
"
"
Check if input string is an int
"
try
:
try
:
...
...
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