1 # ==================================================================================
3 # Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # ==================================================================================
19 Handles subscription messages from enbs and gnbs through rmr.
23 from ricxappframe.xapp_frame import RMRXapp, rmr
24 from ..utils.constants import Constants
25 from ._BaseHandler import _BaseHandler
26 from ..manager.SdlManager import SdlManager
27 class SubscriptionHandler(_BaseHandler):
29 def __init__(self, rmr_xapp: RMRXapp, msgtype):
30 super().__init__(rmr_xapp, msgtype)
33 def request_handler(self, rmr_xapp, summary, sbuf):
35 Handles subscription messages.
39 rmr_xapp: rmr Instance Context
41 summary: dict (required)
47 self._rmr_xapp.rmr_free(sbuf)
49 req = json.loads(summary[rmr.RMR_MS_PAYLOAD]) # input should be a json encoded as bytes
50 self.logger.debug("SubscriptionHandler.resp_handler:: Handler processing request")
51 except (json.decoder.JSONDecodeError, KeyError):
52 self.logger.error("Subscription.resp_handler:: Handler failed to parse request")
55 if self.verifySubscription(req):
56 self.logger.info("SubscriptionHandler.resp_handler:: Handler processed request: {}".format(req))
58 self.logger.error("SubscriptionHandler.resp_handler:: Request verification failed: {}".format(req))
60 self.logger.debug("SubscriptionHandler.resp_handler:: Request verification success: {}".format(req))
63 def verifySubscription(self, req: dict):
64 for i in ["subscription_id", "message"]: