Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nemu3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
nemu3
Commits
14dd7ce4
Commit
14dd7ce4
authored
Aug 24, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some fixes
parent
164de9bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
16 deletions
+39
-16
sample.py
sample.py
+37
-15
src/netns/environ.py
src/netns/environ.py
+2
-1
No files found.
sample.py
100644 → 100755
View file @
14dd7ce4
#/usr/bin/env python
#
!
/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import
netns
,
subprocess
...
...
@@ -6,7 +6,8 @@ import netns, subprocess
node0
=
netns
.
Node
()
node1
=
netns
.
Node
()
node2
=
netns
.
Node
()
print
"Nodes started with pids: %s
\
n
"
%
str
((
node0
.
pid
,
node1
.
pid
,
node2
.
pid
))
print
"Nodes started with pids: %s"
%
str
((
node0
.
pid
,
node1
.
pid
,
node2
.
pid
))
# interface object maps to a veth pair with one end in a netns
if0
=
netns
.
NodeInterface
(
node0
)
...
...
@@ -17,6 +18,7 @@ if1a = netns.NodeInterface(node1)
switch0
=
netns
.
Switch
(
bandwidth
=
100
*
1024
*
1024
,
delay
=
0.01
,
# 10 ms
delay_jitter
=
0.001
,
# 1ms
delay_correlation
=
0.25
,
# 25% correlation
loss
=
0.005
)
...
...
@@ -28,33 +30,53 @@ switch0.connect(if1a)
switch0
.
up
=
if0
.
up
=
if1a
.
up
=
if1b
.
up
=
if2
.
up
=
True
# Add IP addresses
if0
.
add_v4_address
(
addr
=
'10.0.0.1'
,
prefix_len
=
24
)
if1a
.
add_v4_address
(
addr
=
'10.0.0.2'
,
prefix_len
=
24
)
if1b
.
add_v4_address
(
addr
=
'10.0.1.1'
,
prefix_len
=
24
)
if2
.
add_v4_address
(
addr
=
'10.0.1.2'
,
prefix_len
=
24
)
if0
.
add_v4_address
(
addr
ess
=
'10.0.0.1'
,
prefix_len
=
24
)
if1a
.
add_v4_address
(
addr
ess
=
'10.0.0.2'
,
prefix_len
=
24
)
if1b
.
add_v4_address
(
addr
ess
=
'10.0.1.1'
,
prefix_len
=
24
)
if2
.
add_v4_address
(
addr
ess
=
'10.0.1.2'
,
prefix_len
=
24
)
# RFC-4193 Unique local addresses.
# Pre-generated random block: fde2:4a1d:8870::/48
if0
.
add_v6_address
(
addr
=
'fde2:4a1d:8870:0::0'
,
prefix_len
=
32
)
if1a
.
add_v6_address
(
addr
=
'fde2:4a1d:8870:0::1'
,
prefix_len
=
32
)
if1b
.
add_v6_address
(
addr
=
'fde2:4a1d:8870:1::0'
,
prefix_len
=
32
)
if2
.
add_v6_address
(
addr
=
'fde2:4a1d:8870:1::1'
,
prefix_len
=
32
)
if0
.
add_v6_address
(
address
=
'fde2:4a1d:8870:0::1'
,
prefix_len
=
32
)
if1a
.
add_v6_address
(
address
=
'fde2:4a1d:8870:0::2'
,
prefix_len
=
32
)
if1b
.
add_v6_address
(
address
=
'fde2:4a1d:8870:1::1'
,
prefix_len
=
32
)
if2
.
add_v6_address
(
address
=
'fde2:4a1d:8870:1::2'
,
prefix_len
=
32
)
# Configure routing
node0
.
add_route
(
prefix
=
'10.0.1.0'
,
prefix_len
=
24
,
nexthop
=
'10.0.0.2'
)
node2
.
add_route
(
prefix
=
'10.0.0.0'
,
prefix_len
=
24
,
nexthop
=
'10.0.1.1'
)
node0
.
add_route
(
prefix
=
'10.0.1.0'
,
prefix_len
=
24
,
nexthop
=
'10.0.0.2'
)
node2
.
add_route
(
prefix
=
'10.0.0.0'
,
prefix_len
=
24
,
nexthop
=
'10.0.1.1'
)
node0
.
add_route
(
prefix
=
'fde2:4a1d:8870:1::'
,
prefix_len
=
32
,
nexthop
=
'fde2:4a1d:8870:0::1'
)
node2
.
add_route
(
prefix
=
'fde2:4a1d:8870:0::'
,
prefix_len
=
32
,
nexthop
=
'fde2:4a1d:8870:1::0'
)
# Test connectivity first. Run process, hide output and check return code
app0
=
node0
.
Popen
(
"ping -c 1 10.0.1.2"
,
shell
=
True
,
stdout
=
subprocess
.
NONE
)
# Test connectivity first. Run process, hide output and check
# return code
null
=
file
(
"/dev/null"
,
"w"
)
app0
=
node0
.
Popen
(
"ping -c 1 10.0.1.2"
,
shell
=
True
,
stdout
=
null
)
ret
=
app0
.
wait
()
assert
ret
==
0
app1
=
node2
.
Popen
(
"ping -c 1 10.0.0.1"
,
shell
=
True
,
stdout
=
subprocess
.
NONE
)
app1
=
node2
.
Popen
(
"ping -c 1 10.0.0.1"
,
shell
=
True
,
stdout
=
null
)
ret
=
app1
.
wait
()
assert
ret
==
0
print
"Connectivity IPv4 OK!"
# if arguments speficied as array, no need to invoke the shell
app2
=
node0
.
Popen
([
"ping6"
,
"-c1"
,
"fde2:4a1d:8870:1::2"
])
#, stdout = null)
ret
=
app2
.
wait
()
#assert ret == 0
app3
=
node0
.
Popen
([
"ping6"
,
"-c1"
,
"fde2:4a1d:8870:0::1"
],
stdout
=
null
)
ret
=
app3
.
wait
()
#assert ret == 0
print
"Connectivity IPv6 OK!"
src/netns/environ.py
View file @
14dd7ce4
...
...
@@ -52,7 +52,8 @@ except:
"continue."
)
def
execute
(
cmd
):
#print " ".join(cmd)#; return
# FIXME: create a global debug variable
#print "[pid %d]" % os.getpid(), " ".join(cmd)
null
=
open
(
"/dev/null"
,
"r+"
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
null
,
stderr
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment