summaryrefslogtreecommitdiff
path: root/src/lbdata.hh
blob: 3f90b1eadadf8a62f45ce08c618543e0f6fe6db4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Module: lbdata.hh
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation.
 */
#ifndef __LBDATA_HH__
#define __LBDATA_HH__

#include <map>
#include <set>
#include <vector>
#include <string>

using namespace std;

class LBRule {
 public:
  typedef map<string, int> InterfaceDistColl;
  typedef map<string, int>::iterator InterfaceDistIter;

  typedef enum {ALL,ICMP,UDP,TCP} Protocol;

  LBRule() :
    _proto("all"),
    _exclude(false),
    _failover(false),
    _enable_source_based_routing(false)      {}

 public:
  string _proto;
  string _s_addr;
  string _s_port;
  string _s_port_ipt;

  string _d_addr;
  string _d_port;
  string _d_port_ipt;

  bool _exclude;
  bool _failover;

  bool _enable_source_based_routing;

  string _in_iface;
  InterfaceDistColl _iface_dist_coll;
};


class LBHealthHistory {
public:
  LBHealthHistory(int buffer_size);

  //push in the ping response for this...
  int push(int rtt);


public:
  //results of health testing
  unsigned long _last_success;
  unsigned long _last_failure;

  unsigned long _failure_count;

  static int _buffer_size;
  vector<int> _resp_data;
  int _index;
};

class LBHealth {
 public:
  LBHealth(int interface_index) :
    _success_ct(0),
    _failure_ct(0),
    _ping_resp_time(0),
    _hresults(10),
    _is_active(true),
    _state_changed(true),
    _last_time_state_changed(0),
    _interface_index(interface_index)
      {}

  void put(int rtt);

  bool 
  state_changed() const {return _state_changed;}

  unsigned long
  last_success() const {return _hresults._last_success;}

  unsigned long
  last_failure() const {return _hresults._last_failure;}

  unsigned long
  failure_count() const {return _failure_ct;}

  int _success_ct;
  int _failure_ct;
  string _ping_target;
  int _ping_resp_time;
  string _nexthop;
  LBHealthHistory _hresults;
  bool _is_active;
  bool _state_changed;
  unsigned long _last_time_state_changed;
  int _interface_index;
  string _address;
};


class LBData {
 public:
  typedef map<int,LBRule> LBRuleColl;
  typedef map<int,LBRule>::iterator LBRuleIter;
  typedef map<int,LBRule>::const_iterator LBRuleConstIter;
  typedef map<string,LBHealth> InterfaceHealthColl;
  typedef map<string,LBHealth>::iterator InterfaceHealthIter;
  typedef map<string,LBHealth>::const_iterator InterfaceHealthConstIter;

  LBData() : _disable_source_nat(false),_flush_conntrack(false) {}

  bool
  error() {return false;}

  bool
  is_active(const string &iface);

  bool
  state_changed();

  void
  reset_state_changed();

  void
  dump();

 public:
  string _filename;

  LBRuleColl _lb_rule_coll;
  InterfaceHealthColl _iface_health_coll;

  bool _disable_source_nat;
  bool _flush_conntrack;
};

#endif //__LBDATA_HH__