8 #include <boost/asio.hpp>
9 #include <boost/bind/bind.hpp>
11 using namespace boost::asio;
12 using namespace boost::placeholders;
19 boost::asio::ip::address ip_address,
int port) :
TcpServer(
evm), evm_(
evm),
20 session_(NULL), server_ep_(ip_address, port), connect_complete_(false) {
35 int port,
const std::string &cpu_pin_policy) {
62 memset(&msg, 0,
sizeof(msg));
69 KSyncBufferList::iterator it = iovec->begin();
70 iovec->insert(it, buffer((
char *)
nl_client_->cl_buf, offset));
72 int count = iovec->size();
73 for(i = 0; i < count; i++) {
74 mutable_buffers_1 buf = iovec->at(i);
75 size_t buf_size = boost::asio::buffer_size(buf);
76 void* cbuf = boost::asio::buffer_cast<void*>(buf);
78 iov[i].iov_base = cbuf;
79 iov[i].iov_len = buf_size;
84 ret = sendmsg(fd, &msg, 0);
86 LOG(ERROR,
"sendmsg failure " << ret <<
"len " << len);
109 uint32_t buf_len = 0;
112 return bulk_sandesh_context->
Decoder(buf, buf_len, NLA_ALIGNTO,
IsMoreData(data));
121 uint32_t bytes_read = 0;
122 boost::system::error_code ec;
123 const struct nlmsghdr *nlh = NULL;
126 mutable_buffers_1 netlink_header(buffer_cast<void *>(buf),
127 sizeof(
struct nlmsghdr));
131 while (bytes_read <
sizeof(
struct nlmsghdr)) {
132 mutable_buffers_1 buffer =
133 static_cast<mutable_buffers_1
>(netlink_header + bytes_read);
140 if (bytes_read ==
sizeof(
struct nlmsghdr)) {
141 nlh = buffer_cast<struct nlmsghdr *>(buf);
145 if (nlh->nlmsg_type == NLMSG_ERROR) {
146 LOG(ERROR,
"Netlink error for seqno " << nlh->nlmsg_seq
147 <<
" len " << nlh->nlmsg_len);
152 uint32_t payload_size = nlh->nlmsg_len -
sizeof(
struct nlmsghdr);
154 mutable_buffers_1 data(buffer_cast<void *>(buf +
sizeof(
struct nlmsghdr)),
157 while (bytes_read < payload_size) {
158 mutable_buffers_1 buffer =
159 static_cast<mutable_buffers_1
>(data + bytes_read);
181 struct nlmsghdr *nlh = NULL;
182 struct nlmsghdr tnlh;
184 int bytes_transferred = 0;
187 if (bytes_transferred <= 0) {
188 LOG(ERROR,
"Connection to dpdk-vrouter lost.");
194 if (
remain_ <
sizeof(
struct nlmsghdr)) {
197 (
sizeof(
struct nlmsghdr) -
remain_));
207 bufp += (nlh->nlmsg_len -
remain_);
210 offset = nlh->nlmsg_len -
remain_;
213 while (offset < bytes_transferred) {
214 if ((
unsigned int)(bytes_transferred - offset) >= (
sizeof(
struct nlmsghdr))) {
215 nlh = (
struct nlmsghdr *)(
rx_buff_ + offset);
216 if ((
unsigned int)(bytes_transferred - offset) >= nlh->nlmsg_len) {
219 offset += nlh->nlmsg_len;
228 remain_ = bytes_transferred - offset;
240 Task(scheduler->GetTaskId(
"Ksync::KSyncSockTcpRead"), 0),
sock_(sock) {
256 static int started = 0;
257 boost::system::error_code ec;
276 LOG(ERROR,
"Connection to dpdk-vrouter lost.");
295 bool async_ready) :
TcpSession(server, sock, async_ready) {
318 int remain = size - offset;
324 const struct nlmsghdr *nlh =
326 return nlh->nlmsg_len;
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)
std::string Description() const
Gives a description of the task.
KSyncSockTcpReadTask(TaskScheduler *scheduler, KSyncSockTcp *sock)
bool Run()
Code to execute in a task. Returns true if task is completed. Return false to reschedule the task.
virtual const int GetHeaderLenSize()
virtual int MsgLength(Buffer buffer, int offset)
KSyncSockTcpSessionReader(TcpSession *session, ReceiveCallback callback)
KSyncSockTcpSessionReader * reader_
virtual void OnRead(Buffer buffer)
KSyncSockTcpSession(TcpServer *server, Socket *sock, bool async_ready=false)
virtual ~KSyncSockTcpSession()
virtual bool IsMoreData(char *data)
boost::asio::ip::tcp::endpoint server_ep_
virtual void AsyncReceive(boost::asio::mutable_buffers_1, HandlerCb)
virtual void Receive(boost::asio::mutable_buffers_1)
virtual uint32_t GetSeqno(char *data)
bool ReceiveMsg(const u_int8_t *msg, size_t size)
KSyncSockTcp(EventManager *evm, boost::asio::ip::address ip_addr, int port)
boost::asio::ip::tcp::socket * tcp_socket_
virtual std::size_t SendTo(KSyncBufferList *iovec, uint32_t seq_no)
void OnSessionEvent(TcpSession *session, TcpSession::Event event)
virtual bool Validate(char *data)
virtual bool BulkDecoder(char *data, KSyncBulkSandeshContext *ctxt)
virtual TcpSession * AllocSession(Socket *socket)
virtual bool Decoder(char *data, AgentSandeshContext *ctxt)
static void Init(EventManager *evm, boost::asio::ip::address ip_addr, int port, const std::string &cpu_pin_policy)
virtual void AsyncSendTo(KSyncBufferList *iovec, uint32_t seq_no, HandlerCb cb)
static AgentSandeshContext * GetAgentSandeshContext(uint32_t type)
void reset_use_wait_tree()
void set_process_data_inline()
uint32_t max_bulk_buf_size_
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....
virtual void OnRead(Buffer buffer)
boost::function< bool(const uint8_t *, size_t)> ReceiveCallback
boost::asio::const_buffer Buffer
virtual void Connect(TcpSession *session, Endpoint remote)
virtual TcpSession * CreateSession()
boost::asio::ip::tcp::socket Socket
boost::system::error_code SetTcpSendBufSize(uint32_t size)
virtual Socket * socket() const
static const uint8_t * BufferData(const Buffer &buffer)
boost::system::error_code SetTcpRecvBufSize(uint32_t size)
boost::system::error_code SetTcpNoDelay()
static size_t BufferSize(const Buffer &buffer)
void set_observer(EventObserver observer)
boost::asio::const_buffer Buffer
boost::asio::ip::tcp::socket Socket
bool NetlinkMsgDone(char *data)
bool ValidateNetlink(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)
std::vector< boost::asio::mutable_buffers_1 > KSyncBufferList
#define LOG(_Level, _Msg)