afb584381cb82bb4a29a6cd80f13509bd0fa0680
[ric-app/admin.git] / src / protector-plugin / admission_policy.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 /* The control  wrapper class around the plugin
22    The wrapper class is responsible for control operations of the plugin :
23    set policy
24    get policy
25    report metrics
26
27    the plugin handles X2AP messages 
28 */
29 #pragma once
30 #ifndef ADMISSION_CTRL
31 #define ADMISSION_CTRL
32 #include <map>
33 #include <plugin-interface.hpp>
34 #include <mdclog/mdclog.h>
35 #include <NetworkProtector.h>
36 #include <chrono>
37 #include <sstream>
38
39 class admission: virtual public Policy
40 {
41 public:
42   admission(std::string, std::string, std::string, unsigned int, bool report_only=true);
43   ~admission(void);
44   protector * get_protector_instance(unsigned int);
45   bool setPolicy(const char *, int , std::string & );
46   bool getPolicy(const char * , int, std::string & );
47   std::string getName(void);
48   int getMetrics(std::string & ) ;
49   
50 private:
51   void storePolicy(void);
52   void init_log(void);
53   void setPolicyVars(void);
54   void instantiate_protector_plugin(bool);
55
56   std::map<std::string, int> current_config;
57   std::map<std::string, int> prev_config;
58   std::vector<protector> _plugin_instances;
59
60   std::vector<TrieNode> policy_vars;
61   std::vector<TrieNode> set_policy_response;
62   std::vector<TrieNode> get_policy_response;
63   std::vector<TrieNode> metric_responses;
64   std::vector<TrieNode *> policy_pointer;
65  
66   jsonHandler set_policy_req_obj;
67   jsonHandler set_policy_resp_obj;
68   
69   jsonHandler get_policy_req_obj;
70   jsonHandler get_policy_resp_obj;
71   
72   jsonHandler metrics_obj;
73
74   std::vector<int> prev_values;
75   std::vector<int> curr_values;
76
77   unsigned long int prev_time_stamp;
78 };
79
80 #endif