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_vm_uve_table_base_h 7 : #define vnsw_agent_vm_uve_table_base_h 8 : 9 : #include <string> 10 : #include <vector> 11 : #include <set> 12 : #include <map> 13 : #include <mutex> 14 : 15 : #include <boost/scoped_ptr.hpp> 16 : #include <boost/shared_ptr.hpp> 17 : #include <virtual_machine_types.h> 18 : #include <uve/vm_stat.h> 19 : #include <uve/vm_stat_data.h> 20 : #include <oper/vm.h> 21 : #include <oper/peer.h> 22 : #include <cmn/index_vector.h> 23 : #include <uve/vm_uve_entry_base.h> 24 : #include "base/queue_task.h" 25 : 26 : //The container class for objects representing VirtualMachine UVEs 27 : //Defines routines for storing and managing (add, delete, change and send) 28 : //VirtualMachine UVEs 29 : class VmUveTableBase { 30 : public: 31 : struct VmUveInterfaceState :public DBState { 32 167 : VmUveInterfaceState(const boost::uuids::uuid u, 33 : const std::string cfg_name) 34 167 : : vm_uuid_(u), interface_cfg_name_(cfg_name) {} 35 : boost::uuids::uuid vm_uuid_; 36 : std::string interface_cfg_name_; 37 : std::string vm_name_; 38 : }; 39 : 40 : class VmUveVmState: public DBState { 41 : public: 42 165 : VmUveVmState() : stat_(NULL) { }; 43 : VmStat *stat_; 44 : }; 45 : typedef boost::shared_ptr<VmUveEntryBase> VmUveEntryPtr; 46 : typedef std::map<const boost::uuids::uuid, VmUveEntryPtr> UveVmMap; 47 : typedef std::pair<const boost::uuids::uuid, VmUveEntryPtr> UveVmPair; 48 : 49 : VmUveTableBase(Agent *agent, uint32_t default_intvl); 50 : virtual ~VmUveTableBase(); 51 : void RegisterDBClients(); 52 : void Shutdown(void); 53 : virtual void DispatchVmMsg(const UveVirtualMachineAgent &uve); 54 : bool TimerExpiry(); 55 : 56 : protected: 57 : virtual void VmStatCollectionStart(VmUveVmState *state, const VmEntry *vm); 58 : virtual void VmStatCollectionStop(VmUveVmState *state); 59 : VmUveEntryBase* UveEntryFromVm(const boost::uuids::uuid &u); 60 : virtual void SendVmDeleteMsg(const std::string &vm_config_name); 61 : 62 : UveVmMap uve_vm_map_; 63 : Agent *agent_; 64 : /* For exclusion between kTaskFlowStatsCollector and kTaskDBExclude */ 65 : std::mutex uve_vm_map_mutex_; 66 : private: 67 : virtual VmUveEntryPtr Allocate(const VmEntry *vm); 68 : void InterfaceNotify(DBTablePartBase *partition, DBEntryBase *e); 69 : void VmNotify(DBTablePartBase *partition, DBEntryBase *e); 70 : void InterfaceAddHandler(const VmEntry* vm, const VmInterface *vmi); 71 : void InterfaceDeleteHandler(const boost::uuids::uuid &u, 72 : const std::string &intf_cfg_name); 73 : void UpdateVmName(const boost::uuids::uuid &u, const std::string &vm_name); 74 : void MarkChanged(const boost::uuids::uuid &u); 75 : VmUveEntryBase* Add(const VmEntry *vm, bool vm_notify); 76 : void Delete(const boost::uuids::uuid &u); 77 : void Change(const VmEntry *vm); 78 : void set_expiry_time(int time); 79 : void SendVmMsg(VmUveEntryBase *entry, const boost::uuids::uuid &u); 80 : 81 : DBTableBase::ListenerId intf_listener_id_; 82 : DBTableBase::ListenerId vm_listener_id_; 83 : // Last visited VmEntry by timer 84 : boost::uuids::uuid timer_last_visited_; 85 : Timer *timer_; 86 : int expiry_time_; 87 : DISALLOW_COPY_AND_ASSIGN(VmUveTableBase); 88 : }; 89 : 90 : #endif // vnsw_agent_vm_uve_table_base_h