virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { /* * Controllo per vedere se il pacchetto entrante è un packetPlus */ if(m->type() != MSG_ID(PacketPlus)) throw std::runtime_error("wrong message type in metric_block"); pkt_count++; auto pktp = static_cast<const PacketPlus *>(m.get()); if ( !(pktp->is_udp() && pktp->src_port() == 53 ) ) // && pktp->get_DNSflag() == 0) ) { send_out_through(std::move(m), id_outgate); return; } buff_mon.Reset(); /* auto packet = pktp->getPacket(); */ // uint64_t time_packet_us = pktp->timestamp_us(); // double time_packet = time_packet_us/1000000.0; // std::vector<uint32_t> answersIP; // pktp->get_answersIP(answersIP); // std::string domain = pktp->get_domain_query(); // buff_mon << domain; // // for(unsigned int i = 0; i < answersIP.size(); i++) // { // answersIP[i] = answersIP[i] & 0xFFFF0000; // } // for(unsigned int i=0; i<answersIP.size(); i++) // { // buff_det.Reset(); // buff_det << domain << answersIP[i]; // if(!bloom->check( (unsigned char*) buff_det.GetRawData(), buff_det.GetLength())) // { // bloom->add((unsigned char*)buff_det.GetRawData(), buff_det.GetLength()); // counter->add(buff_mon, 1, time_packet); // } // } // pktp->setMetrics(metric_id, counter->get(buff_mon, time_packet)); send_out_through(std::move(m), id_outgate); }
/** * listens on the capture socket, retrieves a batch of packets and sends them out as Packet messages * Uses optimized allocation. */ void _do_async() { net::queue b = m_pfq.read(10 /* microseconds */); auto it_e = b.end(); for (auto it = b.begin(); it != it_e; ++it) { auto actual_payload = reinterpret_cast<uint8_t *>(it.data()); while (!it->commit) {} #if defined(USE_SIMPLE_PACKET) || defined(USE_SLICED_PACKET) uint16_t len = it->len, caplen = it->caplen; uint32_t sec = it->tstamp.tv.sec, nsec = it->tstamp.tv.nsec; #endif #if defined(USE_SIMPLE_PACKET) auto sp = blockmon::NewPacket::SimplePacket(const_buffer<uint8_t>(actual_payload, it->caplen), *m_allocator, len, caplen, sec, nsec); #elif defined(USE_SLICED_PACKET) auto sp = blockmon::NewPacket::SlicedPacket(const_buffer<uint8_t>(actual_payload, it->caplen), *m_allocator, len, caplen, sec, nsec); #else auto sp = alloc_msg_from_buffer<Packet>(m_mem_block, it->caplen, const_buffer<uint8_t>(actual_payload, it->caplen)); #endif send_out_through(std::move(sp), m_gate_id); } }
void RRDemux::_receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { // Send the message through the current gate send_out_through(move(m), m_current_outgate); // Update the current gate m_current_outgate++; if (m_current_outgate >= m_outgates_number) m_current_outgate = 0; }
/** * the actual filtering function * Expects Packet messages, otherwise it throws * @param m the message to be checked */ virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type() != MSG_ID(Packet)) { throw std::runtime_error("PacketFiler: wrong message type"); } m_msg_recv++; /* if(m_msg_recv % 100000 == 0) std::cout << "Received pkt no." << m_msg_recv << std::endl; */ const Packet* packet = static_cast<const Packet* > (m.get()); struct timeval tval; tval.tv_sec = packet->timestamp_s(); tval.tv_usec = packet->timestamp().tv_nsec / 1000; if(m_msg_recv % 100000 == 0) { auto now = std::chrono::system_clock::now(); auto duration = now.time_since_epoch(); auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count(); std::cout << "Received pkt no." << m_msg_recv << " at time [ms] " << millis << std::endl; } int plen = std::min((int)packet->caplen(),MAXIP); //const uint8_t* pkt_last = packet->iphdr() + packet->ip_length() +2 -1; const uint8_t* pkt_last = packet->base() + packet->caplen() - 1; /* printf("[%d;%d] buf=%x plen=%d\n",tval.tv_sec,tval.tv_usec,pkt_last-packet->iphdr(),plen); const uint8_t* pp = packet->iphdr(); printf("%x %x %x\n", *pp,*(pp+1), *(pp+2)); pp = pkt_last; printf("%x %x %x\n", *pp,*(pp-1), *(pp-2)); */ tstat_next_pckt(&tval, (struct ip*)packet->iphdr(), (uint8_t*)pkt_last, (int)plen, 0); send_out_through(std::move(m), m_out_gate); m_msg_sent++; //if(m_msg_recv == 33725814) // 01 //if(m_msg_recv == 29388596) //02 //if(m_msg_recv == 36850357) //00 // tstat_close(&report); }
/** * Retrieves tweets and send them out as WordRecord message */ void _do_async() { if(m_msg_sent == 0) { gettimeofday(&firsttime, NULL); } if(file.eof()) { sleep(5); } std::string json_tweet; getline(file, json_tweet); std::shared_ptr<Tweet> m(new Tweet(json_tweet)); send_out_through(move(m), m_outgate_ids[next_out_port]); next_out_port = (next_out_port + 1) % num_gates; m_msg_sent++; }
virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type() != MSG_ID(Packet)) throw std::runtime_error("AppendTag: wrong message type"); uint64_t random_garbage = m_generator(); switch (m_tag_type) { case(in): m->emplace_tag<int>(m_handle,(int)random_garbage); break; case(ll): m->emplace_tag<double>(m_handle,(double)random_garbage); break; case(fl): m->emplace_tag<uint64_t>(m_handle,(uint64_t)random_garbage); break; default: throw std::runtime_error("wrong tag type"); } send_out_through(std::move(m),m_outgate_id); }
/** * If the message received is not of type RawPacket throw an exception, * otherwise count it * @param m The message * @param index The index of the gate the message came on */ void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */) { if(m->type()!=MSG_ID(Packet)) { throw std::runtime_error("wrong message type in pkt counter"); } if(m_reset==1) { m_pkt_cnt = 0; m_byte_cnt = 0; m_byte_rate = 0; m_pkt_rate = 0; m_reset = 0; } const Packet* packet_ptr = static_cast<const Packet*>(m.get()); ++m_pkt_cnt; m_byte_cnt += packet_ptr->length(); send_out_through(std::move(m), m_outgate_id); }
/** * Handle packet received from parent class and send it to output gate as a Packet message. */ void handle_packet(unsigned char * packet, unsigned char * data, unsigned char* hw_data, int data_len, int hw_data_len) { send_out_through(alloc_msg_from_buffer<Packet>(m_mem_block, data_len, const_buffer<unsigned char>(reinterpret_cast<const unsigned char *>(data), data_len), 0), m_gate_id); }
/** * helper function, sends the packet out of the out gage * @param m the packet to be forwarded */ inline void flow_passed(std::shared_ptr<const Msg>&& m) { send_out_through(std::move(m),m_out_gate); }