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 2 : PktModule::PktModule(Agent *agent) : 22 2 : agent_(agent), control_interface_(NULL), 23 2 : pkt_handler_(NULL), flow_proto_(NULL), 24 4 : packet_buffer_manager_(new PacketBufferManager(this)) { 25 2 : } 26 : 27 4 : PktModule::~PktModule() { 28 4 : } 29 : 30 2 : void PktModule::Init(bool run_with_vrouter) { 31 2 : boost::asio::io_context &io = *agent_->event_manager()->io_service(); 32 : 33 2 : pkt_handler_.reset(new PktHandler(agent_, this)); 34 : 35 2 : if (control_interface_) { 36 2 : control_interface_->Init(pkt_handler_.get()); 37 : } 38 : 39 2 : flow_proto_.reset(new FlowProto(agent_, io)); 40 2 : flow_proto_->Init(); 41 : 42 2 : uint16_t table_count = agent_->flow_thread_count(); 43 4 : for (uint8_t i = 0; i < table_count; i++) { 44 2 : flow_mgmt_manager_list_.push_back(new FlowMgmtManager(agent_, i)); 45 2 : flow_mgmt_manager_list_[i]->Init(); 46 : } 47 2 : FlowMgmtManager::InitLogQueue(agent_); 48 2 : } 49 : 50 2 : void PktModule::InitDone() { 51 2 : flow_proto_->InitDone(); 52 2 : } 53 : 54 2 : void PktModule::set_control_interface(ControlInterface *intf) { 55 2 : control_interface_ = intf; 56 2 : } 57 : 58 2 : void PktModule::Shutdown() { 59 2 : flow_proto_->Shutdown(); 60 2 : flow_proto_.reset(NULL); 61 : 62 2 : control_interface_->Shutdown(); 63 2 : control_interface_ = NULL; 64 : 65 2 : FlowMgmtManagerList::iterator it = flow_mgmt_manager_list_.begin(); 66 4 : while (it != flow_mgmt_manager_list_.end()) { 67 2 : (*it)->Shutdown(); 68 2 : it++; 69 : } 70 : 71 2 : STLDeleteValues(&flow_mgmt_manager_list_); 72 2 : FlowMgmtManager::ShutdownLogQueue(); 73 2 : } 74 : 75 2 : void PktModule::IoShutdown() { 76 2 : control_interface_->IoShutdown(); 77 2 : } 78 : 79 2 : void PktModule::FlushFlows() { 80 2 : flow_proto_->FlushFlows(); 81 2 : } 82 : 83 2 : void PktModule::CreateInterfaces() { 84 2 : if (control_interface_ == NULL) 85 0 : return; 86 : 87 2 : Interface::Transport transport = Interface::TRANSPORT_ETHERNET; 88 2 : if (agent_->vrouter_on_host_dpdk()) { 89 0 : transport = Interface::TRANSPORT_SOCKET; 90 : } 91 : 92 2 : PacketInterface::Create(agent_->interface_table(), 93 2 : 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 : }