OpenSDN source code
ksync_sock.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <atomic>
7 #include <string>
8 
9 #include "base/os.h"
10 
11 #if defined(__linux__)
12 #include <asm/types.h>
13 #include <linux/netlink.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/genetlink.h>
16 #include <linux/sockios.h>
17 #endif
18 
19 #include <sys/socket.h>
20 
21 #include <boost/bind/bind.hpp>
22 
23 #include <base/logging.h>
24 #include <db/db.h>
25 #include <db/db_entry.h>
26 #include <db/db_table.h>
27 #include <db/db_table_partition.h>
28 
29 #include "ksync_index.h"
30 #include "ksync_entry.h"
31 #include "ksync_object.h"
32 #include "ksync_sock.h"
33 #include "ksync_sock_user.h"
34 #include "ksync_types.h"
35 
36 #include "nl_util.h"
37 #include "udp_util.h"
38 #include "vr_genetlink.h"
39 #include "vr_types.h"
40 
41 using namespace boost::asio;
42 using namespace boost::placeholders;
43 
44 /* Note SO_RCVBUFFORCE is supported only for linux version 2.6.14 and above */
45 typedef boost::asio::detail::socket_option::integer<SOL_SOCKET,
46  SO_RCVBUFFORCE> ReceiveBuffForceSize;
47 
50 std::unique_ptr<KSyncSock> KSyncSock::sock_;
51 pid_t KSyncSock::pid_;
52 std::atomic<bool> KSyncSock::shutdown_;
53 
54 // Name of task used in KSync Response work-queues
56  {
57  "Agent::Uve",
58  "Agent::KSync"
59  };
61 // Netlink utilities
63 uint32_t GetNetlinkSeqno(char *data) {
64  struct nlmsghdr *nlh = (struct nlmsghdr *)data;
65  return nlh->nlmsg_seq;
66 }
67 
68 bool NetlinkMsgDone(char *data) {
69  struct nlmsghdr *nlh = (struct nlmsghdr *)data;
70  return ((nlh->nlmsg_flags & NLM_F_MULTI) != 0);
71 }
72 
73 // Common validation for netlink messages
74 bool ValidateNetlink(char *data) {
75  struct nlmsghdr *nlh = (struct nlmsghdr *)data;
76  if (nlh->nlmsg_type == NLMSG_ERROR) {
77  LOG(ERROR, "Netlink error for seqno " << nlh->nlmsg_seq << " len "
78  << nlh->nlmsg_len);
79  assert(0);
80  return false;
81  }
82 
83  if (nlh->nlmsg_len > KSyncSock::kBufLen) {
84  LOG(ERROR, "Length of " << nlh->nlmsg_len << " is more than expected "
85  "length of " << KSyncSock::kBufLen);
86  assert(0);
87  return false;
88  }
89 
90  if (nlh->nlmsg_type == NLMSG_DONE) {
91  return true;
92  }
93 
94  // Sanity checks for generic-netlink message
95  if (nlh->nlmsg_type != KSyncSock::GetNetlinkFamilyId()) {
96  LOG(ERROR, "Netlink unknown message type : " << nlh->nlmsg_type);
97  assert(0);
98  return false;
99  }
100 
101  struct genlmsghdr *genlh = (struct genlmsghdr *) (data + NLMSG_HDRLEN);
102  if (genlh->cmd != SANDESH_REQUEST) {
103  LOG(ERROR, "Unknown generic netlink cmd : " << genlh->cmd);
104  assert(0);
105  return false;
106  }
107 
108  struct nlattr * attr = (struct nlattr *)(data + NLMSG_HDRLEN
109  + GENL_HDRLEN);
110  if (attr->nla_type != NL_ATTR_VR_MESSAGE_PROTOCOL) {
111  LOG(ERROR, "Unknown generic netlink TLV type : " << attr->nla_type);
112  assert(0);
113  return false;
114  }
115 
116  return true;
117 }
118 
119 void GetNetlinkPayload(char *data, char **buf, uint32_t *buf_len) {
120  struct nlmsghdr *nlh = (struct nlmsghdr *)data;
121  int len = 0;
122  if (nlh->nlmsg_type == NLMSG_DONE) {
123  len = NLMSG_HDRLEN;
124  } else {
125  len = NLMSG_HDRLEN + GENL_HDRLEN + NLA_HDRLEN;
126  }
127 
128  *buf = data + len;
129  *buf_len = nlh->nlmsg_len - len;
130 }
131 
132 void InitNetlink(nl_client *client) {
133  nl_init_generic_client_req(client, KSyncSock::GetNetlinkFamilyId());
134  unsigned char *nl_buf;
135  uint32_t nl_buf_len;
136  assert(nl_build_header(client, &nl_buf, &nl_buf_len) >= 0);
137 }
138 
139 void ResetNetlink(nl_client *client) {
140  unsigned char *nl_buf;
141  uint32_t nl_buf_len;
142  client->cl_buf_offset = 0;
143  nl_build_header(client, &nl_buf, &nl_buf_len);
144 }
145 
146 void UpdateNetlink(nl_client *client, uint32_t len, uint32_t seq_no) {
147  nl_update_header(client, len);
148  struct nlmsghdr *nlh = (struct nlmsghdr *)client->cl_buf;
149  nlh->nlmsg_pid = KSyncSock::GetPid();
150  nlh->nlmsg_seq = seq_no;
151 }
152 
153 void DecodeSandeshMessages(char *buf, uint32_t buf_len, SandeshContext *sandesh_context,
154  uint32_t alignment) {
155  while (buf_len > (alignment - 1)) {
156  int error;
157  int decode_len = Sandesh::ReceiveBinaryMsgOne((uint8_t *)buf, buf_len,
158  &error, sandesh_context);
159  if (decode_len < 0) {
160  LOG(DEBUG, "Incorrect decode len " << decode_len);
161  break;
162  }
163  buf += decode_len;
164  buf_len -= decode_len;
165  }
166 }
167 
169 // KSyncSock routines
172  nl_client_(NULL), wait_tree_(), send_queue_(this),
173  max_bulk_msg_count_(kMaxBulkMsgCount),
174  bulk_seq_no_(kInvalidBulkSeqNo), bulk_buf_size_(0), bulk_msg_count_(0),
175  rx_buff_(NULL), read_inline_(true), bulk_msg_context_(NULL),
176  use_wait_tree_(true), process_data_inline_(false),
177  ksync_bulk_sandesh_context_(), uve_bulk_sandesh_context_(),
178  tx_count_(0), ack_count_(0), err_count_(0),
179  rx_process_queue_(TaskScheduler::GetInstance()->GetTaskId("Agent::KSync"), 0,
180  boost::bind(&KSyncSock::ProcessRxData, this, _1)) {
182 
183  uint32_t uve_task_id =
185  uint32_t ksync_task_id =
187  for(uint32_t i = 0; i < kRxWorkQueueCount; i++) {
189  ksync_task_id, i, "KSync Receive Queue");
191  uve_task_id, i, "KSync UVE Receive Queue");
192  }
193 
194  nl_client_ = (nl_client *)malloc(sizeof(nl_client));
195  memset(nl_client_, 0, sizeof(nl_client));
196  rx_buff_ = NULL;
197  seqno_ = 0;
198  uve_seqno_ = 0;
199 
200  memset(bulk_mctx_arr_, 0, sizeof(bulk_mctx_arr_));
201  bmca_prod_ = bmca_cons_ = 0;
202 }
203 
205  assert(wait_tree_.size() == 0);
206 
207  if (rx_buff_) {
208  delete [] rx_buff_;
209  rx_buff_ = NULL;
210  }
211 
212  for(int i = 0; i < kRxWorkQueueCount; i++) {
213  ksync_rx_queue[i]->Shutdown();
214  delete ksync_rx_queue[i];
215 
216  uve_rx_queue[i]->Shutdown();
217  delete uve_rx_queue[i];
218  }
219 
220  if (nl_client_->cl_buf) {
221  free(nl_client_->cl_buf);
222  }
223  free(nl_client_);
224 }
225 
227  shutdown_ = true;
228  sock_->send_queue_.Shutdown();
229  sock_.release();
230 }
231 
232 void KSyncSock::Init(bool use_work_queue, const std::string &cpu_pin_policy) {
233  sock_->send_queue_.Init(use_work_queue, cpu_pin_policy);
234  pid_ = getpid();
235  shutdown_ = false;
236 }
237 
239 (KSyncBulkSandeshContext ctxt[], uint32_t task_id, uint32_t instance,
240  const char *name) {
241  KSyncReceiveQueue *queue;
242  queue = new KSyncReceiveQueue
243  (task_id, instance, boost::bind(&KSyncSock::ProcessKernelData, this,
244  &ctxt[instance], _1));
245  char tmp[128];
246  sprintf(tmp, "%s-%d", name, instance);
247  queue->set_name(tmp);
248  return queue;
249 }
250 
252  sock_->send_queue_.set_measure_busy_time(val);
253  for (int i = 0; i < kRxWorkQueueCount; i++) {
255  }
256 }
257 
258 void KSyncSock::Start(bool read_inline) {
259  sock_->read_inline_ = read_inline;
260  if (sock_->read_inline_) {
261  return;
262  }
263  sock_->rx_buff_ = new char[kBufLen];
264  sock_->AsyncReceive(boost::asio::buffer(sock_->rx_buff_, kBufLen),
265  boost::bind(&KSyncSock::ReadHandler, sock_.get(),
266  placeholders::error,
267  placeholders::bytes_transferred));
268 }
269 
271  assert(sock_.get() == NULL);
272  sock_.reset(sock);
273 }
274 
277  InitNetlink(sock_->nl_client_);
278 }
279 
280 uint32_t KSyncSock::WaitTreeSize() const {
281  return wait_tree_.size();
282 }
283 
284 void KSyncSock::SetSeqno(uint32_t seq) {
285  seqno_ = seq;
286  uve_seqno_ = seq;
287 }
288 
289 uint32_t KSyncSock::AllocSeqNo(IoContext::Type type, uint32_t instance) {
290  uint32_t seq;
291  if (type == IoContext::IOC_UVE) {
292  seq = uve_seqno_.fetch_add(1);
293  seq = (seq * kRxWorkQueueCount + (instance % kRxWorkQueueCount)) << 1;
294  } else {
295  seq = seqno_.fetch_add(1);
296  seq = (seq * kRxWorkQueueCount + (instance % kRxWorkQueueCount)) << 1;
297  seq |= KSYNC_DEFAULT_Q_ID_SEQ;
298  }
299  if (seq == kInvalidBulkSeqNo) {
300  return AllocSeqNo(type, instance);
301  }
302  return seq;
303 }
304 
306  return AllocSeqNo(type, 0);
307 }
308 
310  uint32_t instance) {
311  if (type == IoContext::IOC_UVE) {
312  return uve_rx_queue[instance % kRxWorkQueueCount];
313  } else {
314  return ksync_rx_queue[instance % kRxWorkQueueCount];
315  }
316 }
317 
320  if (seqno & KSYNC_DEFAULT_Q_ID_SEQ)
322  else
324 
325  uint32_t instance = (seqno >> 1) % kRxWorkQueueCount;
326  return GetReceiveQueue(type, instance);
327 }
330 }
332  assert(data.event_ != KSyncEntry::INVALID);
333  KSyncObject *object = data.entry_->GetObject();
334  object->NetlinkAck(data.entry_, data.event_);
335  return true;
336 }
338 
339  uint32_t instance = (seqno >> 1) % kRxWorkQueueCount;
340  if (seqno & KSYNC_DEFAULT_Q_ID_SEQ)
341  return &ksync_bulk_sandesh_context_[instance];
342  else
343  return &uve_bulk_sandesh_context_[instance];
344 }
345 
347  return sock_.get();
348 }
349 
351  assert(idx == 0);
352  return sock_.get();
353 }
354 
356  Validate(data);
357 
358  KSyncReceiveQueue *queue;
359  if (context) {
360  queue = GetReceiveQueue(context->io_context_type(),
361  context->work_queue_index());
362  } else {
363  queue = GetReceiveQueue(GetSeqno(data));
364  }
365  queue->Enqueue(KSyncRxData(data, context));
366  return true;
367 }
368 
369 // Read handler registered with boost::asio. Demux done based on seqno_
370 void KSyncSock::ReadHandler(const boost::system::error_code& error,
371  size_t bytes_transferred) {
372  if (error) {
373  LOG(ERROR, "Error reading from Ksync sock. Error : " <<
374  boost::system::system_error(error).what());
375  if (shutdown_ == false) {
376  assert(0);
377  }
378  return;
379  }
380 
382 
383  rx_buff_ = new char[kBufLen];
384  AsyncReceive(boost::asio::buffer(rx_buff_, kBufLen),
385  boost::bind(&KSyncSock::ReadHandler, this,
386  placeholders::error,
387  placeholders::bytes_transferred));
388 }
389 
390 // Process kernel data - executes in the task specified by IoContext
391 // Currently only Agent::KSync and Agent::Uve are possibilities
393  const KSyncRxData &data) {
394  KSyncBulkMsgContext *bulk_message_context = data.bulk_msg_context_;
395  WaitTree::iterator it;
396  if (data.bulk_msg_context_ == NULL) {
397  uint32_t seqno = GetSeqno(data.buff_);
398  {
399  std::scoped_lock lock(mutex_);
400  it = wait_tree_.find(seqno);
401  }
402  if (it == wait_tree_.end()) {
403  LOG(ERROR, "KSync error in finding for sequence number : "
404  << seqno);
405  assert(0);
406  }
407  bulk_message_context = &(it->second);
408  }
409 
410  bulk_sandesh_context->set_bulk_message_context(bulk_message_context);
411  BulkDecoder(data.buff_, bulk_sandesh_context);
412  // Remove the IoContext only on last netlink message
413  if (IsMoreData(data.buff_) == false) {
414  if (data.bulk_msg_context_ != NULL) {
415  delete data.bulk_msg_context_;
416  } else {
417  std::scoped_lock lock(mutex_);
418  wait_tree_.erase(it);
419  }
420  }
421  delete[] data.buff_;
422  return true;
423 }
424 
426  char data[kBufLen];
427  bool ret = false;
428 
429  do {
430  Receive(boost::asio::buffer(data, kBufLen));
432  ctxt->SetErrno(0);
433  // BlockingRecv used only during Init and doesnt support bulk messages
434  // Use non-bulk version of decoder
435  Decoder(data, ctxt);
436  if (ctxt->GetErrno() != 0 && ctxt->GetErrno() != EEXIST) {
437  KSYNC_ERROR(VRouterError, "VRouter operation failed. Error <",
438  ctxt->GetErrno(), ":",
440  ">. Object <", "N/A", ">. State <", "N/A",
441  ">. Message number :", 0);
442  ret = true;
443  }
444  } while (IsMoreData(data));
445 
446  return ret;
447 }
448 
449 // BlockingSend does not support bulk messages.
450 size_t KSyncSock::BlockingSend(char *msg, int msg_len) {
451  KSyncBufferList iovec;
452  iovec.push_back(buffer(msg, msg_len));
453  bulk_buf_size_ = msg_len;
454  return SendTo(&iovec, 0);
455 }
456 
458  send_queue_.Enqueue(ioc);
459 }
460 
461 void KSyncSock::SendAsync(KSyncEntry *entry, int msg_len, char *msg,
462  KSyncEntry::KSyncEvent event) {
463  KSyncIoContext *ioc = new KSyncIoContext(this, entry, msg_len, msg, event);
464  // Pre-allocate buffers to minimize processing in KSyncTxQueue context
465  if (read_inline_ && entry->pre_alloc_rx_buffer()) {
466  ioc->rx_buffer1_ = new char [kBufLen];
467  ioc->rx_buffer2_ = new char [kBufLen];
468  } else {
469  ioc->rx_buffer1_ = ioc->rx_buffer2_ = NULL;
470  }
471  send_queue_.Enqueue(ioc);
472 }
473 
474 // Write handler registered with boost::asio
475 void KSyncSock::WriteHandler(const boost::system::error_code& error,
476  size_t bytes_transferred) {
477  if (error) {
478  LOG(ERROR, "Ksync sock write error : " <<
479  boost::system::system_error(error).what());
480  if (shutdown_ == false) {
481  assert(0);
482  }
483  }
484 }
485 
486 // End of messages in the work-queue. Send messages pending in bulk context
487 void KSyncSock::OnEmptyQueue(bool done) {
489  return;
490 
491  KSyncBulkMsgContext *bulk_message_context = NULL;
492  if (use_wait_tree_) {
493  if (read_inline_ == false) {
494  std::scoped_lock lock(mutex_);
495  WaitTree::iterator it = wait_tree_.find(bulk_seq_no_);
496  assert(it != wait_tree_.end());
497  bulk_message_context = &it->second;
498  } else {
499  bulk_message_context = bulk_msg_context_;
500  }
501  } else {
502  bulk_message_context = bulk_mctx_arr_[bmca_prod_];
503  }
504 
505  SendBulkMessage(bulk_message_context, bulk_seq_no_);
506 }
507 
508 // Send messages accumilated in bulk context
510  uint32_t seqno) {
511  KSyncBufferList iovec;
512  // Get all buffers to send into single io-vector
513  bulk_message_context->Data(&iovec);
514  tx_count_++;
515 
516  if (!read_inline_) {
517  if (!use_wait_tree_) {
518  bmca_prod_++;
520  bmca_prod_ = 0;
521  }
522  }
523 
524  AsyncSendTo(&iovec, seqno,
525  boost::bind(&KSyncSock::WriteHandler, this,
526  placeholders::error,
527  placeholders::bytes_transferred));
528  } else {
529  SendTo(&iovec, seqno);
530  bool more_data = false;
531  do {
532  char *rxbuf = bulk_message_context->GetReceiveBuffer();
533  Receive(boost::asio::buffer(rxbuf, kBufLen));
534  more_data = IsMoreData(rxbuf);
535  if (!process_data_inline_) {
536  ValidateAndEnqueue(rxbuf, bulk_message_context);
537  } else {
538  ProcessDataInline(rxbuf);
539  }
540  } while(more_data);
541  }
542 
543  bulk_msg_context_ = NULL;
545  return true;
546 }
547 
548 // Get the bulk-context for sequence-number
550 (uint32_t seqno, IoContext::Type io_context_type,
551  uint32_t work_queue_index) {
552  if (read_inline_) {
554  assert(bulk_msg_context_ == NULL);
555  bulk_seq_no_ = seqno;
556  bulk_buf_size_ = 0;
557  bulk_msg_count_ = 0;
558  bulk_msg_context_ = new KSyncBulkMsgContext(io_context_type,
559  work_queue_index);
560  }
561  return bulk_msg_context_;
562  }
563 
564  if (use_wait_tree_) {
565  std::scoped_lock lock(mutex_);
567  bulk_seq_no_ = seqno;
568  bulk_buf_size_ = 0;
569  bulk_msg_count_ = 0;
570 
571  wait_tree_.insert(WaitTreePair(seqno,
572  KSyncBulkMsgContext(io_context_type,
573  work_queue_index)));
574  }
575 
576  WaitTree::iterator it = wait_tree_.find(bulk_seq_no_);
577  assert(it != wait_tree_.end());
578  return &it->second;
579  } else {
581  bulk_seq_no_ = seqno;
582  bulk_buf_size_ = 0;
583  bulk_msg_count_ = 0;
584 
585  bulk_mctx_arr_[bmca_prod_] = new KSyncBulkMsgContext(io_context_type,
586  work_queue_index);
588  }
589 
590  return bulk_mctx_arr_[bmca_prod_];
591  }
592 
593  return NULL;
594 }
595 
596 // Try adding an io-context to bulk context. Returns
597 // - true : if message can be added to bulk context
598 // - false : if message cannot be added to bulk context
599 bool KSyncSock::TryAddToBulk(KSyncBulkMsgContext *bulk_message_context,
600  IoContext *ioc) {
602  return false;
603 
604  if (bulk_message_context->io_context_type() != ioc->type())
605  return false;
606 
607  if (use_wait_tree_) {
608  if (bulk_message_context->work_queue_index() != ioc->index())
609  return false;
610  }
611 
612  bulk_buf_size_ += ioc->GetMsgLen();
613  bulk_msg_count_++;
614 
615  bulk_message_context->Insert(ioc);
616  if (ioc->rx_buffer1()) {
617  bulk_message_context->AddReceiveBuffer(ioc->rx_buffer1());
618  ioc->reset_rx_buffer1();
619 
620  }
621  if (ioc->rx_buffer2()) {
622  bulk_message_context->AddReceiveBuffer(ioc->rx_buffer2());
623  ioc->reset_rx_buffer2();
624  }
625  return true;
626 }
627 
629  KSyncBulkMsgContext *bulk_message_context =
630  LocateBulkContext(ioc->GetSeqno(), ioc->type(), ioc->index());
631  // Try adding message to bulk-message list
632  if (TryAddToBulk(bulk_message_context, ioc)) {
633  // Message added to bulk-list. Nothing more to do
634  return true;
635  }
636 
637  // Message cannot be added to bulk-list. Send the current list
638  SendBulkMessage(bulk_message_context, bulk_seq_no_);
639 
640  // Allocate a new context and add message to it
641  bulk_message_context = LocateBulkContext(ioc->GetSeqno(), ioc->type(),
642  ioc->index());
643  assert(TryAddToBulk(bulk_message_context, ioc));
644  return true;
645 }
646 
647 
649 // KSyncSockNetlink routines
651 KSyncSockNetlink::KSyncSockNetlink(boost::asio::io_context &ios, int protocol)
652  : sock_(ios, protocol) {
653  ReceiveBuffForceSize set_rcv_buf;
654  set_rcv_buf = KSYNC_SOCK_RECV_BUFF_SIZE;
655  boost::system::error_code ec;
656  sock_.set_option(set_rcv_buf, ec);
657  if (ec.value() != 0) {
658  LOG(ERROR, "Error Changing netlink receive sock buffer size to " <<
659  set_rcv_buf.value() << " error = " <<
660  boost::system::system_error(ec).what());
661  }
662  boost::asio::socket_base::receive_buffer_size rcv_buf_size;
663  boost::system::error_code ec1;
664  sock_.get_option(rcv_buf_size, ec);
665  LOG(INFO, "Current receive sock buffer size is " << rcv_buf_size.value());
666 }
667 
669 }
670 
671 void KSyncSockNetlink::Init(io_service &ios, int protocol, bool use_work_queue,
672  const std::string &cpu_pin_policy) {
674  KSyncSock::Init(use_work_queue, cpu_pin_policy);
675 }
676 
677 uint32_t KSyncSockNetlink::GetSeqno(char *data) {
678  return GetNetlinkSeqno(data);
679 }
680 
682  return NetlinkMsgDone(data);
683 }
684 
685 bool KSyncSockNetlink::Validate(char *data) {
686  return ValidateNetlink(data);
687 }
688 
689 //netlink socket class for interacting with kernel
690 void KSyncSockNetlink::AsyncSendTo(KSyncBufferList *iovec, uint32_t seq_no,
691  HandlerCb cb) {
693  KSyncBufferList::iterator it = iovec->begin();
694  iovec->insert(it, buffer((char *)nl_client_->cl_buf,
695  nl_client_->cl_buf_offset));
697 
698  boost::asio::netlink::raw::endpoint ep;
699  sock_.async_send_to(*iovec, ep, cb);
700 }
701 
702 size_t KSyncSockNetlink::SendTo(KSyncBufferList *iovec, uint32_t seq_no) {
704  KSyncBufferList::iterator it = iovec->begin();
705  iovec->insert(it, buffer((char *)nl_client_->cl_buf,
706  nl_client_->cl_buf_offset));
708 
709  boost::asio::netlink::raw::endpoint ep;
710  return sock_.send_to(*iovec, ep);
711 }
712 
713 // Static method to decode non-bulk message
715  assert(ValidateNetlink(data));
716  char *buf = NULL;
717  uint32_t buf_len = 0;
718  GetNetlinkPayload(data, &buf, &buf_len);
719  DecodeSandeshMessages(buf, buf_len, ctxt, NLA_ALIGNTO);
720 }
721 
722 bool KSyncSockNetlink::Decoder(char *data, AgentSandeshContext *context) {
723  NetlinkDecoder(data, context);
724  return true;
725 }
726 
727 // Static method used in ksync_sock_user only
729  bool more) {
730  assert(ValidateNetlink(data));
731  char *buf = NULL;
732  uint32_t buf_len = 0;
733  GetNetlinkPayload(data, &buf, &buf_len);
734  KSyncBulkSandeshContext *bulk_sandesh_context =
735  dynamic_cast<KSyncBulkSandeshContext *>(ctxt);
736  bulk_sandesh_context->Decoder(buf, buf_len, NLA_ALIGNTO, more);
737 }
738 
740  KSyncBulkSandeshContext *bulk_sandesh_context) {
741  // Get sandesh buffer and buffer-length
742  uint32_t buf_len = 0;
743  char *buf = NULL;
744  GetNetlinkPayload(data, &buf, &buf_len);
745  return bulk_sandesh_context->Decoder(buf, buf_len, NLA_ALIGNTO, IsMoreData(data));
746 }
747 
748 void KSyncSockNetlink::AsyncReceive(mutable_buffers_1 buf, HandlerCb cb) {
749  sock_.async_receive(buf, cb);
750 }
751 
752 void KSyncSockNetlink::Receive(mutable_buffers_1 buf) {
753  sock_.receive(buf);
754  struct nlmsghdr *nlh = buffer_cast<struct nlmsghdr *>(buf);
755  if (nlh->nlmsg_type == NLMSG_ERROR) {
756  LOG(ERROR, "Netlink error for seqno " << nlh->nlmsg_seq
757  << " len " << nlh->nlmsg_len);
758  assert(0);
759  }
760 }
761 
763 // KSyncSockUdp routines
765 //Udp socket class for interacting with kernel
766 KSyncSockUdp::KSyncSockUdp(boost::asio::io_context &ios, int port) :
767  sock_(ios, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0)),
768  server_ep_(boost::asio::ip::address::from_string("127.0.0.1"), port) {
769 }
770 
771 void KSyncSockUdp::Init(io_service &ios, int port,
772  const std::string &cpu_pin_policy) {
774  KSyncSock::Init(false, cpu_pin_policy);
775 }
776 
777 uint32_t KSyncSockUdp::GetSeqno(char *data) {
778  struct uvr_msg_hdr *hdr = (struct uvr_msg_hdr *)data;
779  return hdr->seq_no;
780 }
781 
782 bool KSyncSockUdp::IsMoreData(char *data) {
783  struct uvr_msg_hdr *hdr = (struct uvr_msg_hdr *)data;
784  return ((hdr->flags & UVR_MORE) == UVR_MORE);
785 }
786 
787 // We dont expect any non-bulk operation on UDP
788 bool KSyncSockUdp::Decoder(char *data, AgentSandeshContext *context) {
789  assert(0);
790  return false;
791 }
792 
794  KSyncBulkSandeshContext *bulk_sandesh_context) {
795  struct uvr_msg_hdr *hdr = (struct uvr_msg_hdr *)data;
796  uint32_t buf_len = hdr->msg_len;
797  char *buf = data + sizeof(struct uvr_msg_hdr);
798  return bulk_sandesh_context->Decoder(buf, buf_len, 1, IsMoreData(data));
799 }
800 
801 void KSyncSockUdp::AsyncSendTo(KSyncBufferList *iovec, uint32_t seq_no,
802  HandlerCb cb) {
803  struct uvr_msg_hdr hdr;
804  hdr.seq_no = seq_no;
805  hdr.flags = 0;
806  hdr.msg_len = bulk_buf_size_;
807 
808  KSyncBufferList::iterator it = iovec->begin();
809  iovec->insert(it, buffer((char *)(&hdr), sizeof(hdr)));
810 
811  sock_.async_send_to(*iovec, server_ep_, cb);
812 }
813 
814 size_t KSyncSockUdp::SendTo(KSyncBufferList *iovec, uint32_t seq_no) {
815  struct uvr_msg_hdr hdr;
816  hdr.seq_no = seq_no;
817  hdr.flags = 0;
818  hdr.msg_len = bulk_buf_size_;
819 
820  KSyncBufferList::iterator it = iovec->begin();
821  iovec->insert(it, buffer((char *)(&hdr), sizeof(hdr)));
822 
823  return sock_.send_to(*iovec, server_ep_, MSG_DONTWAIT);
824 }
825 
826 bool KSyncSockUdp::Validate(char *data) {
827  return true;
828 }
829 
830 void KSyncSockUdp::AsyncReceive(mutable_buffers_1 buf, HandlerCb cb) {
831  boost::asio::ip::udp::endpoint ep;
832  sock_.async_receive_from(buf, ep, cb);
833 }
834 
835 void KSyncSockUdp::Receive(mutable_buffers_1 buf) {
836  boost::asio::ip::udp::endpoint ep;
837  sock_.receive_from(buf, ep);
838 }
839 
841  KSyncBulkMsgContext *bulk_message_context = NULL;
842  KSyncBulkSandeshContext *bulk_sandesh_context;
843  uint32_t seqno = GetSeqno(data);
844 
845  assert(!use_wait_tree_);
846  Validate(data);
847 
848  bulk_sandesh_context = GetBulkSandeshContext(seqno);
849  bulk_message_context = bulk_mctx_arr_[bmca_cons_];
850  assert(bulk_message_context->seqno() == seqno);
851 
852  bulk_sandesh_context->set_bulk_message_context(bulk_message_context);
853  BulkDecoder(data, bulk_sandesh_context);
854 
855  // Remove the IoContext only on last netlink message
856  if (IsMoreData(data) == false) {
857  delete bulk_message_context;
858  bmca_cons_++;
860  bmca_cons_ = 0;
861  }
862  }
863 
864  return;
865 }
866 
868 // KSyncIoContext routines
871  int msg_len, char *msg,
872  KSyncEntry::KSyncEvent event) :
873  IoContext(msg, msg_len, 0,
874  sock->GetAgentSandeshContext(sync_entry->GetTableIndex()),
875  IoContext::IOC_KSYNC, sync_entry->GetTableIndex()),
876  entry_(sync_entry), event_(event), sock_(sock) {
877  SetSeqno(sock->AllocSeqNo(type(), index()));
878 }
879 
882 }
883 
886 }
887 
889 // Routines for KSyncBulkSandeshContext
892  AgentSandeshContext(), bulk_msg_context_(NULL) { }
893 
895 }
896 
897 // Sandesh responses for old context are done. Check for any errors
900  AgentSandeshContext *sandesh_context = io_context->GetSandeshContext();
901 
902  sandesh_context->set_ksync_io_ctx(NULL);
903  if (sandesh_context->GetErrno() != 0 &&
904  sandesh_context->GetErrno() != EEXIST) {
905  io_context->ErrorHandler(sandesh_context->GetErrno());
906  }
907  io_context->Handler();
908 }
909 
913  AgentSandeshContext *sandesh_context = io_context.GetSandeshContext();
914  sandesh_context->set_ksync_io_ctx
915  (static_cast<KSyncIoContext *>(&io_context));
916 }
917 
918 // Process the sandesh messages
919 // There can be more then one sandesh messages in the netlink buffer.
920 // Iterate and process all of them
921 bool KSyncBulkSandeshContext::Decoder(char *data, uint32_t len,
922  uint32_t alignment, bool more) {
923  DecodeSandeshMessages(data, len, this, alignment);
926  if (more == true)
927  return false;
928 
929  IoContextDone();
930 
931  // No more netlink messages. Validate that iterator points to last element
932  // in IoContextList
936  return true;
937 }
938 
941  context->SetErrno(err);
942 }
943 
946  return bulk_msg_context_->io_context_list_it_->GetSandeshContext();
947 }
948 
949 void KSyncBulkSandeshContext::IfMsgHandler(vr_interface_req *req) {
951  context->IfMsgHandler(req);
952 }
953 
954 void KSyncBulkSandeshContext::NHMsgHandler(vr_nexthop_req *req) {
956  context->NHMsgHandler(req);
957 }
958 
961  context->RouteMsgHandler(req);
962 }
963 
966  context->MplsMsgHandler(req);
967 }
968 
971  context->QosConfigMsgHandler(req);
972 }
973 
976  context->ForwardingClassMsgHandler(req);
977 }
978 
979 // vr_response message is treated as delimiter in a bulk-context. So, move to
980 // next io-context within bulk-message context.
982  AgentSandeshContext *sandesh_context = NULL;
983  // If this is first vr_reponse received, move io-context to first entry in
984  // bulk context
988  sandesh_context =
989  bulk_msg_context_->io_context_list_it_->GetSandeshContext();
990  IoContextStart();
991  } else {
992  // Sandesh responses for old io-context are done.
993  // Check for any errors and trigger state-machine for old io-context
994  IoContextDone();
995  // Move to the next io-context
999  sandesh_context =
1000  bulk_msg_context_->io_context_list_it_->GetSandeshContext();
1001  IoContextStart();
1002  }
1003  return sandesh_context->VrResponseMsgHandler(resp);
1004 }
1005 
1008  context->MirrorMsgHandler(req);
1009 }
1010 
1013  context->FlowMsgHandler(req);
1014 }
1015 
1018  context->FlowResponseHandler(req);
1019 }
1020 
1021 void KSyncBulkSandeshContext::VrfAssignMsgHandler(vr_vrf_assign_req *req) {
1023  context->VrfAssignMsgHandler(req);
1024 }
1025 
1028  context->VrfMsgHandler(req);
1029 }
1030 
1031 void KSyncBulkSandeshContext::VrfStatsMsgHandler(vr_vrf_stats_req *req) {
1033  context->VrfStatsMsgHandler(req);
1034 }
1035 
1036 void KSyncBulkSandeshContext::DropStatsMsgHandler(vr_drop_stats_req *req) {
1038  context->DropStatsMsgHandler(req);
1039 }
1040 
1043  context->VxLanMsgHandler(req);
1044 }
1045 
1048  context->VrouterOpsMsgHandler(req);
1049 }
1050 
1052 // KSyncBulkMsgContext routines
1055  uint32_t index) :
1056  io_context_list_(), io_context_type_(type), work_queue_index_(index),
1057  rx_buffer_index_(0), vr_response_count_(0), io_context_list_it_() {
1058 }
1059 
1061  io_context_list_(), io_context_type_(rhs.io_context_type_),
1062  work_queue_index_(rhs.work_queue_index_),
1063  rx_buffer_index_(0), vr_response_count_(0), io_context_list_it_() {
1064  assert(rhs.vr_response_count_ == 0);
1065  assert(rhs.rx_buffer_index_ == 0);
1066  assert(rhs.io_context_list_.size() == 0);
1067 }
1068 
1070  void operator() (IoContext *io_context) { delete io_context; }
1071 };
1072 
1074  assert(vr_response_count_ == io_context_list_.size());
1075  io_context_list_.clear_and_dispose(IoContextDisposer());
1076  for (uint32_t i = 0; i < rx_buffer_index_; i++) {
1077  delete[] rx_buffers_[i];
1078  }
1079 }
1080 
1082  if (rx_buffer_index_ == 0)
1083  return new char[KSyncSock::kBufLen];
1084 
1085  return rx_buffers_[--rx_buffer_index_];
1086 }
1087 
1090  rx_buffers_[rx_buffer_index_++] = buff;
1091 }
1092 
1094  io_context_list_.push_back(*ioc);
1095  return;
1096 }
1097 
1099  IoContextList::iterator it = io_context_list_.begin();
1100  while (it != io_context_list_.end()) {
1101  iovec->push_back(buffer(it->GetMsg(), it->GetMsgLen()));
1102  it++;
1103  }
1104 }
void set_ksync_io_ctx(const KSyncIoContext *ioc)
Definition: ksync_sock.h:82
virtual void MplsMsgHandler(vr_mpls_req *req)=0
virtual void VrfAssignMsgHandler(vr_vrf_assign_req *req)=0
int GetErrno() const
Definition: ksync_sock.h:81
virtual void VrfMsgHandler(vr_vrf_req *req)=0
virtual void MirrorMsgHandler(vr_mirror_req *req)=0
virtual void NHMsgHandler(vr_nexthop_req *req)=0
virtual void QosConfigMsgHandler(vr_qos_map_req *req)=0
virtual void VrouterOpsMsgHandler(vrouter_ops *req)=0
virtual void SetErrno(int err)
Definition: ksync_sock.h:79
virtual void FlowResponseHandler(vr_flow_response *req)
Definition: ksync_sock.h:67
virtual void IfMsgHandler(vr_interface_req *req)=0
virtual void FlowMsgHandler(vr_flow_req *req)=0
virtual void ForwardingClassMsgHandler(vr_fc_map_req *req)=0
virtual void RouteMsgHandler(vr_route_req *req)=0
virtual void DropStatsMsgHandler(vr_drop_stats_req *req)=0
virtual void VrfStatsMsgHandler(vr_vrf_stats_req *req)=0
virtual void VxLanMsgHandler(vr_vxlan_req *req)=0
virtual int VrResponseMsgHandler(vr_response *resp)=0
AgentSandeshContext * GetSandeshContext()
Definition: ksync_sock.h:135
char * rx_buffer1() const
Definition: ksync_sock.h:142
virtual void ErrorHandler(int err)
Definition: ksync_sock.h:133
uint32_t index() const
Definition: ksync_sock.h:146
char * rx_buffer1_
Definition: ksync_sock.h:162
static const char * io_wq_names[MAX_WORK_QUEUES]
Definition: ksync_sock.h:105
virtual void Handler()
Definition: ksync_sock.h:132
@ MAX_WORK_QUEUES
Definition: ksync_sock.h:102
void reset_rx_buffer2()
Definition: ksync_sock.h:145
uint32_t GetSeqno() const
Definition: ksync_sock.h:139
uint32_t GetMsgLen() const
Definition: ksync_sock.h:141
char * rx_buffer2()
Definition: ksync_sock.h:144
void reset_rx_buffer1()
Definition: ksync_sock.h:143
Type type()
Definition: ksync_sock.h:136
void SetSeqno(uint32_t seqno)
Definition: ksync_sock.h:138
char * rx_buffer2_
Definition: ksync_sock.h:163
void set_seqno(uint32_t seq)
Definition: ksync_sock.h:247
uint32_t rx_buffer_index_
Definition: ksync_sock.h:263
KSyncBulkMsgContext(IoContext::Type type, uint32_t index)
Definition: ksync_sock.cc:1054
void Insert(IoContext *ioc)
Definition: ksync_sock.cc:1093
void Data(KSyncBufferList *iovec)
Definition: ksync_sock.cc:1098
char * GetReceiveBuffer()
Definition: ksync_sock.cc:1081
char * rx_buffers_[kMaxRxBufferCount]
Definition: ksync_sock.h:261
uint32_t vr_response_count_
Definition: ksync_sock.h:269
static const unsigned kMaxRxBufferCount
Definition: ksync_sock.h:234
IoContextList::iterator io_context_list_it_
Definition: ksync_sock.h:271
IoContextList io_context_list_
Definition: ksync_sock.h:252
IoContext::Type io_context_type() const
Definition: ksync_sock.h:241
uint32_t work_queue_index() const
Definition: ksync_sock.h:246
uint32_t seqno()
Definition: ksync_sock.h:248
void AddReceiveBuffer(char *buff)
Definition: ksync_sock.cc:1088
void set_bulk_message_context(KSyncBulkMsgContext *bulk_context)
Definition: ksync_sock.h:300
void VxLanMsgHandler(vr_vxlan_req *req)
Definition: ksync_sock.cc:1041
void IfMsgHandler(vr_interface_req *req)
Definition: ksync_sock.cc:949
void DropStatsMsgHandler(vr_drop_stats_req *req)
Definition: ksync_sock.cc:1036
bool Decoder(char *buff, uint32_t buff_len, uint32_t alignment, bool more)
Definition: ksync_sock.cc:921
void ForwardingClassMsgHandler(vr_fc_map_req *req)
Definition: ksync_sock.cc:974
void VrfAssignMsgHandler(vr_vrf_assign_req *req)
Definition: ksync_sock.cc:1021
void NHMsgHandler(vr_nexthop_req *req)
Definition: ksync_sock.cc:954
KSyncBulkMsgContext * bulk_msg_context_
Definition: ksync_sock.h:308
void FlowResponseHandler(vr_flow_response *req)
Definition: ksync_sock.cc:1016
virtual ~KSyncBulkSandeshContext()
Definition: ksync_sock.cc:894
void VrfStatsMsgHandler(vr_vrf_stats_req *req)
Definition: ksync_sock.cc:1031
void VrouterOpsMsgHandler(vrouter_ops *req)
Definition: ksync_sock.cc:1046
void RouteMsgHandler(vr_route_req *req)
Definition: ksync_sock.cc:959
void QosConfigMsgHandler(vr_qos_map_req *req)
Definition: ksync_sock.cc:969
void SetErrno(int err)
Definition: ksync_sock.cc:939
int VrResponseMsgHandler(vr_response *resp)
Definition: ksync_sock.cc:981
void MplsMsgHandler(vr_mpls_req *req)
Definition: ksync_sock.cc:964
AgentSandeshContext * GetSandeshContext()
Definition: ksync_sock.cc:944
void VrfMsgHandler(vr_vrf_req *req)
Definition: ksync_sock.cc:1026
void MirrorMsgHandler(vr_mirror_req *req)
Definition: ksync_sock.cc:1006
void FlowMsgHandler(vr_flow_req *req)
Definition: ksync_sock.cc:1011
virtual KSyncObject * GetObject() const =0
virtual bool pre_alloc_rx_buffer() const
Definition: ksync_entry.h:168
virtual void ErrorHandler(int err, uint32_t seqno, KSyncEvent event) const
static std::string VrouterErrorToString(uint32_t error)
KSyncEntry * entry_
Definition: ksync_sock.h:182
void ErrorHandler(int err)
Definition: ksync_sock.cc:884
KSyncSock * sock_
Definition: ksync_sock.h:185
KSyncIoContext(KSyncSock *sock, KSyncEntry *sync_entry, int msg_len, char *msg, KSyncEntry::KSyncEvent event)
Definition: ksync_sock.cc:870
virtual void Handler()
Definition: ksync_sock.cc:880
KSyncEntry::KSyncEvent event_
Definition: ksync_sock.h:183
virtual void NetlinkAck(KSyncEntry *entry, KSyncEntry::KSyncEvent event)
virtual void Receive(boost::asio::mutable_buffers_1)
Definition: ksync_sock.cc:835
virtual void AsyncReceive(boost::asio::mutable_buffers_1, HandlerCb)
Definition: ksync_sock.cc:830
static void Init(boost::asio::io_context &ios, int port, const std::string &cpu_pin_policy)
Definition: ksync_sock.cc:771
virtual bool BulkDecoder(char *data, KSyncBulkSandeshContext *ctxt)
Definition: ksync_sock.cc:793
KSyncSockUdp(boost::asio::io_context &ios, int port)
Definition: ksync_sock.cc:766
virtual bool IsMoreData(char *data)
Definition: ksync_sock.cc:782
boost::asio::ip::udp::endpoint server_ep_
Definition: ksync_sock.h:562
virtual void AsyncSendTo(KSyncBufferList *iovec, uint32_t seq_no, HandlerCb cb)
Definition: ksync_sock.cc:801
virtual bool Validate(char *data)
Definition: ksync_sock.cc:826
boost::asio::ip::udp::socket sock_
Definition: ksync_sock.h:561
virtual uint32_t GetSeqno(char *data)
Definition: ksync_sock.cc:777
virtual std::size_t SendTo(KSyncBufferList *iovec, uint32_t seq_no)
Definition: ksync_sock.cc:814
virtual bool Decoder(char *data, AgentSandeshContext *ctxt)
Definition: ksync_sock.cc:788
WorkQueue< KSyncRxData > KSyncReceiveQueue
Definition: ksync_sock.h:344
static std::unique_ptr< KSyncSock > sock_
Definition: ksync_sock.h:503
static AgentSandeshContext * agent_sandesh_ctx_[kRxWorkQueueCount]
Definition: ksync_sock.h:510
uint32_t bmca_prod_
Definition: ksync_sock.h:449
static AgentSandeshContext * GetAgentSandeshContext(uint32_t type)
Definition: ksync_sock.h:395
static pid_t pid_
Definition: ksync_sock.h:504
static const unsigned kInvalidBulkSeqNo
Definition: ksync_sock.h:322
std::size_t BlockingSend(char *msg, int msg_len)
Definition: ksync_sock.cc:450
KSyncReceiveQueue * ksync_rx_queue[kRxWorkQueueCount]
Definition: ksync_sock.h:432
bool ProcessKernelData(KSyncBulkSandeshContext *ksync_context, const KSyncRxData &data)
Definition: ksync_sock.cc:392
static uint32_t GetPid()
Definition: ksync_sock.h:391
virtual bool Validate(char *data)=0
void EnqueueRxProcessData(KSyncEntry *entry, KSyncEntry::KSyncEvent event)
Definition: ksync_sock.cc:328
KSyncBulkSandeshContext ksync_bulk_sandesh_context_[kRxWorkQueueCount]
Definition: ksync_sock.h:491
std::atomic< uint32_t > seqno_
Definition: ksync_sock.h:483
virtual uint32_t GetSeqno(char *data)=0
std::mutex mutex_
Definition: ksync_sock.h:426
virtual void Receive(boost::asio::mutable_buffers_1)=0
std::pair< uint32_t, KSyncBulkMsgContext > WaitTreePair
Definition: ksync_sock.h:325
uint32_t bulk_seq_no_
Definition: ksync_sock.h:443
std::atomic< uint32_t > uve_seqno_
Definition: ksync_sock.h:484
KSyncBulkMsgContext * LocateBulkContext(uint32_t seqno, IoContext::Type io_context_type, uint32_t work_queue_index)
Definition: ksync_sock.cc:550
void OnEmptyQueue(bool done)
Definition: ksync_sock.cc:487
virtual bool Decoder(char *data, AgentSandeshContext *ctxt)=0
static void Init(bool use_work_queue, const std::string &cpu_pin_policy)
Definition: ksync_sock.cc:232
virtual void AsyncSendTo(KSyncBufferList *iovec, uint32_t seq_no, HandlerCb cb)=0
void ProcessDataInline(char *data)
Definition: ksync_sock.cc:840
bool read_inline_
Definition: ksync_sock.h:487
static void Shutdown()
Definition: ksync_sock.cc:226
void ReadHandler(const boost::system::error_code &error, size_t bytes_transferred)
Definition: ksync_sock.cc:370
bool ValidateAndEnqueue(char *data, KSyncBulkMsgContext *context)
Definition: ksync_sock.cc:355
void GenericSend(IoContext *ctx)
Definition: ksync_sock.cc:457
int SendBulkMessage(KSyncBulkMsgContext *bulk_context, uint32_t seqno)
Definition: ksync_sock.cc:509
bool SendAsyncImpl(IoContext *ioc)
Definition: ksync_sock.cc:628
static void Start(bool read_inline)
Definition: ksync_sock.cc:258
uint32_t WaitTreeSize() const
Definition: ksync_sock.cc:280
void SendAsync(KSyncEntry *entry, int msg_len, char *msg, KSyncEntry::KSyncEvent event)
Definition: ksync_sock.cc:461
uint32_t bulk_buf_size_
Definition: ksync_sock.h:445
static const int kRxWorkQueueCount
Definition: ksync_sock.h:315
virtual ~KSyncSock()
Definition: ksync_sock.cc:204
KSyncReceiveQueue * AllocQueue(KSyncBulkSandeshContext ctxt[], uint32_t task_id, uint32_t instance, const char *name)
Definition: ksync_sock.cc:239
bool BlockingRecv()
Definition: ksync_sock.cc:425
static void SetSockTableEntry(KSyncSock *sock)
Definition: ksync_sock.cc:270
KSyncBulkSandeshContext uve_bulk_sandesh_context_[kRxWorkQueueCount]
Definition: ksync_sock.h:492
KSyncRxWorkQueue rx_process_queue_
Definition: ksync_sock.h:502
static void SetNetlinkFamilyId(int id)
Definition: ksync_sock.cc:275
boost::function< void(const boost::system::error_code &, size_t)> HandlerCb
Definition: ksync_sock.h:327
static const unsigned kBufLen
Definition: ksync_sock.h:317
void WriteHandler(const boost::system::error_code &error, size_t bytes_transferred)
Definition: ksync_sock.cc:475
void SetMeasureQueueDelay(bool val)
Definition: ksync_sock.cc:251
bool TryAddToBulk(KSyncBulkMsgContext *bulk_context, IoContext *ioc)
Definition: ksync_sock.cc:599
char * rx_buff_
Definition: ksync_sock.h:482
KSyncReceiveQueue * GetReceiveQueue(IoContext::Type type, uint32_t instance)
Definition: ksync_sock.cc:309
virtual std::size_t SendTo(KSyncBufferList *iovec, uint32_t seq_no)=0
uint32_t AllocSeqNo(IoContext::Type type)
Definition: ksync_sock.cc:305
WaitTree wait_tree_
Definition: ksync_sock.h:429
uint32_t bulk_msg_count_
Definition: ksync_sock.h:447
nl_client * nl_client_
Definition: ksync_sock.h:427
void SetSeqno(uint32_t seq)
Definition: ksync_sock.cc:284
KSyncTxQueue send_queue_
Definition: ksync_sock.h:430
static KSyncSock * Get(DBTablePartBase *partition)
Definition: ksync_sock.cc:346
bool use_wait_tree_
Definition: ksync_sock.h:489
virtual bool BulkDecoder(char *data, KSyncBulkSandeshContext *ctxt)=0
KSyncReceiveQueue * uve_rx_queue[kRxWorkQueueCount]
Definition: ksync_sock.h:431
virtual void AsyncReceive(boost::asio::mutable_buffers_1, HandlerCb)=0
uint32_t max_bulk_msg_count_
Definition: ksync_sock.h:437
KSyncBulkSandeshContext * GetBulkSandeshContext(uint32_t seqno)
Definition: ksync_sock.cc:337
KSyncBulkMsgContext * bulk_mctx_arr_[KSYNC_BMC_ARR_SIZE]
Definition: ksync_sock.h:451
static int vnsw_netlink_family_id_
Definition: ksync_sock.h:505
int tx_count_
Definition: ksync_sock.h:495
KSyncBulkMsgContext * bulk_msg_context_
Definition: ksync_sock.h:488
bool ProcessRxData(KSyncRxQueueData data)
Definition: ksync_sock.cc:331
uint32_t bmca_cons_
Definition: ksync_sock.h:450
virtual bool IsMoreData(char *data)=0
bool process_data_inline_
Definition: ksync_sock.h:490
static std::atomic< bool > shutdown_
Definition: ksync_sock.h:511
static int GetNetlinkFamilyId()
Definition: ksync_sock.h:392
bool Enqueue(IoContext *io_context)
static int32_t ReceiveBinaryMsgOne(u_int8_t *buf, u_int32_t buf_len, int *error, SandeshContext *client_context)
Definition: sandesh.cc:644
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
int GetTaskId(const std::string &name)
Definition: task.cc:884
static TaskScheduler * GetInstance()
Definition: task.cc:574
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:249
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:153
void set_measure_busy_time(bool val) const
Definition: queue_task.h:380
void set_name(const std::string &name)
Definition: queue_task.h:308
#define KSYNC_ERROR(obj,...)
Definition: ksync_entry.h:17
bool NetlinkMsgDone(char *data)
Definition: ksync_sock.cc:68
bool ValidateNetlink(char *data)
Definition: ksync_sock.cc:74
void GetNetlinkPayload(char *data, char **buf, uint32_t *buf_len)
Definition: ksync_sock.cc:119
void UpdateNetlink(nl_client *client, uint32_t len, uint32_t seq_no)
Definition: ksync_sock.cc:146
boost::asio::detail::socket_option::integer< SOL_SOCKET, SO_RCVBUFFORCE > ReceiveBuffForceSize
Definition: ksync_sock.cc:46
void InitNetlink(nl_client *client)
Definition: ksync_sock.cc:132
uint32_t GetNetlinkSeqno(char *data)
Definition: ksync_sock.cc:63
void ResetNetlink(nl_client *client)
Definition: ksync_sock.cc:139
void DecodeSandeshMessages(char *buf, uint32_t buf_len, SandeshContext *sandesh_context, uint32_t alignment)
Definition: ksync_sock.cc:153
std::vector< boost::asio::mutable_buffers_1 > KSyncBufferList
Definition: ksync_sock.h:38
#define KSYNC_BMC_ARR_SIZE
Definition: ksync_sock.h:32
#define KSYNC_DEFAULT_Q_ID_SEQ
Definition: ksync_sock.h:29
#define KSYNC_SOCK_RECV_BUFF_SIZE
Definition: ksync_sock.h:31
uint8_t type
Definition: load_balance.h:2
#define LOG(_Level, _Msg)
Definition: logging.h:35
void operator()(IoContext *io_context)
Definition: ksync_sock.cc:1070
KSyncBulkMsgContext * bulk_msg_context_
Definition: ksync_sock.h:334
KSyncEntry::KSyncEvent event_
Definition: ksync_sock.h:348