OpenSDN source code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ifmap_client.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef __DB_IFMAP_CLIENT_H__
6 #define __DB_IFMAP_CLIENT_H__
7 
8 #include <inttypes.h>
9 #include <map>
10 #include <string>
11 #include <vector>
12 #include <boost/unordered_set.hpp>
13 
14 class IFMapExporter;
15 class IFMapState;
16 
17 // An XmppPeer that receives IFMap updates from the server component
18 class IFMapClient {
19 public:
20  typedef std::map<std::string, std::string> VmMap;
21  static const int kIndexInvalid = -1;
22 
23  IFMapClient();
24  virtual ~IFMapClient();
25 
26  virtual const std::string &identifier() const = 0;
27  virtual bool SendUpdate(const std::string &msg) = 0;
28  virtual const std::string &name() const { return name_; }
29  virtual void SetName(const std::string &name) { name_ = name; }
30 
31  int index() const { return index_; }
32  uint64_t msgs_sent() const { return msgs_sent_; }
33  uint64_t msgs_blocked() const { return msgs_blocked_; }
34  uint64_t bytes_sent() const { return bytes_sent_; }
35  uint64_t update_nodes_sent() const { return update_nodes_sent_; }
36  uint64_t delete_nodes_sent() const { return delete_nodes_sent_; }
37  uint64_t update_links_sent() const { return update_links_sent_; }
38  uint64_t delete_links_sent() const { return delete_links_sent_; }
39  bool send_is_blocked() const { return send_is_blocked_; }
40  uint64_t created_at() const { return created_at_; }
41 
42  void incr_msgs_sent() { ++msgs_sent_; }
44  void incr_bytes_sent(uint64_t bytes) { bytes_sent_ += bytes; }
49  void set_send_is_blocked(bool is_blocked) { send_is_blocked_ = is_blocked; }
50 
51  void Initialize(IFMapExporter *exporter, int index);
52 
53  // Called when the switch register for a specific network.
54  void OnRegister(const std::string &vnet);
55 
56  // Called when the switch unregisters from a virtual network.
57  void OnUnregister(const std::string &vnet);
58 
59  void AddVm(const std::string &vm_uuid) {
60  vm_map_.insert(make_pair(vm_uuid, vm_uuid));
61  }
62  void DeleteVm(const std::string &vm_uuid) {
63  vm_map_.erase(vm_uuid);
64  }
65  bool HasAddedVm(const std::string &vm_uuid) {
66  return ((vm_map_.count(vm_uuid) == 1) ? true : false);
67  }
68  bool HasVms() {
69  return (vm_map_.size() != 0);
70  }
71  size_t VmCount() {
72  return vm_map_.size();
73  }
74  // return vm_map_ as a list of strings
75  std::vector<std::string> vm_list() const;
76 
77 private:
78  int index_;
80  uint64_t msgs_sent_;
81  uint64_t msgs_blocked_;
82  uint64_t bytes_sent_;
89  std::string name_;
90  uint64_t created_at_;
91 };
92 
93 #endif
virtual void SetName(const std::string &name)
Definition: ifmap_client.h:29
virtual const std::string & identifier() const =0
void incr_delete_nodes_sent()
Definition: ifmap_client.h:46
std::vector< std::string > vm_list() const
Definition: ifmap_client.cc:27
void incr_msgs_sent()
Definition: ifmap_client.h:42
uint64_t delete_nodes_sent() const
Definition: ifmap_client.h:36
void OnUnregister(const std::string &vnet)
int index() const
Definition: ifmap_client.h:31
bool send_is_blocked_
Definition: ifmap_client.h:87
void incr_delete_links_sent()
Definition: ifmap_client.h:48
uint64_t update_nodes_sent() const
Definition: ifmap_client.h:35
uint64_t bytes_sent() const
Definition: ifmap_client.h:34
void Initialize(IFMapExporter *exporter, int index)
Definition: ifmap_client.cc:22
uint64_t msgs_sent() const
Definition: ifmap_client.h:32
IFMapExporter * exporter_
Definition: ifmap_client.h:79
uint64_t delete_links_sent_
Definition: ifmap_client.h:86
uint64_t msgs_blocked_
Definition: ifmap_client.h:81
static const int kIndexInvalid
Definition: ifmap_client.h:21
uint64_t msgs_sent_
Definition: ifmap_client.h:80
uint64_t update_links_sent_
Definition: ifmap_client.h:85
uint64_t created_at_
Definition: ifmap_client.h:90
void incr_update_links_sent()
Definition: ifmap_client.h:47
uint64_t msgs_blocked() const
Definition: ifmap_client.h:33
virtual ~IFMapClient()
Definition: ifmap_client.cc:19
bool HasAddedVm(const std::string &vm_uuid)
Definition: ifmap_client.h:65
VmMap vm_map_
Definition: ifmap_client.h:88
uint64_t delete_nodes_sent_
Definition: ifmap_client.h:84
void AddVm(const std::string &vm_uuid)
Definition: ifmap_client.h:59
std::map< std::string, std::string > VmMap
Definition: ifmap_client.h:20
void DeleteVm(const std::string &vm_uuid)
Definition: ifmap_client.h:62
bool HasVms()
Definition: ifmap_client.h:68
uint64_t update_links_sent() const
Definition: ifmap_client.h:37
void incr_bytes_sent(uint64_t bytes)
Definition: ifmap_client.h:44
std::string name_
Definition: ifmap_client.h:89
uint64_t delete_links_sent() const
Definition: ifmap_client.h:38
uint64_t bytes_sent_
Definition: ifmap_client.h:82
uint64_t created_at() const
Definition: ifmap_client.h:40
bool send_is_blocked() const
Definition: ifmap_client.h:39
virtual const std::string & name() const
Definition: ifmap_client.h:28
void OnRegister(const std::string &vnet)
uint64_t update_nodes_sent_
Definition: ifmap_client.h:83
void incr_msgs_blocked()
Definition: ifmap_client.h:43
void set_send_is_blocked(bool is_blocked)
Definition: ifmap_client.h:49
void incr_update_nodes_sent()
Definition: ifmap_client.h:45
size_t VmCount()
Definition: ifmap_client.h:71
virtual bool SendUpdate(const std::string &msg)=0