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
343b00df
Commit
343b00df
authored
Apr 15, 2022
by
zhifan huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v1
parent
78a1dac7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
re6st/tests/test_network/my_net.py
re6st/tests/test_network/my_net.py
+22
-0
No files found.
re6st/tests/test_network/my_net.py
0 → 100644
View file @
343b00df
import
subprocess
import
time
app1
=
subprocess
.
Popen
(
"unshare -n"
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
)
app2
=
subprocess
.
Popen
(
"unshare -n"
,
shell
=
True
,
stdin
=
subprocess
.
PIPE
)
print
(
"pid, 1:{}, 2:{}"
.
format
(
app1
.
pid
,
app2
.
pid
))
subprocess
.
check_call
([
'ip'
,
'link'
,
'add'
,
'veth0'
,
'netns'
,
str
(
app1
.
pid
+
2
)
,
'type'
,
'veth'
,
'peer'
,
'veth1'
])
subprocess
.
check_call
([
'nsenter'
,
'-t'
,
str
(
app1
.
pid
+
2
),
'-n'
]
+
[
'ip'
,
'link'
,
'set'
,
'up'
,
'veth0'
])
subprocess
.
check_call
([
'ip'
,
'link'
,
'set'
,
'up'
,
'veth1'
])
subprocess
.
check_call
([
'nsenter'
,
'-t'
,
str
(
app1
.
pid
+
2
),
'-n'
]
+
[
'ip'
,
'addr'
,
'add'
,
'dev'
,
'veth0'
,
'10.1.1.1/24'
])
subprocess
.
check_call
([
'ip'
,
'addr'
,
'add'
,
'dev'
,
'veth1'
,
'10.1.1.2/24'
])
subprocess
.
check_call
(
"ip addr"
,
shell
=
True
)
# subprocess.check_call(['nsenter', '-t', str(app1.pid), '-n','ip', 'route', 'add', '10.1.1.0/24', 'via', '10.1.1.1'])
# subprocess.check_call(['ip', 'route', 'add', '10.1.1.0/24', 'via', '10.1.1.2'])
subprocess
.
check_call
(
"ping 10.1.1.1"
,
shell
=
True
)
print
(
"good bye!"
)
\ No newline at end of file
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