Fixes and enhancements:
[ric-plt/xapp-frame-py.git] / examples / ping_xapp.py
1 """
2 Test xapp 1
3 """
4 # ==================================================================================
5 #       Copyright (c) 2020 Nokia
6 #       Copyright (c) 2020 AT&T Intellectual Property.
7 #
8 #   Licensed under the Apache License, Version 2.0 (the "License");
9 #   you may not use this file except in compliance with the License.
10 #   You may obtain a copy of the License at
11 #
12 #          http://www.apache.org/licenses/LICENSE-2.0
13 #
14 #   Unless required by applicable law or agreed to in writing, software
15 #   distributed under the License is distributed on an "AS IS" BASIS,
16 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 #   See the License for the specific language governing permissions and
18 #   limitations under the License.
19 # ==================================================================================
20
21
22 import time
23 import json
24 from threading import Thread
25 from rmr import rmr
26 from ricxappframe.xapp_frame import Xapp
27
28 # Now we use the framework to echo back the acks
29 class MyXapp(Xapp):
30     def entrypoint(self):
31         my_ns = "myxapp"
32         number = 0
33         while True:
34             # test healthcheck
35             print("Healthy? {}".format(xapp.healthcheck()))
36
37             # rmr send
38             val = json.dumps({"test_send": number}).encode()
39             self.rmr_send(val, 60000)
40             number += 1
41
42             # store it in SDL and read it back; delete and read
43             self.sdl_set(my_ns, "numba", number)
44             print((self.sdl_get(my_ns, "numba"), self.sdl_find_and_get(my_ns, "num")))
45             self.sdl_delete(my_ns, "numba")
46             print(self.sdl_get(my_ns, "numba"))
47
48             # rmr receive
49             for (summary, sbuf) in self.rmr_get_messages():
50                 print(summary)
51                 self.rmr_free(sbuf)
52
53             time.sleep(1)
54
55
56 xapp = MyXapp(4564, use_fake_sdl=True)
57 xapp.run()