Initial commit of Admission Control xAPP and E2AP/X2AP definitions
[ric-app/admin.git] / src / protector-plugin / sliding_window.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 #ifndef SLIDING_WINDOW_
21 #define SLIDING_WINDOW_
22
23 #include <iostream>
24 #include <vector>
25 #include <chrono>
26 #include <thread>
27 #include <sstream>
28
29 #define MIN_WINDOW_SIZE 1  // in seconds
30 #define MAX_WINDOW_SIZE 604800 // in seconds 1 week
31
32 class sliding_window {
33
34 public:
35   sliding_window(unsigned int);
36   bool update_window (unsigned int);
37   std::string display_window(void);
38   bool resize_window(unsigned int);
39   std::string get_error(void) { return error_string ;};
40   unsigned int net_events;
41   void clear(void);
42   
43 private:  
44   std::vector<unsigned int> sliding_window_;
45   unsigned int head, tail,  window_size_;
46   std::chrono::time_point<std::chrono::steady_clock>  leading_edge_;
47   std::string error_string;
48 };
49
50
51 #endif