void EventLogger::deparser_start(const Packet &packet, const Deparser &deparser) { typedef struct : msg_hdr_t { int deparser_id; } __attribute__((packed)) msg_t; msg_t msg; fill_msg_hdr(EventType::DEPARSER_START, packet, &msg); msg.deparser_id = deparser.get_id(); transport_instance->send((char *) &msg, sizeof(msg)); };
void EventLogger::deparser_done(const Packet &packet, const Deparser &deparser) { typedef struct : msg_hdr_t { int deparser_id; } __attribute__((packed)) msg_t; msg_t msg; fill_msg_hdr(EventType::DEPARSER_DONE, device_id, packet, &msg); msg.deparser_id = deparser.get_id(); transport_instance->send(reinterpret_cast<char *>(&msg), sizeof(msg)); }
void SimpleSwitch::pipeline_thread() { Pipeline *ingress_mau = this->get_pipeline("ingress"); Pipeline *egress_mau = this->get_pipeline("egress"); Parser *parser = this->get_parser("parser"); Deparser *deparser = this->get_deparser("deparser"); PHV *phv; while (1) { std::unique_ptr<Packet> packet; input_buffer.pop_back(&packet); phv = packet->get_phv(); int ingress_port = packet->get_ingress_port(); BMLOG_DEBUG_PKT(*packet, "Processing packet received on port {}", ingress_port); phv->get_field("standard_metadata.ingress_port").set(ingress_port); ingress_port = phv->get_field("standard_metadata.ingress_port").get_int(); std::cout << ingress_port << std::endl; parser->parse(packet.get()); ingress_mau->apply(packet.get()); int egress_port = phv->get_field("standard_metadata.egress_port").get_int(); BMLOG_DEBUG_PKT(*packet, "Egress port is {}", egress_port); int learn_id = phv->get_field("intrinsic_metadata.learn_id").get_int(); BMLOG_DEBUG_PKT(*packet, "Learn id is {}", learn_id); unsigned int mgid = phv->get_field("intrinsic_metadata.mgid").get_uint(); BMLOG_DEBUG_PKT(*packet, "Mgid is {}", mgid); if (learn_id > 0) { get_learn_engine()->learn(learn_id, *packet.get()); phv->get_field("intrinsic_metadata.learn_id").set(0); } if (egress_port == 511 && mgid == 0) { BMLOG_DEBUG_PKT(*packet, "Dropping packet"); continue; } if (mgid != 0) { assert(mgid == 1); phv->get_field("intrinsic_metadata.mgid").set(0); packet_id_t copy_id = 1; const auto pre_out = pre->replicate({mgid}); for (const auto &out : pre_out) { egress_port = out.egress_port; if (ingress_port == egress_port) continue; // pruning BMLOG_DEBUG_PKT(*packet, "Replicating packet on port {}", egress_port); std::unique_ptr<Packet> packet_copy = packet->clone_with_phv_ptr(); packet_copy->set_egress_port(egress_port); egress_mau->apply(packet_copy.get()); deparser->deparse(packet_copy.get()); output_buffer.push_front(std::move(packet_copy)); } } else { packet->set_egress_port(egress_port); egress_mau->apply(packet.get()); deparser->deparse(packet.get()); output_buffer.push_front(std::move(packet)); } } }