Merge "Test env updates"
[nonrtric.git] / test / usecases / linkfailure / simulators / message_generator.py
1
2 #  ============LICENSE_START===============================================
3 #  Copyright (C) 2021 Nordix Foundation. 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 #  ============LICENSE_END=================================================
17 #
18
19 import requests
20 import time
21 import random
22 import json
23
24 # Randomly, between 0 and 10 seconds sends a "CUS Link Failure" alarm event to the Message Router. The ID of the O-RU is also
25 # randomly generated between 0 and 9.
26 # When the modulo of the ID is 1, a "heartbeat" message will also be sent to MR.
27
28 linkFailureMessage = {
29     "event": {
30         "commonEventHeader": {
31             "domain": "fault",
32             "eventId": "nt:network-topology/nt:topology/nt:node/nt:node-id",
33             "eventName": "fault_O-RAN-RU-Fault_Alarms_CUS_Link_Failure",
34             "eventType": "O-RAN-RU-Fault_Alarms",
35             "sequence": 0,
36             "priority": "High",
37             "reportingEntityId": "uro1",
38             "reportingEntityName": "@controllerName@",
39             "sourceId": "",
40             "sourceName": "nt:network-topology/nt:topology/nt:node/nt:node-id",
41             "startEpochMicrosec": "@timestamp@",
42             "lastEpochMicrosec": "@timestamp@",
43             "nfNamingCode": "",
44             "nfVendorName": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-name",
45             "timeZoneOffset": "+00:00",
46             "version": "4.1",
47             "vesEventListenerVersion": "7.2.1"
48         },
49         "faultFields": {
50             "faultFieldsVersion": "4.0",
51             "alarmCondition": "o-ran-fm:alarm-notif/fault-id",
52             "alarmInterfaceA": "o-ran-fm:alarm-notif/fault-source",
53             "eventSourceType": "ietf-hardware (RFC8348) /hardware/component[not(parent)][1]/mfg-model or \"O-RU\"",
54             "specificProblem": "CUS Link Failure",
55             "eventSeverity": "CRITICAL",
56             "vfStatus": "Active",
57             "alarmAdditionalInformation": {
58                 "eventTime": "@eventTime@",
59                 "equipType": "@type@",
60                 "vendor": "@vendor@",
61                 "model": "@model@"
62             }
63         }
64     }
65 }
66
67 heartBeatMessage = {
68    "event": {
69      "commonEventHeader": {
70        "version": 3.0,
71        "domain": "heartbeat",
72        "eventName": "Heartbeat\_vIsbcMmc",
73        "eventId": "ab305d54-85b4-a31b-7db2fb6b9e546015",
74        "sequence": 0,
75        "priority": "Normal",
76        "reportingEntityId": "cc305d54-75b4-431badb2eb6b9e541234",
77        "reportingEntityName": "EricssonOamVf",
78        "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014",
79        "sourceName": "ibcx0001vm002ssc001",
80        "nfNamingCode": "ibcx",
81        "nfcNamingCode": "ssc",
82        "startEpochMicrosec": 1413378172000000,
83        "lastEpochMicrosec": 1413378172000000
84       }
85    }
86  }
87
88 while True:
89     random_time = int(10 * random.random())
90     if (random_time % 3 == 1):
91         print("Sent heart beat")
92         requests.post("http://localhost:3904/events/ALARMS-WRITE", json=heartBeatMessage);
93
94     o_ru_id = "O-RAN-RU-0" + str(random_time)
95     print("Sent link failure for O-RAN-RU: " + o_ru_id)
96     msg_as_json = json.loads(json.dumps(linkFailureMessage))
97     msg_as_json["event"]["commonEventHeader"]["reportingEntityId"] = o_ru_id
98     requests.post("http://localhost:3904/events/ALARMS-WRITE", json=msg_as_json);
99
100     time.sleep(random_time)
101