OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ovsdb_client.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #include <ovsdb_object.h>
6 #include <oper/agent_sandesh.h>
7 #include <ovsdb_types.h>
8 #include <ovsdb_client.h>
9 #include <ovsdb_client_ssl.h>
10 #include <ovsdb_client_tcp.h>
14 
15 using OVSDB::OvsdbClient;
17 
18 OvsdbClient::OvsdbClient(OvsPeerManager *manager, int keepalive_interval,
19  int ha_stale_route_interval) :
20  peer_manager_(manager), ksync_obj_manager_(KSyncObjectManager::Init()),
21  keepalive_interval_(keepalive_interval),
22  ha_stale_route_interval_(ha_stale_route_interval) {
23 }
24 
26 }
27 
30 }
31 
34 }
35 
38 }
39 
41  return connection_table_.get();
42 }
43 
45  return ksync_obj_manager_;
46 }
47 
49  if (keepalive_interval_ < 0) {
50  // unconfigured return default
51  return OVSDBKeepAliveTimer;
52  }
53 
54  if (keepalive_interval_ != 0 &&
57  }
58 
59  return keepalive_interval_;
60 }
61 
63  if (ha_stale_route_interval_ < 0) {
64  // unconfigured return default
66  }
67 
70  }
71 
73 }
74 
76 }
77 
79  OvsPeerManager *manager) {
81  if (params->tor_protocol() == "tcp") {
82  return (new OvsdbClientTcp(agent, IpAddress(params->tor_ip()),
83  params->tor_port(), params->tsn_ip(),
84  params->keepalive_interval(),
85  params->ha_stale_route_interval(), manager));
86  } else if (params->tor_protocol() == "pssl") {
87  return (new OvsdbClientSsl(agent, IpAddress(params->tor_ip()),
88  params->tor_port(), params->tsn_ip(),
89  params->keepalive_interval(),
90  params->ha_stale_route_interval(),
91  params->ssl_cert(), params->ssl_privkey(),
92  params->ssl_cacert(), manager));
93  }
94  return NULL;
95 }
96 
98 // Sandesh routines
100 class OvsdbClientSandesTask : public Task {
101 public:
102  OvsdbClientSandesTask(std::string resp_ctx) :
103  Task((TaskScheduler::GetInstance()->GetTaskId("Agent::KSync")), 0),
104  resp_(new OvsdbClientResp()), resp_data_(resp_ctx) {
105  }
106 
108 
109  virtual bool Run() {
110  SandeshOvsdbClient client_data;
112  client_data.set_protocol(client->protocol());
113  client_data.set_server(client->server());
114  client_data.set_port(client->port());
115  client_data.set_tor_service_node(client->tsn_ip().to_string());
116  client_data.set_keepalive_interval(client->keepalive_interval());
117  client_data.set_ha_stale_route_interval(client->ha_stale_route_interval());
118  client->AddSessionInfo(client_data);
119  resp_->set_client(client_data);
120  SendResponse();
121  return true;
122  }
123  std::string Description() const { return "OvsdbClientSandesTask"; }
124 
125 private:
126  void SendResponse() {
127  resp_->set_context(resp_data_);
128  resp_->set_more(false);
129  resp_->Response();
130  }
131 
132  OvsdbClientResp *resp_;
133  std::string resp_data_;
135 };
136 
137 void OvsdbClientReq::HandleRequest() const {
140  scheduler->Enqueue(task);
141 }
142 
Ip4Address tsn_ip() const
int ha_stale_route_interval() const
Definition: ovsdb_client.cc:62
OVSDB::OvsdbClient * ovsdb_client() const
Definition: agent.h:1126
static Agent * GetInstance()
Definition: agent.h:436
int keepalive_interval() const
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
void SendResponse(HttpSession *session, const std::string &msg, int status_code)
boost::asio::ip::address IpAddress
Definition: address.h:13
virtual ~OvsdbClient()
Definition: ovsdb_client.cc:25
OvsdbClientSandesTask(std::string resp_ctx)
void RegisterConnectionTable(Agent *agent)
Definition: ovsdb_client.cc:36
virtual Ip4Address tsn_ip()=0
static const int OVSDBMinHaStaleRouteTimer
Definition: ovsdb_client.h:29
Definition: task_int.h:10
static const uint32_t OVSDBKeepAliveTimer
Definition: ovsdb_client.h:21
static const int OVSDBMinKeepAliveTimer
Definition: ovsdb_client.h:24
Ip4Address tor_ip() const
virtual void AddSessionInfo(SandeshOvsdbClient &client)=0
static OvsdbClient * Allocate(Agent *agent, TorAgentParam *params, OvsPeerManager *manager)
Definition: ovsdb_client.cc:78
OvsdbClientResp * resp_
std::string tor_protocol() const
std::string ssl_privkey() const
Definition: agent.h:358
KSyncObjectManager * ksync_obj_manager_
Definition: ovsdb_client.h:71
static TaskScheduler * GetInstance()
Definition: task.cc:547
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq...
Definition: task.cc:636
int keepalive_interval() const
Definition: ovsdb_client.cc:48
std::string ssl_cert() const
boost::scoped_ptr< ConnectionStateTable > connection_table_
Definition: ovsdb_client.h:70
virtual bool Run()
Code to execute. Returns true if task is completed. Return false to reschedule the task...
#define DISALLOW_COPY_AND_ASSIGN(_Class)
Definition: util.h:15
std::string Description() const
virtual const std::string protocol()=0
ConnectionStateTable * connection_table()
Definition: ovsdb_client.cc:40
boost::function< void(OvsdbClientSession *)> SessionEventCb
Definition: ovsdb_client.h:19
virtual uint16_t port()=0
int ha_stale_route_interval() const
uint16_t tor_port() const
void set_connect_complete_cb(SessionEventCb cb)
Definition: ovsdb_client.cc:28
virtual const std::string server()=0
static KSyncObjectManager * Init()
SessionEventCb connect_complete_cb_
Definition: ovsdb_client.h:66
SessionEventCb pre_connect_complete_cb_
Definition: ovsdb_client.h:67
void set_pre_connect_complete_cb(SessionEventCb cb)
Definition: ovsdb_client.cc:32
OvsPeerManager * peer_manager_
Definition: ovsdb_client.h:64
KSyncObjectManager * ksync_obj_manager()
Definition: ovsdb_client.cc:44
Task is a wrapper over tbb::task to support policies.
Definition: task.h:86
virtual ~OvsdbClientSandesTask()
static const uint32_t OVSDBHaStaleRouteTimer
Definition: ovsdb_client.h:26
std::string ssl_cacert() const