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