2 ==================================================================================
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
21 /* The control wrapper class around the plugin
22 The wrapper class is responsible for control operations of the plugin :
27 the plugin handles X2AP messages
30 #ifndef ADMISSION_CTRL
31 #define ADMISSION_CTRL
33 #include <rapidjson/document.h>
34 #include <rapidjson/writer.h>
35 #include <rapidjson/stringbuffer.h>
36 #include <rapidjson/schema.h>
41 #include <plugin-interface.hpp>
42 #include <mdclog/mdclog.h>
43 #include <NetworkProtector.h>
47 #define MAX_INSTANCES 10
49 class admission: virtual public Policy
52 admission(std::string, std::string, std::string, unsigned int, std::string, bool report_only=true);
54 protector * get_protector_instance(unsigned int);
55 bool setPolicy(const char *, int , std::string & );
56 bool getPolicy(const char * , int, std::string & );
57 std::string getName(void);
58 int getMetrics(std::vector<std::string> & ) ;
59 std::string get_error(void) const {return error_string;};
60 unsigned int get_num_policies(void) {return policy_table.size();};
62 void storePolicy(void);
64 void setPolicyVars(void);
65 void instantiate_protector_plugin(bool);
66 bool load_file(std::string, std::string &) ;
67 bool load_schema(const std::string & , const std::string & , std::unique_ptr<rapidjson::SchemaDocument> & , std::unique_ptr<rapidjson::SchemaValidator> &);
68 void process_counters(int , std::string & );
70 std::vector<protector> _plugin_instances;
71 std::map<std::string, int> policy_table;
72 std::map<std::string, rapidjson::Pointer> window_policy_vars;
73 std::map<std::string, rapidjson::Pointer> generic_policy_vars;
74 std::map<std::string, rapidjson::Pointer> metric_vars;
77 std::unique_ptr<rapidjson::SchemaDocument> downstream_schema_ref_, notify_schema_ref_, metrics_schema_ref_;
78 std::unique_ptr<rapidjson::SchemaValidator> downstream_validator_, notify_validator_, metrics_validator_;
79 rapidjson::Document notify_message_, metrics_message_;
83 // stores past count of requests, reject and time stamp
84 std::map<int, std::vector<long int>> counters;
85 std::string error_string;
86 unsigned long int prev_time_stamp;