Tommy Carpenter | 5ad8f03 | 2019-05-30 14:33:21 -0400 | [diff] [blame] | 1 | # ================================================================================== |
| 2 | # Copyright (c) 2019 Nokia |
| 3 | # Copyright (c) 2018-2019 AT&T Intellectual Property. |
| 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 | # ================================================================================== |
| 17 | import time |
| 18 | import random |
| 19 | import string |
| 20 | import os |
| 21 | import signal |
| 22 | import sys |
| 23 | from rmr import rmr |
| 24 | |
| 25 | |
| 26 | DELAY_MS = int(os.environ.get("BOMBARD_DELAY_MS", 100)) |
| 27 | |
| 28 | # Init rmr |
| 29 | mrc = rmr.rmr_init(b"4565", rmr.RMR_MAX_RCV_BYTES, 0x00) |
| 30 | while rmr.rmr_ready(mrc) == 0: |
| 31 | time.sleep(1) |
| 32 | print("not yet ready") |
| 33 | rmr.rmr_set_stimeout(mrc, 2) |
| 34 | sbuf = rmr.rmr_alloc_msg(mrc, 256) |
| 35 | |
| 36 | |
| 37 | while True: |
| 38 | # generate a random value between 1 and 256 bytes, then gen some random bytes with several nulls thrown in |
| 39 | val = "BOMBS AWAY".encode("utf8") |
| 40 | rmr.set_payload_and_length(val, sbuf) |
| 41 | rmr.generate_and_set_transaction_id(sbuf) |
| 42 | sbuf.contents.state = 0 |
| 43 | sbuf.contents.mtype = random.choice([20001, 10001]) |
| 44 | print("Pre send summary: {}".format(rmr.message_summary(sbuf))) |
| 45 | sbuf = rmr.rmr_send_msg(mrc, sbuf) |
| 46 | print("Post send summary: {}".format(rmr.message_summary(sbuf))) |
| 47 | time.sleep(0.001 * DELAY_MS) |