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
c1f6c799
Commit
c1f6c799
authored
Jul 20, 2010
by
Martín Ferrari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API changes
parent
a6425bf6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
24 deletions
+30
-24
sample-api.py
sample-api.py
+14
-10
src/netns/__init__.py
src/netns/__init__.py
+3
-2
t/test_interfaces.py
t/test_interfaces.py
+13
-12
No files found.
sample-api.py
View file @
c1f6c799
...
...
@@ -19,9 +19,13 @@ b = netns.Node()
print
"Nodes started with pids: %d and %d"
%
(
a
.
pid
,
b
.
pid
)
# interface object maps to a veth pair with one end in a netns
# XXX: should it be named lladdr instead?
if0
=
a
.
add_if
(
mac_address
=
'42:71:e0:90:ca:42'
)
if0
=
a
.
add_if
(
lladdr
=
'42:71:e0:90:ca:42'
)
# This is equivalent
#if0 = netns.NodeInterface(a)
#if0.lladdr = '42:71:e0:90:ca:42'
if1
=
b
.
add_if
(
mtu
=
1492
)
# for using with a tun device, to connect to the outside world
if2
=
b
.
import_if
(
'tun0'
)
...
...
@@ -37,7 +41,6 @@ link0 = netns.Link(bandwidth = 100 * 1024 * 1024,
# connect to the bridge
link0
.
connect
(
if0
)
link0
.
connect
(
if1
)
#link0.connect(if2)
# Should be experimented with Tom Geoff's patch to see if the bridge could be
# avoided; but for that the API would be slightly different, as these would be
...
...
@@ -45,13 +48,17 @@ link0.connect(if1)
# ppp0 = netns.PPPLink(a, b, bandwidth = ....)
# if0 = ppp0.interface(a)
# For now, we have simple P2P interfaces:
(
pppa
,
pppb
)
=
netns
.
P2PInterface
(
a
,
b
)
# Add and connect a tap device (as if a external router were plugged into a
# switch)
link0
.
add_tunnel_if
()
if2
=
netns
.
ExternalInterface
(
'tap0'
)
link0
.
connect
(
if2
)
link0
.
enabled
=
True
if0
.
enabled
=
True
if1
.
enabled
=
True
link0
.
up
=
True
if0
.
up
=
True
if1
.
up
=
True
# addresses as iproute
if0
.
add_v4_address
(
addr
=
'10.0.0.1'
,
prefix_len
=
24
)
...
...
@@ -75,9 +82,6 @@ nodes = netns.get_nodes()
links
=
netns
.
get_links
()
stats
=
link0
.
get_stats
()
# IDEA: implement Node.popen and build the others upon it.
# IDEA: use SCM_RIGHTS to pass filedescriptors instead of using pipes/sockets
# Run a process in background
import
subprocess
app0
=
a
.
Popen
(
"ping -c 3 10.0.0.2"
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
...
...
src/netns/__init__.py
View file @
c1f6c799
...
...
@@ -2,7 +2,8 @@
# vim:ts=4:sw=4:et:ai:sts=4
import
os
,
pwd
from
netns.node
import
Node
from
netns.node
import
*
from
netns.interface
import
*
class
__Config
(
object
):
def
__init__
(
self
):
...
...
@@ -37,7 +38,7 @@ class __Config(object):
"Default user to run applications as"
)
config
=
__Config
()
get_nodes
=
Node
.
get_nodes
# FIXME: set atfork hooks
# http://code.google.com/p/python-atfork/source/browse/atfork/__init__.py
...
...
t/test_interfaces.py
View file @
c1f6c799
...
...
@@ -34,20 +34,20 @@ class TestInterfaces(unittest.TestCase):
devs
=
get_devs
()
for
i
in
range
(
5
):
self
.
assertTrue
(
ifaces
[
i
].
peer_name
in
devs
)
peer_name
=
netns
.
iproute
.
get_if
(
ifaces
[
i
].
control_index
).
name
self
.
assertTrue
(
peer_name
in
devs
)
self
.
assertEquals
(
set
(
ifaces
),
node0
.
get_interfaces
())
@
test_util
.
skipUnless
(
os
.
getuid
()
==
0
,
"Test requires root privileges"
)
def
test_interface_settings
(
self
):
node0
=
netns
.
Node
()
if0
=
node0
.
add_if
(
mac_address
=
'42:71:e0:90:ca:42'
,
mtu
=
1492
)
self
.
assertEquals
(
if0
.
mac_address
,
'42:71:e0:90:ca:42'
)
if0
.
mac_address
=
'4271E090CA42'
self
.
assertEquals
(
if0
.
mac_address
,
'42:71:e0:90:ca:42'
)
self
.
assertRaises
(
BaseException
,
setattr
,
if0
,
'mac_address'
,
'foo'
)
self
.
assertRaises
(
BaseException
,
setattr
,
if0
,
'mac_address'
,
'12345678901'
)
if0
=
node0
.
add_if
(
lladdr
=
'42:71:e0:90:ca:42'
,
mtu
=
1492
)
self
.
assertEquals
(
if0
.
lladdr
,
'42:71:e0:90:ca:42'
)
if0
.
lladdr
=
'4271E090CA42'
self
.
assertEquals
(
if0
.
lladdr
,
'42:71:e0:90:ca:42'
)
self
.
assertRaises
(
BaseException
,
setattr
,
if0
,
'lladdr'
,
'foo'
)
self
.
assertRaises
(
BaseException
,
setattr
,
if0
,
'lladdr'
,
'12345678901'
)
self
.
assertEquals
(
if0
.
mtu
,
1492
)
self
.
assertRaises
(
BaseException
,
setattr
,
if0
,
'mtu'
,
0
)
self
.
assertRaises
(
BaseException
,
setattr
,
if0
,
'mtu'
,
65537
)
...
...
@@ -55,7 +55,7 @@ class TestInterfaces(unittest.TestCase):
devs
=
get_devs_netns
(
node0
)
self
.
assertTrue
(
if0
.
name
in
devs
)
self
.
assertFalse
(
devs
[
if0
.
name
][
'up'
])
self
.
assertEquals
(
devs
[
if0
.
name
][
'lladdr'
],
if0
.
mac_address
)
self
.
assertEquals
(
devs
[
if0
.
name
][
'lladdr'
],
if0
.
lladdr
)
self
.
assertEquals
(
devs
[
if0
.
name
][
'mtu'
],
if0
.
mtu
)
if0
.
enable
=
True
...
...
@@ -70,7 +70,8 @@ class TestInterfaces(unittest.TestCase):
# FIXME: get_stats
@
test_util
.
skipUnless
(
os
.
getuid
()
==
0
,
"Test requires root privileges"
)
#@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
@
test_util
.
skip
(
"Not implemented"
)
def
test_interface_migration
(
self
):
node0
=
netns
.
Node
()
dummyname
=
"dummy%d"
%
os
.
getpid
()
...
...
@@ -80,12 +81,12 @@ class TestInterfaces(unittest.TestCase):
self
.
assertTrue
(
dummyname
in
devs
)
if0
=
node0
.
import_if
(
dummyname
)
if0
.
mac_address
=
'42:71:e0:90:ca:43'
if0
.
lladdr
=
'42:71:e0:90:ca:43'
if0
.
mtu
=
1400
devs
=
get_devs_netns
(
node0
)
self
.
assertTrue
(
if0
.
name
in
devs
)
self
.
assertEquals
(
devs
[
if0
.
name
][
'lladdr'
],
if0
.
mac_address
)
self
.
assertEquals
(
devs
[
if0
.
name
][
'lladdr'
],
if0
.
lladdr
)
self
.
assertEquals
(
devs
[
if0
.
name
][
'mtu'
],
if0
.
mtu
)
@
test_util
.
skipUnless
(
os
.
getuid
()
==
0
,
"Test requires root privileges"
)
...
...
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