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
9281719d
Commit
9281719d
authored
11 years ago
by
Brian O'Connor
Browse files
Options
Downloads
Patches
Plain Diff
Made net compliant with dict semantics and added function comments
Fixed locals bug (now they are persisent across calls)
parent
8e04a9f8
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
+11
-16
11 additions, 16 deletions
mininet/cli.py
mininet/net.py
+9
-3
9 additions, 3 deletions
mininet/net.py
with
20 additions
and
19 deletions
mininet/cli.py
+
11
−
16
View file @
9281719d
...
...
@@ -43,6 +43,8 @@ class CLI( Cmd ):
def
__init__
(
self
,
mininet
,
stdin
=
sys
.
stdin
,
script
=
None
):
self
.
mn
=
mininet
# CLI locals for py commands
self
.
locals
=
{
'
net
'
:
mininet
}
# Attempt to handle input
self
.
stdin
=
stdin
self
.
inPoller
=
poll
()
...
...
@@ -71,11 +73,10 @@ def emptyline( self ):
"
Don
'
t repeat last command when you hit return.
"
pass
def
l
ocals
(
self
):
def
getL
ocals
(
self
):
"
Local variable bindings for py command
"
locals
=
{
'
net
'
:
self
.
mn
}
locals
.
update
(
self
.
mn
)
return
locals
self
.
locals
.
update
(
self
.
mn
)
return
self
.
locals
# Disable pylint "Unused argument: 'arg's'" messages, as well as
# "method could be a function" warning, since each CLI function
...
...
@@ -109,14 +110,12 @@ def do_help( self, line ):
def
do_nodes
(
self
,
_line
):
"
List all nodes.
"
# self.mn.values()
nodes
=
'
'
.
join
(
[
node
.
name
for
node
in
sorted
(
self
.
mn
)
]
)
nodes
=
'
'
.
join
(
sorted
(
self
.
mn
)
)
output
(
'
available nodes are:
\n
%s
\n
'
%
nodes
)
def
do_net
(
self
,
_line
):
"
List network connections.
"
# self.mn.values()
dumpNodeConnections
(
self
.
mn
)
dumpNodeConnections
(
self
.
mn
.
values
()
)
def
do_sh
(
self
,
line
):
"
Run an external shell command
"
...
...
@@ -129,7 +128,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
.
l
ocals
()
)
result
=
eval
(
line
,
globals
(),
self
.
getL
ocals
()
)
if
not
result
:
return
elif
isinstance
(
result
,
str
):
...
...
@@ -146,7 +145,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
.
l
ocals
()
)
exec
(
line
,
globals
(),
self
.
getL
ocals
()
)
except
Exception
,
e
:
output
(
str
(
e
)
+
'
\n
'
)
...
...
@@ -177,7 +176,6 @@ def do_iperf( self, line ):
hosts
=
[]
err
=
False
for
arg
in
args
:
# self.mn.keys()
if
arg
not
in
self
.
mn
:
err
=
True
error
(
"
node
'
%s
'
not in network
\n
"
%
arg
)
...
...
@@ -211,15 +209,13 @@ def do_iperfudp( self, line ):
def
do_intfs
(
self
,
_line
):
"
List interfaces.
"
# self.mn.values()
for
node
in
self
.
mn
:
for
node
in
self
.
mn
.
values
():
output
(
'
%s: %s
\n
'
%
(
node
.
name
,
'
,
'
.
join
(
node
.
intfNames
()
)
)
)
def
do_dump
(
self
,
_line
):
"
Dump node info.
"
# self.mn.values()
for
node
in
self
.
mn
:
for
node
in
self
.
mn
.
values
():
output
(
'
%s
\n
'
%
repr
(
node
)
)
def
do_link
(
self
,
line
):
...
...
@@ -239,7 +235,6 @@ def do_xterm( self, line, term='xterm' ):
error
(
'
usage: %s node1 node2 ...
\n
'
%
term
)
else
:
for
arg
in
args
:
# self.mn.keys()
if
arg
not
in
self
.
mn
:
error
(
"
node
'
%s
'
not in network
\n
"
%
arg
)
else
:
...
...
This diff is collapsed.
Click to expand it.
mininet/net.py
+
9
−
3
View file @
9281719d
...
...
@@ -237,21 +237,27 @@ 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
)
for
node
in
chain
(
self
.
hosts
,
self
.
switches
,
self
.
controllers
):
yield
node
.
name
def
__len__
(
self
):
"
returns number of nodes in net
"
return
len
(
self
.
hosts
)
+
len
(
self
.
switches
)
+
len
(
self
.
controllers
)
def
__contains__
(
self
,
item
):
"
returns True if net contains named node
"
return
item
in
self
.
keys
()
def
keys
(
self
):
return
[
node
.
name
for
node
in
self
.
__iter__
()
]
"
return a list of all node names or net
'
s keys
"
return
list
(
self
.
__iter__
()
)
def
values
(
self
):
return
list
(
self
.
__iter__
()
)
"
return a list of all nodes or net
'
s values
"
return
[
self
[
name
]
for
name
in
self
.
__iter__
()
]
def
items
(
self
):
"
return (key,value) tuple list for every node in net
"
return
zip
(
self
.
keys
(),
self
.
values
()
)
def
addLink
(
self
,
node1
,
node2
,
port1
=
None
,
port2
=
None
,
...
...
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