Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef vnsw_agent_sg_hpp 6 : #define vnsw_agent_sg_hpp 7 : 8 : #include <cmn/agent_cmn.h> 9 : #include <cmn/agent.h> 10 : #include <agent_types.h> 11 : #include <oper/oper_db.h> 12 : 13 : struct SgKey : public AgentOperDBKey { 14 0 : SgKey(boost::uuids::uuid sg_uuid) : AgentOperDBKey(), sg_uuid_(sg_uuid) {} 15 0 : virtual ~SgKey() {} 16 : 17 : boost::uuids::uuid sg_uuid_; 18 : }; 19 : 20 : struct SgData : public AgentOperDBData { 21 0 : SgData(Agent *agent, IFMapNode *node, const uint32_t &sg_id, 22 : const boost::uuids::uuid &egress_acl_id, 23 0 : const boost::uuids::uuid &ingress_acl_id) : 24 0 : AgentOperDBData(agent, node), sg_id_(sg_id), 25 0 : egress_acl_id_(egress_acl_id), 26 0 : ingress_acl_id_(ingress_acl_id) { 27 0 : } 28 0 : virtual ~SgData() { } 29 : 30 : uint32_t sg_id_; 31 : boost::uuids::uuid egress_acl_id_; 32 : boost::uuids::uuid ingress_acl_id_; 33 : }; 34 : 35 : class SgEntry : AgentRefCount<SgEntry>, public AgentOperDBEntry { 36 : public: 37 : SgEntry(boost::uuids::uuid sg_uuid, uint32_t sg_id) : 38 : sg_uuid_(sg_uuid), sg_id_(sg_id), 39 : egress_acl_(NULL), ingress_acl_(NULL) {} 40 0 : SgEntry(boost::uuids::uuid sg_uuid) : sg_uuid_(sg_uuid) {} 41 0 : virtual ~SgEntry() {} 42 : 43 : virtual bool IsLess(const DBEntry &rhs) const; 44 : virtual KeyPtr GetDBRequestKey() const; 45 : virtual void SetKey(const DBRequestKey *key); 46 : virtual string ToString() const; 47 : 48 0 : const boost::uuids::uuid &GetSgUuid() const {return sg_uuid_;}; 49 0 : const uint32_t &GetSgId() const {return sg_id_;}; 50 0 : const AclDBEntry *GetIngressAcl() const {return ingress_acl_.get();}; 51 0 : const AclDBEntry *GetEgressAcl() const {return egress_acl_.get();}; 52 : bool IsEgressAclSet() const { return (egress_acl_ != NULL);}; 53 : bool IsIngressAclSet() const { return (ingress_acl_ != NULL);}; 54 0 : bool IsAclSet() const { return (egress_acl_ != NULL || ingress_acl_ != NULL);}; 55 : 56 0 : uint32_t GetRefCount() const { 57 0 : return AgentRefCount<SgEntry>::GetRefCount(); 58 : } 59 : 60 : bool DBEntrySandesh(Sandesh *sresp, std::string &name) const; 61 : void SendObjectLog(SandeshTraceBufferPtr ptr, 62 : AgentLogEvent::type event) const; 63 : private: 64 : friend class SgTable; 65 : boost::uuids::uuid sg_uuid_; 66 : uint32_t sg_id_; 67 : AclDBEntryRef egress_acl_; 68 : AclDBEntryRef ingress_acl_; 69 : DISALLOW_COPY_AND_ASSIGN(SgEntry); 70 : }; 71 : 72 : class SgTable : public AgentOperDBTable { 73 : public: 74 : static const uint32_t kInvalidSgId = 0; 75 1 : SgTable(DB *db, const std::string &name) : AgentOperDBTable(db, name) { } 76 2 : virtual ~SgTable() { } 77 : 78 : virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const; 79 0 : virtual size_t Hash(const DBEntry *entry) const {return 0;}; 80 0 : virtual size_t Hash(const DBRequestKey *key) const {return 0;}; 81 : 82 : virtual DBEntry *OperDBAdd(const DBRequest *req); 83 : virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req); 84 : virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req); 85 : 86 : virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, 87 : const boost::uuids::uuid &u); 88 : virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u); 89 : virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, 90 : const std::string &context); 91 : bool ProcessConfig(IFMapNode *node, DBRequest &req, 92 : const boost::uuids::uuid &u); 93 : 94 : static DBTableBase *CreateTable(DB *db, const std::string &name); 95 : static SgTable *GetInstance() {return sg_table_;}; 96 : 97 : private: 98 : static SgTable* sg_table_; 99 : bool ChangeHandler(DBEntry *entry, const DBRequest *req); 100 : DISALLOW_COPY_AND_ASSIGN(SgTable); 101 : }; 102 : 103 : #endif // vnsw_agent_sg_hpp