OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interface_uve_table.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_interface_uve_table_h
6 #define vnsw_agent_interface_uve_table_h
7 
8 #include <string>
9 #include <vector>
10 #include <set>
11 #include <map>
12 #include <boost/scoped_ptr.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <interface_types.h>
15 #include <uve/l4_port_bitmap.h>
16 #include <oper/vm.h>
17 #include <oper/peer.h>
18 #include <cmn/index_vector.h>
19 #include <oper/interface_common.h>
20 #include <vnsw/agent/uve/uve_types.h>
22 
23 /* Structure used to pass Endpoint data from FlowStatsCollector to UVE module */
25  const VmInterface *vmi;
27  std::string policy; //has policy-name and rule-uuid
28  std::string local_vn;
29  std::string remote_vn;
31  std::string remote_prefix;
32  std::string action;
33  uint64_t diff_bytes;
34  uint64_t diff_pkts;
35  /* The following bool field indicates diff_bytes and diff_pkts are
36  * in_stats or out_stats */
37  bool in_stats;
38  /* The following bool field indicates whether endpoint data corresponds to
39  * client session or server session.
40  * Ingress+Forward and Egress+Reverse are client flows.
41  * Egress+Forward and Ingress+Reverse are server flows.
42  * in_stats or out_stats */
43  bool client;
44 };
45 
46 //The container class for objects representing VMInterface UVEs
47 //Defines routines for storing and managing (add, delete, change and send)
48 //VMInterface UVEs
50 public:
51  struct UveInterfaceState :public DBState {
53  : cfg_name_(intf->cfg_name()),
54  fip_list_(intf->floating_ip_list().list_) {}
55  std::string cfg_name_;
57  };
58 
59  struct FloatingIp;
60 
61  struct FipInfo {
62  uint64_t bytes_;
63  uint64_t packets_;
64  uint32_t fip_;
69  std::string vn_;
71  FipInfo() : bytes_(0), packets_(0), fip_(0),
72  fip_vmi_(AgentKey::ADD_DEL_CHANGE, boost::uuids::nil_uuid(), ""),
73  is_local_flow_(false), is_ingress_flow_(false),
74  is_reverse_flow_(false), rev_fip_(NULL) {
75  }
76  };
77  struct FloatingIp {
78  FloatingIp(const IpAddress &ip, const std::string &vn)
79  : family_(ip.is_v4() ? Address::INET : Address::INET6),
80  fip_(ip), vn_(vn) {
81  in_bytes_ = 0;
82  in_packets_ = 0;
83  out_bytes_ = 0;
84  out_packets_ = 0;
85  }
86  FloatingIp(const IpAddress &ip, const std::string &vn, uint64_t in_b,
87  uint64_t in_p, uint64_t out_b, uint64_t out_p)
88  : family_(ip.is_v4() ? Address::INET : Address::INET6),
89  fip_(ip), vn_(vn), in_bytes_(in_b), in_packets_(in_p),
90  out_bytes_(out_b), out_packets_(out_p) {
91  }
92  void UpdateFloatingIpStats(const FipInfo &fip_info);
93 
96  std::string vn_;
97  uint64_t in_bytes_;
98  uint64_t in_packets_;
99  uint64_t out_bytes_;
100  uint64_t out_packets_;
101  };
102  typedef boost::shared_ptr<FloatingIp> FloatingIpPtr;
103 
105  public:
106  bool operator()(const FloatingIpPtr &lhs,
107  const FloatingIpPtr &rhs) const {
108  if (lhs.get()->fip_ != rhs.get()->fip_) {
109  return lhs.get()->fip_ < rhs.get()->fip_;
110  }
111  return (lhs.get()->vn_ < rhs.get()->vn_);
112  }
113  };
114  typedef std::set<FloatingIpPtr, FloatingIpCmp> FloatingIpSet;
115 
116  struct AceStats {
117  const std::string ace_uuid;
118  mutable uint64_t count;
119  mutable uint64_t prev_count;
120  AceStats(const std::string &ace) : ace_uuid(ace), count(0),
121  prev_count(0) {
122  }
123  bool operator<(const AceStats &rhs) const {
124  return ace_uuid < rhs.ace_uuid;
125  }
126  };
127  //Forward declaration
128  struct UveInterfaceEntry;
130  /* We have added local_tagset here as well as at interface level. During
131  * transient cases of change of local_tagset of VMI, we want to track
132  * the local_tagset for which the statistics correspond to. This will
133  * also help in retaining stats for old local_tagset when tag_sets have
134  * changed. While export Endpoint objectlogs, always pick local_tagset
135  * from here instead of interface level local_tagset */
138  std::string remote_prefix;
139  std::string remote_vn;
140  std::string local_vn;
141  std::string action;
142  uint64_t added;
143  uint64_t deleted;
144  uint64_t active;
145  uint64_t dropped_short;
146  uint64_t in_bytes;
147  uint64_t in_pkts;
148  uint64_t out_bytes;
149  uint64_t out_pkts;
150  uint64_t prev_in_bytes;
151  uint64_t prev_in_pkts;
152  uint64_t prev_out_bytes;
153  uint64_t prev_out_pkts;
154  uint64_t prev_added;
155  uint64_t prev_deleted;
156  UveSecurityPolicyStats(const TagList &ltset, const TagList &rtset,
157  const std::string &rprefix,
158  const std::string &rvn, const std::string &lvn,
159  const std::string &action_str) :
160  local_tagset(ltset), remote_tagset(rtset), remote_prefix(rprefix),
161  remote_vn(rvn), local_vn(lvn), action(action_str), added(0),
162  deleted(0), active(0), dropped_short(0), in_bytes(0), in_pkts(0),
163  out_bytes(0), out_pkts(0) , prev_in_bytes(0) , prev_in_pkts(0),
165  }
166  };
167  typedef boost::shared_ptr<UveSecurityPolicyStats> UveSecurityPolicyStatsPtr;
168  struct PolicyCmp {
170  const UveSecurityPolicyStatsPtr &rhs) const {
171  if (lhs->local_vn.compare(rhs->local_vn) != 0) {
172  return lhs->local_vn < rhs->local_vn;
173  }
174  if (lhs->remote_vn.compare(rhs->remote_vn) != 0) {
175  return lhs->remote_vn < rhs->remote_vn;
176  }
177  if (lhs->local_tagset != rhs->local_tagset) {
178  return lhs->local_tagset < rhs->local_tagset;
179  }
180  if (lhs->remote_tagset != rhs->remote_tagset) {
181  return lhs->remote_tagset < rhs->remote_tagset;
182  }
183  return lhs->remote_prefix < rhs->remote_prefix;
184  }
185  };
186  typedef std::set<UveSecurityPolicyStatsPtr, PolicyCmp>
192  if (client) {
193  return client_list;
194  } else {
195  return server_list;
196  }
197  }
198  };
199  typedef std::map<std::string, EndpointStatsContainer>
201  typedef std::pair<std::string, EndpointStatsContainer>
203  typedef std::set<AceStats> AceStatsSet;
210  bool changed_;
211  bool deleted_;
212  bool renewed_;
214  VMIStats uve_stats_;
218  VMITags prev_tags_uve_;
219  /* For exclusion between kTaskFlowStatsCollector and Agent::Uve
220  * (1) port_bitmap_ and fip_tree_ are updated by kTaskFlowStatsCollector
221  * and read by Agent::Uve.
222  * (2) security_policy_stats_map_ is cleared and updated by both
223  * kTaskFlowStatsCollector and Agent::Uve
224  * -- Agent::Uve task updates session_count
225  * (inside security_policy_stats_map_), clears and adds entries
226  * to security_policy_stats_map_
227  * -- kTaskFlowStatsCollector updates stats of
228  * security_policy_stats_map_ and resets
229  * security_policy_stats_map_
230  */
231  tbb::mutex mutex_;
232 
234  uuid_(i->GetUuid()), port_bitmap_(),
235  fip_tree_(), prev_fip_tree_(), changed_(true), deleted_(false),
236  renewed_(false), uve_stats_() { }
237  virtual ~UveInterfaceEntry() {}
238  void UpdateFloatingIpStats(const FipInfo &fip_info);
239  bool FillFloatingIpStats(vector<VmFloatingIPStats> &result,
240  vector<VmFloatingIPStats> &diff_list,
241  bool &diff_list_send);
242  void SetStats(VmFloatingIPStats &fip, uint64_t in_bytes,
243  uint64_t in_pkts, uint64_t out_bytes, uint64_t out_pkts) const;
244  void SetDiffStats(VmFloatingIPStats &fip, uint64_t in_bytes,
245  uint64_t in_pkts, uint64_t out_bytes, uint64_t out_pkts,
246  bool &diff_list_send) const;
247  void RemoveFloatingIp(const VmInterface::FloatingIp &fip);
248  void AddFloatingIp(const VmInterface::FloatingIp &fip);
250  const std::string &vn);
251  bool FrameInterfaceMsg(const std::string &name,
252  UveVMInterfaceAgent *s_intf) const;
253  bool FrameTagsUveMsg(Agent *agent, const std::string &name,
254  VMITags *uve);
255  bool FrameInterfaceAceStatsMsg(const std::string &name,
256  VMIStats *s_intf);
257  bool GetVmInterfaceGateway(const VmInterface *vm_intf,
258  std::string &gw) const;
259  bool FipAggStatsChanged(const vector<VmFloatingIPStats> &list) const;
260  bool PortBitmapChanged(const PortBucketBitmap &bmap) const;
261  bool InBandChanged(uint64_t in_band) const;
262  bool OutBandChanged(uint64_t out_band) const;
263  void SetVnVmInfo(UveVMInterfaceAgent *uve) const;
264  void SetVMIStatsVnVm(VMIStats *uve) const;
265  void UpdateInterfaceAceStats(const std::string &ace_uuid);
266  void Reset();
267  void UpdatePortBitmap(uint8_t proto, uint16_t sport, uint16_t dport);
269  void UpdateCounters(const FlowUveFwPolicyInfo &info,
273  UveSecurityPolicyStats *stats);
274  void FillEndpointStats(Agent *agent, EndpointSecurityStats *obj);
275  void BuildInterfaceUveInfo(InterfaceUveInfo *r) const;
276  void FillTagSetAndPolicyList(VMIStats *obj);
277  void BuildSandeshUveTagList(const TagList &list,
278  std::vector<SandeshUveTagInfo> *rts) const;
279  void HandleTagListChange();
280  void FillSecurityPolicyList(Agent *agent,
281  const SecurityPolicyStatsSet &ilist,
282  std::vector<SecurityPolicyFlowStats> *ol);
284  (const SecurityPolicyStatsSet &ilist,
285  std::vector<SandeshUveRemoteEndpoint> *olist) const;
286  std::string GetVmName() const;
287  };
288  typedef boost::shared_ptr<UveInterfaceEntry> UveInterfaceEntryPtr;
289 
290  typedef std::map<std::string, UveInterfaceEntryPtr> InterfaceMap;
291  typedef std::pair<std::string, UveInterfaceEntryPtr> InterfacePair;
292 
293  InterfaceUveTable(Agent *agent, uint32_t default_intvl);
294  virtual ~InterfaceUveTable();
295  void RegisterDBClients();
296  void Shutdown(void);
297  virtual void DispatchInterfaceMsg(const UveVMInterfaceAgent &uve);
298  virtual void DispatchInterfaceObjectLog(EndpointSecurityStats *obj);
299  void DispatchVMITagsMsg(const VMITags &uve) const;
300  virtual void DispatchVMIStatsMsg(const VMIStats &uve);
301  bool TimerExpiry();
302  virtual void SendInterfaceAceStats(const string &name,
303  UveInterfaceEntry *entry) {
304  }
305  void HandleVmiTagListChange(const std::string &name);
306 
307 protected:
308  void SendInterfaceDeleteMsg(const std::string &config_name);
309 
312  /* For exclusion between kTaskFlowStatsCollector and kTaskDBExclude */
314 private:
315  virtual UveInterfaceEntryPtr Allocate(const VmInterface *vm);
316  void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e);
317  void InterfaceAddHandler(const VmInterface* intf,
318  const VmInterface::FloatingIpSet &old_list);
319  void InterfaceDeleteHandler(const std::string &name);
320  void set_expiry_time(int time);
321  void SendInterfaceMsg(const std::string &name, UveInterfaceEntry *entry);
322 
324  // Last visited Interface by timer
325  std::string timer_last_visited_;
329 };
330 
331 #endif // vnsw_agent_interface_uve_table_h
void SetStats(VmFloatingIPStats &fip, uint64_t in_bytes, uint64_t in_pkts, uint64_t out_bytes, uint64_t out_pkts) const
bool FrameTagsUveMsg(Agent *agent, const std::string &name, VMITags *uve)
void UpdatePortBitmap(uint8_t proto, uint16_t sport, uint16_t dport)
void UpdateInterfaceAceStats(const std::string &ace_uuid)
std::pair< std::string, EndpointStatsContainer > SecurityPolicyStatsPair
void SetVMIStatsVnVm(VMIStats *uve) const
void set_expiry_time(int time)
AceStats(const std::string &ace)
InterfaceMap interface_tree_
bool FipAggStatsChanged(const vector< VmFloatingIPStats > &list) const
std::map< std::string, EndpointStatsContainer > SecurityPolicyStatsMap
std::set< AceStats > AceStatsSet
void UpdateSecurityPolicyStats(const EndpointStatsInfo &info)
const VmInterface * vmi
Family
Definition: address.h:24
boost::asio::ip::address IpAddress
Definition: address.h:13
DBTableBase::ListenerId intf_listener_id_
FloatingIp(const IpAddress &ip, const std::string &vn)
int ListenerId
Definition: db_table.h:62
FloatingIp(const IpAddress &ip, const std::string &vn, uint64_t in_b, uint64_t in_p, uint64_t out_b, uint64_t out_p)
UveSecurityPolicyStats(const TagList &ltset, const TagList &rtset, const std::string &rprefix, const std::string &rvn, const std::string &lvn, const std::string &action_str)
boost::uuids::uuid uuid
void DispatchVMITagsMsg(const VMITags &uve) const
tbb::mutex interface_tree_mutex_
void InterfaceAddHandler(const VmInterface *intf, const VmInterface::FloatingIpSet &old_list)
virtual void DispatchInterfaceObjectLog(EndpointSecurityStats *obj)
VmInterface::FloatingIpSet fip_list_
std::set< UveSecurityPolicyStatsPtr, PolicyCmp > SecurityPolicyStatsSet
InterfaceUveTable(Agent *agent, uint32_t default_intvl)
void UpdateInterfaceFwPolicyStats(const FlowUveFwPolicyInfo &info)
void RemoveFloatingIp(const VmInterface::FloatingIp &fip)
boost::shared_ptr< FloatingIp > FloatingIpPtr
void UpdateFloatingIpStats(const FipInfo &fip_info)
virtual void DispatchInterfaceMsg(const UveVMInterfaceAgent &uve)
virtual UveInterfaceEntryPtr Allocate(const VmInterface *vm)
void HandleVmiTagListChange(const std::string &name)
Definition: agent.h:358
bool OutBandChanged(uint64_t out_band) const
bool operator()(const UveSecurityPolicyStatsPtr &lhs, const UveSecurityPolicyStatsPtr &rhs) const
bool InBandChanged(uint64_t in_band) const
void UpdateSecurityPolicyStatsInternal(const EndpointStatsInfo &info, UveSecurityPolicyStats *stats)
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
std::pair< std::string, UveInterfaceEntryPtr > InterfacePair
void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e)
bool GetVmInterfaceGateway(const VmInterface *vm_intf, std::string &gw) const
bool operator()(const FloatingIpPtr &lhs, const FloatingIpPtr &rhs) const
SecurityPolicyStatsSet & ToList(bool client)
void UpdateCounters(const FlowUveFwPolicyInfo &info, UveSecurityPolicyStats *obj)
void AddFloatingIp(const VmInterface::FloatingIp &fip)
bool PortBitmapChanged(const PortBucketBitmap &bmap) const
bool FillFloatingIpStats(vector< VmFloatingIPStats > &result, vector< VmFloatingIPStats > &diff_list, bool &diff_list_send)
void FillEndpointStats(Agent *agent, EndpointSecurityStats *obj)
void SendInterfaceDeleteMsg(const std::string &config_name)
bool operator<(const AceStats &rhs) const
void FillSecurityPolicyList(Agent *agent, const SecurityPolicyStatsSet &ilist, std::vector< SecurityPolicyFlowStats > *ol)
UveInterfaceState(const VmInterface *intf)
virtual void DispatchVMIStatsMsg(const VMIStats &uve)
void SetVnVmInfo(UveVMInterfaceAgent *uve) const
InterfaceUveTable::FloatingIp * FipEntry(uint32_t ip, const std::string &vn)
std::string timer_last_visited_
bool FrameInterfaceAceStatsMsg(const std::string &name, VMIStats *s_intf)
void UpdateFloatingIpStats(const FipInfo &fip_info)
void BuildSandeshUveTagList(const TagList &list, std::vector< SandeshUveTagInfo > *rts) const
SecurityPolicyStatsMap security_policy_stats_map_
std::set< FloatingIp, FloatingIp > FloatingIpSet
Definition: vm_interface.h:567
void SendInterfaceMsg(const std::string &name, UveInterfaceEntry *entry)
boost::shared_ptr< UveInterfaceEntry > UveInterfaceEntryPtr
void BuildInterfaceUveInfo(InterfaceUveInfo *r) const
std::set< FloatingIpPtr, FloatingIpCmp > FloatingIpSet
void InterfaceDeleteHandler(const std::string &name)
boost::shared_ptr< UveSecurityPolicyStats > UveSecurityPolicyStatsPtr
Definition: timer.h:54
virtual void SendInterfaceAceStats(const string &name, UveInterfaceEntry *entry)
void BuildInterfaceUveSecurityPolicyList(const SecurityPolicyStatsSet &ilist, std::vector< SandeshUveRemoteEndpoint > *olist) const
std::map< std::string, UveInterfaceEntryPtr > InterfaceMap
DISALLOW_COPY_AND_ASSIGN(InterfaceUveTable)
bool FrameInterfaceMsg(const std::string &name, UveVMInterfaceAgent *s_intf) const
std::vector< int > TagList
Definition: agent.h:202