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  */
4 
5 #ifndef vnsw_agent_metadata_proxy_h_
6 #define vnsw_agent_metadata_proxy_h_
7 
8 #include <map>
9 #include <mutex>
10 
12 #include "http/http_session.h"
13 #include "oper/vm_interface.h"
14 
15 class MetadataServer;
16 class MetadataClient;
17 
19 public:
20  struct SessionData {
21  SessionData(HttpConnection *c, bool conn_close)
22  : conn(c), content_len(0), data_sent(0),
23  close_req(conn_close), header_end(false) {}
24 
26  uint32_t content_len;
27  uint32_t data_sent;
28  bool close_req;
29  bool header_end;
30  };
31 
32  struct MetadataStats {
35 
36  uint32_t requests;
37  uint32_t responses;
38  uint32_t proxy_sessions;
39  uint32_t internal_errors;
40  };
41 
42  typedef std::map<HttpSession *, SessionData> SessionMap;
43  typedef std::pair<HttpSession *, SessionData> SessionPair;
44  typedef std::map<HttpConnection *, HttpSession *> ConnectionSessionMap;
45  typedef std::pair<HttpConnection *, HttpSession *> ConnectionSessionPair;
46  typedef boost::intrusive_ptr<HttpSession> HttpSessionPtr;
47 
48  MetadataProxy(ServicesModule *module, const std::string &secret);
49  virtual ~MetadataProxy();
50  void CloseSessions();
51  void Shutdown();
52 
53  void HandleMetadataRequest(HttpSession *session, const HttpRequest *request);
55  std::string &msg, boost::system::error_code &ec);
56 
59 
60  const MetadataStats &metadatastats() const { return metadata_stats_; }
62 
66  int VhostIndex(const std::string& vhost_name);
67 
73  bool NetlinkGetVhostIp(Ip6Address& vhost_ll_ip);
74 
79  void NetlinkAddVhostNb(const IpAddress& nb_ip, const MacAddress& via_mac);
80 
84  void NetlinkAddInterfaceRoute(const IpAddress& intf_addr);
85 
94  const Ip6Address& ll_ip, const VrfEntry* intf_vrf);
95 
100  void DeleteMetaDataLinkLocalRoute(const VmInterface* vm_intf);
101 
104  const Ip6Address& Ipv6ServiceAddress() const;
105 
107  void InitializeHttp6Server(const VmInterface *vhost0);
108 
111  void AdvertiseVhostRoute();
112 
113 
116  void DeleteVhostRoute();
117 
123  void OnAVrfChange(DBTablePartBase *part, DBEntryBase *e);
124 
134 
142 
145  void RegisterListeners();
146 
151  void UnregisterListeners();
152 
153 private:
155  bool conn_close,
156  std::string *nova_hostname);
157  void CloseServerSession(HttpSession *session);
159  void ErrorClose(HttpSession *sesion, uint16_t error);
160 
162  std::string shared_secret_;
163 
167 
171 
176 
180 
184 
188 
192 
197  std::map<std::string, Ip6Address> ll_ipv6_addresses_;
198 
204 
206 };
207 
208 #endif // vnsw_agent_metadata_proxy_h_
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:15
boost::asio::ip::address IpAddress
Definition: address.h:13
int ListenerId
Definition: db_table.h:62
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:89
SessionData(HttpConnection *c, bool conn_close)