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