2 # Copyright (c) 2019 Erik Schilling
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
22 from jinja2
import Environment
, FileSystemLoader
24 from emuvim
.api
.osm
.pre_configured_osm
import PreConfiguredOSM
25 from emuvim
.api
.util
.docker_utils
import build_dockerfile_dir
28 # sys.path.append('/vim-emu/pycharm-debug.egg')
30 # pydevd.settrace('10.0.2.2', port=21001, stdoutToServer=True, stderrToServer=True, suspend=False)
32 prefix
= os
.path
.dirname(os
.path
.abspath(__file__
))
34 build_dockerfile_dir('../images/trafficdebug/', 'trafficdebug')
37 loader
=FileSystemLoader(os
.path
.join(prefix
, '../templates/'))
39 template
= env
.get_template('vnffg-nsd.yaml')
44 def run_iperf(node
, target_ip
, target_port
):
45 vnffg_iperf_out
= node
.cmd('iperf3 -J -t %d -c %s -p %d' % (IPERF_TIME
, target_ip
, target_port
))
46 print(vnffg_iperf_out
)
47 vnffg_iperf
= json
.loads(vnffg_iperf_out
)
48 vnffg_rtt
= vnffg_iperf
['end']['streams'][0]['sender']['mean_rtt']
49 vnffg_bits_per_second
= vnffg_iperf
['end']['sum_received']['bits_per_second']
50 return vnffg_rtt
, vnffg_bits_per_second
54 with
open('vnffg-%d.csv' % time
.time(), 'w') as csvfile
:
55 fieldnames
= ['n', 'deploy', 'vnffg_iperf_rtt', 'vnffg_iperf_bps',
56 'normal_iperf_rtt', 'normal_iperf_bps', 'delete']
57 writer
= csv
.DictWriter(csvfile
, fieldnames
=fieldnames
)
61 # vim-emu increases the subnet ip part by 1 for each run
64 for n
in range(1, 15 + 1):
65 # render NSD template for current iteration
66 with
open(os
.path
.join(prefix
, '../autogenerated/vnffg-nsd/vnffg-nsd.yml'), 'w') as f
:
67 f
.write(template
.render(n
=n
, subnet
=subnet
))
69 with
PreConfiguredOSM(osm_version
='master') as osm
:
70 osm
.onboard_vnfd('../vnfs/vnffg')
71 nsd_id
= osm
.onboard_nsd('../autogenerated/vnffg-nsd')
72 ns_create
= time
.time()
73 osm
.ns_create('vnffg-%d' % n
, nsd_id
)
75 osm
.ns_wait_until_all_in_status('running')
77 ns_deploy_done
= time
.time()
79 # ensure that port chains are created, they are not reported by the API.
82 first_name
= 'dc1_vnffg-%d-1--1' % n
83 last_name
= 'dc1_vnffg-%d-%d--1' % (n
, n
+ 1)
84 first_node
= osm
.api
.compute
.find_server_by_name_or_id(first_name
).emulator_compute
85 last_node
= osm
.api
.compute
.find_server_by_name_or_id(last_name
).emulator_compute
87 last_node
.cmd('iperf3 -s -p 80 > /dev/null &')
88 last_node
.cmd('iperf3 -s -p 81 > /dev/null &')
90 # give iperf3 servers time to start up
93 target_ip
= '10.0.%d.%d' % (subnet
, n
+ 2)
94 vnffg_rtt
, vnffg_bits_per_second
= run_iperf(first_node
, target_ip
, 80)
95 normal_rtt
, normal_bits_per_second
= run_iperf(first_node
, target_ip
, 81)
97 ns_delete
= time
.time()
98 for ns
in osm
.ns_list():
99 osm
.ns_delete(ns
['id'])
101 osm
.ns_wait_until_all_in_status('terminated')
103 ns_delete_done
= time
.time()
106 'deploy': ns_deploy_done
- ns_create
,
107 'vnffg_iperf_rtt': vnffg_rtt
,
108 'vnffg_iperf_bps': vnffg_bits_per_second
,
109 'normal_iperf_rtt': normal_rtt
,
110 'normal_iperf_bps': normal_bits_per_second
,
111 'delete': ns_delete_done
- ns_delete
113 writer
.writerow(measurement
)
119 if __name__
== '__main__':