LCOV - code coverage report
Current view: top level - vnsw/agent/vgw - cfg_vgw.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 13 41 31.7 %
Date: 2026-06-08 02:02:55 Functions: 10 24 41.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : #ifndef vnsw_agent_vgw_cfg_h
       5             : #define vnsw_agent_vgw_cfg_h
       6             : 
       7             : #include <boost/property_tree/ptree.hpp>
       8             : #include <base/address.h>
       9             : 
      10             : class InetInterface;
      11             : 
      12             : // Simple Virtual Gateway config class
      13             : // Supports virtual-gateway for single virtual-network for now.
      14             : class VirtualGatewayConfig {
      15             : public:
      16             :     struct Subnet {
      17           0 :         Subnet() : ip_(0), plen_(0) {}
      18           0 :         Subnet(const Ip4Address &ip, uint8_t plen) : ip_(ip), plen_(plen) {}
      19           0 :         ~Subnet() {}
      20           0 :         bool operator<(const Subnet &rhs) const {
      21           0 :             if (ip_ != rhs.ip_)
      22           0 :                 return ip_ < rhs.ip_;
      23             : 
      24           0 :             return (plen_ < rhs.plen_);
      25             :         }
      26             : 
      27             :         Ip4Address ip_;
      28             :         uint8_t plen_;
      29             :     };
      30             :     typedef std::vector<Subnet> SubnetList;
      31             : 
      32          68 :     VirtualGatewayConfig(const std::string &interface_name) :
      33          68 :         interface_name_(interface_name), vrf_name_(""), subnets_(), routes_(),
      34          68 :         interface_(), version_(0) {}
      35           0 :     VirtualGatewayConfig(const std::string &interface_name,
      36             :                          const std::string &vrf_name,
      37             :                          const SubnetList &subnets,
      38             :                          const SubnetList &routes,
      39           0 :                          uint32_t version) :
      40           0 :         interface_name_(interface_name), vrf_name_(vrf_name),
      41           0 :         subnets_(subnets), routes_(routes), version_(version) {}
      42           0 :     VirtualGatewayConfig(const VirtualGatewayConfig &rhs) :
      43           0 :         interface_name_(rhs.interface_name_), vrf_name_(rhs.vrf_name_),
      44           0 :         subnets_(rhs.subnets_), routes_(rhs.routes_), version_(rhs.version_) {}
      45          86 :     ~VirtualGatewayConfig() {}
      46             : 
      47         351 :     const std::string& interface_name() const { return interface_name_; }
      48         166 :     const std::string& vrf_name() const { return vrf_name_; }
      49          87 :     const SubnetList& subnets() const { return subnets_; }
      50         100 :     const SubnetList& routes() const { return routes_; }
      51           0 :     uint32_t version() const { return version_; }
      52           0 :     void set_subnets(const SubnetList &subnets) const { subnets_ = subnets; }
      53           0 :     void set_routes(const SubnetList &routes) const { routes_ = routes; }
      54           0 :     const InetInterface *get_interface() const { return interface_; }
      55           0 :     void set_interface(InetInterface *intrface) const {
      56           0 :         interface_ = intrface;
      57           0 :     }
      58           0 :     void set_version(uint32_t version) const { version_ = version; }
      59             : 
      60             : private:
      61             :     // Interface connecting gateway to host-os
      62             :     std::string interface_name_;
      63             :     // Public network name
      64             :     std::string vrf_name_;
      65             :     // Vector of subnets
      66             :     mutable SubnetList subnets_;
      67             :     // Vector of routes
      68             :     mutable SubnetList routes_;
      69             :     // Inet interface pointer
      70             :     mutable InetInterface *interface_;
      71             :     // client version number of the entry
      72             :     mutable uint32_t version_;
      73             : };
      74             : 
      75             : struct VirtualGatewayInfo {
      76             :     std::string interface_name_;
      77             :     std::string vrf_name_;
      78             :     VirtualGatewayConfig::SubnetList subnets_;
      79             :     VirtualGatewayConfig::SubnetList routes_;
      80             : 
      81           0 :     VirtualGatewayInfo(const std::string &interfacestr)
      82           0 :         : interface_name_(interfacestr) {}
      83             :     VirtualGatewayInfo(const std::string &interfacestr, const std::string &vrf,
      84             :                        VirtualGatewayConfig::SubnetList &subnets,
      85             :                        VirtualGatewayConfig::SubnetList &routes)
      86             :         : interface_name_(interfacestr), vrf_name_(vrf) {
      87             :         subnets_.swap(subnets);
      88             :         routes_.swap(routes);
      89             :     }
      90             : };
      91             : 
      92             : struct VirtualGatewayData {
      93             :     enum MessageType {
      94             :         Add,
      95             :         Delete,
      96             :         Audit
      97             :     };
      98             : 
      99             :     MessageType message_type_;
     100             :     std::vector<VirtualGatewayInfo> vgw_list_;
     101             :     uint32_t version_;
     102             : 
     103           0 :     VirtualGatewayData(MessageType type, std::vector<VirtualGatewayInfo> &list,
     104             :                        uint32_t version)
     105           0 :         : message_type_(type), version_(version) {
     106           0 :         vgw_list_.swap(list);
     107           0 :     }
     108             :     VirtualGatewayData(MessageType type, uint32_t version)
     109             :         : message_type_(type), version_(version) {}
     110             : };
     111             : 
     112             : class VirtualGatewayConfigTable {
     113             : public:
     114             :     struct VirtualGatewayConfigCompare {
     115         150 :         bool operator()(const VirtualGatewayConfig &cfg1,
     116             :                         const VirtualGatewayConfig &cfg2) const {
     117         150 :             return cfg1.interface_name() < cfg2.interface_name();
     118             :         }
     119             :     };
     120             : 
     121             :     typedef std::set<VirtualGatewayConfig, VirtualGatewayConfigCompare> Table;
     122             : 
     123           1 :     VirtualGatewayConfigTable() : agent_(NULL), work_queue_(nullptr) { }
     124           1 :     ~VirtualGatewayConfigTable() { }
     125             : 
     126             :     void InitFromConfig(const boost::property_tree::ptree pt);
     127             :     void InitDone(Agent *agent);
     128             :     void Shutdown();
     129          96 :     const Table &table() const {return table_;}
     130             : 
     131             :     void Enqueue(boost::shared_ptr<VirtualGatewayData> request);
     132             :     bool ProcessRequest(boost::shared_ptr<VirtualGatewayData> request);
     133             : 
     134             : private:
     135             :     void BuildSubnetList(const std::string &subnets,
     136             :                          VirtualGatewayConfig::SubnetList &results);
     137             :     bool AddVgw(VirtualGatewayInfo &vgw, uint32_t version);
     138             :     bool DeleteVgw(const std::string &interface_name);
     139             :     void DeleteVgw(Table::iterator it);
     140             :     void DeleteAllOldVersionVgw(uint32_t version);
     141             :     bool FindChange(const VirtualGatewayConfig::SubnetList &old_subnets,
     142             :                     const VirtualGatewayConfig::SubnetList &new_subnets,
     143             :                     VirtualGatewayConfig::SubnetList &add_list,
     144             :                     VirtualGatewayConfig::SubnetList &del_list);
     145             : 
     146             :     Agent *agent_;
     147             :     Table table_;
     148             :     std::unique_ptr< WorkQueue<boost::shared_ptr<VirtualGatewayData> > > work_queue_;
     149             :     DISALLOW_COPY_AND_ASSIGN(VirtualGatewayConfigTable);
     150             : };
     151             : 
     152             : #endif //vnsw_agent_vgw_cfg_h

Generated by: LCOV version 1.14