Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include <io/event_manager.h> 6 : #include <cmn/agent_cmn.h> 7 : #include <cmn/agent_factory.h> 8 : #include "sandesh/sandesh_trace.h" 9 : #include "pkt/pkt_init.h" 10 : #include "pkt/pkt_handler.h" 11 : #include "pkt/proto.h" 12 : #include "pkt/proto_handler.h" 13 : #include "pkt/flow_proto.h" 14 : #include "pkt/flow_table.h" 15 : #include "pkt/packet_buffer.h" 16 : #include "pkt/control_interface.h" 17 : #include "pkt/flow_mgmt.h" 18 : 19 : SandeshTraceBufferPtr PacketTraceBuf(SandeshTraceBufferCreate("Packet", 1000)); 20 : 21 3 : PktModule::PktModule(Agent *agent) : 22 3 : agent_(agent), control_interface_(NULL), 23 3 : pkt_handler_(NULL), flow_proto_(NULL), 24 6 : packet_buffer_manager_(new PacketBufferManager(this)) { 25 3 : } 26 : 27 6 : PktModule::~PktModule() { 28 6 : } 29 : 30 3 : void PktModule::Init(bool run_with_vrouter) { 31 3 : boost::asio::io_context &io = *agent_->event_manager()->io_service(); 32 : 33 3 : pkt_handler_.reset(new PktHandler(agent_, this)); 34 : 35 3 : if (control_interface_) { 36 3 : control_interface_->Init(pkt_handler_.get()); 37 : } 38 : 39 3 : flow_proto_.reset(new FlowProto(agent_, io)); 40 3 : flow_proto_->Init(); 41 : 42 3 : uint16_t table_count = agent_->flow_thread_count(); 43 6 : for (uint8_t i = 0; i < table_count; i++) { 44 3 : flow_mgmt_manager_list_.push_back(new FlowMgmtManager(agent_, i)); 45 3 : flow_mgmt_manager_list_[i]->Init(); 46 : } 47 3 : FlowMgmtManager::InitLogQueue(agent_); 48 3 : } 49 : 50 3 : void PktModule::InitDone() { 51 3 : flow_proto_->InitDone(); 52 3 : } 53 : 54 3 : void PktModule::set_control_interface(ControlInterface *intf) { 55 3 : control_interface_ = intf; 56 3 : } 57 : 58 3 : void PktModule::Shutdown() { 59 3 : flow_proto_->Shutdown(); 60 3 : flow_proto_.reset(NULL); 61 : 62 3 : control_interface_->Shutdown(); 63 3 : control_interface_ = NULL; 64 : 65 3 : FlowMgmtManagerList::iterator it = flow_mgmt_manager_list_.begin(); 66 6 : while (it != flow_mgmt_manager_list_.end()) { 67 3 : (*it)->Shutdown(); 68 3 : it++; 69 : } 70 : 71 3 : STLDeleteValues(&flow_mgmt_manager_list_); 72 3 : FlowMgmtManager::ShutdownLogQueue(); 73 3 : } 74 : 75 3 : void PktModule::IoShutdown() { 76 3 : control_interface_->IoShutdown(); 77 3 : } 78 : 79 3 : void PktModule::FlushFlows() { 80 3 : flow_proto_->FlushFlows(); 81 3 : } 82 : 83 3 : void PktModule::CreateInterfaces() { 84 3 : if (control_interface_ == NULL) 85 0 : return; 86 : 87 3 : Interface::Transport transport = Interface::TRANSPORT_ETHERNET; 88 3 : if (agent_->vrouter_on_host_dpdk()) { 89 0 : transport = Interface::TRANSPORT_SOCKET; 90 : } 91 : 92 3 : PacketInterface::Create(agent_->interface_table(), 93 3 : control_interface_->Name(), 94 : transport); 95 : } 96 : 97 0 : FlowTable *PktModule::flow_table(uint16_t index) const { 98 0 : return flow_proto_->GetTable(index); 99 : }