X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fprotector-plugin%2FNetworkProtector.h;fp=src%2Fprotector-plugin%2FNetworkProtector.h;h=8a69f15995a0e1bee79d7abd5269ed4986e79a58;hb=b9d7e9c232a4371ddfed51c58e5a57f87b057229;hp=0000000000000000000000000000000000000000;hpb=59f84608ec15c016958a6e0e0ddd813f376c0925;p=ric-app%2Fadmin.git diff --git a/src/protector-plugin/NetworkProtector.h b/src/protector-plugin/NetworkProtector.h new file mode 100644 index 0000000..8a69f15 --- /dev/null +++ b/src/protector-plugin/NetworkProtector.h @@ -0,0 +1,72 @@ +/* +================================================================================== + + Copyright (c) 2018-2019 AT&T Intellectual Property. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +================================================================================== +*/ + + +#ifndef NETWORKPROTECTOR_H +#define NETWORKPROTECTOR_H + +#include "sliding_window.hpp" +#include +#include // to decode the X2AP payload +#include // to respond + +#ifdef __GNUC__ +#define likely(x) __builtin_expect((x), 1) +#define unlikely(x) __builtin_expect((x), 0) +#else +#define likely(x) (x) +#define unlikely(x) (x) +#endif + +class protector +{ +public: + + protector( bool enforce, int windowSize_, int threshold_, double blockRate_); + + bool operator()(unsigned char *, size_t , unsigned char *, size_t *); + + bool configure(bool enforce, int windowSize_, int threshold_, double blockRate_); + void clear(); + bool selectiveBlock(); + + unsigned long int get_requests(void) const; + unsigned long int get_rejects(void) const; + std::string get_error(void) { return error_string;}; + +private: + bool m_enforce; // whether to execute logic or not + int m_counter; // count the # of attaching access + int m_windowSize; // time in seconds window for the # of counts + int m_threshold; // count above which we start enforcing if enforce set + double m_blockRate; // % of rejecting rate for counter > threshold + time_t m_timeWindow; // time active window started + unsigned long int m_req; // number of requests + unsigned long int m_rej; // number of rejects + + std::unique_ptr m_window_ref; + std::unique_ptr m_access; + sgnb_addition_helper sgnb_data; + sgnb_addition_request sgnb_req; + sgnb_addition_response sgnb_resp; + + std::string error_string; +}; + +#endif