OpenSDN source code
metadata_proxy.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_metadata_proxy_h_
7 #define vnsw_agent_metadata_proxy_h_
8 
9 #include <map>
10 #include <mutex>
11 
13 #include "http/http_session.h"
14 #include "oper/vm_interface.h"
15 
16 class MetadataServer;
17 class MetadataClient;
18 
20 public:
21  struct SessionData {
22  SessionData(HttpConnection *c, bool conn_close)
23  : conn(c), content_len(0), data_sent(0),
24  close_req(conn_close), header_end(false) {}
25 
27  uint32_t content_len;
28  uint32_t data_sent;
29  bool close_req;
30  bool header_end;
31  };
32 
33  struct MetadataStats {
36 
37  uint32_t requests;
38  uint32_t responses;
39  uint32_t proxy_sessions;
40  uint32_t internal_errors;
41  };
42 
43  typedef std::map<HttpSession *, SessionData> SessionMap;
44  typedef std::pair<HttpSession *, SessionData> SessionPair;
45  typedef std::map<HttpConnection *, HttpSession *> ConnectionSessionMap;
46  typedef std::pair<HttpConnection *, HttpSession *> ConnectionSessionPair;
47  typedef boost::intrusive_ptr<HttpSession> HttpSessionPtr;
48 
49  MetadataProxy(ServicesModule *module, const std::string &secret);
50  virtual ~MetadataProxy();
51  void CloseSessions();
52  void Shutdown();
53 
54  void HandleMetadataRequest(HttpSession *session, const HttpRequest *request);
56  std::string &msg, boost::system::error_code &ec);
57 
60 
61  const MetadataStats &metadatastats() const { return metadata_stats_; }
63 
67  int VhostIndex(const std::string& vhost_name);
68 
74  bool NetlinkGetVhostIp(Ip6Address& vhost_ll_ip);
75 
80  void NetlinkAddVhostNb(const IpAddress& nb_ip, const MacAddress& via_mac);
81 
85  void NetlinkAddInterfaceRoute(const IpAddress& intf_addr);
86 
95  const Ip6Address& ll_ip, const VrfEntry* intf_vrf);
96 
101  void DeleteMetaDataLinkLocalRoute(const VmInterface* vm_intf);
102 
105  const Ip6Address& Ipv6ServiceAddress() const;
106 
108  void InitializeHttp6Server(const VmInterface *vhost0);
109 
112  void AdvertiseVhostRoute();
113 
114 
117  void DeleteVhostRoute();
118 
124  void OnAVrfChange(DBTablePartBase *part, DBEntryBase *e);
125 
135 
143 
146  void RegisterListeners();
147 
152  void UnregisterListeners();
153 
154 private:
156  bool conn_close,
157  std::string *nova_hostname);
158  void CloseServerSession(HttpSession *session);
160  void ErrorClose(HttpSession *sesion, uint16_t error);
161 
163  std::string shared_secret_;
164 
168 
172 
177 
181 
185 
189 
193 
198  std::map<std::string, Ip6Address> ll_ipv6_addresses_;
199 
205 
207 };
208 
209 #endif // vnsw_agent_metadata_proxy_h_
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
int ListenerId
Definition: db_table.h:63
void HandleMetadataResponse(HttpConnection *conn, HttpSessionPtr session, std::string &msg, boost::system::error_code &ec)
DBTableBase::ListenerId fabric_notify_id_
an ID of a listener (callback) that acts when a Fabric Policy VRF entry is modified
DISALLOW_COPY_AND_ASSIGN(MetadataProxy)
MetadataClient * http_client_
std::map< HttpConnection *, HttpSession * > ConnectionSessionMap
void CloseClientSession(HttpConnection *conn)
void NetlinkAddVhostNb(const IpAddress &nb_ip, const MacAddress &via_mac)
Adds a new neighbour (an arp entry) with given IP and MAC addresses.
void ErrorClose(HttpSession *sesion, uint16_t error)
void DeleteVhostRoute()
Deletes the LL route to vhost0 interface in the fabric VRF instance.
DBTableBase::ListenerId vrf_table_notify_id_
an ID of a listener (callback) that acts when the VRF Table is modified
std::pair< HttpConnection *, HttpSession * > ConnectionSessionPair
void RegisterListeners()
Registers callbacks to intercept Agent's events emerging when a VRF entry is modified or an Interface...
const MetadataStats & metadatastats() const
std::map< std::string, Ip6Address > ll_ipv6_addresses_
A correspondence table between a name of a vm interface, which requests a data from the service and t...
void AdvertiseVhostRoute()
Advertises the LL route to vhost0 interface in the fabric VRF instance.
DBTableBase::ListenerId intf_table_notify_id_
an ID of a listener (callback) that acts when an InterfaceTable entry is modified
void AdvertiseMetaDataLinkLocalRoutes(const VmInterface *vm, const Ip6Address &ll_ip, const VrfEntry *intf_vrf)
Advertises routes to a given vm-interface via a given IPv6 address. Routes are announced in the fabri...
void OnAVrfChange(DBTablePartBase *part, DBEntryBase *e)
A callback that is invoked each time when a VRF entry is modified: added, changed or deleted.
MetadataProxy(ServicesModule *module, const std::string &secret)
bool NetlinkGetVhostIp(Ip6Address &vhost_ll_ip)
Adds an IP address specified in vhost_ll_ip to vhost0 interface inet6 addresses.
MetadataStats metadata_stats_
std::string shared_secret_
MetadataServer * http_server6_
A pointer to a HTTP server listening on a IPv6 socket for Metadata requests from tenants / virtual ma...
void OnAnInterfaceChange(DBTablePartBase *part, DBEntryBase *e)
A callback which is invoked everytime any vm interface is changed. Handles deletion of routes associa...
Ip6Address ipv6_service_address_
An IPv6 address on which Metadata6 link local service listens on. We use it instead of IPv4 compute I...
void OnServerSessionEvent(HttpSession *session, TcpSession::Event event)
void HandleMetadataRequest(HttpSession *session, const HttpRequest *request)
std::map< HttpSession *, SessionData > SessionMap
void UnregisterListeners()
Unregisters all callbacks that were registered earlier to intercept Agent's events: MetadataProxy::On...
const Ip6Address & Ipv6ServiceAddress() const
Returns an IPv6 address of the Metadata TF link local service.
void DeleteMetaDataLinkLocalRoute(const VmInterface *vm_intf)
Deletes an announced earlier route to a vm interface via a given IPv6 address.
void NetlinkAddInterfaceRoute(const IpAddress &intf_addr)
Adds routes to internal addresses of VM's interfaces.
HttpConnection * GetProxyConnection(HttpSession *session, bool conn_close, std::string *nova_hostname)
ServicesModule * services_
virtual ~MetadataProxy()
int VhostIndex(const std::string &vhost_name)
Returns index of a network device that is specified by vhost_name.
MetadataServer * http_server_
A pointer to a HTTP server listening on a IPv4 socket for Metadata requests from tenants / virtual ma...
void OnAFabricRouteChange(DBTablePartBase *part, DBEntryBase *e)
A callback that is invoked each time when a route is modified in the fabric policy VRF inet4 unicast ...
boost::intrusive_ptr< HttpSession > HttpSessionPtr
std::pair< HttpSession *, SessionData > SessionPair
ConnectionSessionMap metadata_proxy_sessions_
SessionMap metadata_sessions_
void InitializeHttp6Server(const VmInterface *vhost0)
Initializes an HTTP server for IPv6 requests.
void OnClientSessionEvent(HttpClientSession *session, TcpSession::Event event)
std::mutex ll_ipv6_addr_mutex_
A mutex which prevents simultaneous access to MetadataProxy::ll_ipv6_addresses_ table and member func...
void CloseServerSession(HttpSession *session)
Definition: vrf.h:90
SessionData(HttpConnection *c, bool conn_close)