@@ -278,23 +278,37 @@ SimpleSwitch::receive_(port_t port_num, const char *buffer, int len) {
278278void
279279SimpleSwitch::start_and_return_ () {
280280 check_queueing_metadata ();
281- #ifdef PKT_FANOUT_ON
282- auto ingress_thread = std::thread (&SimpleSwitch::ingress_thread, this );
283- FanoutPktMgr::instance ().register_thread (
284- ingress_thread.get_id ());
285- threads_.push_back (std::move (ingress_thread));
286- for (size_t i = 0 ; i < nb_egress_threads; i++) {
287- auto egress_thread = std::thread (&SimpleSwitch::egress_thread, this , i);
281+ if (FanoutPktMgr::pkt_fanout_on) {
282+ auto ingress_thread = std::thread (&SimpleSwitch::ingress_thread, this );
288283 FanoutPktMgr::instance ().register_thread (
289- egress_thread.get_id ());
290- threads_.push_back (std::move (egress_thread));
291- }
292- #else
293- threads_.push_back (std::thread (&SimpleSwitch::ingress_thread, this ));
294- for (size_t i = 0 ; i < nb_egress_threads; i++) {
295- threads_.push_back (std::thread (&SimpleSwitch::egress_thread, this , i));
284+ ingress_thread.get_id (), [&](const bm::Packet *pkt) {
285+ this ->input_buffer ->push_front (
286+ InputBuffer::PacketType::SELECTOR_FANOUT,
287+ std::unique_ptr<bm::Packet>(const_cast <bm::Packet *>(pkt)));
288+ BMLOG_DEBUG_PKT (*pkt,
289+ " SELECTOR_FANOUT packet pushed to ingress_buffer" );
290+ });
291+
292+ threads_.push_back (std::move (ingress_thread));
293+ for (size_t i = 0 ; i < nb_egress_threads; i++) {
294+ auto egress_thread = std::thread (&SimpleSwitch::egress_thread, this , i);
295+
296+ FanoutPktMgr::instance ().register_thread (
297+ egress_thread.get_id (), [&](const bm::Packet *pkt) {
298+ this ->egress_buffers .push_front (i, 0 ,
299+ std::unique_ptr<bm::Packet>(const_cast <bm::Packet *>(pkt)));
300+ BMLOG_DEBUG_PKT (*pkt,
301+ " SELECTOR_FANOUT packet pushed to egress_buffer" );
302+ });
303+
304+ threads_.push_back (std::move (egress_thread));
305+ }
306+ } else {
307+ threads_.push_back (std::thread (&SimpleSwitch::ingress_thread, this ));
308+ for (size_t i = 0 ; i < nb_egress_threads; i++) {
309+ threads_.push_back (std::thread (&SimpleSwitch::egress_thread, this , i));
310+ }
296311 }
297- #endif
298312 threads_.push_back (std::thread (&SimpleSwitch::transmit_thread, this ));
299313}
300314
@@ -524,9 +538,9 @@ SimpleSwitch::ingress_thread() {
524538 deparser. TODO? */
525539 const Packet::buffer_state_t packet_in_state = packet->save_buffer_state ();
526540
527- // Check if the packet has an optional continue node
541+ // Check if the packet has an optional continue node for pkt fanout
528542 // TODO(Hao): update the doc/simple_switch.md
529- if (packet->has_next_node ()) {
543+ if (FanoutPktMgr::pkt_fanout_on && packet->has_next_node ()) {
530544 ingress_mau->apply_from_next_node (packet.get ());
531545 } else {
532546 parser->parse (packet.get ());
@@ -542,20 +556,6 @@ SimpleSwitch::ingress_thread() {
542556
543557 ingress_mau->apply (packet.get ());
544558 }
545-
546- #ifdef PKT_FANOUT_ON
547- {
548- auto &fanout_pkts = FanoutPktMgr::instance ().get_fanout_pkts ();
549- for (auto pkt : fanout_pkts) {
550- input_buffer->push_front (InputBuffer::PacketType::SELECTOR_FANOUT,
551- std::unique_ptr<bm::Packet>(pkt));
552- BMLOG_DEBUG_PKT (*pkt,
553- " SELECTOR_FANOUT packet pushed to ingress_buffer" );
554- }
555- fanout_pkts.clear ();
556- }
557- #endif
558-
559559 packet->reset_exit ();
560560
561561 Field &f_egress_spec = phv->get_field (" standard_metadata.egress_spec" );
@@ -694,7 +694,8 @@ SimpleSwitch::egress_thread(size_t worker_id) {
694694 Pipeline *egress_mau = this ->get_pipeline (" egress" );
695695
696696 phv = packet->get_phv ();
697-
697+ Field &f_egress_spec = phv->get_field (" standard_metadata.egress_spec" );
698+
698699 if (packet->has_next_node ()) {
699700 egress_mau->apply_from_next_node (packet.get ());
700701 } else {
@@ -717,7 +718,6 @@ SimpleSwitch::egress_thread(size_t worker_id) {
717718 }
718719
719720 phv->get_field (" standard_metadata.egress_port" ).set (port);
720- Field &f_egress_spec = phv->get_field (" standard_metadata.egress_spec" );
721721 // When egress_spec == drop_port the packet will be dropped, thus
722722 // here we initialize egress_spec to a value different from drop_port.
723723 f_egress_spec.set (drop_port + 1 );
@@ -728,17 +728,6 @@ SimpleSwitch::egress_thread(size_t worker_id) {
728728 egress_mau->apply (packet.get ());
729729 }
730730
731- #ifdef PKT_FANOUT_ON
732- {
733- auto &fanout_pkts = FanoutPktMgr::instance ().get_fanout_pkts ();
734- for (auto pkt : fanout_pkts) {
735- egress_buffers.push_front (worker_id, 0 , std::unique_ptr<Packet>(pkt));
736- BMLOG_DEBUG_PKT (*pkt, " SELECTOR_FANOUT packet pushed to egress_buffer" );
737- }
738- fanout_pkts.clear ();
739- }
740- #endif
741-
742731 auto clone_mirror_session_id =
743732 RegisterAccess::get_clone_mirror_session_id (packet.get ());
744733 auto clone_field_list = RegisterAccess::get_clone_field_list (packet.get ());
0 commit comments