OpenSDN source code
ovsdb_client_session.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_SESSION_H_
6 #define SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_SESSION_H_
7 
8 #include <atomic>
9 #include <assert.h>
10 
11 #include <base/timer.h>
12 
13 #include <cmn/agent_cmn.h>
14 #include <cmn/agent.h>
15 #include <io/tcp_session.h>
16 
17 class OvsPeer;
18 class OvsPeerManager;
19 class KSyncObjectManager;
20 class SandeshOvsdbClientSession;
21 
22 namespace OVSDB {
23 class OvsdbClientIdl;
25 public:
28  };
29 
30  OvsdbClientSession(Agent *agent, OvsPeerManager *manager);
31  virtual ~OvsdbClientSession();
32 
33  // Callback triggered for session cleanup
34  virtual void OnCleanup() = 0;
35 
36  // method to trigger close of session
37  virtual void TriggerClose() = 0;
38 
39  virtual int keepalive_interval() = 0;
40 
41  // maximum number of inflight txn messages allowed
42  virtual bool ThrottleInFlightTxnMessages() { return false; }
43 
44  virtual const boost::system::error_code &ovsdb_close_reason() const = 0;
47  virtual Ip4Address remote_ip() const = 0;
48  virtual uint16_t remote_port() const = 0;
49  virtual Ip4Address tsn_ip() = 0;
50  virtual std::string status() = 0;
51  virtual void SendMsg(u_int8_t *buf, std::size_t len) = 0;
52  void MessageProcess(const u_int8_t *buf, std::size_t len);
53  // Send encode json rpc messgage to OVSDB server
54  void SendJsonRpc(struct jsonrpc_msg *msg);
55  void OnEstablish();
56  void OnClose();
58 
59  void AddSessionInfo(SandeshOvsdbClientSession &session);
60 
61  // UT overrides this to allow concurrency check on NULL task
62  virtual bool TestConcurrencyAllow() { return false; }
63 
64 protected:
65  // ovsdb io task ID.
66  static int ovsdb_io_task_id_;
67 
68 private:
69  friend class OvsdbClientIdl;
73  struct json_parser * parser_;
74  std::atomic<bool> idl_inited_;
75  std::string connection_time_;
77 };
78 }; // namespace OVSDB
79 
80 #define OVSDB_SM_TRACE(obj, ...)\
81 do {\
82  Ovsdb##obj::TraceMsg(OvsdbSMTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
83 } while (false)
84 
85 #define OVSDB_SESSION_TRACE(obj, session, ...)\
86 do {\
87  Ovsdb##obj::TraceMsg(OvsdbSMTraceBuf, __FILE__, __LINE__,\
88  "Session " + session->remote_ip().to_string() +\
89  ":" + integerToString(session->remote_port()) +\
90  " - " + __VA_ARGS__);\
91 } while (false)
92 
93 #endif // SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_SESSION_H_
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
Definition: agent.h:360
virtual int keepalive_interval()=0
virtual const boost::system::error_code & ovsdb_close_reason() const =0
std::atomic< bool > idl_inited_
virtual void TriggerClose()=0
virtual Ip4Address remote_ip() const =0
struct json_parser * parser_
void SendJsonRpc(struct jsonrpc_msg *msg)
virtual uint16_t remote_port() const =0
virtual std::string status()=0
virtual KSyncObjectManager * ksync_obj_manager()=0
virtual bool ThrottleInFlightTxnMessages()
void AddSessionInfo(SandeshOvsdbClientSession &session)
virtual void OnCleanup()=0
virtual void SendMsg(u_int8_t *buf, std::size_t len)=0
virtual ConnectionStateTable * connection_table()=0
virtual Ip4Address tsn_ip()=0
OvsdbClientSession(Agent *agent, OvsPeerManager *manager)
void MessageProcess(const u_int8_t *buf, std::size_t len)
DISALLOW_COPY_AND_ASSIGN(OvsdbClientSession)
Definition: agent.h:43
boost::intrusive_ptr< OvsdbClientIdl > OvsdbClientIdlPtr