OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
metadata_proxy.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_metadata_proxy_h_
6 #define vnsw_agent_metadata_proxy_h_
7 
9 #include "http/http_session.h"
10 #include "oper/vm_interface.h"
11 #include <map>
12 
13 class MetadataServer;
14 class MetadataClient;
15 
17 public:
18  struct SessionData {
19  SessionData(HttpConnection *c, bool conn_close)
20  : conn(c), content_len(0), data_sent(0),
21  close_req(conn_close), header_end(false) {}
22 
24  uint32_t content_len;
25  uint32_t data_sent;
26  bool close_req;
27  bool header_end;
28  };
29 
30  struct MetadataStats {
33 
34  uint32_t requests;
35  uint32_t responses;
36  uint32_t proxy_sessions;
37  uint32_t internal_errors;
38  };
39 
40  typedef std::map<HttpSession *, SessionData> SessionMap;
41  typedef std::pair<HttpSession *, SessionData> SessionPair;
42  typedef std::map<HttpConnection *, HttpSession *> ConnectionSessionMap;
43  typedef std::pair<HttpConnection *, HttpSession *> ConnectionSessionPair;
44  typedef boost::intrusive_ptr<HttpSession> HttpSessionPtr;
45 
46  MetadataProxy(ServicesModule *module, const std::string &secret);
47  virtual ~MetadataProxy();
48  void CloseSessions();
49  void Shutdown();
50 
51  void HandleMetadataRequest(HttpSession *session, const HttpRequest *request);
53  std::string &msg, boost::system::error_code &ec);
54 
57 
58  const MetadataStats &metadatastats() const { return metadata_stats_; }
60 
64  int VhostIndex(const std::string& vhost_name);
65 
71  bool NetlinkGetVhostIp(Ip6Address& vhost_ll_ip);
72 
77  void NetlinkAddVhostNb(const IpAddress& nb_ip, const MacAddress& via_mac);
78 
82  void NetlinkAddInterfaceRoute(const IpAddress& intf_addr);
83 
92  const Ip6Address& ll_ip, const VrfEntry* intf_vrf);
93 
98  void DeleteMetaDataLinkLocalRoute(const VmInterface* vm_intf);
99 
102  const Ip6Address& Ipv6ServiceAddress() const;
103 
105  void InitializeHttp6Server(const VmInterface *vhost0);
106 
109  void AdvertiseVhostRoute();
110 
111 
114  void DeleteVhostRoute();
115 
121  void OnAVrfChange(DBTablePartBase *part, DBEntryBase *e);
122 
132 
140 
143  void RegisterListeners();
144 
149  void UnregisterListeners();
150 
151 private:
153  bool conn_close,
154  std::string *nova_hostname);
155  void CloseServerSession(HttpSession *session);
157  void ErrorClose(HttpSession *sesion, uint16_t error);
158 
160  std::string shared_secret_;
161 
165 
169 
174 
178 
182 
186 
190 
195  std::map<std::string, Ip6Address> ll_ipv6_addresses_;
196 
202 
204 };
205 
206 #endif // vnsw_agent_metadata_proxy_h_
virtual ~MetadataProxy()
void ErrorClose(HttpSession *sesion, uint16_t error)
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 ...
std::string shared_secret_
Definition: vrf.h:86
MetadataServer * http_server6_
A pointer to a HTTP server listening on a IPv6 socket for Metadata requests from tenants / virtual ma...
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)
std::map< HttpConnection *, HttpSession * > ConnectionSessionMap
boost::asio::ip::address IpAddress
Definition: address.h:13
DBTableBase::ListenerId fabric_notify_id_
an ID of a listener (callback) that acts when a Fabric Policy VRF entry is modified ...
const Ip6Address & Ipv6ServiceAddress() const
Returns an IPv6 address of the Metadata TF link local service.
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...
int ListenerId
Definition: db_table.h:62
void UnregisterListeners()
Unregisters all callbacks that were registered earlier to intercept Agent&#39;s events: MetadataProxy::On...
std::pair< HttpConnection *, HttpSession * > ConnectionSessionPair
MetadataStats metadata_stats_
SessionMap metadata_sessions_
void HandleMetadataResponse(HttpConnection *conn, HttpSessionPtr session, std::string &msg, boost::system::error_code &ec)
bool NetlinkGetVhostIp(Ip6Address &vhost_ll_ip)
Adds an IP address specified in vhost_ll_ip to vhost0 interface inet6 addresses.
DISALLOW_COPY_AND_ASSIGN(MetadataProxy)
void OnAVrfChange(DBTablePartBase *part, DBEntryBase *e)
A callback that is invoked each time when a VRF entry is modified: added, changed or deleted...
boost::intrusive_ptr< HttpSession > HttpSessionPtr
DBTableBase::ListenerId intf_table_notify_id_
an ID of a listener (callback) that acts when an InterfaceTable entry is modified ...
tbb::mutex ll_ipv6_addr_mutex_
A mutex which prevents simultaneous access to MetadataProxy::ll_ipv6_addresses_ table and member func...
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 OnClientSessionEvent(HttpClientSession *session, TcpSession::Event event)
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
void OnAnInterfaceChange(DBTablePartBase *part, DBEntryBase *e)
A callback which is invoked everytime any vm interface is changed. Handles deletion of routes associa...
MetadataProxy(ServicesModule *module, const std::string &secret)
void InitializeHttp6Server(const VmInterface *vhost0)
Initializes an HTTP server for IPv6 requests.
int VhostIndex(const std::string &vhost_name)
Returns index of a network device that is specified by vhost_name.
void NetlinkAddVhostNb(const IpAddress &nb_ip, const MacAddress &via_mac)
Adds a new neighbour (an arp entry) with given IP and MAC addresses.
std::pair< HttpSession *, SessionData > SessionPair
ServicesModule * services_
void DeleteVhostRoute()
Deletes the LL route to vhost0 interface in the fabric VRF instance.
const MetadataStats & metadatastats() const
SessionData(HttpConnection *c, bool conn_close)
void NetlinkAddInterfaceRoute(const IpAddress &intf_addr)
Adds routes to internal addresses of VM&#39;s interfaces.
HttpConnection * GetProxyConnection(HttpSession *session, bool conn_close, std::string *nova_hostname)
std::map< HttpSession *, SessionData > SessionMap
DBTableBase::ListenerId vrf_table_notify_id_
an ID of a listener (callback) that acts when the VRF Table is modified
void HandleMetadataRequest(HttpSession *session, const HttpRequest *request)
MetadataServer * http_server_
A pointer to a HTTP server listening on a IPv4 socket for Metadata requests from tenants / virtual ma...
void CloseClientSession(HttpConnection *conn)
void RegisterListeners()
Registers callbacks to intercept Agent&#39;s events emerging when a VRF entry is modified or an Interface...
void DeleteMetaDataLinkLocalRoute(const VmInterface *vm_intf)
Deletes an announced earlier route to a vm interface via a given IPv6 address.
MetadataClient * http_client_
void AdvertiseVhostRoute()
Advertises the LL route to vhost0 interface in the fabric VRF instance.
void CloseServerSession(HttpSession *session)
ConnectionSessionMap metadata_proxy_sessions_