Open Kilda Java Documentation
stress_test_2.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 
19 bootstrap_servers = 'kafka.pendev:9092'
20 topic = 'kilda.topo.eng'
21 
22 MT_SWITCH = "org.openkilda.messaging.info.event.SwitchInfoData"
23 MT_ISL = "org.openkilda.messaging.info.event.IslInfoData"
24 MT_INFO="org.openkilda.messaging.info.InfoMessage"
25 
26 
27 producer = KafkaProducer(bootstrap_servers=bootstrap_servers)
28 
29 
30 producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952134, "destination":"TOPOLOGY_ENGINE", "payload": {"clazz": "%s", "switch_id": "00:00:00:00:00:00:00:00", "state": "ADDED", "address":"00:00:00:00:00:00:00:00", "hostname":"hostname", "description":"description", "controller":"controller"}}' % (MT_INFO, MT_SWITCH))
31 producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952134, "destination":"TOPOLOGY_ENGINE", "payload": {"clazz": "%s", "switch_id": "00:00:00:00:00:00:00:01", "state": "ADDED", "address":"00:00:00:00:00:00:00:01", "hostname":"hostname", "description":"description", "controller":"controller"}}' % (MT_INFO, MT_SWITCH))
32 
33 producer.flush()
34 
35 i = 2
36 
37 while i < 10000:
38  producer.send(topic,
39  b'{"clazz": "%s", "timestamp": 23478952136, "destination":"TOPOLOGY_ENGINE", "payload": {"clazz": "%s", "state":"DISCOVERED", "latency_ns": 1123, "speed":1000000, "available_bandwidth":1000000, "path": [{"switch_id": "00:00:00:00:00:00:00:00", "port_no": 1, "seq_id": "0", "segment_latency": 1123}, {"switch_id": "00:00:00:00:00:00:00:01", "port_no": 1, "seq_id": "1"}]}}' % (MT_INFO, MT_ISL))
40  i += 1
41  producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952136, "destination":"TOPOLOGY_ENGINE", "payload": {"clazz": "%s", "state": "DISCOVERED", "latency_ns": 1123, "speed":1000000, "available_bandwidth":1000000, "path": [{"switch_id": "00:00:00:00:00:00:00:01", "port_no": 1, "seq_id": "0", "segment_latency": 1123}, {"switch_id": "00:00:00:00:00:00:00:00", "port_no": 1, "seq_id": "1"}]}}' % (MT_INFO, MT_ISL))
42  i += 1
43  producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952136, '
44  b'"destination":"TOPOLOGY_ENGINE", "payload": {"clazz": "%s", "state": "FAILED", "path": [{"switch_id": "00:00:00:00:00:00:00:00", "port_no": 1}]}}' % (MT_INFO, MT_ISL))
45  i += 1
46  producer.send(topic, b'{"clazz": "%s", "timestamp": 23478952136, '
47  b'"destination":"TOPOLOGY_ENGINE", "payload": {"clazz": "%s", "state": "FAILED", "path": [{"switch_id": "00:00:00:00:00:00:00:01", "port_no": 1}]}}' % (MT_INFO, MT_ISL))
48  i += 1
49  print i
50 
51 producer.flush()