Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
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
Kirill Smelkov
bcc
Commits
06cfc59c
Commit
06cfc59c
authored
Aug 04, 2015
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #110 from iovisor/yhs_dev
better clean up of created namespace/interfaces if ctrl-c is pressed
parents
930573e3
c90becea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
11 deletions
+26
-11
examples/simulation.py
examples/simulation.py
+26
-11
No files found.
examples/simulation.py
View file @
06cfc59c
...
@@ -24,7 +24,15 @@ class Simulation(object):
...
@@ -24,7 +24,15 @@ class Simulation(object):
if
name
in
self
.
ipdbs
:
if
name
in
self
.
ipdbs
:
ns_ipdb
=
self
.
ipdbs
[
name
]
ns_ipdb
=
self
.
ipdbs
[
name
]
else
:
else
:
ns_ipdb
=
IPDB
(
nl
=
NetNS
(
name
))
try
:
nl
=
NetNS
(
name
)
self
.
namespaces
.
append
(
nl
)
except
KeyboardInterrupt
:
# remove the namespace if it has been created
pyroute2
.
netns
.
remove
(
name
)
raise
ns_ipdb
=
IPDB
(
nl
)
self
.
ipdbs
[
nl
.
netns
]
=
ns_ipdb
if
disable_ipv6
:
if
disable_ipv6
:
cmd
=
[
"sysctl"
,
"-q"
,
"-w"
,
cmd
=
[
"sysctl"
,
"-q"
,
"-w"
,
"net.ipv6.conf.default.disable_ipv6=1"
]
"net.ipv6.conf.default.disable_ipv6=1"
]
...
@@ -33,17 +41,26 @@ class Simulation(object):
...
@@ -33,17 +41,26 @@ class Simulation(object):
ns_ipdb
.
interfaces
.
lo
.
up
().
commit
()
ns_ipdb
.
interfaces
.
lo
.
up
().
commit
()
if
in_ifc
:
if
in_ifc
:
in_ifname
=
in_ifc
.
ifname
in_ifname
=
in_ifc
.
ifname
with
in_ifc
as
v
:
# move half of veth into namespace
v
.
net_ns_fd
=
ns_ipdb
.
nl
.
netns
else
:
else
:
out_ifc
=
self
.
ipdb
.
create
(
ifname
=
"%sa"
%
ifc_base_name
,
kind
=
"veth"
,
try
:
peer
=
"%sb"
%
ifc_base_name
).
commit
()
out_ifc
=
self
.
ipdb
.
create
(
ifname
=
"%sa"
%
ifc_base_name
,
kind
=
"veth"
,
in_ifc
=
self
.
ipdb
.
interfaces
[
out_ifc
.
peer
]
peer
=
"%sb"
%
ifc_base_name
).
commit
()
in_ifname
=
in_ifc
.
ifname
in_ifc
=
self
.
ipdb
.
interfaces
[
out_ifc
.
peer
]
with
in_ifc
as
v
:
in_ifname
=
in_ifc
.
ifname
# move half of veth into namespace
with
in_ifc
as
v
:
v
.
net_ns_fd
=
ns_ipdb
.
nl
.
netns
v
.
net_ns_fd
=
ns_ipdb
.
nl
.
netns
in_ifc
=
ns_ipdb
.
interfaces
[
in_ifname
]
except
KeyboardInterrupt
:
# explicitly remove the interface
out_ifname
=
"%sa"
%
ifc_base_name
if
out_ifname
in
self
.
ipdb
.
interfaces
:
self
.
ipdb
.
interfaces
[
out_ifname
].
remove
().
commit
()
raise
if
out_ifc
:
out_ifc
.
up
().
commit
()
if
out_ifc
:
out_ifc
.
up
().
commit
()
ns_ipdb
.
interfaces
.
lo
.
up
().
commit
()
ns_ipdb
.
interfaces
.
lo
.
up
().
commit
()
in_ifc
=
ns_ipdb
.
interfaces
[
in_ifname
]
with
in_ifc
as
v
:
with
in_ifc
as
v
:
v
.
ifname
=
ns_ifc
v
.
ifname
=
ns_ifc
if
ipaddr
:
v
.
add_ip
(
"%s"
%
ipaddr
)
if
ipaddr
:
v
.
add_ip
(
"%s"
%
ipaddr
)
...
@@ -68,8 +85,6 @@ class Simulation(object):
...
@@ -68,8 +85,6 @@ class Simulation(object):
(
ns_ipdb
,
out_ifc
,
in_ifc
)
=
self
.
_ns_add_ifc
(
name
,
"eth0"
,
name
,
in_ifc
,
out_ifc
,
(
ns_ipdb
,
out_ifc
,
in_ifc
)
=
self
.
_ns_add_ifc
(
name
,
"eth0"
,
name
,
in_ifc
,
out_ifc
,
ipaddr
,
macaddr
,
fn
,
cmd
,
action
,
ipaddr
,
macaddr
,
fn
,
cmd
,
action
,
disable_ipv6
)
disable_ipv6
)
self
.
ipdbs
[
ns_ipdb
.
nl
.
netns
]
=
ns_ipdb
self
.
namespaces
.
append
(
ns_ipdb
.
nl
)
return
(
ns_ipdb
,
out_ifc
,
in_ifc
)
return
(
ns_ipdb
,
out_ifc
,
in_ifc
)
def
release
(
self
):
def
release
(
self
):
...
...
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