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
8e04a9f8
Commit
8e04a9f8
authored
11 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
Replaced nodelist and nodemap in CLI with mn
Updated Mininet to be more compliant with dict Fixes #182
parent
6df4371d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mininet/cli.py
+29
-24
29 additions, 24 deletions
mininet/cli.py
mininet/net.py
+16
-0
16 additions, 0 deletions
mininet/net.py
with
45 additions
and
24 deletions
mininet/cli.py
+
29
−
24
View file @
8e04a9f8
...
...
@@ -43,13 +43,6 @@ class CLI( Cmd ):
def
__init__
(
self
,
mininet
,
stdin
=
sys
.
stdin
,
script
=
None
):
self
.
mn
=
mininet
self
.
nodelist
=
self
.
mn
.
controllers
+
self
.
mn
.
switches
+
self
.
mn
.
hosts
self
.
nodemap
=
{}
# map names to Node objects
for
node
in
self
.
nodelist
:
self
.
nodemap
[
node
.
name
]
=
node
# Local variable bindings for py command
self
.
locals
=
{
'
net
'
:
mininet
}
self
.
locals
.
update
(
self
.
nodemap
)
# Attempt to handle input
self
.
stdin
=
stdin
self
.
inPoller
=
poll
()
...
...
@@ -63,7 +56,7 @@ def __init__( self, mininet, stdin=sys.stdin, script=None ):
while
True
:
try
:
# Make sure no nodes are still waiting
for
node
in
self
.
nodelist
:
for
node
in
self
.
mn
.
values
()
:
while
node
.
waiting
:
node
.
sendInt
()
node
.
monitor
()
...
...
@@ -78,6 +71,12 @@ def emptyline( self ):
"
Don
'
t repeat last command when you hit return.
"
pass
def
locals
(
self
):
"
Local variable bindings for py command
"
locals
=
{
'
net
'
:
self
.
mn
}
locals
.
update
(
self
.
mn
)
return
locals
# Disable pylint "Unused argument: 'arg's'" messages, as well as
# "method could be a function" warning, since each CLI function
# must have the same interface
...
...
@@ -110,12 +109,14 @@ def do_help( self, line ):
def
do_nodes
(
self
,
_line
):
"
List all nodes.
"
nodes
=
'
'
.
join
(
[
node
.
name
for
node
in
sorted
(
self
.
nodelist
)
]
)
# self.mn.values()
nodes
=
'
'
.
join
(
[
node
.
name
for
node
in
sorted
(
self
.
mn
)
]
)
output
(
'
available nodes are:
\n
%s
\n
'
%
nodes
)
def
do_net
(
self
,
_line
):
"
List network connections.
"
dumpNodeConnections
(
self
.
nodelist
)
# self.mn.values()
dumpNodeConnections
(
self
.
mn
)
def
do_sh
(
self
,
line
):
"
Run an external shell command
"
...
...
@@ -128,7 +129,7 @@ def do_py( self, line ):
"""
Evaluate a Python expression.
Node names may be used, e.g.: py h1.cmd(
'
ls
'
)
"""
try
:
result
=
eval
(
line
,
globals
(),
self
.
locals
)
result
=
eval
(
line
,
globals
(),
self
.
locals
()
)
if
not
result
:
return
elif
isinstance
(
result
,
str
):
...
...
@@ -145,7 +146,7 @@ def do_px( self, line ):
"""
Execute a Python statement.
Node names may be used, e.g.: px print h1.cmd(
'
ls
'
)
"""
try
:
exec
(
line
,
globals
(),
self
.
locals
)
exec
(
line
,
globals
(),
self
.
locals
()
)
except
Exception
,
e
:
output
(
str
(
e
)
+
'
\n
'
)
...
...
@@ -176,11 +177,12 @@ def do_iperf( self, line ):
hosts
=
[]
err
=
False
for
arg
in
args
:
if
arg
not
in
self
.
nodemap
:
# self.mn.keys()
if
arg
not
in
self
.
mn
:
err
=
True
error
(
"
node
'
%s
'
not in network
\n
"
%
arg
)
else
:
hosts
.
append
(
self
.
n
odemap
[
arg
]
)
hosts
.
append
(
self
.
m
n
[
arg
]
)
if
not
err
:
self
.
mn
.
iperf
(
hosts
)
else
:
...
...
@@ -196,11 +198,11 @@ def do_iperfudp( self, line ):
hosts
=
[]
err
=
False
for
arg
in
args
[
1
:
3
]:
if
arg
not
in
self
.
n
odemap
:
if
arg
not
in
self
.
m
n
:
err
=
True
error
(
"
node
'
%s
'
not in network
\n
"
%
arg
)
else
:
hosts
.
append
(
self
.
n
odemap
[
arg
]
)
hosts
.
append
(
self
.
m
n
[
arg
]
)
if
not
err
:
self
.
mn
.
iperf
(
hosts
,
l4Type
=
'
UDP
'
,
udpBw
=
udpBw
)
else
:
...
...
@@ -209,13 +211,15 @@ def do_iperfudp( self, line ):
def
do_intfs
(
self
,
_line
):
"
List interfaces.
"
for
node
in
self
.
nodelist
:
# self.mn.values()
for
node
in
self
.
mn
:
output
(
'
%s: %s
\n
'
%
(
node
.
name
,
'
,
'
.
join
(
node
.
intfNames
()
)
)
)
def
do_dump
(
self
,
_line
):
"
Dump node info.
"
for
node
in
self
.
nodelist
:
# self.mn.values()
for
node
in
self
.
mn
:
output
(
'
%s
\n
'
%
repr
(
node
)
)
def
do_link
(
self
,
line
):
...
...
@@ -235,10 +239,11 @@ def do_xterm( self, line, term='xterm' ):
error
(
'
usage: %s node1 node2 ...
\n
'
%
term
)
else
:
for
arg
in
args
:
if
arg
not
in
self
.
nodemap
:
# self.mn.keys()
if
arg
not
in
self
.
mn
:
error
(
"
node
'
%s
'
not in network
\n
"
%
arg
)
else
:
node
=
self
.
n
odemap
[
arg
]
node
=
self
.
m
n
[
arg
]
self
.
mn
.
terms
+=
makeTerms
(
[
node
],
term
=
term
)
def
do_x
(
self
,
line
):
...
...
@@ -329,11 +334,11 @@ def default( self, line ):
args
=
args
[
:
-
1
]
rest
=
args
.
split
(
'
'
)
if
first
in
self
.
n
odemap
:
node
=
self
.
n
odemap
[
first
]
if
first
in
self
.
m
n
:
node
=
self
.
m
n
[
first
]
# Substitute IP addresses for node names in command
rest
=
[
self
.
n
odemap
[
arg
].
defaultIntf
().
updateIP
()
if
arg
in
self
.
n
odemap
else
arg
rest
=
[
self
.
m
n
[
arg
].
defaultIntf
().
updateIP
()
if
arg
in
self
.
m
n
else
arg
for
arg
in
rest
]
rest
=
'
'
.
join
(
rest
)
# Run cmd on node:
...
...
This diff is collapsed.
Click to expand it.
mininet/net.py
+
16
−
0
View file @
8e04a9f8
...
...
@@ -236,8 +236,24 @@ def __getitem__( self, *args ):
def
__iter__
(
self
):
"
return iterator over nodes
"
#or dow we want to iterate of the keys i.e. node.name like a dict
return
chain
(
self
.
hosts
,
self
.
switches
,
self
.
controllers
)
def
__len__
(
self
):
return
len
(
self
.
hosts
)
+
len
(
self
.
switches
)
+
len
(
self
.
controllers
)
def
__contains__
(
self
,
item
):
return
item
in
self
.
keys
()
def
keys
(
self
):
return
[
node
.
name
for
node
in
self
.
__iter__
()
]
def
values
(
self
):
return
list
(
self
.
__iter__
()
)
def
items
(
self
):
return
zip
(
self
.
keys
(),
self
.
values
()
)
def
addLink
(
self
,
node1
,
node2
,
port1
=
None
,
port2
=
None
,
cls
=
None
,
**
params
):
""""
Add a link from node1 to node2
...
...
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