Updated documentation for mock a1 tool
[ric-app/admin.git] / src / adm-ctrl-xapp.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 /* Author : Ashwin Sridharan
20    Date    : Feb 2019
21 */
22
23 #pragma once
24 #ifndef ADM_CTRL_XAPP_
25 #define ADM_CTRL_XAPP_
26
27 #include <limits>
28 #include <map>
29 #include <getopt.h>
30 #include <csignal>
31 #include <cstdlib>
32 #include <time.h>
33 #include <errno.h>
34 #include <xapp_utils.hpp>
35 #include <rmr/RIC_message_types.h>
36 #include <curl_interface.hpp>
37 #include <e2sm.hpp>
38 #include "admission_policy.hpp"
39 #include "message_processor_class.hpp"
40
41 #define MAX_SLEEP 86400
42 #define DEFAULT_A1_SCHEMA_FILE "/etc/xapp/a1-schema.json"
43 #define DEFAULT_VES_SCHEMA_FILE "/etc/xapp/ves-schema.json"
44 #define DEFAULT_SAMPLE_FILE "/etc/xapp/samples.json"
45 #define DEFAULT_VES_COLLECTOR_URL "127.0.0.1:6350"
46 #define DEFAULT_XAPP_ID "ac-xapp-123"
47 #define DEFAULT_VES_MEASUREMENT_INTERVAL 10
48 #define MAX_SUBSCRIPTION_ATTEMPTS 10
49 #define RATE_CONTROL_POLICY_ID 21000
50 //================================================
51
52 // convenient typedef for the list of plugins to be loaded
53 // currently only the admission control plugin. any plugin
54 // should be inheriting from the Policy abstract class
55 typedef  std::vector<std::unique_ptr<Policy> > plugin_list;
56
57
58 // configuration parameters 
59 struct configuration {
60   
61   char name[128] = "xapp_adm_ctrl";
62   char port[16] = "tcp:4560";
63   
64   int num_threads = 1;
65   std::unique_ptr<XaPP> my_xapp;
66   std::string a1_schema_file ;
67   std::string sample_file ;
68   std::string ves_schema_file ;
69   std::string ves_collector_url;
70   unsigned int measurement_interval = 0;
71   int log_level = MDCLOG_WARN;
72   int test_mode = 0;
73   ProcessingLevelTypes processing_level = ProcessingLevelTypes::ALL;
74   bool report_mode_only = true;
75   std::string operating_mode = "REPORT";
76   int max_sub_loops = 2;
77   std::string xapp_id;
78   void fill_gnodeb_list(char * gNodeB_string){
79     gNodeB_list.clear();
80     char * gnb = strtok(gNodeB_string, ",");
81     while(gnb != NULL){
82       gNodeB_list.push_back(gnb);
83       gnb = strtok(NULL, ",");
84     }
85     
86   };
87   
88   std::vector<string> gNodeB_list;
89
90 };
91
92 // class that handles startup and shutdown operations
93 class  init {
94 public:
95   init(XaPP & , subscription_handler & , configuration &);
96   void startup(void);
97   void shutdown(void);
98   
99 private:
100   void startup_subscribe_requests(void );
101   void shutdown_subscribe_deletes(void);
102   void startup_get_policies(void );
103   
104   subscription_handler * sub_handler_ref;
105   XaPP * xapp_ref;
106   configuration * config_ref;
107 };
108
109 void usage(char *command);
110 void get_environment_config(configuration & config_instance);
111 void get_command_line_config(int argc, char **argv, configuration &config_instance);
112
113 extern int run_program;
114 extern bool report_mode_only;
115
116 #endif