OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ovsdb_client_ssl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved.
3  */
4 #ifndef SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_SSL_H_
5 #define SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_SSL_H_
6 #include <boost/asio.hpp>
7 #include <boost/asio/buffer.hpp>
8 
9 #include <base/timer.h>
10 #include <io/ssl_session.h>
11 #include <base/queue_task.h>
12 
13 #include <cmn/agent_cmn.h>
14 #include <cmn/agent.h>
15 #include <agent_types.h>
16 #include <ovsdb_client.h>
17 #include <ovsdb_client_idl.h>
18 #include <ovsdb_client_session.h>
19 #include <ovsdb_client_tcp.h>
20 
21 namespace OVSDB {
22 class OvsdbClientSsl;
24 public:
26  OvsdbClientSsl *server, SslSocket *sock, bool async_ready = true);
28 
29  // Send message to OVSDB server
30  void SendMsg(u_int8_t *buf, std::size_t len);
31  // Receive message from OVSDB server
32  bool RecvMsg(const u_int8_t *buf, std::size_t len);
33 
34  int keepalive_interval();
35 
36  // Throttle in flight message to ovsdb-server with ssl.
37  // without throttling, during scaled config ssl message gets corrupted
38  // in send resulting in connection drop by ovsdb-server and lots of
39  // churn in processing of config and ovsdb data.
40  // TODO(prabhjot) need to remove this throttling once we find the
41  // appropriate reason for write message corruption in SSL.
42  bool ThrottleInFlightTxnMessages() { return true; }
43 
44  const boost::system::error_code &ovsdb_close_reason() const;
45 
49 
50  void set_status(std::string status) {status_ = status;}
51  std::string status() {return status_;}
52 
53  void OnCleanup();
54 
55  // method to trigger close of session
56  void TriggerClose();
57 
58  // method to return ip address of remoter endpoint
59  virtual Ip4Address remote_ip() const;
60  virtual uint16_t remote_port() const;
61 
62  // Dequeue event from workqueue for processing
63  bool ProcessSessionEvent(OvsdbSessionEvent event);
64 
65  void EnqueueEvent(TcpSession::Event event);
66 
67 protected:
68  virtual void OnRead(Buffer buffer);
69 
70  // the default io::ReaderTask task for TCP session has task exclusion
71  // defined with db::DBTable task, Overriding reader task id with
72  // OVSDB::IO task to run the message receive and keep alive reply
73  // independent of db::DBTable task.
74  virtual int reader_task_id() const {
75  return ovsdb_io_task_id_;
76  }
77 
78 private:
79  friend class OvsdbClientSsl;
80  std::string status_;
84 };
85 
86 class OvsdbClientSsl : public SslServer, public OvsdbClient {
87 public:
88  typedef std::pair<Ip4Address, uint16_t> SessionKey;
89  typedef std::map<SessionKey, OvsdbClientSslSession *> SessionMap;
90 
91  OvsdbClientSsl(Agent *agent, IpAddress tor_ip, int tor_port,
93  int ha_stale_route_interval, const std::string &ssl_cert,
94  const std::string &ssl_privkey, const std::string &ssl_cacert,
95  OvsPeerManager *manager);
96  virtual ~OvsdbClientSsl();
97 
98  virtual SslSession *AllocSession(SslSocket *socket);
99  void RegisterClients();
100  void OnSessionEvent(TcpSession *session, TcpSession::Event event);
101  const std::string protocol();
102  const std::string server();
103  uint16_t port();
104  Ip4Address tsn_ip();
105 
106  // API to shutdown the TCP server
107  void shutdown();
108 
111  void AddSessionInfo(SandeshOvsdbClient &client);
112 
113 private:
114  friend class OvsdbClientSslSession;
115 
116  // return true to accept incoming session or reject.
117  bool AcceptSession(TcpSession *session);
118 
122  bool shutdown_;
125 };
126 };
127 
128 #endif //SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_SSL_H_
129 
int ha_stale_route_interval() const
Definition: ovsdb_client.cc:62
boost::asio::const_buffer Buffer
Definition: tcp_session.h:64
void SendMsg(u_int8_t *buf, std::size_t len)
KSyncObjectManager * ksync_obj_manager()
boost::asio::ip::address IpAddress
Definition: address.h:13
OvsdbClientSession * FindSession(Ip4Address ip, uint16_t port)
DISALLOW_COPY_AND_ASSIGN(OvsdbClientSsl)
OvsdbClientSslSession(Agent *agent, OvsPeerManager *manager, OvsdbClientSsl *server, SslSocket *sock, bool async_ready=true)
std::pair< Ip4Address, uint16_t > SessionKey
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
Definition: ssl_session.h:18
const std::string server()
DISALLOW_COPY_AND_ASSIGN(OvsdbClientSslSession)
virtual Ip4Address remote_ip() const
OvsdbClientSession * NextSession(OvsdbClientSession *session)
std::map< SessionKey, OvsdbClientSslSession * > SessionMap
const std::string protocol()
virtual void OnRead(Buffer buffer)
void AddSessionInfo(SandeshOvsdbClient &client)
void set_status(std::string status)
Definition: agent.h:358
bool AcceptSession(TcpSession *session)
ConnectionStateTable * connection_table()
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
Definition: ssl_server.h:16
int keepalive_interval() const
Definition: ovsdb_client.cc:48
const boost::system::error_code & ovsdb_close_reason() const
OvsdbClientTcpSessionReader * reader_
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
bool ProcessSessionEvent(OvsdbSessionEvent event)
WorkQueue< OvsdbSessionEvent > * session_event_queue_
virtual SslSession * AllocSession(SslSocket *socket)
OvsdbClientSsl(Agent *agent, IpAddress tor_ip, int tor_port, IpAddress tsn_ip, int keepalive_interval, int ha_stale_route_interval, const std::string &ssl_cert, const std::string &ssl_privkey, const std::string &ssl_cacert, OvsPeerManager *manager)
TcpServer * server()
Definition: tcp_session.h:88
void OnSessionEvent(TcpSession *session, TcpSession::Event event)
virtual uint16_t remote_port() const
virtual int reader_task_id() const
bool RecvMsg(const u_int8_t *buf, std::size_t len)
void EnqueueEvent(TcpSession::Event event)