OpenSDN source code
ovsdb_client.cc
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 #include <ovsdb_object.h>
7 #include <oper/agent_sandesh.h>
8 #include <ovsdb_types.h>
9 #include <ovsdb_client.h>
10 #include <ovsdb_client_ssl.h>
11 #include <ovsdb_client_tcp.h>
15 
16 using OVSDB::OvsdbClient;
18 
19 OvsdbClient::OvsdbClient(OvsPeerManager *manager, int keepalive_interval,
20  int ha_stale_route_interval) :
21  peer_manager_(manager), ksync_obj_manager_(KSyncObjectManager::Init()),
22  keepalive_interval_(keepalive_interval),
23  ha_stale_route_interval_(ha_stale_route_interval) {
24 }
25 
27 }
28 
31 }
32 
35 }
36 
39 }
40 
42  return connection_table_.get();
43 }
44 
46  return ksync_obj_manager_;
47 }
48 
50  if (keepalive_interval_ < 0) {
51  // unconfigured return default
52  return OVSDBKeepAliveTimer;
53  }
54 
55  if (keepalive_interval_ != 0 &&
58  }
59 
60  return keepalive_interval_;
61 }
62 
64  if (ha_stale_route_interval_ < 0) {
65  // unconfigured return default
67  }
68 
71  }
72 
74 }
75 
77 }
78 
80  OvsPeerManager *manager) {
82  if (params->tor_protocol() == "tcp") {
83  return (new OvsdbClientTcp(agent, IpAddress(params->tor_ip()),
84  params->tor_port(), params->tsn_ip(),
85  params->keepalive_interval(),
86  params->ha_stale_route_interval(), manager));
87  } else if (params->tor_protocol() == "pssl") {
88  return (new OvsdbClientSsl(agent, IpAddress(params->tor_ip()),
89  params->tor_port(), params->tsn_ip(),
90  params->keepalive_interval(),
91  params->ha_stale_route_interval(),
92  params->ssl_cert(), params->ssl_privkey(),
93  params->ssl_cacert(), manager));
94  }
95  return NULL;
96 }
97 
99 // Sandesh routines
101 class OvsdbClientSandesTask : public Task {
102 public:
103  OvsdbClientSandesTask(std::string resp_ctx) :
104  Task((TaskScheduler::GetInstance()->GetTaskId("Agent::KSync")), 0),
105  resp_(new OvsdbClientResp()), resp_data_(resp_ctx) {
106  }
107 
109 
110  virtual bool Run() {
111  SandeshOvsdbClient client_data;
113  client_data.set_protocol(client->protocol());
114  client_data.set_server(client->server());
115  client_data.set_port(client->port());
116  client_data.set_tor_service_node(client->tsn_ip().to_string());
117  client_data.set_keepalive_interval(client->keepalive_interval());
118  client_data.set_ha_stale_route_interval(client->ha_stale_route_interval());
119  client->AddSessionInfo(client_data);
120  resp_->set_client(client_data);
121  SendResponse();
122  return true;
123  }
124  std::string Description() const { return "OvsdbClientSandesTask"; }
125 
126 private:
127  void SendResponse() {
128  resp_->set_context(resp_data_);
129  resp_->set_more(false);
130  resp_->Response();
131  }
132 
133  OvsdbClientResp *resp_;
134  std::string resp_data_;
136 };
137 
138 void OvsdbClientReq::HandleRequest() const {
141  scheduler->Enqueue(task);
142 }
143 
boost::asio::ip::address IpAddress
Definition: address.h:14
Definition: agent.h:361
OVSDB::OvsdbClient * ovsdb_client() const
Definition: agent.h:1129
static Agent * GetInstance()
Definition: agent.h:439
static KSyncObjectManager * Init()
virtual const std::string server()=0
OvsPeerManager * peer_manager_
Definition: ovsdb_client.h:65
static OvsdbClient * Allocate(Agent *agent, TorAgentParam *params, OvsPeerManager *manager)
Definition: ovsdb_client.cc:79
SessionEventCb pre_connect_complete_cb_
Definition: ovsdb_client.h:68
virtual uint16_t port()=0
static const int OVSDBMinHaStaleRouteTimer
Definition: ovsdb_client.h:30
virtual ~OvsdbClient()
Definition: ovsdb_client.cc:26
boost::scoped_ptr< ConnectionStateTable > connection_table_
Definition: ovsdb_client.h:71
KSyncObjectManager * ksync_obj_manager_
Definition: ovsdb_client.h:72
SessionEventCb connect_complete_cb_
Definition: ovsdb_client.h:67
void set_connect_complete_cb(SessionEventCb cb)
Definition: ovsdb_client.cc:29
static const int OVSDBMinKeepAliveTimer
Definition: ovsdb_client.h:25
ConnectionStateTable * connection_table()
Definition: ovsdb_client.cc:41
static const uint32_t OVSDBHaStaleRouteTimer
Definition: ovsdb_client.h:27
void RegisterConnectionTable(Agent *agent)
Definition: ovsdb_client.cc:37
virtual Ip4Address tsn_ip()=0
int keepalive_interval() const
Definition: ovsdb_client.cc:49
KSyncObjectManager * ksync_obj_manager()
Definition: ovsdb_client.cc:45
virtual void AddSessionInfo(SandeshOvsdbClient &client)=0
boost::function< void(OvsdbClientSession *)> SessionEventCb
Definition: ovsdb_client.h:20
static const uint32_t OVSDBKeepAliveTimer
Definition: ovsdb_client.h:22
virtual const std::string protocol()=0
void set_pre_connect_complete_cb(SessionEventCb cb)
Definition: ovsdb_client.cc:33
int ha_stale_route_interval() const
Definition: ovsdb_client.cc:63
std::string Description() const
Gives a description of the task.
OvsdbClientResp * resp_
DISALLOW_COPY_AND_ASSIGN(OvsdbClientSandesTask)
virtual ~OvsdbClientSandesTask()
OvsdbClientSandesTask(std::string resp_ctx)
virtual bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
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:662
static TaskScheduler * GetInstance()
Definition: task.cc:574
Task is a class to describe a computational task within OpenSDN control plane applications....
Definition: task.h:82
std::string ssl_privkey() const
uint16_t tor_port() const
int keepalive_interval() const
std::string tor_protocol() const
std::string ssl_cert() const
Ip4Address tor_ip() const
Ip4Address tsn_ip() const
std::string ssl_cacert() const
int ha_stale_route_interval() const
void SendResponse(HttpSession *session, const std::string &msg, int status_code)
Definition: task_int.h:11