Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __dns_oper_h__ 7 : #define __dns_oper_h__ 8 : 9 : #include <list> 10 : #include <map> 11 : #include <set> 12 : 13 : #include <boost/function.hpp> 14 : #include <boost/shared_ptr.hpp> 15 : #include <boost/scoped_ptr.hpp> 16 : 17 : #include "ifmap/ifmap_link.h" 18 : #include "ifmap/ifmap_table.h" 19 : #include "ifmap/ifmap_node_proxy.h" 20 : #include "vnc_cfg_types.h" 21 : #include "cmn/dns_types.h" 22 : 23 : class IFMapNodeProxy; 24 : struct IpamConfig; 25 : struct VirtualDnsConfig; 26 : struct VirtualDnsRecordConfig; 27 : 28 : struct DnsConfig { 29 : std::string name_; 30 : mutable uint8_t flags_; 31 : 32 : enum DnsConfigEvent { 33 : CFG_ADD, 34 : CFG_CHANGE, 35 : CFG_DELETE, 36 : }; 37 : 38 : enum DnsConfigFlags { 39 : DnsConfigValid = 1 << 0, // DnsManager received the config 40 : DnsConfigNotified = 1 << 1, // DnsManager installed the config 41 : DnsConfigDeleteMarked = 1 << 2, // Config is deleted 42 : DnsConfigErrorLogged = 1 << 3, // Config error logged 43 : }; 44 : 45 60 : void MarkValid() { flags_ |= DnsConfigValid; } 46 501 : bool IsValid() const { return (flags_ & DnsConfigValid); } 47 0 : void ClearValid() { flags_ &= ~DnsConfigValid; } 48 44 : void MarkNotified() const { flags_ |= DnsConfigNotified; } 49 382 : bool IsNotified() const { return (flags_ & DnsConfigNotified); } 50 105 : void ClearNotified() const { flags_ &= ~DnsConfigNotified; } 51 64 : void MarkDelete() { flags_ |= DnsConfigDeleteMarked; } 52 443 : bool IsDeleted() const { return (flags_ & DnsConfigDeleteMarked); } 53 5 : void ClearDelete() { flags_ &= ~DnsConfigDeleteMarked; } 54 0 : void MarkErrorLogged() { flags_ |= DnsConfigErrorLogged; } 55 0 : bool IsErrorLogged() const { return (flags_ & DnsConfigErrorLogged); } 56 : 57 59 : DnsConfig(const std::string &name) : name_(name), flags_(0) {} 58 953 : const std::string &GetName() const { return name_; } 59 : 60 : typedef boost::function<void(const DnsConfig *, 61 : DnsConfig::DnsConfigEvent)> Callback; 62 : typedef boost::function<void(const Subnet &, const VirtualDnsConfig *, 63 : DnsConfig::DnsConfigEvent)> ZoneCallback; 64 : static Callback VdnsCallback; 65 : static Callback VdnsRecordCallback; 66 : static ZoneCallback VdnsZoneCallback; 67 : static const std::string EventString[]; 68 72 : static const std::string &ToEventString(DnsConfigEvent ev) { 69 72 : return EventString[ev]; 70 : } 71 : 72 : }; 73 : 74 : struct VnniConfig : public DnsConfig { 75 : typedef std::map<std::string, VnniConfig *> DataMap; 76 : typedef std::pair<std::string, VnniConfig *> DataPair; 77 : 78 : Subnets subnets_; 79 : IpamConfig *ipam_; 80 : static DataMap vnni_config_; 81 : 82 : VnniConfig(IFMapNode *node); 83 : ~VnniConfig(); 84 : bool operator <(VnniConfig &rhs) const { 85 : return (GetName() < rhs.GetName()); 86 : } 87 : 88 : void OnAdd(IFMapNode *node); 89 : void OnDelete(); 90 : void OnChange(IFMapNode *node); 91 : 92 : void UpdateIpam(IFMapNode *node); 93 151 : Subnets &GetSubnets() { return subnets_; } 94 : void FindSubnets(IFMapNode *node, Subnets &subnets); 95 : bool NotifySubnets(Subnets &old_nets, Subnets &new_nets, 96 : VirtualDnsConfig *vdns); 97 : 98 : static VnniConfig *Find(std::string name); 99 : }; 100 : 101 : struct IpamConfig : public DnsConfig { 102 : typedef std::set<VnniConfig *> VnniList; 103 : typedef std::map<std::string, IpamConfig *> DataMap; 104 : typedef std::pair<std::string, IpamConfig *> DataPair; 105 : 106 : autogen::IpamType rec_; 107 : VirtualDnsConfig *virtual_dns_; 108 : VnniList vnni_list_; 109 : static DataMap ipam_config_; 110 : 111 : IpamConfig(IFMapNode *node); 112 : ~IpamConfig(); 113 : 114 : void OnAdd(IFMapNode *node); 115 : void OnDelete(); 116 : void OnChange(IFMapNode *node); 117 : 118 : void Add(VirtualDnsConfig *vdns); 119 : void Delete(); 120 : void Notify(DnsConfig::DnsConfigEvent ev); 121 : 122 : bool GetObject(IFMapNode *node, autogen::IpamType &data); 123 16 : void AddVnni(VnniConfig *vnni) { vnni_list_.insert(vnni); } 124 7 : void DelVnni(VnniConfig *vnni) { vnni_list_.erase(vnni); } 125 47 : std::string &GetVirtualDnsName() { 126 47 : return rec_.ipam_dns_server.virtual_dns_server_name; 127 : } 128 153 : VirtualDnsConfig *GetVirtualDns() { return virtual_dns_; } 129 97 : const VnniList &GetVnniList() const { return vnni_list_; } 130 : 131 : void Trace(const std::string &ev); 132 : 133 : static IpamConfig *Find(std::string name); 134 : static void AssociateIpamVdns(VirtualDnsConfig *vdns); 135 : }; 136 : 137 : struct VirtualDnsConfig : public DnsConfig { 138 : typedef std::set<IpamConfig *> IpamList; 139 : typedef std::set<VirtualDnsRecordConfig *> VDnsRec; 140 : typedef std::map<std::string, VirtualDnsConfig *> DataMap; 141 : typedef std::pair<std::string, VirtualDnsConfig *> DataPair; 142 : 143 : autogen::VirtualDnsType rec_; 144 : autogen::VirtualDnsType old_rec_; 145 : VDnsRec virtual_dns_records_; 146 : IpamList ipams_; 147 : static DataMap virt_dns_config_; 148 : 149 : VirtualDnsConfig(IFMapNode *node); 150 : VirtualDnsConfig(const std::string &name); 151 : ~VirtualDnsConfig(); 152 : void OnAdd(IFMapNode *node); 153 : void OnDelete(); 154 : void OnChange(IFMapNode *node); 155 : 156 : void AddRecord(VirtualDnsRecordConfig *record); 157 : void DelRecord(VirtualDnsRecordConfig *record); 158 11 : void AddIpam(IpamConfig *ipam) { ipams_.insert(ipam); } 159 11 : void DelIpam(IpamConfig *ipam) { ipams_.erase(ipam); } 160 159 : const IpamList &GetIpamList() const { return ipams_; } 161 83 : autogen::VirtualDnsType GetVDns() const { return rec_; } 162 : 163 : bool GetObject(IFMapNode *node, autogen::VirtualDnsType &data); 164 : bool GetSubnet(const IpAddress &addr, Subnet &subnet) const; 165 : void NotifyPendingDnsRecords(); 166 : bool HasChanged(); 167 : 168 : void VirtualDnsTrace(VirtualDnsTraceData &rec); 169 : void Trace(const std::string &ev); 170 : 171 : std::string GetViewName() const; 172 : std::string GetNextDns() const; 173 519 : std::string GetDomainName() const { return rec_.domain_name; } 174 16 : std::string GetOldDomainName() const { return old_rec_.domain_name; } 175 193 : std::string GetRecordOrder() const { return rec_.record_order; } 176 427 : bool IsExternalVisible() const { return rec_.external_visible; } 177 496 : bool IsReverseResolutionEnabled() const { return rec_.reverse_resolution; } 178 8 : bool HasReverseResolutionChanged() const { 179 8 : return rec_.reverse_resolution != old_rec_.reverse_resolution; 180 : } 181 : bool DynamicUpdatesEnabled() const; 182 126 : int GetTtl() const { return rec_.default_ttl_seconds; } 183 65 : int GetNegativeCacheTtl() const { return rec_.soa_record.negative_cache_ttl_seconds; } 184 : 185 : static VirtualDnsConfig *Find(std::string name); 186 72 : static DataMap &GetVirtualDnsMap() { return virt_dns_config_; } 187 : }; 188 : 189 : struct VirtualDnsRecordConfig : public DnsConfig { 190 : typedef std::map<std::string, VirtualDnsRecordConfig *> DataMap; 191 : typedef std::pair<std::string, VirtualDnsRecordConfig *> DataPair; 192 : 193 : enum Source { 194 : Config, 195 : Agent 196 : }; 197 : 198 : DnsItem rec_; 199 : VirtualDnsConfig *virt_dns_; 200 : std::string virtual_dns_name_; 201 : Source src_; 202 : static DataMap virt_dns_rec_config_; 203 : 204 : VirtualDnsRecordConfig(IFMapNode *node); 205 : VirtualDnsRecordConfig(const std::string &name, 206 : const std::string &vdns_name, const DnsItem &item); 207 : ~VirtualDnsRecordConfig(); 208 : void OnAdd(IFMapNode *node = NULL); 209 : void OnDelete(); 210 : void OnChange(IFMapNode *node); 211 : void OnChange(const DnsItem &new_rec); 212 : bool UpdateVdns(IFMapNode *node); 213 : 214 : bool CanNotify(); 215 : bool HasChanged(DnsItem &rhs); 216 : bool OnlyTtlChange(DnsItem &rhs); 217 : autogen::VirtualDnsType GetVDns() const; 218 106 : const DnsItem &GetRecord() const { return rec_; } 219 : std::string GetViewName() const; 220 115 : VirtualDnsConfig *GetVirtualDns() const { return virt_dns_; } 221 : bool GetObject(IFMapNode *node, DnsItem &item); 222 : 223 : void VirtualDnsRecordTrace(VirtualDnsRecordTraceData &rec); 224 : void Trace(const std::string &ev); 225 : 226 : static VirtualDnsRecordConfig *Find(std::string name); 227 : static void UpdateVirtualDns(VirtualDnsConfig *vdns); 228 : }; 229 : 230 : struct GlobalQosConfig : public DnsConfig { 231 : GlobalQosConfig(IFMapNode *node); 232 : ~GlobalQosConfig(); 233 : 234 : void OnAdd(IFMapNode *node); 235 : void OnDelete(); 236 : void OnChange(IFMapNode *node); 237 : void SetDscp(); 238 : static GlobalQosConfig *Find(const std::string &name); 239 : 240 : uint8_t control_dscp_; 241 : uint8_t analytics_dscp_; 242 : static GlobalQosConfig *singleton_; 243 : }; 244 : #endif // __dns_oper_h__