Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
zhifan huang
re6stnet
Commits
e99fcb5b
Commit
e99fcb5b
authored
Apr 29, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dada
parent
8b3dfc3d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
46 deletions
+55
-46
re6st/tests/test_network/my_net.py
re6st/tests/test_network/my_net.py
+54
-45
re6st/tests/test_network/test_net.py
re6st/tests/test_network/test_net.py
+1
-1
No files found.
re6st/tests/test_network/my_net.py
View file @
e99fcb5b
"""thie moudle use net namespace to create different net node"""
import
subprocess
from
subprocess
import
PIPE
import
weakref
import
sys
import
os
import
logging
import
time
import
ipaddress
...
...
@@ -53,13 +54,6 @@ class Device(object):
class
Netns
(
object
):
"""a network namespace"""
@
property
def
ip
(
self
):
return
self
.
out
.
ips
[
-
1
]
@
property
def
out
(
self
):
return
self
.
devices
[
-
1
]
def
__init__
(
self
):
self
.
devices
=
[]
...
...
@@ -140,6 +134,23 @@ class Netns(object):
except
:
pass
class
Host
(
Netns
):
"""node used to run a application, not for connecting
use the first create veth, and it's ip to avoid multi device/ip situation
"""
def
__init__
(
self
):
super
(
Host
,
self
).
__init__
()
@
property
def
ip
(
self
):
return
self
.
out
.
ips
[
0
]
@
property
def
out
(
self
):
return
self
.
devices
[
1
]
def
connectible_test
(
nm
):
"""test each node can ping to their registry
nm: NetManger
...
...
@@ -152,14 +163,13 @@ def connectible_test(nm):
logging
.
debug
(
"each node can ping to their registry"
)
def
net_simple
():
""" registry .1 ------ .2 node
10.1.1
"""
nm
=
NetManager
()
node1
=
Netns
()
node2
=
Netns
()
node1
=
Host
()
node2
=
Host
()
dev1
,
dev2
=
node1
.
connect_direct
(
node2
)
dev1
.
add_ip4
(
"10.1.1.1"
,
prefix
=
24
)
dev2
.
add_ip4
(
"10.1.1.2"
,
prefix
=
24
)
...
...
@@ -177,9 +187,9 @@ def net_route():
router
=
Netns
()
router
.
add_device_bridge
()
registry
=
Netns
()
node1
=
Netns
()
node2
=
Netns
()
registry
=
Host
()
node1
=
Host
()
node2
=
Host
()
veth_r
,
_
=
registry
.
connect_router
(
router
)
veth_n1
,
_
=
node1
.
connect_router
(
router
)
...
...
@@ -196,43 +206,41 @@ def net_route():
return
nm
def
net_demo
():
# Underlying network:
#
# registry .2------ ------.2 registry2
# | |
# 10.0.0| |10.3.0
# .1 | |.1
# ---------------Internet----------------
# |.1 |.1 |.1
# |10.1.0 |10.2.0 |
# |.2 |.2
|
# gateway1 gateway2 s3:10.0.1
# |.1 |.1 |.2 |.3 |.4
# s1:10.1.1 --s2:10.2.1-- m6 m7 m8
# |.2 |.3 |.2 |.3 |.4 |.5
# m1 m2 m3 m4 m5 m10
#
"""
Underlying network:
registry .2------
|
10.0.0|
.1 |
---------------Internet----------------
|.1 |.1 |.1
|10.1.0 |10.2.0
|
|.2 |.2 |
gateway1 gateway2 s3:10.0.1
|.1 |.1 |.2 |.3 |.4
s1:10.1.1 --s2:10.2.1-- m6 m7 m8
|.2 |.3 |.2 |.3 |.4
m1 m2 m3 m4 m5
"""
nm
=
NetManager
()
internet
=
Netns
()
gateway1
=
Netns
()
router1
=
Netns
()
gateway2
=
Netns
()
router2
=
Netns
()
router3
=
Netns
()
registry
=
Netns
()
node1
=
Netns
()
node2
=
Netns
()
node3
=
Netns
()
node4
=
Netns
()
node5
=
Netns
()
node6
=
Netns
()
node7
=
Netns
()
node8
=
Netns
()
registry
=
Host
()
node1
=
Host
()
node2
=
Host
()
node3
=
Host
()
node4
=
Host
()
node5
=
Host
()
node6
=
Host
()
node7
=
Host
()
node8
=
Host
()
router1
.
add_device_bridge
()
router2
.
add_device_bridge
()
...
...
@@ -251,6 +259,7 @@ def net_demo():
veth_g1_1
.
add_ip4
(
"10.1.0.2"
,
24
)
gateway1
.
add_route
(
"10.0.0.0/8"
,
'via'
,
"10.1.0.1"
)
# sign ip for node
ip
=
ipaddress
.
ip_address
(
u"10.1.1.1"
)
for
node
in
[
gateway1
,
node1
,
node2
]:
dev
,
_
=
node
.
connect_router
(
router1
)
...
...
@@ -288,14 +297,14 @@ def net_demo():
internet
.
add_route
(
"10.2.0.0/16"
,
'via'
,
"10.2.0.2"
)
# time.sleep(100000)
gateway1
.
proc
=
gateway1
.
Popen
([
'miniupnpd'
,
'-d'
,
'-f'
,
'miniupnpd.conf'
,
'-P'
,
'miniupnpd.pid'
,
'-a'
,
gateway1
.
devices
[
-
1
].
name
,
'-i'
,
gateway1
.
devices
[
-
1
].
name
],
stdout
=
PIPE
,
stderr
=
PIPE
)
nm
.
object
+=
[
internet
,
gateway1
,
gateway2
,
router1
,
router2
,
router3
]
nm
.
registrys
[
registry
]
=
[
node1
,
node2
,
node3
,
node4
,
node5
,
node6
,
node7
,
node8
]
connectible_test
(
nm
)
gateway1
.
proc
=
gateway1
.
Popen
([
'miniupnpd'
,
'-d'
,
'-f'
,
'miniupnpd.conf'
,
'-P'
,
'miniupnpd.pid'
,
'-a'
,
gateway1
.
devices
[
-
1
].
name
,
'-i'
,
gateway1
.
devices
[
-
1
].
name
],
stdout
=
PIPE
,
stderr
=
PIPE
)
return
nm
if
__name__
==
"__main__"
:
...
...
re6st/tests/test_network/test_net.py
View file @
e99fcb5b
...
...
@@ -131,7 +131,7 @@ class TestNet(unittest.TestCase):
nm
=
my_net
.
net_route
()
nodes
,
registrys
=
deploy_re6st
(
nm
)
wait_stable
(
nodes
,
2
0
)
wait_stable
(
nodes
,
4
0
)
time
.
sleep
(
10
)
self
.
assertTrue
(
wait_stable
(
nodes
,
20
),
" ping test failed"
)
...
...
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