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
76a8a163
Commit
76a8a163
authored
11 years ago
by
Bob Lantz
Browse files
Options
Downloads
Patches
Plain Diff
Clean up sshd.py and its test so it works on VirtualBox
parent
568f6424
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
examples/sshd.py
+19
-13
19 additions, 13 deletions
examples/sshd.py
examples/test/test_sshd.py
+1
-1
1 addition, 1 deletion
examples/test/test_sshd.py
with
20 additions
and
14 deletions
examples/sshd.py
+
19
−
13
View file @
76a8a163
...
...
@@ -21,7 +21,7 @@
from
mininet.net
import
Mininet
from
mininet.cli
import
CLI
from
mininet.log
import
lg
from
mininet.node
import
Node
,
OVSKernelSwitch
from
mininet.node
import
Node
from
mininet.topolib
import
TreeTopo
from
mininet.link
import
Link
...
...
@@ -30,29 +30,33 @@ def TreeNet( depth=1, fanout=2, **kwargs ):
topo
=
TreeTopo
(
depth
,
fanout
)
return
Mininet
(
topo
,
**
kwargs
)
def
connectToRootNS
(
network
,
switch
,
ip
,
prefixLen
,
routes
):
def
connectToRootNS
(
network
,
switch
,
ip
,
routes
):
"""
Connect hosts to root namespace via switch. Starts network.
network: Mininet() network object
switch: switch to connect to root namespace
ip: IP address for root namespace node
prefixLen: IP address prefix length (e.g. 8, 16, 24)
routes: host networks to route to
"""
# Create a node in root namespace and link to switch 0
root
=
Node
(
'
root
'
,
inNamespace
=
False
)
intf
=
Link
(
root
,
switch
).
intf1
root
.
setIP
(
ip
,
prefixLen
,
intf
)
root
.
setIP
(
ip
,
intf
=
intf
)
# Start network that now includes link to root namespace
network
.
start
()
# Add routes from root ns to hosts
for
route
in
routes
:
root
.
cmd
(
'
route add -net
'
+
route
+
'
dev
'
+
str
(
intf
)
)
def
sshd
(
network
,
cmd
=
'
/usr/sbin/sshd
'
,
opts
=
'
-D
'
):
"
Start a network, connect it to root ns, and run sshd on all hosts.
"
switch
=
network
.
switches
[
0
]
# switch to use
ip
=
'
10.123.123.1
'
# our IP address on host network
routes
=
[
'
10.0.0.0/8
'
]
# host networks to route to
connectToRootNS
(
network
,
switch
,
ip
,
8
,
routes
)
def
sshd
(
network
,
cmd
=
'
/usr/sbin/sshd
'
,
opts
=
'
-D
'
,
ip
=
'
10.123.123.1/32
'
,
routes
=
None
,
switch
=
None
):
"""
Start a network, connect it to root ns, and run sshd on all hosts.
ip: root-eth0 IP address in root namespace (10.123.123.1/32)
routes: Mininet host networks to route to (10.0/24)
switch: Mininet switch to connect to root namespace (s1)
"""
if
not
switch
:
switch
=
network
[
'
s1
'
]
# switch to use
if
not
routes
:
routes
=
[
'
10.0.0.0/24
'
]
connectToRootNS
(
network
,
switch
,
ip
,
routes
)
for
host
in
network
.
hosts
:
host
.
cmd
(
cmd
+
'
'
+
opts
+
'
&
'
)
print
...
...
@@ -69,7 +73,9 @@ def sshd( network, cmd='/usr/sbin/sshd', opts='-D' ):
if
__name__
==
'
__main__
'
:
lg
.
setLogLevel
(
'
info
'
)
net
=
TreeNet
(
depth
=
1
,
fanout
=
4
,
switch
=
OVSKernelSwitch
)
# get sshd args from the command line; default: -D
opts
=
'
'
.
join
(
sys
.
argv
[
1
:
]
)
if
len
(
sys
.
argv
)
>
1
else
'
-D
'
net
=
TreeNet
(
depth
=
1
,
fanout
=
4
)
# get sshd args from the command line or use default args
# useDNS=no -u0 to avoid reverse DNS lookup timeout
opts
=
'
'
.
join
(
sys
.
argv
[
1
:
]
)
if
len
(
sys
.
argv
)
>
1
else
(
'
-D -o UseDNS=no -u0
'
)
sshd
(
net
,
opts
=
opts
)
This diff is collapsed.
Click to expand it.
examples/test/test_sshd.py
+
1
−
1
View file @
76a8a163
...
...
@@ -40,7 +40,7 @@ def setUp( self ):
sh
(
'
cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys
'
)
cmd
=
(
'
python -m mininet.examples.sshd -D
'
'
-o AuthorizedKeysFile=/tmp/ssh/authorized_keys
'
'
-o StrictModes=no
'
)
'
-o StrictModes=no
-o UseDNS=no -u0
'
)
# run example with custom sshd args
self
.
net
=
pexpect
.
spawn
(
cmd
)
self
.
net
.
expect
(
'
mininet>
'
)
...
...
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