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