Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_uve_base_h 6 : #define vnsw_agent_uve_base_h 7 : 8 : #include "nodeinfo_types.h" 9 : #include <base/connection_info.h> 10 : #include <uve/vn_uve_table_base.h> 11 : #include <uve/vm_uve_table_base.h> 12 : #include <uve/vrouter_uve_entry_base.h> 13 : #include <uve/prouter_uve_table.h> 14 : #include <uve/interface_uve_table.h> 15 : #include <boost/scoped_ptr.hpp> 16 : 17 : class VrouterStatsCollector; 18 : 19 : /* Structure used to build and carry tags of different types across APIs */ 20 : struct UveTagData { 21 : enum FillType { 22 : STRING, 23 : SET, 24 : VECTOR 25 : }; 26 : std::string application; 27 : std::string tier; 28 : std::string site; 29 : std::string deployment; 30 : /* Semi-colon separated list of labels. This format is imposed by analytics 31 : * module as it expects labels in semi-colon separated string */ 32 : std::string labels; 33 : std::set<string> label_set; 34 : std::vector<string> label_vector; 35 : /* Semi-colon separated list of custom-tags. This format is imposed by 36 : * analytics module as it expects custom-tags in semi-colon separated 37 : * string */ 38 : std::string custom_tags; 39 : std::set<string> custom_tag_set; 40 : std::vector<string> custom_tag_vector; 41 : FillType fill_type; 42 0 : void Reset() { 43 0 : application = tier = site = deployment = labels = custom_tags = ""; 44 0 : if (fill_type == SET) { 45 0 : label_set.clear(); 46 0 : custom_tag_set.clear(); 47 0 : } else if (fill_type == VECTOR) { 48 0 : label_vector.clear(); 49 0 : custom_tag_vector.clear(); 50 : } 51 0 : } 52 0 : UveTagData() : fill_type(STRING) { Reset(); } 53 0 : UveTagData(FillType type) : fill_type(type) { Reset(); } 54 : }; 55 : 56 : //The class to drive UVE module initialization for agent. 57 : //Defines objects required for statistics collection from vrouter and 58 : //objects required for sending UVE information to collector. 59 : class AgentUveBase { 60 : public: 61 : /* Number of UVEs to be sent each time, the timer callback is Run */ 62 : static const uint32_t kUveCountPerTimer = 64; 63 : /* The interval at which timer is fired */ 64 : static const uint32_t kDefaultInterval = (30 * 1000); // time in millisecs 65 : /* When timer is Run, we send atmost 'kUveCountPerTimer' UVEs. If there 66 : * are more UVEs to be sent, we reschedule timer at the following shorter 67 : * interval*/ 68 : static const uint32_t kIncrementalInterval = (1000); // time in millisecs 69 : 70 : static const uint64_t kBandwidthInterval = (1000000); // time in microseconds 71 : 72 : AgentUveBase(Agent *agent, uint64_t intvl, 73 : uint32_t default_intvl, uint32_t incremental_intvl); 74 : virtual ~AgentUveBase(); 75 : 76 : virtual void Shutdown(); 77 0 : uint64_t bandwidth_intvl() const { return bandwidth_intvl_; } 78 385 : VnUveTableBase* vn_uve_table() const { return vn_uve_table_.get(); } 79 111 : VmUveTableBase* vm_uve_table() const { return vm_uve_table_.get(); } 80 313 : Agent* agent() const { return agent_; } 81 162 : VrouterUveEntryBase* vrouter_uve_entry() const { 82 162 : return vrouter_uve_entry_.get(); 83 : } 84 87 : ProuterUveTable* prouter_uve_table() const { 85 87 : return prouter_uve_table_.get(); 86 : } 87 285 : InterfaceUveTable* interface_uve_table() const { 88 285 : return interface_uve_table_.get(); 89 : } 90 106 : VrouterStatsCollector *vrouter_stats_collector() const { 91 106 : return vrouter_stats_collector_.get(); 92 : } 93 : 94 : void Init(); 95 : virtual void InitDone(); 96 : virtual void RegisterDBClients(); 97 : static AgentUveBase *GetInstance() {return singleton_;} 98 : uint8_t ExpectedConnections(uint8_t &num_c_nodes, uint8_t &num_d_servers); 99 0 : uint32_t default_interval() const { return default_interval_; } 100 0 : uint32_t incremental_interval() const { return incremental_interval_; } 101 : void BuildTagNamesFromList(const TagList &tl, UveTagData *info) const; 102 : void BuildTagIdsFromList(const TagList &tl, UveTagData *info) const; 103 : 104 : /// @brief Sets the default interval (time between two dispatches of 105 : /// Agent's information to UVE). 106 : void set_default_interval(uint32_t new_interval = kDefaultInterval); 107 : 108 : /// @brief Sets the incremental interval (time between dispatches of 109 : /// Agent's information and its remnant to UVE). 110 : void set_incremental_interval(uint32_t new_interval = 111 : kIncrementalInterval); 112 : 113 : protected: 114 : boost::scoped_ptr<VnUveTableBase> vn_uve_table_; 115 : boost::scoped_ptr<VmUveTableBase> vm_uve_table_; 116 : boost::scoped_ptr<VrouterUveEntryBase> vrouter_uve_entry_; 117 : boost::scoped_ptr<ProuterUveTable> prouter_uve_table_; 118 : boost::scoped_ptr<InterfaceUveTable> interface_uve_table_; 119 : uint32_t default_interval_; 120 : uint32_t incremental_interval_; 121 : static AgentUveBase *singleton_; 122 : 123 : private: 124 : std::string TagIDToHexString(uint64_t value) const; 125 : friend class UveTest; 126 : void VrouterAgentProcessState( 127 : const std::vector<process::ConnectionInfo> &c, 128 : process::ProcessState::type &state, std::string &message); 129 : void UpdateMessage(const process::ConnectionInfo &info, 130 : std::string &message); 131 : bool HasSelfConfiguration() const; 132 : 133 : Agent *agent_; 134 : uint64_t bandwidth_intvl_; //in microseconds 135 : process::ConnectionStateManager 136 : *connection_state_manager_; 137 : DISALLOW_COPY_AND_ASSIGN(AgentUveBase); 138 : protected: 139 : boost::scoped_ptr<VrouterStatsCollector> vrouter_stats_collector_; 140 : }; 141 : 142 : #endif //vnsw_agent_uve_base_h