Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_vm_hpp 6 : #define vnsw_agent_vm_hpp 7 : 8 : #include <atomic> 9 : 10 : #include <cmn/agent_cmn.h> 11 : #include <oper/oper_db.h> 12 : #include <agent_types.h> 13 : 14 : typedef std::map<std::string, boost::uuids::uuid> VmNameUuidTree; 15 : 16 : struct VmKey : public AgentOperDBKey { 17 248 : VmKey(boost::uuids::uuid id) : AgentOperDBKey(), uuid_(id) {} ; 18 382 : virtual ~VmKey() { } 19 : 20 : boost::uuids::uuid uuid_; 21 : }; 22 : 23 : struct VmData : public AgentOperDBData { 24 : typedef vector<boost::uuids::uuid> SGUuidList; 25 106 : VmData(Agent *agent, IFMapNode *node, const std::string &name, 26 106 : const SGUuidList &sg_list) : 27 106 : AgentOperDBData(agent, node), name_(name), sg_list_(sg_list) { } 28 212 : virtual ~VmData() { } 29 : 30 : std::string name_; 31 : SGUuidList sg_list_; 32 : }; 33 : 34 : class VmEntry : AgentRefCount<VmEntry>, public AgentOperDBEntry { 35 : public: 36 : static const int kVectorIncreaseSize = 16; 37 : 38 : VmEntry(const boost::uuids::uuid &id); 39 : virtual ~VmEntry(); 40 : 41 : virtual bool IsLess(const DBEntry &rhs) const; 42 : virtual KeyPtr GetDBRequestKey() const; 43 : virtual void SetKey(const DBRequestKey *key); 44 : virtual string ToString() const; 45 201 : const string &GetCfgName() const { return name_; } 46 26 : void SetCfgName(std::string name) { name_ = name; } 47 : 48 453 : const boost::uuids::uuid &GetUuid() const { return uuid_; } 49 : 50 160 : uint32_t GetRefCount() const { 51 160 : return AgentRefCount<VmEntry>::GetRefCount(); 52 : } 53 : 54 : void SendObjectLog(AgentLogEvent::type event) const; 55 : bool DBEntrySandesh(Sandesh *sresp, std::string &name) const; 56 : 57 24 : uint32_t flow_count() const { return flow_count_; } 58 : void update_flow_count(int val) const; 59 : 60 0 : uint32_t linklocal_flow_count() const { return linklocal_flow_count_; } 61 0 : void update_linklocal_flow_count(int val) const { 62 0 : int tmp = linklocal_flow_count_.fetch_add(val); 63 0 : if (val < 0) 64 0 : assert(tmp >= val); 65 0 : } 66 : 67 54 : bool drop_new_flows() const { return drop_new_flows_; } 68 : 69 : private: 70 : void SetInterfacesDropNewFlows(bool drop_new_flows) const; 71 : friend class VmTable; 72 : boost::uuids::uuid uuid_; 73 : std::string name_; 74 : mutable std::atomic<int> flow_count_; 75 : mutable std::atomic<int> linklocal_flow_count_; 76 : mutable bool drop_new_flows_; 77 : DISALLOW_COPY_AND_ASSIGN(VmEntry); 78 : }; 79 : 80 : class VmTable : public AgentOperDBTable { 81 : public: 82 2 : VmTable(DB *db, const std::string &name) : AgentOperDBTable(db, name) { } 83 4 : virtual ~VmTable() { } 84 : 85 : virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const; 86 286 : virtual size_t Hash(const DBEntry *entry) const {return 0;} 87 248 : virtual size_t Hash(const DBRequestKey *key) const {return 0;} 88 : 89 : virtual DBEntry *OperDBAdd(const DBRequest *req); 90 : virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req); 91 : virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req); 92 : virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, 93 : const boost::uuids::uuid &u); 94 : virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u); 95 : bool ProcessConfig(IFMapNode *node, DBRequest &req, 96 : const boost::uuids::uuid &u); 97 : virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, 98 : const std::string &context); 99 : 100 : static DBTableBase *CreateTable(DB *db, const std::string &name); 101 : static VmTable *GetInstance() {return vm_table_;} 102 : 103 : boost::uuids::uuid GetVmUuid(const std::string &name); 104 : 105 : private: 106 : static VmTable *vm_table_; 107 : VmNameUuidTree vm_name_uuid_tree_; 108 : DISALLOW_COPY_AND_ASSIGN(VmTable); 109 : }; 110 : 111 : #endif // vnsw_agent_vm_hpp