8 #include <boost/asio.hpp>
9 #include <boost/bind/bind.hpp>
14 using namespace boost::asio;
15 using namespace boost::placeholders;
25 Task(scheduler->GetTaskId(
"Ksync::KSyncSockUdsRead"), 0), queue_(queue) {
34 std::string
Description()
const {
return "KSyncSockUdsRead"; }
46 server_ep_(sockpath_),
52 boost::system::error_code ec;
69 char *ret_buff =
new char[1024*
kBufLen];
70 boost::system::error_code ec;
76 struct nlmsghdr *nlh = NULL;
80 size_t bytes_transferred = 0;
86 LOG(INFO,
" dpdk vrouter is down, exiting.. errno:" << errno);
90 if (errno != EAGAIN) {
106 if (
remain_ <
sizeof(
struct nlmsghdr)) {
109 (
sizeof(
struct nlmsghdr) -
remain_));
118 bufp += (nlh->nlmsg_len -
remain_);
121 offset = nlh->nlmsg_len -
remain_;
123 while (offset < bytes_transferred) {
124 if ((bytes_transferred - offset) >= (
sizeof(
struct nlmsghdr))) {
125 nlh = (
struct nlmsghdr *)(
rx_buff_ + offset);
126 if ((bytes_transferred - offset) >= nlh->nlmsg_len) {
127 memcpy(ret_buff,
rx_buff_ + offset, nlh->nlmsg_len);
130 offset += nlh->nlmsg_len;
139 remain_ = bytes_transferred - offset;
145 const std::string &sockpathvr) {
168 uint32_t buf_len = 0;
171 return bulk_sandesh_context->
Decoder(buf, buf_len, NLA_ALIGNTO,
IsMoreData(data));
186 memset(&msg, 0,
sizeof(msg));
193 KSyncBufferList::iterator it = iovec->begin();
194 iovec->insert(it, buffer((
char *)
nl_client_->cl_buf, offset));
196 int count = iovec->size();
197 for(i = 0; i < count; i++) {
198 mutable_buffers_1 buf = iovec->at(i);
199 size_t buf_size = boost::asio::buffer_size(buf);
200 void* cbuf = boost::asio::buffer_cast<void*>(buf);
202 iov[i].iov_base = cbuf;
203 iov[i].iov_len = buf_size;
207 ret = sendmsg(
socket_, &msg, 0);
209 LOG(ERROR,
"sendmsg failure " << ret <<
"len " << len);
219 static int started = 0;
230 boost::system::error_code ec;
231 uint32_t bytes_read = 0;
232 const struct nlmsghdr *nlh = NULL;
234 char *netlink_header(buffer_cast<char *>(buf));
236 while (bytes_read <
sizeof(
struct nlmsghdr)) {
237 char *buffer = netlink_header + bytes_read;
238 bytes_read += recv(
socket_, buffer,
sizeof(
struct nlmsghdr) - bytes_read, 0);
241 if (bytes_read ==
sizeof(
struct nlmsghdr)) {
242 nlh = buffer_cast<struct nlmsghdr *>(buf);
246 if (nlh->nlmsg_type == NLMSG_ERROR) {
247 LOG(ERROR,
"Netlink error for seqno " << nlh->nlmsg_seq
248 <<
" len " << nlh->nlmsg_len);
253 uint32_t payload_size = nlh->nlmsg_len -
sizeof(
struct nlmsghdr);
254 char *data(buffer_cast<char *>(buf +
sizeof(
struct nlmsghdr)));
256 while (bytes_read < payload_size) {
257 char *buffer = data + bytes_read;
258 bytes_read += recv(
socket_, buffer, payload_size - bytes_read, 0);
virtual void SetErrno(int err)
bool Decoder(char *buff, uint32_t buff_len, uint32_t alignment, bool more)
static void NetlinkDecoder(char *data, SandeshContext *ctxt)
KSyncSockUdsReadTask(TaskScheduler *scheduler, KSyncSockUds *queue)
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
std::string Description() const
Gives a description of the task.
virtual bool IsMoreData(char *data)
static void Init(boost::asio::io_context &ios, const std::string &cpu_pin_policy, const std::string &sockpathvr="")
KSyncSockUds(boost::asio::io_context &ios)
virtual void AsyncSendTo(KSyncBufferList *iovec, uint32_t seq_no, HandlerCb cb)
virtual std::size_t SendTo(KSyncBufferList *iovec, uint32_t seq_no)
boost::asio::local::stream_protocol::endpoint server_ep_
boost::asio::local::stream_protocol::socket sock_
virtual bool BulkDecoder(char *data, KSyncBulkSandeshContext *ctxt)
virtual void Receive(boost::asio::mutable_buffers_1)
virtual void AsyncReceive(boost::asio::mutable_buffers_1, HandlerCb)
virtual bool Validate(char *data)
virtual bool Decoder(char *data, AgentSandeshContext *ctxt)
virtual uint32_t GetSeqno(char *data)
static AgentSandeshContext * GetAgentSandeshContext(uint32_t type)
void reset_use_wait_tree()
void set_process_data_inline()
static void Init(bool use_work_queue, const std::string &cpu_pin_policy)
void ProcessDataInline(char *data)
static void SetSockTableEntry(KSyncSock *sock)
static void SetNetlinkFamilyId(int id)
boost::function< void(const boost::system::error_code &, size_t)> HandlerCb
static const unsigned kBufLen
uint32_t max_bulk_msg_count_
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
void Enqueue(Task *task)
Enqueues a task for running. Starts task if all policy rules are met else puts task in waitq....
static TaskScheduler * GetInstance()
Task is a class to describe a computational task within OpenSDN control plane applications....
bool NetlinkMsgDone(char *data)
void GetNetlinkPayload(char *data, char **buf, uint32_t *buf_len)
void UpdateNetlink(nl_client *client, uint32_t len, uint32_t seq_no)
uint32_t GetNetlinkSeqno(char *data)
void ResetNetlink(nl_client *client)
#define KSYNC_AGENT_VROUTER_SOCK_PATH
std::vector< boost::asio::mutable_buffers_1 > KSyncBufferList
#define LOG(_Level, _Msg)