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