/
interface_uve_table.h
193 lines (178 loc) · 7.22 KB
/
interface_uve_table.h
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
*/
#ifndef vnsw_agent_interface_uve_table_h
#define vnsw_agent_interface_uve_table_h
#include <string>
#include <vector>
#include <set>
#include <map>
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
#include <sandesh/sandesh_types.h>
#include <sandesh/sandesh_constants.h>
#include <sandesh/sandesh.h>
#include <interface_types.h>
#include <uve/l4_port_bitmap.h>
#include <oper/vm.h>
#include <oper/peer.h>
#include <cmn/index_vector.h>
#include <oper/interface_common.h>
//The container class for objects representing VMInterface UVEs
//Defines routines for storing and managing (add, delete, change and send)
//VMInterface UVEs
class InterfaceUveTable {
public:
struct UveInterfaceState :public DBState {
UveInterfaceState(const VmInterface *intf)
: cfg_name_(intf->cfg_name()),
fip_list_(intf->floating_ip_list().list_) {}
std::string cfg_name_;
VmInterface::FloatingIpSet fip_list_;
};
struct FloatingIp;
struct FipInfo {
uint64_t bytes_;
uint64_t packets_;
uint32_t fip_;
VmInterfaceKey fip_vmi_;
bool is_local_flow_;
bool is_ingress_flow_;
bool is_reverse_flow_;
std::string vn_;
FloatingIp *rev_fip_;
FipInfo() : bytes_(0), packets_(0), fip_(0),
fip_vmi_(AgentKey::ADD_DEL_CHANGE, nil_uuid(), ""),
is_local_flow_(false), is_ingress_flow_(false),
is_reverse_flow_(false), rev_fip_(NULL) {
}
};
struct FloatingIp {
FloatingIp(const IpAddress &ip, const std::string &vn)
: family_(ip.is_v4() ? Address::INET : Address::INET6),
fip_(ip), vn_(vn) {
in_bytes_ = 0;
in_packets_ = 0;
out_bytes_ = 0;
out_packets_ = 0;
}
FloatingIp(const IpAddress &ip, const std::string &vn, uint64_t in_b,
uint64_t in_p, uint64_t out_b, uint64_t out_p)
: family_(ip.is_v4() ? Address::INET : Address::INET6),
fip_(ip), vn_(vn), in_bytes_(in_b), in_packets_(in_p),
out_bytes_(out_b), out_packets_(out_p) {
}
void UpdateFloatingIpStats(const FipInfo &fip_info);
Address::Family family_;
IpAddress fip_;
std::string vn_;
uint64_t in_bytes_;
uint64_t in_packets_;
uint64_t out_bytes_;
uint64_t out_packets_;
};
typedef boost::shared_ptr<FloatingIp> FloatingIpPtr;
class FloatingIpCmp {
public:
bool operator()(const FloatingIpPtr &lhs,
const FloatingIpPtr &rhs) const {
if (lhs.get()->fip_ != rhs.get()->fip_) {
return lhs.get()->fip_ < rhs.get()->fip_;
}
return (lhs.get()->vn_ < rhs.get()->vn_);
}
};
typedef std::set<FloatingIpPtr, FloatingIpCmp> FloatingIpSet;
struct AceStats {
const std::string ace_uuid;
mutable uint64_t count;
mutable uint64_t prev_count;
AceStats(const std::string &ace) : ace_uuid(ace), count(0),
prev_count(0) {
}
bool operator<(const AceStats &rhs) const {
return ace_uuid < rhs.ace_uuid;
}
};
typedef std::set<AceStats> AceStatsSet;
struct UveInterfaceEntry {
const VmInterface *intf_;
boost::uuids::uuid uuid_;
L4PortBitmap port_bitmap_;
FloatingIpSet fip_tree_;
FloatingIpSet prev_fip_tree_;
bool changed_;
bool deleted_;
bool renewed_;
bool ace_stats_changed_;
UveVMInterfaceAgent uve_info_;
AceStatsSet ace_set_;
/* For exclusion between kTaskFlowStatsCollector and Agent::Uve */
tbb::mutex mutex_;
UveInterfaceEntry(const VmInterface *i) : intf_(i),
uuid_(i->GetUuid()), port_bitmap_(),
fip_tree_(), prev_fip_tree_(), changed_(true), deleted_(false),
renewed_(false), uve_info_() { }
virtual ~UveInterfaceEntry() {}
void UpdateFloatingIpStats(const FipInfo &fip_info);
bool FillFloatingIpStats(vector<VmFloatingIPStats> &result,
vector<VmFloatingIPStats> &diff_list,
bool &diff_list_send);
void SetStats(VmFloatingIPStats &fip, uint64_t in_bytes,
uint64_t in_pkts, uint64_t out_bytes, uint64_t out_pkts) const;
void SetDiffStats(VmFloatingIPStats &fip, uint64_t in_bytes,
uint64_t in_pkts, uint64_t out_bytes, uint64_t out_pkts,
bool &diff_list_send) const;
void RemoveFloatingIp(const VmInterface::FloatingIp &fip);
void AddFloatingIp(const VmInterface::FloatingIp &fip);
InterfaceUveTable::FloatingIp *FipEntry(uint32_t ip,
const std::string &vn);
bool FrameInterfaceMsg(const std::string &name,
UveVMInterfaceAgent *s_intf) const;
bool FrameInterfaceAceStatsMsg(const std::string &name,
UveVMInterfaceAgent *s_intf);
bool GetVmInterfaceGateway(const VmInterface *vm_intf,
std::string &gw) const;
bool FipAggStatsChanged(const vector<VmFloatingIPStats> &list) const;
bool PortBitmapChanged(const PortBucketBitmap &bmap) const;
bool InBandChanged(uint64_t in_band) const;
bool OutBandChanged(uint64_t out_band) const;
void SetVnVmInfo(UveVMInterfaceAgent *uve) const;
void UpdateInterfaceAceStats(const std::string &ace_uuid);
void Reset();
void UpdatePortBitmap(uint8_t proto, uint16_t sport, uint16_t dport);
};
typedef boost::shared_ptr<UveInterfaceEntry> UveInterfaceEntryPtr;
typedef std::map<std::string, UveInterfaceEntryPtr> InterfaceMap;
typedef std::pair<std::string, UveInterfaceEntryPtr> InterfacePair;
InterfaceUveTable(Agent *agent, uint32_t default_intvl);
virtual ~InterfaceUveTable();
void RegisterDBClients();
void Shutdown(void);
virtual void DispatchInterfaceMsg(const UveVMInterfaceAgent &uve);
bool TimerExpiry();
virtual void SendInterfaceAceStats(const string &name,
UveInterfaceEntry *entry) {
}
protected:
void SendInterfaceDeleteMsg(const std::string &config_name);
Agent *agent_;
InterfaceMap interface_tree_;
/* For exclusion between kTaskFlowStatsCollector and kTaskDBExclude */
tbb::mutex interface_tree_mutex_;
private:
virtual UveInterfaceEntryPtr Allocate(const VmInterface *vm);
void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e);
void InterfaceAddHandler(const VmInterface* intf,
const VmInterface::FloatingIpSet &old_list);
void InterfaceDeleteHandler(const std::string &name);
void set_expiry_time(int time);
void SendInterfaceMsg(const std::string &name, UveInterfaceEntry *entry);
DBTableBase::ListenerId intf_listener_id_;
// Last visited Interface by timer
std::string timer_last_visited_;
Timer *timer_;
int expiry_time_;
DISALLOW_COPY_AND_ASSIGN(InterfaceUveTable);
};
#endif // vnsw_agent_interface_uve_table_h