LCOV - code coverage report
Current view: top level - vnsw/agent/oper - global_vrouter.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 9 23 39.1 %
Date: 2026-11-09 02:10:49 Functions: 7 15 46.7 %
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 vnsw_agent_global_router_h_
       7             : #define vnsw_agent_global_router_h_
       8             : 
       9             : #include <cmn/agent_cmn.h>
      10             : #include <oper/oper_db.h>
      11             : #include <oper/ecmp_load_balance.h>
      12             : #include <oper/agent_route_walker.h>
      13             : 
      14             : class OperDB;
      15             : class VnEntry;
      16             : class VrfEntry;
      17             : class IFMapNode;
      18             : class AgentRouteResync;
      19             : class AgentRouteEncap;
      20             : class AgentUtXmlFlowThreshold;
      21             : class EcmpLoadBalance;
      22             : class CryptTunnelTable;
      23             : 
      24             : namespace autogen {
      25             :     struct LinklocalServiceEntryType;
      26             :     struct FlowAgingTimeout;
      27             :     class GlobalVrouterConfig;
      28             : }
      29             : 
      30             : struct LinkLocalDBState : DBState {
      31             :     const VrfEntry *vrf_;
      32             :     // set of linklocal addresses added to the VN
      33             :     std::set<IpAddress> addresses_;
      34             : 
      35          66 :     LinkLocalDBState(const VrfEntry *vrf) : DBState(), vrf_(vrf) {}
      36           0 :     void Add(const IpAddress &address) { addresses_.insert(address); }
      37           0 :     void Delete(const IpAddress &address) { addresses_.erase(address); }
      38             : };
      39             : 
      40             : struct PortConfig {
      41           4 :     PortConfig() : port_count(0) {}
      42             : 
      43             :     struct PortRange {
      44           0 :         PortRange(uint16_t start, uint16_t end):
      45           0 :             port_start(start), port_end(end) {}
      46             : 
      47             :         uint16_t port_start;
      48             :         uint16_t port_end;
      49             :     };
      50             : 
      51             :     void Trim();
      52             :     uint16_t port_count;
      53             :     std::vector<PortRange> port_range;
      54             : };
      55             : 
      56             : // Handle Global Vrouter configuration
      57             : class GlobalVrouter : public OperIFMapTable {
      58             : public:
      59             :     enum CryptMode {
      60             :         CRYPT_ALL_TRAFFIC,
      61             :         CRYPT_FLOW,
      62             :         CRYPT_NONE
      63             :     };
      64             :     static const std::string kMetadataService;
      65             :     static const std::string kMetadataService6;
      66             :     static const Ip4Address kLoopBackIp;
      67             :     static const int32_t kDefaultFlowExportRate = 0;
      68             :     static const int32_t kDisableSampling = -1;
      69             : 
      70             :     struct LinkLocalServiceKey {
      71             :         IpAddress linklocal_service_ip;
      72             :         uint16_t   linklocal_service_port;
      73             : 
      74          18 :         LinkLocalServiceKey(const IpAddress &addr, uint16_t port)
      75          18 :             : linklocal_service_ip(addr), linklocal_service_port(port) {}
      76             :         bool operator<(const LinkLocalServiceKey &rhs) const;
      77             :     };
      78             : 
      79             :     // Config data for each linklocal service
      80             :     struct LinkLocalService {
      81             :         std::string linklocal_service_name;
      82             :         std::string ipfabric_dns_service_name;
      83             :         std::vector<Ip4Address>  ipfabric_service_ip;
      84             :         uint16_t                 ipfabric_service_port;
      85             : 
      86             :         LinkLocalService(const std::string &service_name,
      87             :                          const std::string &fabric_dns_name,
      88             :                          const std::vector<Ip4Address> &fabric_ip,
      89             :                          uint16_t fabric_port);
      90             :         bool operator==(const LinkLocalService &rhs) const;
      91             :         bool IsAddressInUse(const Ip4Address &ip) const;
      92             :         DBTable::DBTableWalkRef vn_update_walk_ref_;
      93             :     };
      94             : 
      95             :     struct FlowAgingTimeoutKey {
      96           0 :         FlowAgingTimeoutKey(uint8_t proto, uint16_t port_arg):
      97           0 :             protocol(proto), port(port_arg) { }
      98             :         uint8_t protocol;
      99             :         uint16_t port;
     100             :         bool operator==(const FlowAgingTimeoutKey &rhs) const {
     101             :             return (protocol == rhs.protocol && port == rhs.port);
     102             :         }
     103             : 
     104           0 :         bool operator<(const FlowAgingTimeoutKey &rhs) const {
     105           0 :             if (protocol != rhs.protocol) {
     106           0 :                 return protocol < rhs.protocol;
     107             :             }
     108           0 :             return port < rhs.port;
     109             :         }
     110             :     };
     111             : 
     112             :     typedef std::string CryptTunnelKey;
     113             :     struct CryptTunnel {
     114             :         CryptMode mode;
     115           0 :         CryptTunnel(CryptMode cmode): mode(cmode) {};
     116           0 :         bool operator==(const CryptTunnel &rhs) const {
     117           0 :             return (mode == rhs.mode);
     118             :         }
     119             :         bool operator<(const CryptTunnel &rhs) const {
     120             :             return (mode < rhs.mode);
     121             :         }
     122             :     };
     123             : 
     124             :     // map of linklocal service data, with (ip, port) as key
     125             :     typedef std::map<LinkLocalServiceKey, LinkLocalService> LinkLocalServicesMap;
     126             :     typedef std::pair<LinkLocalServiceKey, LinkLocalService> LinkLocalServicesPair;
     127             : 
     128             :     typedef std::map<CryptTunnelKey, CryptTunnel> CryptTunnelsMap;
     129             :     typedef std::pair<CryptTunnelKey, CryptTunnel> CryptTunnelsPair;
     130             : 
     131             :     typedef std::map<FlowAgingTimeoutKey, uint32_t> FlowAgingTimeoutMap;
     132             :     typedef std::pair<FlowAgingTimeoutKey, uint32_t> FlowAgingTimeoutPair;
     133             : 
     134             :     //Map used to audit for port pool configuration change
     135             :     typedef std::map<uint8_t, PortConfig> ProtocolPortSet;
     136             : 
     137             :     GlobalVrouter(Agent *agent);
     138             :     virtual ~GlobalVrouter();
     139             :     void CreateDBClients();
     140             : 
     141          66 :     const LinkLocalServicesMap &linklocal_services_map() const {
     142          66 :         return linklocal_services_map_;
     143             :     }
     144         114 :     int32_t flow_export_rate() const { return flow_export_rate_; }
     145             : 
     146             :     void ConfigDelete(IFMapNode *node);
     147             :     void ConfigAddChange(IFMapNode *node);
     148             :     void ConfigManagerEnqueue(IFMapNode *node);
     149             : 
     150             :     void GlobalVrouterConfig(IFMapNode *node);
     151             :     void UpdateSLOConfig(IFMapNode *node);
     152             : 
     153             :     /// @brief Get link local service configuration info, for a
     154             :     /// given service name
     155             :     bool FindLinkLocalService(const std::string &service_name,
     156             :         IpAddress *service_ip,
     157             :         uint16_t *service_port,
     158             :         std::string *fabric_hostname,
     159             :         Ip4Address *fabric_ip,
     160             :         uint16_t *fabric_port) const;
     161             : 
     162             :     /// @brief Get link local service info for a given linklocal
     163             :     /// service <ip, port>
     164             :     bool FindLinkLocalService(const IpAddress &service_ip,
     165             :         uint16_t service_port,
     166             :         std::string *service_name,
     167             :         Ip4Address *fabric_ip,
     168             :         uint16_t *fabric_port) const;
     169             : 
     170             :     /// @brief Get link local services, for a given service name
     171             :     bool FindLinkLocalService(const std::string &service_name,
     172             :         std::set<IpAddress> *service_ip) const;
     173             : 
     174             :     /// @brief Get link local services info for a given linklocal
     175             :     /// service <ip>
     176             :     bool FindLinkLocalService(const IpAddress &service_ip,
     177             :         std::set<std::string> *service_names) const;
     178             : 
     179             :     void LinkLocalRouteUpdate(const std::vector<Ip4Address> &addr_list);
     180             :     bool IsAddressInUse(const Ip4Address &ip) const;
     181             :     bool IsLinkLocalAddressInUse(const IpAddress &ip) const;
     182         651 :     Agent::ForwardingMode forwarding_mode() const {return forwarding_mode_;}
     183           0 :     boost::uuids::uuid slo_uuid() const {return slo_uuid_;}
     184             : 
     185             :     uint64_t PendingFabricDnsRequests() const;
     186             :     void ResyncRoutes();
     187             :     const EcmpLoadBalance &ecmp_load_balance() const;
     188          62 :     bool configured() const { return configured_; }
     189             : 
     190             :     friend class AgentUtXmlFlowThreshold;
     191             : private:
     192             :     class FabricDnsResolver;
     193             :     class LinkLocalRouteManager;
     194             :     typedef std::vector<autogen::LinklocalServiceEntryType> LinkLocalServiceList;
     195             :     typedef std::vector<autogen::EncryptionTunnelEndpoint> EncryptionTunnelEndpointList;
     196             :     typedef std::vector<autogen::FlowAgingTimeout> FlowAgingTimeoutList;
     197             : 
     198             :     void UpdateLinkLocalServiceConfig(const LinkLocalServiceList &linklocal_list);
     199             :     void DeleteLinkLocalServiceConfig();
     200             :     bool ChangeNotify(LinkLocalServicesMap *old_value,
     201             :                       LinkLocalServicesMap *new_value);
     202             :     void AddLinkLocalService(const LinkLocalServicesMap::iterator &it);
     203             :     void DeleteLinkLocalService(const LinkLocalServicesMap::iterator &it);
     204             :     void ChangeLinkLocalService(const LinkLocalServicesMap::iterator &old_it,
     205             :                                 const LinkLocalServicesMap::iterator &new_it);
     206             : 
     207             :     bool IsVrouterPresentCryptTunnelConfig(const EncryptionTunnelEndpointList &endpoint_list);
     208             :     void UpdateCryptTunnelEndpointConfig(const EncryptionTunnelEndpointList &endpoint_list,
     209             :                                          const std::string encrypt_mode_str);
     210             :     void DeleteCryptTunnelEndpointConfig();
     211             :     bool ChangeNotifyCryptTunnels(CryptTunnelsMap *old_value,
     212             :                                   CryptTunnelsMap *new_value);
     213             :     void AddCryptTunnelEndpoint(const CryptTunnelsMap::iterator &it);
     214             :     void DeleteCryptTunnelEndpoint(const CryptTunnelsMap::iterator &it);
     215             :     void ChangeCryptTunnelEndpoint(const CryptTunnelsMap::iterator &old_it,
     216             :                                    const CryptTunnelsMap::iterator &new_it);
     217             : 
     218             :     void UpdateFlowAging(autogen::GlobalVrouterConfig *cfg);
     219             :     void DeleteFlowAging();
     220             : 
     221             :     void UpdatePortConfig(autogen::GlobalVrouterConfig *cfg);
     222             :     void DeletePortConfig();
     223             : 
     224             :     /// Reads configuration flow global flow limits
     225             :     void ReadFlowsLimits(const autogen::GlobalVrouterConfig &cfg);
     226             : 
     227             :     LinkLocalServicesMap linklocal_services_map_;
     228             :     CryptTunnelsMap crypt_tunnels_map_;
     229             :     CryptMode crypt_mode_;
     230             :     boost::scoped_ptr<LinkLocalRouteManager> linklocal_route_mgr_;
     231             :     boost::scoped_ptr<FabricDnsResolver> fabric_dns_resolver_;
     232             :     AgentRouteWalkerPtr agent_route_resync_walker_;
     233             :     Agent::ForwardingMode forwarding_mode_;
     234             :     int32_t flow_export_rate_;
     235             :     FlowAgingTimeoutMap flow_aging_timeout_map_;
     236             :     ProtocolPortSet protocol_port_set_;
     237             :     EcmpLoadBalance ecmp_load_balance_;
     238             :     bool configured_; //true when global-vrouter-config stanza is present
     239             :     boost::uuids::uuid slo_uuid_; //SLO associated with global-vrouter
     240             : };
     241             : 
     242             : #endif // vnsw_agent_global_router_h_

Generated by: LCOV version 1.14