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