Added performance test for the startup of the OSM components
[osm/vim-emu.git] / examples / performance_measurements / osm_component_startup.py
1 #!/usr/bin/env python2
2 # Copyright (c) 2019 Erik Schilling
3 # ALL RIGHTS RESERVED.
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 import csv
17
18 import time
19
20 from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
21 from emuvim.api.osm.kafka import Kafka
22 from emuvim.api.osm.lcm import LCM
23 from emuvim.api.osm.mongo import Mongo
24 from emuvim.api.osm.mysql import Mysql
25 from emuvim.api.osm.nbi import NBI
26 from emuvim.api.osm.ro import RO
27 from emuvim.api.osm.zookeeper import Zookeeper
28 from emuvim.dcemulator.net import DCNetwork
29
30
31 from mininet.log import setLogLevel
32 setLogLevel('debug')
33
34 COUNT = 15
35
36 with open('osm_component_startup_%d.csv' % time.time(), 'w') as csvfile:
37 fieldnames = ['other', 'zookeeper', 'kafka', 'mongo', 'nbi', 'ro_db', 'ro', 'lcm']
38 writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
39 writer.writeheader()
40
41 for i in range(COUNT):
42 start = time.time()
43 net = DCNetwork(monitor=False, enable_learning=True)
44 api = None
45 try:
46 dc1 = net.addDatacenter("dc1")
47 api = OpenstackApiEndpoint("0.0.0.0", 6001)
48 api.connect_datacenter(dc1)
49 api.connect_dc_network(net)
50
51 s1 = net.addSwitch('s1')
52
53 zookeeper_ip = '10.0.0.96'
54 kafka_ip = '10.0.0.97'
55 mongo_ip = '10.0.0.98'
56 nbi_ip = '10.0.0.99'
57 ro_db_ip = '10.0.0.100'
58 ro_ip = '10.0.0.101'
59 lcm_ip = '10.0.0.102'
60
61 d1 = net.addDocker('d1', dimage='ubuntu:trusty')
62
63 VERSION = 'releasefive-daily'
64
65 zookeeper = Zookeeper(net, zookeeper_ip)
66 kafka = Kafka(net, kafka_ip, zookeeper_ip)
67 mongo = Mongo(net, mongo_ip)
68 nbi = NBI(net, nbi_ip, mongo_ip, kafka_ip)
69 ro_db = Mysql(net, ro_db_ip)
70 ro = RO(net, ro_ip, ro_db_ip, version=VERSION)
71 lcm = LCM(net, lcm_ip, ro_ip, mongo_ip, kafka_ip)
72
73 net.addLink(d1, s1)
74 net.addLink(zookeeper.instance, s1)
75 net.addLink(kafka.instance, s1)
76 net.addLink(mongo.instance, s1)
77 net.addLink(nbi.instance, s1)
78 net.addLink(ro_db.instance, s1)
79 net.addLink(ro.instance, s1)
80 net.addLink(lcm.instance, s1)
81
82 net.start()
83 api.start()
84
85 other_end = time.time()
86 zookeeper.start()
87 zookeeper_started = time.time()
88 kafka.start()
89 kafka_started = time.time()
90 mongo.start()
91 mongo_started = time.time()
92 nbi.start()
93 nbi_started = time.time()
94 ro_db.start()
95 ro_db_started = time.time()
96 ro.start()
97 ro_started = time.time()
98 lcm.start()
99 lcm_started = time.time()
100
101 writer.writerow({
102 'other': other_end - start,
103 'zookeeper': zookeeper_started - other_end,
104 'kafka': kafka_started - zookeeper_started,
105 'mongo': mongo_started - kafka_started,
106 'nbi': nbi_started - mongo_started,
107 'ro_db': ro_db_started - nbi_started,
108 'ro': ro_started - ro_db_started,
109 'lcm': lcm_started - ro_started,
110 })
111 csvfile.flush()
112 finally:
113 net.stop()
114 api.stop()