OpenSDN source code
controller/src/vnsw/agent/pkt/proto.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 "base/os.h"
7 #include "pkt/proto.h"
8 #include "pkt/proto_handler.h"
9 #include "pkt/pkt_init.h"
10 #include "cmn/agent_stats.h"
11 
13 
14 Proto::Proto(Agent *agent, const char *task_name, PktHandler::PktModuleName mod,
15  boost::asio::io_context &io)
16  : agent_(agent), module_(mod), trace_(true), free_buffer_(false), io_(io),
17  work_queue_(TaskScheduler::GetInstance()->GetTaskId(task_name), mod,
18  boost::bind(&Proto::ProcessProto, this, _1)) {
19  agent->pkt()->pkt_handler()->Register(mod, this);
20  std::ostringstream str;
21  str << "Proto work queue. Module " << mod;
22  work_queue_.set_name(str.str());
23 }
24 
27 }
28 
30  msg->pkt = NULL;
31  msg->eth = NULL;
32  msg->arp = NULL;
33  msg->ip = NULL;
34  msg->transp.tcp = NULL;
35  msg->data = NULL;
36  msg->reset_packet_buffer();
37 }
38 
39 bool Proto::Enqueue(boost::shared_ptr<PktInfo> msg) {
40  if (Validate(msg.get()) == false) {
41  return true;
42  }
43 
44  if (free_buffer_) {
45  FreeBuffer(msg.get());
46  }
47 
48  return work_queue_.Enqueue(msg);
49 }
50 
52  if (handler->Run())
53  delete handler;
54  return true;
55 }
56 
57 // PktHandler enqueues the packet as-is without decoding based on "cmd" in
58 // agent_hdr. Decode the pacekt first. Its possible that protocol handler may
59 // change based on packet decode
60 bool Proto::ProcessProto(boost::shared_ptr<PktInfo> msg_info) {
61  PktHandler *pkt_handler = agent_->pkt()->pkt_handler();
62  if (trace_) {
63  pkt_handler->AddPktTrace(module_, PktTrace::In, msg_info.get());
64  }
65 
66  ProtoHandler *handler = AllocProtoHandler(msg_info, io_);
67  return RunProtoHandler(handler);
68 }
Definition: agent.h:361
PktModule * pkt() const
Definition: agent.cc:969
void AddPktTrace(PktModuleName module, PktTrace::Direction dir, const PktInfo *pkt)
void Register(PktModuleName type, RcvQueueFunc cb)
PktHandler * pkt_handler() const
Definition: pkt_init.h:32
virtual bool Run()=0
bool ProcessProto(boost::shared_ptr< PktInfo > msg_info)
bool RunProtoHandler(ProtoHandler *handler)
void FreeBuffer(PktInfo *msg)
virtual bool Enqueue(boost::shared_ptr< PktInfo > msg)
virtual bool Validate(PktInfo *msg)
boost::asio::io_context & io_
virtual ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)=0
Proto(Agent *agent, const char *task_name, PktHandler::PktModuleName mod, boost::asio::io_context &io)
PktHandler::PktModuleName module_
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:307
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:249
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:153
void set_name(const std::string &name)
Definition: queue_task.h:308
Definition: io_utils.cc:12
uint8_t * pkt
Definition: pkt_handler.h:379
void reset_packet_buffer()
uint8_t * data
Definition: pkt_handler.h:383
struct ether_arp * arp
Definition: pkt_handler.h:422
struct ether_header * eth
Definition: pkt_handler.h:420
struct ip * ip
Definition: pkt_handler.h:423
union PktInfo::@8 transp
struct tcphdr * tcp
Definition: pkt_handler.h:426