Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Alejandro Blanco
openLEON
Commits
c55677dd
Commit
c55677dd
authored
Jun 18, 2019
by
Alejandro Blanco
Browse files
Uploading Containernet scripts
parent
53fa4601
Changes
7
Hide whitespace changes
Inline
Side-by-side
Containernet/analysis-cpu-mem.py
0 → 100644
View file @
c55677dd
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 19 10:34:31 2018
@author: imdea
"""
import
csv
from
collections
import
defaultdict
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
datetime
import
datetime
,
timedelta
import
dateutil.parser
import
matplotlib.dates
as
mdates
cpu_vector
=
[]
memory_vector
=
[]
time_vector
=
[]
columns
=
defaultdict
(
list
)
# each value in each column is appended to a list
with
open
(
'monitor-cpu-memory-load.csv'
)
as
f
:
# obtained through glances
reader
=
csv
.
DictReader
(
f
)
# read rows into a dictionary format
for
row
in
reader
:
# read a row as {column1: value1, column2: value2,...}
for
(
k
,
v
)
in
row
.
items
():
# go over each column name and value
columns
[
k
].
append
(
v
)
# append the value into the appropriate list
# based on column name k
#print(columns['now'])
#print(columns['cpu.user'])
#print(columns['mem.used'])
#print(len(columns['now']),len(columns['mem.used']))
for
j
in
range
(
len
(
columns
[
'now'
])):
d
=
dateutil
.
parser
.
parse
(
columns
[
'now'
][
j
])
time_vector
.
append
(
d
.
strftime
(
'%H:%M:%S'
))
#print(d.strftime('%H:%M:%S')) #==> '09/26/2008'
for
k
in
range
(
len
(
columns
[
'mem.used'
])):
memory_vector
.
append
(
int
(
columns
[
'mem.used'
][
k
]))
print
(
time_vector
[
k
],
int
(
columns
[
'mem.used'
][
k
]))
# printing the file for the mem.used
for
i
in
range
(
len
(
columns
[
'cpu.user'
])):
memory_vector
.
append
(
float
(
columns
[
'cpu.user'
][
i
]))
#print(time_vector[i],float(columns['cpu.user'][i]))# printing the file for the cpu.user
for
l
in
range
(
len
(
columns
[
'cpu.system'
])):
memory_vector
.
append
(
float
(
columns
[
'cpu.system'
][
l
]))
#print(time_vector[l],float(columns['cpu.system'][l]))# printing the file for the cpu.system
Containernet/openleon-datacenter.py
0 → 100644
View file @
c55677dd
# This is a test example
import
unittest
import
sys
import
time
import
os
import
random
import
subprocess
sys
.
path
.
append
(
'.'
)
from
time
import
sleep
from
mininet.net
import
Containernet
from
mininet.node
import
Ryu
,
OVSSwitch
from
mininet.node
import
Host
from
mininet.clean
import
cleanup
from
mininet.link
import
TCLink
from
mininet.cli
import
CLI
from
openleon_datacenter_tier3
import
MyTopo
from
mininet.term
import
cleanUpScreens
,
makeTerms
class
testSwitchTopo
(
object
):
"Test ping with the specified topology"
topoClass
=
None
# Override with topology
ryuParams
=
[
'ryu.app.simple_switch_13'
]
mayDrop
=
0
top
=
MyTopo
(
2
,
2
,
4
,
2
)
# This is to enable the RYU controller, which enables loop-free routes that the standard SDN controller doesn't enable
def
controller
(
self
,
name
,
**
params
):
return
Ryu
(
name
,
*
self
.
ryuParams
,
**
params
)
@
staticmethod
def
tearDown
():
"Clean up the network"
if
sys
.
exc_info
!=
(
None
,
None
,
None
):
cleanup
()
def
testPing
(
self
):
"Create the network and run a ping test"
#
print
(
"*** Creating the datacenter topology"
)
net
=
Containernet
(
topo
=
self
.
topoClass
(
2
,
2
,
4
,
2
),
controller
=
self
.
controller
,
host
=
Host
,
#net = Containernet(topo=self.topoClass(2, 4, 8, 8), controller=self.controller, host=Host,
switch
=
OVSSwitch
,
link
=
TCLink
,
waitConnected
=
True
)
"""Test with the dockers"""
d1
=
net
.
addDocker
(
'd1'
,
ip
=
'10.0.0.112'
,
dimage
=
"ubuntu:trusty"
)
d2
=
net
.
addDocker
(
'd2'
,
ip
=
'10.0.0.113'
,
dimage
=
"ubuntu:trusty"
)
net
.
addLink
(
'd1'
,
's4'
)
net
.
addLink
(
'd2'
,
's4'
)
#net.link.bw=10000
net
.
addNAT
().
configDefault
()
net
.
hosts
[
0
].
cmd
(
'sysctl net.ipv4.ip_forward=1'
)
print
net
.
hosts
[
-
1
]
print
(
"*** End printing hosts"
)
for
i
in
range
(
len
(
net
.
hosts
)
-
1
):
print
(
net
.
hosts
[
i
+
1
])
net
.
hosts
[
1
+
i
].
cmd
(
'sudo ip route add 10.16.0.0/12 via 10.0.0.1'
)
#net.hosts[-1].cmd('sudo ip route add 10.16.0.0/12 via 10.0.0.1')
net
.
hosts
[
0
].
cmd
(
'iptables -t nat -A POSTROUTING -j MASQUERADE'
)
#net.hosts[-1].cmd('sudo ip route add 10.0.0.8 via 10.0.0.1')
net
.
start
()
client
=
[]
server
=
[]
for
i
in
range
((
len
(
net
.
hosts
)
-
1
)
/
2
):
client
.
append
(
net
.
hosts
[
2
*
(
i
)])
server
.
append
(
net
.
hosts
[
2
*
(
i
)
+
1
])
b
=
server
[:]
b_shuffle
=
[
x
for
x
in
range
(
0
,
len
(
server
))]
random
.
shuffle
(
b
)
#print b
#print b_shuffle
CLI
(
net
)
# This open the mininet terminal and it allows to launch Mininet's commands
"""for i in range (len(client)):
b[i].cmd('iperf -s -u &')
client[i].cmd('iperf -c ' + b[i].IP() + ' -t 10000 -i 1 -u -b 10M &')
net.hosts[0].cmd('wireshark')"""
"""sleep(10)
net.hosts[0].cmd('iperf -s &')
net.hosts[1].cmd('iperf -c 10.0.0.1 -t 10000 -i 1 -u -b 50M &')
net.hosts[2].cmd('iperf -s &')
net.hosts[3].cmd('iperf -c 10.0.0.1 -t 10000 -i 1 -u -b 50M &')"""
net
.
stop
()
#net.ping()
#net.myiperf(net.hosts,10)
class
TestDatacenter_tier3
(
testSwitchTopo
,
unittest
.
TestCase
):
"Test the HA Root datacenter topolog"
topoClass
=
MyTopo
ryuParams
=
[
'ryu.app.simple_switch_stp'
]
mayDrop
=
15
if
__name__
==
'__main__'
:
unittest
.
main
()
Containernet/openleon-distr-datacenters.py
0 → 100644
View file @
c55677dd
# openleon distributed edge data centers with containers
import
unittest
import
sys
import
time
import
os
import
random
import
subprocess
sys
.
path
.
append
(
'.'
)
from
time
import
sleep
from
mininet.net
import
Containernet
from
mininet.node
import
Ryu
,
OVSSwitch
from
mininet.node
import
Node
,
Host
from
mininet.node
import
Controller
from
mininet.node
import
Docker
from
mininet.clean
import
cleanup
from
mininet.link
import
TCLink
,
Link
from
mininet.cli
import
CLI
from
mininet.term
import
cleanUpScreens
,
makeTerms
from
mininet.log
import
setLogLevel
,
info
from
sys
import
exit
import
os.path
from
subprocess
import
Popen
,
STDOUT
,
PIPE
def
topology
():
"Create a network with some docker containers acting as hosts."
net
=
Containernet
(
controller
=
Controller
,
switch
=
OVSSwitch
,
link
=
TCLink
,
waitConnected
=
True
)
info
(
'*** Adding controller
\n
'
)
net
.
addController
(
'c0'
)
info
(
'*** Adding switches
\n
'
)
s1
=
net
.
addSwitch
(
's1'
)
s2
=
net
.
addSwitch
(
's2'
)
s3
=
net
.
addSwitch
(
's3'
)
info
(
'*** Adding docker containers and hosts
\n
'
)
###### FIRST edge data center
hepc
=
net
.
addHost
(
'hepc'
,
ip
=
'10.0.0.1/24'
,
mac
=
"00:00:00:00:00:01"
)
h1
=
net
.
addHost
(
'h1'
,
ip
=
'10.0.0.2/24'
,
mac
=
"00:00:00:00:00:02"
)
d1
=
net
.
addDocker
(
'd1'
,
ip
=
'10.0.0.3/24'
,
dimage
=
"furiousgeorge/cpuload"
,
cpu_period
=
50000
,
cpu_quota
=
25000
)
#d1.sendCmd("./CPULoadGenerator.py -c 0 -l 0.3 -d 30")
d2
=
net
.
addDocker
(
'd2'
,
ip
=
'10.0.0.4/24'
,
dimage
=
"furiousgeorge/cpuload"
,
cpu_period
=
50000
,
cpu_quota
=
25000
)
d3
=
net
.
addDocker
(
'd3'
,
ip
=
'10.0.0.5/24'
,
dimage
=
"ubuntu:trusty"
)
d4
=
net
.
addDocker
(
'd4'
,
ip
=
'10.0.0.6/24'
,
dimage
=
"ubuntu:trusty"
)
h2
=
net
.
addHost
(
'h2'
,
ip
=
'10.0.0.7/24'
,
mac
=
"00:00:00:00:00:03"
)
###### SECOND edge data center
h3
=
net
.
addHost
(
'h3'
,
ip
=
'10.0.0.101/24'
,
mac
=
"00:00:00:00:00:04"
)
d5
=
net
.
addDocker
(
'd5'
,
ip
=
'10.0.0.102/24'
,
dimage
=
"sofianinho/iperf3:3.6-ubuntu18.04"
)
# this sets up a iperf3 docker
d6
=
net
.
addDocker
(
'd6'
,
ip
=
'10.0.0.103/24'
,
dimage
=
"ubuntu:trusty"
)
d7
=
net
.
addDocker
(
'd7'
,
ip
=
'10.0.0.104/24'
,
dimage
=
"ubuntu:trusty"
)
h4
=
net
.
addHost
(
'h4'
,
ip
=
'10.0.0.105/24'
,
mac
=
"00:00:00:00:00:05"
)
info
(
'*** Creating links
\n
'
)
net
.
addLink
(
hepc
,
s1
,
bw
=
1000
)
# port 2 of s1, link at 1 Gbps
net
.
addLink
(
h1
,
s2
,
bw
=
1000
)
# port 3 of s1, link at 1 Gbps
net
.
addLink
(
h2
,
s2
,
bw
=
1000
)
# port 4 of s1, link at 1 Gbps
net
.
addLink
(
d1
,
s1
)
net
.
addLink
(
d2
,
s1
)
net
.
addLink
(
d3
,
s1
)
net
.
addLink
(
d4
,
s1
)
net
.
addLink
(
s1
,
s2
)
net
.
addLink
(
s1
,
s3
,
cls
=
TCLink
,
delay
=
'4ms'
)
net
.
addLink
(
s3
,
h3
,
bw
=
1000
)
# port 2 of s2
net
.
addLink
(
s3
,
h4
,
bw
=
1000
)
# port 3 of s2
net
.
addLink
(
s3
,
d5
)
net
.
addLink
(
s3
,
d6
)
net
.
addLink
(
s3
,
d7
)
# router configuration
# building the network
net
.
build
()
# to work, recall to include the NAT right after having created all the links and build the network
net
.
addNAT
().
configDefault
()
net
.
hosts
[
0
].
cmd
(
'sysctl net.ipv4.ip_forward=1'
)
net
.
hosts
[
0
].
cmd
(
'iptables -t nat -A POSTROUTING -j MASQUERADE'
)
for
i
in
range
(
len
(
net
.
hosts
)
-
1
):
#print(net.hosts[i+1])
net
.
hosts
[
1
+
i
].
cmd
(
"sudo ip route add 10.16.0.0/12 via 10.0.0.1"
)
info
(
'*** Starting network
\n
'
)
net
.
start
()
info
(
'*** Running CLI
\n
'
)
CLI
(
net
)
info
(
'*** Stopping network
\n
'
)
net
.
stop
()
if
__name__
==
'__main__'
:
setLogLevel
(
'info'
)
topology
()
Containernet/openleon_datacenter_tier3.py
0 → 100644
View file @
c55677dd
# This file creates a 3-tier data center topology
from
mininet.net
import
Containernet
from
mininet.topo
import
Topo
from
mininet.link
import
TCLink
from
mininet.node
import
CPULimitedHost
from
mininet.node
import
Controller
from
mininet.nodelib
import
NAT
from
mininet.log
import
info
,
setLogLevel
"""setLogLevel('info')"""
class
MyTopo
(
Topo
):
"Simple topology example."
def
__init__
(
self
,
core
=
3
,
aggregation
=
6
,
edge
=
9
,
h
=
2
,
**
opts
):
info
(
"*** Creating custom datacenter topology
\n
"
)
Core
=
[
core
]
Aggr
=
[
aggregation
]
Edge
=
[
edge
]
self
.
Host
=
[
edge
*
h
]
"Topo.__init__(self)"
super
(
MyTopo
,
self
).
__init__
(
**
opts
)
# Add hosts and switches
info
(
"*** Creating Core Switches
\n
"
)
for
i
in
range
(
core
):
Core
.
append
(
self
.
addSwitch
(
's%s'
%
i
))
print
(
Core
[
i
+
1
])
info
(
"*** Creating Aggregation Switches
\n
"
)
for
i
in
range
(
aggregation
):
Aggr
.
append
(
self
.
addSwitch
(
's%s'
%
(
i
+
core
)))
info
(
"*** Creating Edge Switches
\n
"
)
for
i
in
range
(
edge
):
Edge
.
append
(
self
.
addSwitch
(
's%s'
%
(
i
+
core
+
aggregation
)))
info
(
"*** Creating Hosts
\n
"
)
for
i
in
range
(
h
*
edge
):
self
.
Host
.
append
(
self
.
addHost
(
'h%s'
%
i
))
# Add links
"Links between Core and Aggregation Switches: All connected"
for
i
in
range
(
core
):
for
j
in
range
(
aggregation
):
self
.
addLink
(
Core
[
i
+
1
],
Aggr
[
j
+
1
],
bw
=
1000
)
"""LInks between Aggregation and Edge Switches: We make groups depending on
the number of core switches"""
n
=
0
m
=
0
for
k
in
range
(
core
):
for
i
in
range
(
n
,
aggregation
/
core
+
n
):
for
j
in
range
(
m
,
edge
/
core
+
m
):
self
.
addLink
(
Aggr
[
i
+
1
],
Edge
[
j
+
1
],
bw
=
1000
)
n
=
n
+
aggregation
/
core
m
=
m
+
edge
/
core
n
=
0
"""Links between Edge Switches and hosts: h hosts for each Swith"""
for
i
in
range
(
edge
):
for
j
in
range
(
n
,
h
+
n
):
self
.
addLink
(
Edge
[
i
+
1
],
self
.
Host
[
j
+
1
],
bw
=
1000
)
n
=
n
+
h
def
hosts
(
n
=
1
):
return
self
.
Host
[
n
]
topos
=
{
'mytopo'
:
MyTopo
}
print
(
"Finished"
)
Containernet/ping-from-host.sh
0 → 100644
View file @
c55677dd
#!/bin/bash
# script for repeated pings interleaved with <x> seconds
touch
../Documents/claudio-openleon-transports-experiments/ping-distr-datacenters/
$1
ping 10.16.0.2
-c
5 |
tail
-n
1
>
../Documents/claudio-openleon-transports-experiments/ping-distr-datacenters/
$1
for
((
i
=
1
;
i<
=
49
;
i++
))
do
ping 10.16.0.2
-c
5 |
tail
-n
1
>>
../Documents/claudio-openleon-transports-experiments/ping-distr-datacenters/
$1
sleep
4
done
Containernet/pyshark--throughput-analysis.py
0 → 100644
View file @
c55677dd
# The script analyzes directly a PCAP trace
# Remember to include the filter in display_filter
# CF - 2019
import
pyshark
from
datetime
import
datetime
import
time
import
math
import
numpy
as
np
from
matplotlib
import
pyplot
as
plt
###########################################
#
# DATA Traffic (code 1)
#
###########################################
cap
=
pyshark
.
FileCapture
(
'./compressed-trace.pcap'
,
display_filter
=
"ip.src==10.16.0.2 && tcp.srcport==60204 && ip.dst==10.0.0.11 && tcp.dstport==5001"
)
totPkt
=
0
totData
=
0
ref
=
float
(
cap
[
0
].
sniff_timestamp
)
#print (ref)
# dictionary to store in form of key-value the tuple (time/amount of data in the given time)
# and compute throughput
thr_dict
=
{}
for
pkt
in
cap
:
totData
=
totData
+
int
(
pkt
.
tcp
.
len
)
totPkt
=
totPkt
+
1
#print (pkt.sniff_timestamp," ", pkt.tcp.len)
# * * * * to check the time
#inDate=pkt.sniff_time
#d=datetime.strptime(str(inDate), "%Y-%m-%d %H:%M:%S.%f")
#print (time.mktime(d.timetuple()), " ", pkt.tcp.len)
# doing the timediff from the first element to check time progress
timediff
=
float
(
pkt
.
sniff_timestamp
)
-
ref
i
,
d
=
divmod
(
timediff
,
1
)
#print (i,pkt.tcp.len)
# insertion in the dictionary: if the value does not exitst,
# then we create the new tuple, otherwise we just sum the data field
if
i
not
in
thr_dict
:
thr_dict
[
i
]
=
int
(
pkt
.
tcp
.
len
)
else
:
thr_dict
[
i
]
+=
int
(
pkt
.
tcp
.
len
)
# printing the dictionary
for
key
,
value
in
thr_dict
.
items
()
:
print
(
key
,
value
)
# plot
keys
=
np
.
fromiter
(
thr_dict
.
keys
(),
dtype
=
float
)
vals
=
np
.
fromiter
(
thr_dict
.
values
(),
dtype
=
float
)
data
=
(((
vals
*
8
)
/
1024
)
/
1024
)
timeinterval
=
keys
/
1
plt
.
plot
(
timeinterval
,
data
)
plt
.
xlabel
(
"Time (s)"
,
fontsize
=
20
)
plt
.
ylabel
(
"Throughput (Mbit/s)"
,
fontsize
=
20
)
plt
.
show
()
#print("Tot pkt - tot data",totPkt,totData)
Containernet/test.txt
deleted
100644 → 0
View file @
53fa4601
Hola
Write
Preview
Supports
Markdown
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