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)
41 protector( bool enforce, int windowSize_, int threshold_, double blockRate_);
43 bool operator()(unsigned char *, size_t , unsigned char *, size_t *);
45 bool configure(bool enforce, int windowSize_, int threshold_, double blockRate_);
47 bool selectiveBlock();
49 unsigned long int get_requests(void) const;
50 unsigned long int get_rejects(void) const;
51 std::string get_error(void) { return error_string;};
54 bool m_enforce; // whether to execute logic or not
55 int m_counter; // count the # of attaching access
56 int m_windowSize; // time in seconds window for the # of counts
57 int m_threshold; // count above which we start enforcing if enforce set
58 double m_blockRate; // % of rejecting rate for counter > threshold
59 time_t m_timeWindow; // time active window started
60 unsigned long int m_req; // number of requests
61 unsigned long int m_rej; // number of rejects
63 std::unique_ptr<sliding_window> m_window_ref;
64 std::unique_ptr<std::mutex> m_access;
65 sgnb_addition_helper sgnb_data;
66 sgnb_addition_request sgnb_req;
67 sgnb_addition_response sgnb_resp;
69 std::string error_string;