LCOV - code coverage report
Current view: top level - vnsw/agent/pkt - proto.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 36 38 94.7 %
Date: 2026-06-04 02:06:09 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include "base/os.h"
       6             : #include "pkt/proto.h"
       7             : #include "pkt/proto_handler.h"
       8             : #include "pkt/pkt_init.h"
       9             : #include "cmn/agent_stats.h"
      10             : 
      11             : ////////////////////////////////////////////////////////////////////////////////
      12             : 
      13          26 : Proto::Proto(Agent *agent, const char *task_name, PktHandler::PktModuleName mod,
      14          26 :              boost::asio::io_context &io)
      15          26 :     : agent_(agent), module_(mod), trace_(true), free_buffer_(false), io_(io),
      16          26 :       work_queue_(TaskScheduler::GetInstance()->GetTaskId(task_name), mod,
      17          26 :                   boost::bind(&Proto::ProcessProto, this, _1)) {
      18          26 :     agent->pkt()->pkt_handler()->Register(mod, this);
      19          26 :     std::ostringstream str;
      20          26 :     str << "Proto work queue. Module " << mod;
      21          26 :     work_queue_.set_name(str.str());
      22          26 : }
      23             : 
      24          26 : Proto::~Proto() {
      25          26 :     work_queue_.Shutdown();
      26          26 : }
      27             : 
      28          22 : void Proto::FreeBuffer(PktInfo *msg) {
      29          22 :     msg->pkt = NULL;
      30          22 :     msg->eth = NULL;
      31          22 :     msg->arp = NULL;
      32          22 :     msg->ip = NULL;
      33          22 :     msg->transp.tcp = NULL;
      34          22 :     msg->data = NULL;
      35          22 :     msg->reset_packet_buffer();
      36          22 : }
      37             : 
      38         200 : bool Proto::Enqueue(boost::shared_ptr<PktInfo> msg) {
      39         200 :     if (Validate(msg.get()) == false) {
      40           0 :         return true;
      41             :     }
      42             : 
      43         200 :     if (free_buffer_) {
      44           0 :         FreeBuffer(msg.get());
      45             :     }
      46             : 
      47         200 :     return work_queue_.Enqueue(msg);
      48             : }
      49             : 
      50         247 : bool Proto::RunProtoHandler(ProtoHandler *handler) {
      51         247 :     if (handler->Run())
      52         218 :         delete handler;
      53         247 :     return true;
      54             : }
      55             : 
      56             : // PktHandler enqueues the packet as-is without decoding based on "cmd" in
      57             : // agent_hdr. Decode the pacekt first. Its possible that protocol handler may
      58             : // change based on packet decode
      59         222 : bool Proto::ProcessProto(boost::shared_ptr<PktInfo> msg_info) {
      60         222 :     PktHandler *pkt_handler = agent_->pkt()->pkt_handler();
      61         222 :     if (trace_) {
      62         200 :         pkt_handler->AddPktTrace(module_, PktTrace::In, msg_info.get());
      63             :     }
      64             : 
      65         222 :     ProtoHandler *handler = AllocProtoHandler(msg_info, io_);
      66         222 :     return RunProtoHandler(handler);
      67             : }

Generated by: LCOV version 1.14