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 #ifndef NETWORKPROTECTOR_H
22 #define NETWORKPROTECTOR_H
24 #include "sliding_window.hpp"
26 #include <sgnb_addition_request.hpp> // to decode the X2AP payload
27 #include <sgnb_addition_response.hpp> // to respond
30 #define likely(x) __builtin_expect((x), 1)
31 #define unlikely(x) __builtin_expect((x), 0)
34 #define unlikely(x) (x)
37 extern bool report_mode_only;
43 protector( bool , int , int , double , bool rep=true);
45 bool operator()(unsigned char *, size_t , unsigned char *, size_t *);
47 bool configure(bool enforce, int windowSize_, int threshold_, double blockRate_);
49 bool selectiveBlock();
51 unsigned long int get_requests(void) const;
52 unsigned long int get_rejects(void) const;
53 std::string get_error(void) { return error_string;};
56 bool m_enforce; // whether to execute logic or not
57 int m_counter; // count the # of attaching access
58 int m_windowSize; // time in seconds window for the # of counts
59 int m_threshold; // count above which we start enforcing if enforce set
60 double m_blockRate; // % of rejecting rate for counter > threshold
61 time_t m_timeWindow; // time active window started
62 unsigned long int m_req; // number of requests
63 unsigned long int m_rej; // number of rejects
65 std::unique_ptr<sliding_window> m_window_ref;
66 std::unique_ptr<std::mutex> m_access;
67 sgnb_addition_helper sgnb_data;
68 sgnb_addition_request sgnb_req;
69 sgnb_addition_response sgnb_resp;
71 std::string error_string;
72 bool report_mode_only;