OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ovsdb_client_idl.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_IDL_H_
6 #define SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_IDL_H_
7 
8 #include <assert.h>
9 #include <queue>
10 
11 #include <boost/intrusive_ptr.hpp>
12 #include <tbb/atomic.h>
13 
14 #include <cmn/agent_cmn.h>
15 #include <cmn/agent.h>
16 #include <agent_types.h>
17 #include <ksync/ksync_entry.h>
18 
22 
23 #define OVSDB_TRACE(obj, ...)\
24 do {\
25  Ovsdb##obj::TraceMsg(OvsdbTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
26 } while (false)
27 
28 #define OVSDB_PKT_TRACE(obj, ...)\
29 do {\
30  Ovsdb##obj::TraceMsg(OvsdbPktTraceBuf, __FILE__, __LINE__, __VA_ARGS__);\
31 } while (false)
32 
33 class OvsPeer;
34 class OvsPeerManager;
35 class KSyncObjectManager;
36 
37 namespace OVSDB {
38 class OvsdbClientSession;
39 class VMInterfaceKSyncObject;
40 class PhysicalSwitchTable;
41 class LogicalSwitchTable;
42 class PhysicalPortTable;
43 class PhysicalLocatorTable;
44 class VlanPortBindingTable;
45 class PhysicalLocatorTable;
46 class UnicastMacLocalOvsdb;
47 class MulticastMacLocalOvsdb;
48 class VrfOvsdbObject;
49 class VnOvsdbObject;
50 class OvsdbEntryBase;
51 class ConnectionStateTable;
52 class OvsdbResourceVxLanIdTable;
53 
55 typedef boost::intrusive_ptr<OvsdbClientIdl> OvsdbClientIdlPtr;
56 typedef std::set<OvsdbEntryBase *> OvsdbEntryList;
57 
59 public:
60  // OvsdbSessionState represent state of the session.
61  // it starts with OvsdbSessionRcvWait representing that idl is waiting
62  // for a message to come from ovsdb-server on message receive on session
63  // it moves to OvsdbSessionActive state, if keepalive timer fires with
64  // idl being in OvsdbSessionRcvWait state, it triggers an echo req (keep
65  // alive message) and moves to OvsdbSessionEchoWait state waiting for
66  // echo response, if there is no response till the next time timer fires
67  // it triggers the close of session.
69  OvsdbSessionActive = 0, // Actively receiving messages
70  OvsdbSessionRcvWait, // Waiting to receive next message
71  OvsdbSessionEchoWait // Echo Req sent waiting for reply
72  };
73 
74  static const std::size_t OVSDBMaxInFlightPendingTxn = 25;
75  static const std::size_t OVSDBEntriesInBulkTxn = 4;
76 
77  enum Op {
78  OVSDB_DEL = 0,
81  };
82 
83  enum EntryType {
94  };
95 
96  struct OvsdbMsg {
97  OvsdbMsg(struct jsonrpc_msg *m);
98  ~OvsdbMsg();
99  struct jsonrpc_msg *msg;
100  };
101 
102  struct TxnStats {
103  TxnStats();
104  uint64_t txn_initiated;
105  uint64_t txn_succeeded;
106  uint64_t txn_failed;
107  };
108 
109  typedef boost::function<void(OvsdbClientIdl::Op, struct ovsdb_idl_row *)> NotifyCB;
110  typedef std::map<struct ovsdb_idl_txn *, OvsdbEntryList> PendingTxnMap;
111  typedef std::queue<struct jsonrpc_msg *> ThrottledTxnMsgs;
112 
114  virtual ~OvsdbClientIdl();
115 
116  // Callback from receive_queue to process the OVSDB Messages
117  bool ProcessMessage(OvsdbMsg *msg);
118 
119  // Send request to start monitoring OVSDB server
120  void OnEstablish();
121 
122  // Encode and send json rpc message to OVSDB server
123  // takes ownership of jsonrpc message, and free memory
124  void TxnScheduleJsonRpc(struct jsonrpc_msg *msg);
125 
126  // Process the recevied message and trigger update to ovsdb client
127  void MessageProcess(const u_int8_t *buf, std::size_t len);
128  // Create a OVSDB transaction to start encoding an update
129  struct ovsdb_idl_txn *CreateTxn(OvsdbEntryBase *entry,
131  // Create a Bulk OVSDB transaction to start encoding a bulk update
132  struct ovsdb_idl_txn *CreateBulkTxn(OvsdbEntryBase *entry,
134 
135  // encode and send a transaction
136  bool EncodeSendTxn(struct ovsdb_idl_txn *txn, OvsdbEntryBase *skip_entry);
137 
138  // Delete the OVSDB transaction
139  void DeleteTxn(struct ovsdb_idl_txn *txn);
142 
143  // Notify Delete followed by add for a given ovsdb_idl_row
144  void NotifyDelAdd(struct ovsdb_idl_row *row);
145  // Get TOR Service Node IP
146  Ip4Address tsn_ip();
147 
148  // Process jsonrpc_msg for IDL, takes ownership of jsonrpc_msg
149  void MessageProcess(struct jsonrpc_msg *msg);
150 
151  Ip4Address remote_ip() const;
152  uint16_t remote_port() const;
153 
156  OvsPeer *route_peer();
157  bool deleted() { return deleted_; }
158  Agent *agent() const {return agent_;}
170 
171  // Used by Test case
172  bool IsKeepAliveTimerActive();
173  bool IsMonitorInProcess();
174 
175  bool KeepAliveTimerCb();
176  void TriggerDeletion();
177  bool IsDeleted() const { return deleted_; }
178  int refcount() const { return refcount_; }
179 
180  const TxnStats &stats() const;
181  uint64_t pending_txn_count() const;
182  uint64_t pending_send_msg_count() const;
183 
184  // Concurrency Check to validate all idl transactions happen only in
185  // db::DBTable or Agent::KSync task context
186  bool ConcurrencyCheck() const;
187 
188 private:
189  friend void ovsdb_wrapper_idl_callback(void *, int, struct ovsdb_idl_row *);
190  friend void ovsdb_wrapper_idl_txn_ack(void *, struct ovsdb_idl_txn *);
191  friend void intrusive_ptr_add_ref(OvsdbClientIdl *p);
192  friend void intrusive_ptr_release(OvsdbClientIdl *p);
193 
194  void ConnectOperDB();
195 
196  struct ovsdb_idl *idl_;
197  const struct vteprec_global *vtep_global_;
203  bool deleted_;
204  // Queue for handling OVS messages. Message processing accesses many of the
205  // OPER-DB and KSync structures. So, this queue will run in context KSync
206  // task
211 
212  // json for the sent monitor request, used to identify response to the
213  // request, reset to NULL once response if feed to idl for processing
214  // as it free the json for monitor request id
215  struct json *monitor_request_id_;
216 
217  // pointer to current buildup of bulk transaction
218  struct ovsdb_idl_txn *bulk_txn_;
219  // list of entries added to bulk txn
221 
222  // transaction stats per IDL
224 
225  tbb::atomic<int> refcount_;
226  std::unique_ptr<OvsPeer> route_peer_;
227  std::unique_ptr<VMInterfaceKSyncObject> vm_interface_table_;
228  std::unique_ptr<PhysicalSwitchTable> physical_switch_table_;
229  std::unique_ptr<LogicalSwitchTable> logical_switch_table_;
230  std::unique_ptr<PhysicalPortTable> physical_port_table_;
231  std::unique_ptr<PhysicalLocatorTable> physical_locator_table_;
232  std::unique_ptr<VlanPortBindingTable> vlan_port_table_;
233  std::unique_ptr<UnicastMacLocalOvsdb> unicast_mac_local_ovsdb_;
234  std::unique_ptr<MulticastMacLocalOvsdb> multicast_mac_local_ovsdb_;
235  std::unique_ptr<VrfOvsdbObject> vrf_ovsdb_;
236  std::unique_ptr<VnOvsdbObject> vn_ovsdb_;
237  std::unique_ptr<OvsdbResourceVxLanIdTable> vxlan_table_;
239 };
240 }; // namespace OVSDB
241 
242 #endif // SRC_VNSW_AGENT_OVS_TOR_AGENT_OVSDB_CLIENT_OVSDB_CLIENT_IDL_H_
std::unique_ptr< VlanPortBindingTable > vlan_port_table_
void NotifyDelAdd(struct ovsdb_idl_row *row)
std::unique_ptr< PhysicalLocatorTable > physical_locator_table_
bool ConcurrencyCheck() const
std::set< OvsdbEntryBase * > OvsdbEntryList
struct ovsdb_idl_txn * CreateBulkTxn(OvsdbEntryBase *entry, KSyncEntry::KSyncEvent ack_event=KSyncEntry::ADD_ACK)
OvsdbSessionState connection_state_
friend void ovsdb_wrapper_idl_txn_ack(void *, struct ovsdb_idl_txn *)
std::unique_ptr< PhysicalSwitchTable > physical_switch_table_
struct ovsdb_idl * idl_
DISALLOW_COPY_AND_ASSIGN(OvsdbClientIdl)
KSyncObjectManager * ksync_obj_manager()
OvsdbEntryList bulk_entries_
struct ovsdb_idl_txn * bulk_txn_
std::unique_ptr< VMInterfaceKSyncObject > vm_interface_table_
bool ProcessMessage(OvsdbMsg *msg)
ConnectionStateTable * connection_table()
Agent * agent() const
PendingTxnMap pending_txn_
static const std::size_t OVSDBEntriesInBulkTxn
friend void intrusive_ptr_add_ref(OvsdbClientIdl *p)
PhysicalLocatorTable * physical_locator_table()
boost::shared_ptr< TraceBuffer< SandeshTrace > > SandeshTraceBufferPtr
Definition: sandesh_trace.h:18
friend void ovsdb_wrapper_idl_callback(void *, int, struct ovsdb_idl_row *)
VMInterfaceKSyncObject * vm_interface_table()
void Register(EntryType type, NotifyCB cb)
MulticastMacLocalOvsdb * multicast_mac_local_ovsdb()
Ip4Address remote_ip() const
uint16_t remote_port() const
std::unique_ptr< UnicastMacLocalOvsdb > unicast_mac_local_ovsdb_
ThrottledTxnMsgs pending_send_msgs_
std::unique_ptr< VrfOvsdbObject > vrf_ovsdb_
std::queue< struct jsonrpc_msg * > ThrottledTxnMsgs
VnOvsdbObject * vn_ovsdb()
void DeleteTxn(struct ovsdb_idl_txn *txn)
uint8_t type
Definition: load_balance.h:109
Definition: agent.h:358
OvsdbMsg(struct jsonrpc_msg *m)
void MessageProcess(const u_int8_t *buf, std::size_t len)
std::map< struct ovsdb_idl_txn *, OvsdbEntryList > PendingTxnMap
SandeshTraceBufferPtr OvsdbSMTraceBuf
boost::function< void(OvsdbClientIdl::Op, struct ovsdb_idl_row *)> NotifyCB
boost::intrusive_ptr< OvsdbClientIdl > OvsdbClientIdlPtr
OvsdbResourceVxLanIdTable * vxlan_table()
uint64_t pending_send_msg_count() const
WorkQueue< OvsdbMsg * > * receive_queue_
OvsPeerManager * manager_
OvsdbClientSession * session_
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:14
VrfOvsdbObject * vrf_ovsdb()
LogicalSwitchTable * logical_switch_table()
OvsdbClientIdl(OvsdbClientSession *session, Agent *agent, OvsPeerManager *manager)
std::unique_ptr< OvsdbResourceVxLanIdTable > vxlan_table_
std::unique_ptr< OvsPeer > route_peer_
std::unique_ptr< LogicalSwitchTable > logical_switch_table_
void UnRegister(EntryType type)
struct json * monitor_request_id_
PhysicalPortTable * physical_port_table()
NotifyCB callback_[OVSDB_TYPE_COUNT]
uint64_t pending_txn_count() const
struct vteprec_global * vtep_global_
std::unique_ptr< VnOvsdbObject > vn_ovsdb_
void TxnScheduleJsonRpc(struct jsonrpc_msg *msg)
SandeshTraceBufferPtr OvsdbPktTraceBuf
VlanPortBindingTable * vlan_port_table()
UnicastMacLocalOvsdb * unicast_mac_local_ovsdb()
std::unique_ptr< MulticastMacLocalOvsdb > multicast_mac_local_ovsdb_
friend void intrusive_ptr_release(OvsdbClientIdl *p)
static const std::size_t OVSDBMaxInFlightPendingTxn
Definition: timer.h:54
struct ovsdb_idl_txn * CreateTxn(OvsdbEntryBase *entry, KSyncEntry::KSyncEvent ack_event=KSyncEntry::ADD_ACK)
const TxnStats & stats() const
bool EncodeSendTxn(struct ovsdb_idl_txn *txn, OvsdbEntryBase *skip_entry)
tbb::atomic< int > refcount_
SandeshTraceBufferPtr OvsdbTraceBuf
PhysicalSwitchTable * physical_switch_table()
std::unique_ptr< PhysicalPortTable > physical_port_table_