Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __AGENT_OPER_SECURITY_LOGGING_OBJECT_H 6 : #define __AGENT_OPER_SECURITY_LOGGING_OBJECT_H 7 : 8 : #include <cmn/agent.h> 9 : #include <oper_db.h> 10 : #include <cmn/index_vector.h> 11 : 12 : class Agent; 13 : class DB; 14 : 15 : struct SloRuleInfo { 16 : boost::uuids::uuid uuid_; 17 : int rate_; 18 0 : SloRuleInfo(const boost::uuids::uuid &u, int rate) : uuid_(u), rate_(rate) { 19 0 : } 20 0 : bool operator==(const SloRuleInfo &rhs) const { 21 0 : if (uuid_ == rhs.uuid_) { 22 0 : return rate_ == rhs.rate_; 23 : } 24 0 : return false; 25 : } 26 : }; 27 : 28 : typedef std::vector<SloRuleInfo> SloRuleList; 29 : struct SecurityLoggingObjectKey : public AgentOperDBKey { 30 : public: 31 0 : SecurityLoggingObjectKey(const boost::uuids::uuid &uuid): 32 0 : uuid_(uuid) {} 33 : 34 : SecurityLoggingObjectKey(const SecurityLoggingObjectKey &rhs): 35 : uuid_(rhs.uuid_) {} 36 : 37 : bool IsLess(const SecurityLoggingObjectKey &rhs) const { 38 : return uuid_ < rhs.uuid_; 39 : } 40 : 41 : boost::uuids::uuid uuid_; 42 : }; 43 : 44 : struct SecurityLoggingObjectData : public AgentOperDBData { 45 : public: 46 0 : SecurityLoggingObjectData(const Agent *agent, IFMapNode *node, 47 : const std::vector<autogen::SecurityLoggingObjectRuleEntryType> &lst, 48 0 : const int &rate, const bool status, const std::string &name): 49 0 : AgentOperDBData(agent, node), rules_(lst), status_(status), rate_(rate), name_(name), 50 0 : firewall_policy_list_(), firewall_rule_list_() {} 51 : 52 : std::vector<autogen::SecurityLoggingObjectRuleEntryType> rules_; 53 : bool status_; 54 : int rate_; 55 : std::string name_; 56 : SloRuleList firewall_policy_list_; 57 : SloRuleList firewall_rule_list_; 58 : }; 59 : 60 : class SecurityLoggingObject: 61 : AgentRefCount<SecurityLoggingObject>, public AgentOperDBEntry { 62 : public: 63 : SecurityLoggingObject(const boost::uuids::uuid &uuid); 64 : virtual ~SecurityLoggingObject(); 65 : 66 : KeyPtr GetDBRequestKey() const; 67 : virtual void SetKey(const DBRequestKey *key); 68 : std::string ToString() const; 69 : virtual bool IsLess(const DBEntry &rhs) const; 70 : virtual bool DBEntrySandesh(Sandesh *resp, std::string &name) const; 71 : virtual bool Change(const DBRequest *req); 72 : bool IsEqual(const std::vector<autogen::SecurityLoggingObjectRuleEntryType> 73 : &lhs, 74 : const std::vector<autogen::SecurityLoggingObjectRuleEntryType> 75 : &rhs) const; 76 : 77 0 : uint32_t GetRefCount() const { 78 0 : return AgentRefCount<SecurityLoggingObject>::GetRefCount(); 79 : } 80 : 81 0 : bool status() const { 82 0 : return status_; 83 : } 84 0 : const boost::uuids::uuid& uuid() const { 85 0 : return uuid_; 86 : } 87 0 : const std::vector<autogen::SecurityLoggingObjectRuleEntryType> & rules() 88 : const { 89 0 : return rules_; 90 : } 91 0 : int rate() const { return rate_; } 92 : const std::string& name() const { 93 : return name_; 94 : } 95 0 : SloRuleList& firewall_policy_list() { return firewall_policy_list_;} 96 0 : SloRuleList& firewall_rule_list() { return firewall_rule_list_;} 97 : 98 : private: 99 : bool status_; 100 : boost::uuids::uuid uuid_; 101 : std::vector<autogen::SecurityLoggingObjectRuleEntryType> rules_; 102 : int rate_; 103 : std::string name_; 104 : SloRuleList firewall_policy_list_; 105 : SloRuleList firewall_rule_list_; 106 : DISALLOW_COPY_AND_ASSIGN(SecurityLoggingObject); 107 : }; 108 : 109 : class SecurityLoggingObjectTable : public AgentOperDBTable { 110 : public: 111 : SecurityLoggingObjectTable(Agent *agent, DB *db, const std::string &name); 112 : virtual ~SecurityLoggingObjectTable(); 113 : 114 : static DBTableBase *CreateTable(Agent *agent, DB *db, 115 : const std::string &name); 116 : virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const; 117 : virtual DBEntry *OperDBAdd(const DBRequest *req); 118 : virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req); 119 : virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req); 120 : virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, 121 : const boost::uuids::uuid &u); 122 : virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u); 123 : bool ProcessConfig(IFMapNode *node, DBRequest &req, 124 : const boost::uuids::uuid &u); 125 : virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, 126 : const std::string &context); 127 : 128 : private: 129 : SecurityLoggingObjectData* BuildData(IFMapNode *node) const; 130 : DISALLOW_COPY_AND_ASSIGN(SecurityLoggingObjectTable); 131 : }; 132 : #endif