Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __DNS_CONFIG_H__ 6 : #define __DNS_CONFIG_H__ 7 : 8 : #include <list> 9 : #include <map> 10 : #include <set> 11 : 12 : #include <boost/function.hpp> 13 : #include <boost/shared_ptr.hpp> 14 : #include <boost/scoped_ptr.hpp> 15 : #include <boost/ptr_container/ptr_map.hpp> 16 : 17 : #include "base/util.h" 18 : #include "base/queue_task.h" 19 : #include "base/task_trigger.h" 20 : #include "ifmap/ifmap_link.h" 21 : #include "ifmap/ifmap_table.h" 22 : #include "ifmap/ifmap_node_proxy.h" 23 : #include "vnc_cfg_types.h" 24 : #include "sandesh/sandesh_trace.h" 25 : #include "cmn/dns_types.h" 26 : 27 : class ConfigListener; 28 : class DB; 29 : class DBGraph; 30 : class IFMapNodeProxy; 31 : 32 : extern SandeshTraceBufferPtr DnsConfigTraceBuf; 33 : 34 : #define DNS_TRACE(Obj, ...) \ 35 : do { \ 36 : Obj::TraceMsg(DnsConfigTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \ 37 : } while (false) 38 : 39 : typedef boost::shared_ptr<IFMapNodeProxy> IFMapNodeProxyRef; 40 : 41 : struct ConfigDelta { 42 : ConfigDelta(); 43 : ConfigDelta(const ConfigDelta &rhs); 44 : ~ConfigDelta(); 45 : std::string id_type; 46 : std::string id_name; 47 : IFMapNodeProxyRef node; 48 : IFMapObjectRef obj; 49 : }; 50 : 51 : struct DnsConfigData { 52 : typedef std::map<std::string, IFMapNodeProxyRef> DataMap; 53 : typedef std::pair<std::string, IFMapNodeProxyRef> DataPair; 54 : 55 : DataMap data_; 56 : 57 58 : void Add(std::string name, IFMapNodeProxyRef node) { 58 58 : data_.insert(DataPair(name, node)); 59 58 : } 60 : 61 58 : void Del(std::string name) { 62 58 : data_.erase(name); 63 58 : } 64 : 65 171 : IFMapNodeProxy *Find(std::string name) { 66 171 : DataMap::iterator iter = data_.find(name); 67 171 : if (iter != data_.end()) 68 113 : return iter->second.get(); 69 58 : return NULL; 70 : } 71 : }; 72 : 73 : class DnsConfigManager { 74 : public: 75 : static const int kConfigTaskInstanceId = 0; 76 : enum EventType { 77 : CFG_NONE, 78 : CFG_ADD, 79 : CFG_CHANGE, 80 : CFG_DELETE 81 : }; 82 : static const std::string EventString[]; 83 : static const char *config_types[]; 84 : static uint32_t config_types_size; 85 : typedef boost::function<void(IFMapNodeProxy *, 86 : const std::string&, EventType)> Observer; 87 : struct Observers { 88 : Observer virtual_dns; 89 : Observer virtual_dns_record; 90 : Observer ipam; 91 : Observer vnni; 92 : Observer global_qos; 93 : }; 94 : 95 : DnsConfigManager(); 96 : virtual ~DnsConfigManager(); 97 : void Initialize(DB *db, DBGraph *db_graph); 98 15 : void RegisterObservers(const Observers &obs) { obs_ = obs; } 99 : 100 379 : DB *database() { return db_; } 101 620 : DBGraph *graph() { return db_graph_; } 102 : 103 : void OnChange(); 104 : 105 : const std::string &localname() const { return localname_; } 106 : 107 : const std::string &ToEventString(EventType ev) { return EventString[ev]; } 108 : void Terminate(); 109 : 110 : IFMapNode *FindTarget(IFMapNode *node, std::string link_name); 111 : IFMapNode *FindTarget(IFMapNode *node, std::string link_name, 112 : std::string node_type); 113 : private: 114 : typedef std::vector<ConfigDelta> ChangeList; 115 : typedef std::map<std::string, 116 : boost::function<void(const ConfigDelta &)> >IdentifierMap; 117 : 118 : void IdentifierMapInit(); 119 : void ProcessChanges(const ChangeList &change_list); 120 : void ProcessNetworkIpam(const ConfigDelta &delta); 121 : void ProcessVNNI(const ConfigDelta &delta); 122 : void ProcessVirtualDNS(const ConfigDelta &delta); 123 : void ProcessVirtualDNSRecord(const ConfigDelta &delta); 124 : void ProcessGlobalQosConfig(const ConfigDelta &delta); 125 : void ProcessNode(const ConfigDelta &delta, DnsConfigData &config_data, 126 : Observer observer); 127 : 128 : bool ConfigHandler(); 129 : static int config_task_id_; 130 : 131 : DB *db_; 132 : DBGraph *db_graph_; 133 : std::string localname_; 134 : IdentifierMap id_map_; 135 : DnsConfigData ipam_config_; 136 : DnsConfigData vnni_config_; 137 : DnsConfigData virt_dns_config_; 138 : DnsConfigData virt_dns_rec_config_; 139 : DnsConfigData global_qos_config_; 140 : Observers obs_; 141 : TaskTrigger trigger_; 142 : boost::scoped_ptr<ConfigListener> listener_; 143 : DISALLOW_COPY_AND_ASSIGN(DnsConfigManager); 144 : }; 145 : 146 : 147 : #endif // __DNS_CONFIG_H__