Line data Source code
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 903 : virtual const std::string &name() const { return name_; } 29 7 : virtual void SetName(const std::string &name) { name_ = name; } 30 : 31 388 : int index() const { return index_; } 32 0 : uint64_t msgs_sent() const { return msgs_sent_; } 33 0 : uint64_t msgs_blocked() const { return msgs_blocked_; } 34 0 : uint64_t bytes_sent() const { return bytes_sent_; } 35 0 : uint64_t update_nodes_sent() const { return update_nodes_sent_; } 36 0 : uint64_t delete_nodes_sent() const { return delete_nodes_sent_; } 37 0 : uint64_t update_links_sent() const { return update_links_sent_; } 38 0 : uint64_t delete_links_sent() const { return delete_links_sent_; } 39 0 : bool send_is_blocked() const { return send_is_blocked_; } 40 6 : uint64_t created_at() const { return created_at_; } 41 : 42 0 : void incr_msgs_sent() { ++msgs_sent_; } 43 0 : void incr_msgs_blocked() { ++msgs_blocked_; } 44 0 : void incr_bytes_sent(uint64_t bytes) { bytes_sent_ += bytes; } 45 435 : void incr_update_nodes_sent() { ++update_nodes_sent_; } 46 0 : void incr_delete_nodes_sent() { ++delete_nodes_sent_; } 47 468 : void incr_update_links_sent() { ++update_links_sent_; } 48 0 : void incr_delete_links_sent() { ++delete_links_sent_; } 49 0 : 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 0 : void AddVm(const std::string &vm_uuid) { 60 0 : vm_map_.insert(make_pair(vm_uuid, vm_uuid)); 61 0 : } 62 0 : void DeleteVm(const std::string &vm_uuid) { 63 0 : vm_map_.erase(vm_uuid); 64 0 : } 65 0 : bool HasAddedVm(const std::string &vm_uuid) { 66 0 : return ((vm_map_.count(vm_uuid) == 1) ? true : false); 67 : } 68 14 : bool HasVms() { 69 14 : 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_; 79 : IFMapExporter *exporter_; 80 : uint64_t msgs_sent_; 81 : uint64_t msgs_blocked_; 82 : uint64_t bytes_sent_; 83 : uint64_t update_nodes_sent_; 84 : uint64_t delete_nodes_sent_; 85 : uint64_t update_links_sent_; 86 : uint64_t delete_links_sent_; 87 : bool send_is_blocked_; 88 : VmMap vm_map_; 89 : std::string name_; 90 : uint64_t created_at_; 91 : }; 92 : 93 : #endif