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