1. Transitioned to using latest asn1c compiler
[ric-app/admin.git] / src / message_processor_class.hpp
1 /*
2 ==================================================================================
3
4         Copyright (c) 2018-2019 AT&T Intellectual Property.
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19
20
21 #pragma once
22 #include <iostream>
23 #include <cstring>
24 #include <chrono>
25 #include <rmr/RIC_message_types.h>
26 #include <rmr/rmr.h>
27 #include <mdclog/mdclog.h>
28 #include <NetworkProtector.h>
29 #include <e2ap_indication.hpp>
30 #include <e2ap_control.hpp>
31 #include <e2ap_control_response.hpp>
32 #include <subscription_handler.hpp>
33 #include <e2sm.hpp>
34
35 #ifdef __GNUC__
36 #define likely(x)  __builtin_expect((x), 1)
37 #define unlikely(x) __builtin_expect((x), 0)
38 #else
39 #define likely(x) (x)
40 #define unlikely(x) (x)
41 #endif
42
43
44 #define MAX_RMR_RECV_SIZE 2<<15
45
46 typedef enum{
47              NO_ERROR=0,
48              RMR_ERROR,
49              E2AP_INDICATION_ERROR,
50              E2AP_CONTROL_ERROR,
51              E2SM_INDICATION_HEADER_ERROR,
52              E2SM_CONTROL_HEADER_ERROR,
53              E2SM_CONTROL_MESSAGE_ERROR,
54              MISSING_HANDLER_ERROR,
55              BUFFER_ERROR,
56              PLUGIN_ERROR
57 } MessageProcessorStateTypes;
58              
59
60 typedef enum {
61               E2AP_PROC_ONLY = 0,
62               E2SM_PROC_ONLY,
63               ALL
64 } ProcessingLevelTypes;
65
66
67 class message_processor {
68
69 public:
70   message_processor(int mode=ALL, bool rep=true, size_t buffer_length = 2048, size_t reporting_interval = 100);
71   ~message_processor(void);
72   
73   bool operator() (rmr_mbuf_t *);  
74   unsigned long const get_messages (void);
75   void register_subscription_handler(subscription_handler *);
76   void register_protector(protector * );
77   void register_policy_handler (void  (*)(int, const char *, int, std::string &, bool));
78   std::vector<double> & get_metrics(void);
79   int get_state (void) {return state;};
80 private:
81
82   E2N_E2AP_PDU_t * e2ap_recv_pdu;
83   E2N_E2SM_gNB_X2_indicationHeader_t *e2sm_header; // used for decoding
84   E2N_E2SM_gNB_X2_indicationMessage_t *e2sm_message; // used for decoding
85   
86   E2N_E2AP_PDU_t * e2ap_gen_pdu; // just a placeholder for now
87
88   ric_indication_helper indication_data;
89   ric_indication indication_processor;
90
91   ric_control_helper control_data;
92   ric_control_request control_request_processor;
93   ric_control_response control_response_processor;
94   
95   e2sm_header_helper header_helper;
96   e2sm_message_helper message_helper;
97   e2sm_indication e2sm_indication_processor;
98   e2sm_control e2sm_control_processor;
99   
100   subscription_handler * _ref_sub_handler;
101   protector  * _ref_protector;
102   void (* _ref_policy_handler) (int, const char *, int, std::string &, bool);
103   unsigned long _num_messages;
104
105   unsigned char *scratch_buffer;
106   size_t remaining_buffer;
107   size_t current_index;
108   unsigned long int num_indications, num_err_indications;
109   int state = NO_ERROR;
110   int processing_level; // for debugging purposes
111   bool report_mode_only; // suppress e2ap control
112   size_t _buffer_size; // for storing encoding
113
114   // these two parameters are used to report average processing latency.
115   // processing latency is accumalated over every num_proc_packets
116   // and both values are reported out on std log. After each report
117   // counters are reset
118
119   size_t _reporting_interval; // number of packets in a measurement interval
120   size_t num_proc_packets;
121   double processing_duration; // for storing time to process
122   double processing_dev; // for storing standard deviation
123   double max_proc_duration ;
124 };
125
126
127 extern int verbose_flag;