Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_vrouter_uve_entry_base_h 6 : #define vnsw_agent_vrouter_uve_entry_base_h 7 : 8 : #include <string> 9 : #include <vector> 10 : #include <set> 11 : #include <sys/types.h> 12 : #include <net/ethernet.h> 13 : #include <vrouter_types.h> 14 : #include <uve/l4_port_bitmap.h> 15 : #include <pkt/flow_proto.h> 16 : #include <cmn/agent_cmn.h> 17 : #include <vgw/cfg_vgw.h> 18 : 19 : //The class that defines data-structures to store VRouter information 20 : //required for sending VRouter UVE. 21 : class VrouterUveEntryBase { 22 : public: 23 : struct VrouterUveInterfaceState : public DBState { 24 22 : VrouterUveInterfaceState(bool active) : 25 22 : vmport_active_(active) {} 26 44 : ~VrouterUveInterfaceState() {} 27 : bool vmport_active_; 28 : }; 29 : struct VrouterPhysicalDeviceState : public DBState { 30 1 : VrouterPhysicalDeviceState() : master_(false) {} 31 : bool master_; 32 : }; 33 : 34 : // The below const values are dependent on value of 35 : // VrouterStatsCollector::VrouterStatsInterval 36 : static const uint8_t bandwidth_mod_1min = 2; 37 : static const uint8_t bandwidth_mod_5min = 10; 38 : typedef std::set<const Interface *> PhysicalInterfaceSet; 39 : typedef boost::shared_ptr<std::vector<std::string> > StringVectorPtr; 40 : 41 : VrouterUveEntryBase(Agent *agent); 42 : virtual ~VrouterUveEntryBase(); 43 : 44 : void RegisterDBClients(); 45 : void Shutdown(); 46 : 47 : bool AppendVm(DBTablePartBase *part, DBEntryBase *e, StringVectorPtr l); 48 : void VmWalkDone(DBTableBase *base, StringVectorPtr list); 49 : bool AppendVn(DBTablePartBase *part, DBEntryBase *e, StringVectorPtr l); 50 : void VnWalkDone(DBTableBase *base, StringVectorPtr list); 51 : bool AppendInterface(DBTablePartBase *part, DBEntryBase *entry, 52 : StringVectorPtr intf_list, StringVectorPtr err_list, 53 : StringVectorPtr nova_if_list, 54 : StringVectorPtr unmanaged_list); 55 : void InterfaceWalkDone(DBTableBase *base, StringVectorPtr if_l, 56 : StringVectorPtr err_if_l, 57 : StringVectorPtr nova_if_l, 58 : StringVectorPtr unmanaged_list); 59 : virtual bool SendVrouterMsg(); 60 : void SendVrouterProuterAssociation(const std::vector<std::string> &list); 61 : bool TimerExpiry(); 62 : protected: 63 : Agent *agent_; 64 : PhysicalInterfaceSet phy_intf_set_; 65 : VrouterStatsAgent prev_stats_; 66 : VrouterAgent prev_vrouter_; 67 : uint8_t cpu_stats_count_; 68 : bool do_vn_walk_; 69 : bool do_vm_walk_; 70 : bool do_interface_walk_; 71 : DBTable::DBTableWalkRef vn_walk_ref_; 72 : DBTable::DBTableWalkRef vm_walk_ref_; 73 : DBTable::DBTableWalkRef interface_walk_ref_; 74 : 75 : //The following Dispatch functions are not made const function because 76 : //in derived class they need to be non-const 77 : virtual void DispatchVrouterStatsMsg(const VrouterStatsAgent &uve); 78 : virtual void DispatchComputeCpuStateMsg(const ComputeCpuState &ccs); 79 : private: 80 : //The following Dispatch functions are not made const function because 81 : //in derived class they need to be non-const 82 : virtual void DispatchVrouterMsg(const VrouterAgent &uve); 83 : void BuildAndSendComputeCpuStateMsg(const CpuLoadInfo &info); 84 : void PhysicalDeviceNotify(DBTablePartBase *partition, DBEntryBase *e); 85 : void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e); 86 : void VmNotify(DBTablePartBase *partition, DBEntryBase *e); 87 : void VnNotify(DBTablePartBase *partition, DBEntryBase *e); 88 : bool StartVnWalk(); 89 : bool StartVmWalk(); 90 : bool StartInterfaceWalk(); 91 : void StartTimer(); 92 : bool Run(); 93 : std::string GetMacAddress(const MacAddress &mac) const; 94 : void SubnetToStringList(VirtualGatewayConfig::SubnetList &l1, 95 : std::vector<std::string> &l2); 96 : void BuildAgentConfig(VrouterAgent &vrouter_agent); 97 : void AppendInterfaceInternal(const VmInterface *port, 98 : StringVectorPtr intf_list, StringVectorPtr err_if_list); 99 : PhysicalDevice *VmiToPhysicalDevice(const VmInterface *port); 100 : PhysicalDevice *InterfaceToPhysicalDevice(Interface *intf); 101 : 102 : DBTableBase::ListenerId vn_listener_id_; 103 : DBTableBase::ListenerId vm_listener_id_; 104 : DBTableBase::ListenerId intf_listener_id_; 105 : DBTableBase::ListenerId physical_device_listener_id_; 106 : Timer *timer_; 107 : DISALLOW_COPY_AND_ASSIGN(VrouterUveEntryBase); 108 : }; 109 : 110 : #endif // vnsw_agent_vrouter_uve_entry_base_h