User story RICPLT-2620
[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 //================================================
50
51 // convenient typedef for the list of plugins to be loaded
52 // currently only the admission control plugin. any plugin
53 // should be inheriting from the Policy abstract class
54 typedef  std::vector<std::unique_ptr<Policy> > plugin_list;
55
56
57 // configuration parameters 
58 struct configuration {
59   
60   char name[128] = "xapp_adm_ctrl";
61   char port[16] = "tcp:4560";
62   
63   int num_threads = 1;
64   std::unique_ptr<XaPP> my_xapp;
65   std::string a1_schema_file ;
66   std::string sample_file ;
67   std::string ves_schema_file ;
68   std::string ves_collector_url;
69   unsigned int measurement_interval = 0;
70   int log_level = MDCLOG_WARN;
71   int test_mode = 0;
72   ProcessingLevelTypes processing_level = ProcessingLevelTypes::ALL;
73   bool report_mode_only = true;
74   std::string operating_mode = "REPORT";
75   int max_sub_loops = 2;
76   std::string xapp_id;
77   void fill_gnodeb_list(char * gNodeB_string){
78     gNodeB_list.clear();
79     char * gnb = strtok(gNodeB_string, ",");
80     while(gnb != NULL){
81       gNodeB_list.push_back(gnb);
82       gnb = strtok(NULL, ",");
83     }
84     
85   };
86   
87   std::vector<string> gNodeB_list;
88
89 };
90
91 // class that handles startup and shutdown operations
92 class  init {
93 public:
94   init(XaPP & , subscription_handler & , configuration &);
95   void startup(void);
96   void shutdown(void);
97   
98 private:
99   void startup_subscribe_requests(void );
100   void shutdown_subscribe_deletes(void);
101   void startup_get_policies(void );
102   
103   subscription_handler * sub_handler_ref;
104   XaPP * xapp_ref;
105   configuration * config_ref;
106 };
107
108 void usage(char *command);
109 void get_environment_config(configuration & config_instance);
110 void get_command_line_config(int argc, char **argv, configuration &config_instance);
111
112 extern int run_program;
113 extern bool report_mode_only;
114
115 #endif