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