OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
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 
12 
13 Proto::Proto(Agent *agent, const char *task_name, PktHandler::PktModuleName mod,
14  boost::asio::io_context &io)
15  : agent_(agent), module_(mod), trace_(true), free_buffer_(false), io_(io),
16  work_queue_(TaskScheduler::GetInstance()->GetTaskId(task_name), mod,
17  boost::bind(&Proto::ProcessProto, this, _1)) {
18  agent->pkt()->pkt_handler()->Register(mod, this);
19  std::ostringstream str;
20  str << "Proto work queue. Module " << mod;
21  work_queue_.set_name(str.str());
22 }
23 
26 }
27 
29  msg->pkt = NULL;
30  msg->eth = NULL;
31  msg->arp = NULL;
32  msg->ip = NULL;
33  msg->transp.tcp = NULL;
34  msg->data = NULL;
35  msg->reset_packet_buffer();
36 }
37 
38 bool Proto::Enqueue(boost::shared_ptr<PktInfo> msg) {
39  if (Validate(msg.get()) == false) {
40  return true;
41  }
42 
43  if (free_buffer_) {
44  FreeBuffer(msg.get());
45  }
46 
47  return work_queue_.Enqueue(msg);
48 }
49 
51  if (handler->Run())
52  delete handler;
53  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 bool Proto::ProcessProto(boost::shared_ptr<PktInfo> msg_info) {
60  PktHandler *pkt_handler = agent_->pkt()->pkt_handler();
61  if (trace_) {
62  pkt_handler->AddPktTrace(module_, PktTrace::In, msg_info.get());
63  }
64 
65  ProtoHandler *handler = AllocProtoHandler(msg_info, io_);
66  return RunProtoHandler(handler);
67 }
bool RunProtoHandler(ProtoHandler *handler)
The TaskScheduler keeps track of what tasks are currently schedulable. When a task is enqueued it is ...
Definition: task.h:178
struct ip * ip
Definition: pkt_handler.h:423
union PktInfo::@8 transp
void Shutdown(bool delete_entries=true)
Definition: queue_task.h:152
boost::asio::io_context & io_
uint8_t * data
Definition: pkt_handler.h:383
virtual bool Validate(PktInfo *msg)
struct ether_header * eth
Definition: pkt_handler.h:420
void Register(PktModuleName type, RcvQueueFunc cb)
void AddPktTrace(PktModuleName module, PktTrace::Direction dir, const PktInfo *pkt)
virtual bool Enqueue(boost::shared_ptr< PktInfo > msg)
Definition: agent.h:358
uint8_t * pkt
Definition: pkt_handler.h:379
void FreeBuffer(PktInfo *msg)
virtual ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)=0
struct ether_arp * arp
Definition: pkt_handler.h:422
Proto(Agent *agent, const char *task_name, PktHandler::PktModuleName mod, boost::asio::io_context &io)
PktHandler * pkt_handler() const
Definition: pkt_init.h:31
void reset_packet_buffer()
struct tcphdr * tcp
Definition: pkt_handler.h:426
PktModule * pkt() const
Definition: agent.cc:965
PktHandler::PktModuleName module_
bool ProcessProto(boost::shared_ptr< PktInfo > msg_info)
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:248
virtual bool Run()=0
void set_name(const std::string &name)
Definition: queue_task.h:307