LCOV - code coverage report
Current view: top level - dns/cfg - dns_config.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 14 14 100.0 %
Date: 2026-11-09 02:10:49 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14