Open Kilda Java Documentation
stress_test.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # Copyright 2017 Telstra Open Source
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 
17 from kafka import KafkaProducer
18 from itertools import izip
19 
20 bootstrap_servers = 'kafka.pendev:9092'
21 topic = 'kilda.topo.eng'
22 MT_INFO = "org.openkilda.messaging.info.InfoMessage"
23 MT_SWITCH = "org.openkilda.messaging.info.event.SwitchInfoData"
24 
25 producer = KafkaProducer(bootstrap_servers=bootstrap_servers)
26 
27 
28 
30  i = iter(hex(n)[2:].zfill(16))
31  return ':'.join([''.join(a) for a in izip(i, i)])
32 
33 
34 x = xrange(10000)
35 
36 for n in x:
37  switch = generate_swith_name(n)
38 
39  producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952134, '
40  b'"destination":"TOPOLOGY_ENGINE", "payload": '
41  b'{"clazz": "%s", '
42  b'"switch_id": "%s",'
43  b' "state": "ADDED", '
44  b'"address":"%s", '
45  b'"hostname":"hostname", '
46  b'"description":"description", '
47  b'"controller":"controller"}}' % (MT_INFO, MT_SWITCH, switch, switch))
48 
49 
50 producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952134, "destination":"STOP"}' % (MT_INFO))
51 producer.flush()
def generate_swith_name(n)
Definition: stress_test.py:29