Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __AGENT_OPER_QOS_CONFIG_H 6 : #define __AGENT_OPER_QOS_CONFIG_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 : class AgentQosConfigTable; 15 : struct AgentQosConfigData; 16 : 17 : struct AgentQosConfigKey : public AgentOperDBKey { 18 228 : AgentQosConfigKey(const boost::uuids::uuid &uuid): 19 228 : uuid_(uuid) {} 20 : 21 : AgentQosConfigKey(const AgentQosConfigKey &rhs): 22 : uuid_(rhs.uuid_) {} 23 : 24 : bool IsLess(const AgentQosConfigKey &rhs) const { 25 : return uuid_ < rhs.uuid_; 26 : } 27 : 28 : boost::uuids::uuid uuid_; 29 : }; 30 : 31 : typedef std::pair<uint32_t, uint32_t> AgentQosIdForwardingClassPair; 32 : typedef std::map<uint32_t, uint32_t> AgentQosIdForwardingClassMap; 33 : 34 : class AgentQosConfig : 35 : AgentRefCount<AgentQosConfig>, public AgentOperDBEntry { 36 : public: 37 : static const uint32_t kDefaultQosMsgSize = 4098; 38 : typedef enum { 39 : VHOST, 40 : FABRIC, 41 : DEFAULT 42 : } Type; 43 : typedef std::pair<uint32_t, uint32_t> QosIdForwardingClassPair; 44 : typedef std::map<uint32_t, uint32_t> QosIdForwardingClassMap; 45 : 46 : AgentQosConfig(const boost::uuids::uuid uuid); 47 : virtual ~AgentQosConfig(); 48 : 49 : KeyPtr GetDBRequestKey() const; 50 : std::string ToString() const; 51 : virtual bool IsLess(const DBEntry &rhs) const; 52 : virtual bool DBEntrySandesh(Sandesh *resp, std::string &name) const; 53 : 54 : virtual bool Change(const DBRequest *req); 55 : virtual void Delete(const DBRequest *req); 56 : virtual void SetKey(const DBRequestKey *key); 57 : 58 0 : virtual bool DeleteOnZeroRefCount() const { 59 0 : return false; 60 : } 61 0 : virtual void OnZeroRefCount() {}; 62 0 : uint32_t GetRefCount() const { 63 0 : return AgentRefCount<AgentQosConfig>::GetRefCount(); 64 : } 65 : 66 0 : boost::uuids::uuid uuid() const { 67 0 : return uuid_; 68 : } 69 : 70 0 : void set_id(uint32_t id) { 71 0 : id_ = id; 72 0 : } 73 0 : uint32_t id() const { 74 0 : return id_; 75 : } 76 : 77 0 : std::string name() const { 78 0 : return name_; 79 : } 80 : 81 37 : const QosIdForwardingClassMap& dscp_map() const { 82 37 : return dscp_map_; 83 : } 84 : 85 0 : const QosIdForwardingClassMap& vlan_priority_map() const { 86 0 : return vlan_priority_map_; 87 : } 88 : 89 0 : const QosIdForwardingClassMap& mpls_exp_map() const { 90 0 : return mpls_exp_map_; 91 : } 92 : 93 0 : Type type() const { 94 0 : return type_; 95 : } 96 : 97 0 : uint32_t default_forwarding_class() const { 98 0 : return default_forwarding_class_; 99 : } 100 : 101 : int MsgLen() { return kDefaultQosMsgSize; } 102 : 103 : private: 104 : bool VerifyLinkToGlobalQosConfig(const Agent *agent, 105 : const AgentQosConfigData *data); 106 : void HandleVhostQosConfig(const Agent *agent, 107 : const AgentQosConfigData *data, bool deleted); 108 : void HandleFabricQosConfig(const Agent *agent, 109 : const AgentQosConfigData *data, bool deleted); 110 : void HandleGlobalQosConfig(const AgentQosConfigData *data); 111 : bool HandleQosForwardingMapChange(const Agent *agent, 112 : QosIdForwardingClassMap &map, 113 : const AgentQosIdForwardingClassMap &data_map); 114 : boost::uuids::uuid uuid_; 115 : std::string name_; 116 : uint32_t id_; 117 : QosIdForwardingClassMap dscp_map_; 118 : QosIdForwardingClassMap vlan_priority_map_; 119 : QosIdForwardingClassMap mpls_exp_map_; 120 : Type type_; 121 : uint32_t default_forwarding_class_; 122 : DISALLOW_COPY_AND_ASSIGN(AgentQosConfig); 123 : }; 124 : 125 : struct AgentQosConfigData : public AgentOperDBData { 126 0 : AgentQosConfigData(const Agent *agent, IFMapNode *node) : 127 0 : AgentOperDBData(agent, node), default_forwarding_class_(0) {} 128 : 129 : std::string name_; 130 : AgentQosIdForwardingClassMap dscp_map_; 131 : AgentQosIdForwardingClassMap vlan_priority_map_; 132 : AgentQosIdForwardingClassMap mpls_exp_map_; 133 : AgentQosConfig::Type type_; 134 : uint32_t default_forwarding_class_; 135 : }; 136 : 137 : class AgentQosConfigTable : public AgentOperDBTable { 138 : public: 139 : typedef std::map<std::string, AgentQosConfig*> AgentQosConfigNameMap; 140 : typedef std::pair<std::string, AgentQosConfig*> AgentQosConfigNamePair; 141 : 142 : AgentQosConfigTable(Agent *agent, DB *db, const std::string &name); 143 : virtual ~AgentQosConfigTable(); 144 : static const uint32_t kInvalidIndex=0xFFFF; 145 : static const uint32_t kDscpEntries = 63; 146 : static const uint32_t k801pEntries = 7; 147 : static const uint32_t kExpEntries = 7; 148 : 149 : 150 : static DBTableBase *CreateTable(Agent *agent, DB *db, 151 : const std::string &name); 152 : 153 : virtual std::unique_ptr<DBEntry> AllocEntry(const DBRequestKey *k) const; 154 : 155 0 : virtual size_t Hash(const DBEntry *entry) const {return 0;} 156 228 : virtual size_t Hash(const DBRequestKey *key) const {return 0;} 157 : 158 : virtual DBEntry *OperDBAdd(const DBRequest *req); 159 : virtual bool OperDBOnChange(DBEntry *entry, const DBRequest *req); 160 : virtual bool OperDBDelete(DBEntry *entry, const DBRequest *req); 161 : virtual bool OperDBResync(DBEntry *entry, const DBRequest *req); 162 : 163 : virtual bool IFNodeToReq(IFMapNode *node, DBRequest &req, 164 : const boost::uuids::uuid &u); 165 : virtual bool IFNodeToUuid(IFMapNode *node, boost::uuids::uuid &u); 166 : virtual bool ProcessConfig(IFMapNode *node, DBRequest &req, 167 : const boost::uuids::uuid &u); 168 : AgentQosConfigData* BuildData(IFMapNode *node); 169 : void ReleaseIndex(AgentQosConfig *qc); 170 : virtual AgentSandeshPtr GetAgentSandesh(const AgentSandeshArguments *args, 171 : const std::string &context); 172 : 173 12 : const AgentQosConfig* FindByName(const std::string &name) { 174 12 : AgentQosConfigNameMap::const_iterator it = name_map_.find(name); 175 12 : if (it == name_map_.end()) { 176 8 : return NULL; 177 : } 178 4 : return it->second; 179 : } 180 : 181 0 : const AgentQosConfig* FindByIndex(uint32_t idx) const { 182 0 : return index_table_.At(idx); 183 : } 184 : 185 0 : void EraseFabricQosConfig(const boost::uuids::uuid &uuid) { 186 0 : fabric_qos_config_uuids_.erase(uuid); 187 0 : } 188 : 189 0 : void InsertFabricQosConfig(const boost::uuids::uuid &uuid) { 190 0 : fabric_qos_config_uuids_.insert(uuid); 191 0 : } 192 : 193 0 : const boost::uuids::uuid GetActiveFabricQosConfig() { 194 : std::set<boost::uuids::uuid>::const_iterator it = 195 0 : fabric_qos_config_uuids_.begin(); 196 0 : if (it == fabric_qos_config_uuids_.end()) { 197 0 : return boost::uuids::nil_uuid(); 198 : } 199 0 : return *it; 200 : } 201 : 202 0 : void EraseVhostQosConfig(const boost::uuids::uuid &uuid) { 203 0 : vhost_qos_config_uuids_.erase(uuid); 204 0 : } 205 : 206 0 : void InsertVhostQosConfig(const boost::uuids::uuid &uuid) { 207 0 : vhost_qos_config_uuids_.insert(uuid); 208 0 : } 209 : 210 0 : const boost::uuids::uuid GetActiveVhostQosConfig() { 211 : std::set<boost::uuids::uuid>::const_iterator it = 212 0 : vhost_qos_config_uuids_.begin(); 213 0 : if (it == vhost_qos_config_uuids_.end()) { 214 0 : return boost::uuids::nil_uuid(); 215 : } 216 0 : return *it; 217 : } 218 : private: 219 : AgentQosConfigNameMap name_map_; 220 : std::set<boost::uuids::uuid> vhost_qos_config_uuids_; 221 : std::set<boost::uuids::uuid> fabric_qos_config_uuids_; 222 : IndexVector<AgentQosConfig *> index_table_; 223 : DISALLOW_COPY_AND_ASSIGN(AgentQosConfigTable); 224 : }; 225 : #endif