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