Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testbed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Alan Marsh
testbed
Commits
edcd0835
Commit
edcd0835
authored
6 years ago
by
Michael Marsh
Browse files
Options
Downloads
Patches
Plain Diff
updating to not always use docker
parent
a3221919
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README
+7
-12
7 additions, 12 deletions
README
example.yml
+1
-0
1 addition, 0 deletions
example.yml
start_testbed.py
+43
-29
43 additions, 29 deletions
start_testbed.py
stop_testbed.py
+11
-6
11 additions, 6 deletions
stop_testbed.py
with
62 additions
and
47 deletions
README
+
7
−
12
View file @
edcd0835
This repository contains scripts to help you set up a docker-based
testbed, with networking between the containers.
This repository contains scripts to help you set up a simple
namespace-based testbed, with networking between the namespaces.
Optionally, you can start docker containers in the namespaces.
Since
the containers don't need to do much in order
to demonstrate
basic networking (you can change this to suit your
needs), we're
just going to run the command
If we're using docker,
the containers don't need to do much in order
to demonstrate
basic networking (you can change this to suit your
needs), so we're
just going to run the command
tail -f /etc/issue
This will never exit, while it waits for more output to be appended
to the file.
Before running start_testbed.py, you must run:
sudo mkdir -p /var/run/netns
This only needs to be done once for your VM.
To start the testbed, run
./start_testbed.py [-f <config file>]
...
...
@@ -25,5 +20,5 @@ To stop the testbed, run
./stop_testbed.py [-f <config file>]
In both cases, if the config file isn't specified, it will use
example.yml
example.yml
in the current directory.
This diff is collapsed.
Click to expand it.
example.yml
+
1
−
0
View file @
edcd0835
...
...
@@ -10,6 +10,7 @@ docker_opts: ""
# center of the star. Containers will be named
# <name>0 through <name><num-nodes - 1>.
network
:
docker
:
false
name
:
test
num_nodes
:
4
topology
:
mesh
...
...
This diff is collapsed.
Click to expand it.
start_testbed.py
+
43
−
29
View file @
edcd0835
...
...
@@ -19,6 +19,7 @@ with open(args.file) as cfile:
conf
=
yaml
.
load
(
cfile
)
ntwk
=
conf
[
'
network
'
]
use_docker
=
ntwk
.
get
(
'
docker
'
,
False
)
base_addr
=
reduce
(
lambda
a
,
b
:
a
*
256
+
b
,
[
int
(
q
)
for
q
in
ntwk
[
'
subnet_addr
'
].
split
(
'
.
'
)
]
...
...
@@ -27,7 +28,8 @@ subnet = ntwk['subnet_addr']+'/'+str(ntwk['subnet_len'])
nodelist
=
list
()
retval
=
subprocess
.
call
([
'
docker
'
,
'
pull
'
,
conf
[
'
image
'
]])
if
use_docker
:
retval
=
subprocess
.
call
([
'
docker
'
,
'
pull
'
,
conf
[
'
image
'
]])
def
make_ip
(
i
):
addr
=
base_addr
+
i
...
...
@@ -117,40 +119,52 @@ def start_node(base_name,i):
global
nodelist
name
=
base_name
+
str
(
i
)
# Start the container.
command
=
[
'
docker
'
,
'
run
'
,
'
-d
'
,
'
--name
'
,
name
]
if
conf
[
'
docker_opts
'
]:
command
.
extend
(
conf
[
'
docker_opts
'
].
split
())
command
.
append
(
conf
[
'
image
'
])
command
.
extend
(
conf
[
'
image_cmd
'
].
split
())
retval
=
subprocess
.
call
(
command
)
if
use_docker
:
# Start the container.
command
=
[
'
docker
'
,
'
run
'
,
'
-d
'
,
'
--name
'
,
name
]
if
conf
[
'
docker_opts
'
]:
command
.
extend
(
conf
[
'
docker_opts
'
].
split
())
command
.
append
(
conf
[
'
image
'
])
command
.
extend
(
conf
[
'
image_cmd
'
].
split
())
retval
=
subprocess
.
call
(
command
)
entry
=
dict
()
entry
[
'
name
'
]
=
name
# Determine the IP address to use for this node.
entry
[
'
addr
'
]
=
make_ip
(
i
)
# Find the container's process ID.
entry
[
'
pid
'
]
=
subprocess
.
check_output
([
'
docker
'
,
'
inspect
'
,
'
-f
'
,
'
{{.State.Pid}}
'
,
name
]).
strip
()
if
use_docker
:
# Find the container's process ID.
entry
[
'
pid
'
]
=
subprocess
.
check_output
([
'
docker
'
,
'
inspect
'
,
'
-f
'
,
'
{{.State.Pid}}
'
,
name
]).
strip
()
# Set up a network namespace.
subprocess
.
call
([
'
sudo
'
,
'
ln
'
,
'
-s
'
,
'
/proc/{pid}/ns/net
'
.
format
(
pid
=
entry
[
'
pid
'
]),
'
/var/run/netns/{name}
'
.
format
(
name
=
name
)
])
# Set up a network namespace.
subprocess
.
call
([
'
sudo
'
,
'
ln
'
,
'
-s
'
,
'
/proc/{pid}/ns/net
'
.
format
(
pid
=
entry
[
'
pid
'
]),
'
/var/run/netns/{name}
'
.
format
(
name
=
name
)
])
else
:
# Create the network namespace for the node, without docker.
subprocess
.
call
([
'
sudo
'
,
'
ip
'
,
'
netns
'
,
'
add
'
,
name
])
pass
# Add the node's info to our list.
nodelist
.
append
(
entry
)
...
...
This diff is collapsed.
Click to expand it.
stop_testbed.py
+
11
−
6
View file @
edcd0835
...
...
@@ -17,15 +17,20 @@ with open(args.file) as cfile:
conf
=
yaml
.
load
(
cfile
)
ntwk
=
conf
[
'
network
'
]
use_docker
=
ntwk
.
get
(
'
docker
'
,
False
)
def
stop_node
(
name
,
i
):
ctr_name
=
'
{name}{i}
'
.
format
(
name
=
name
,
i
=
i
)
command
=
[
'
docker
'
,
'
kill
'
,
ctr_name
]
retval
=
subprocess
.
call
(
command
)
command
=
[
'
docker
'
,
'
rm
'
,
ctr_name
]
retval
=
subprocess
.
call
(
command
)
command
=
[
'
sudo
'
,
'
rm
'
,
'
/var/run/netns/
'
+
ctr_name
]
retval
=
subprocess
.
call
(
command
)
if
use_docker
:
command
=
[
'
docker
'
,
'
kill
'
,
ctr_name
]
retval
=
subprocess
.
call
(
command
)
command
=
[
'
docker
'
,
'
rm
'
,
ctr_name
]
retval
=
subprocess
.
call
(
command
)
command
=
[
'
sudo
'
,
'
rm
'
,
'
/var/run/netns/
'
+
ctr_name
]
retval
=
subprocess
.
call
(
command
)
else
:
command
=
[
'
sudo
'
,
'
ip
'
,
'
netns
'
,
'
delete
'
,
ctr_name
]
retval
=
subprocess
.
call
(
command
)
for
i
in
range
(
ntwk
[
'
num_nodes
'
]):
stop_node
(
ntwk
[
'
name
'
],
i
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment