Esempio n. 1
0
        /*
         * the main method
         * receives a Flow message and prints out its associated information
         * If the message belongs to another class, an exception is thrown.
         */
        virtual void _receive_msg(std::shared_ptr<const Msg>&& m, int /* index */)
        {
            if ( m->type() == MSG_ID(Flow) )
            {
                auto flow = static_cast<const Flow *>(m.get());
                std::stringstream ss;
                const FlowKey& fk = flow->key();
                int duration = flow->end_time() - flow->start_time();
                ss<<"packets="<<flow->packets() << ",";
                ss<<"bytes="<<flow->bytes() << ",";
                ss<<"start="<<flow->start_time() << ",";
                ss<<"end="<<flow->end_time() << ",";
                ss<<"duration.us="<<duration<< ",";
                ss<<"source.ip4="<<ip_to_string(fk.src_ip4)<< ",";
                ss<<"source.port="<<fk.src_port<< ",";
                ss<<"destination.ip4="<<ip_to_string(fk.dst_ip4)<< ",";
                ss<<"destination.port="<<fk.dst_port;
                /*
                ss<<"Flow of  "<< flow->packets() << " packets and "<<flow->bytes()<<" bytes begin at "<<flow->start_time()<<" end at "<<flow->end_time()<< "duration (ms.) "<<duration <<std::endl;
                ss<<"SRC IP "<<ip_to_string(fk.src_ip4)<<" SRC port "<<fk.src_port<<std::endl;
                ss<<"DST IP "<<ip_to_string(fk.dst_ip4)<<" DST port "<<fk.dst_port<<std::endl;
                //ss<<"protocol "<<fk.proto<<std::endl;
                */
                blocklog(ss.str(),log_info);


            }
                else
            {
                throw std::runtime_error("Flowprinter: wrong message type");
            }
        }
Esempio n. 2
0
 /**
  * @brief Constructor
  * @param name         The name of the ComboPktSource block instance
  * @param invocation   Invocation type of the block (Indirect, Direct, Async)
  */
 ComboPktSource(const std::string &name, invocation_type invocation)
     :ComboSource(name),              //ignore options
     m_gate_id(register_output_gate("out_pkt"))
 {
     if (invocation != invocation_type::Async) {
         blocklog("ComboPktSource must be Async, ignoring configuration", log_warning);
     }
 }
Esempio n. 3
0
    RRDemux::RRDemux(const std::string &name, invocation_type invocation) 
    : Block(name, invocation_type::Direct),
     m_outgates_number(2), m_current_outgate(0)
    {
		register_input_gate("input");
        if (invocation != invocation_type::Direct) {
            blocklog("SynCounter must be direct; ignoring configuration.", log_warning);
        }
	}
Esempio n. 4
0
	IDMEFExporter::IDMEFExporter(const std::string &name, invocation_type invocation):
		Block(name, invocation_type::Direct),
		m_ingate_id(register_input_gate("in_alert")),
		m_export_method(EXP_FILE), m_host(0), m_port(0), m_filename("log"),
		m_tcp_open(false), m_file_open(false),
		m_file_stream()
	{
		if (invocation != invocation_type::Direct) {
			blocklog("IDMEFExporter must be direct; ignoring configuration.", log_warning);
		}
	}
Esempio n. 5
0
 /**
  * @brief Constructor
  * @param name The name of the source block
  * @param invocation Invocation type of the block (Indirect, Direct, Async).
  *                     This block can only be async invoked,
  *                     and will ignore any contrary configuration.
  */
 TweetReader(const std::string &name, invocation_type invocation)
     :Block(name, invocation_type::Async),
     next_out_port(0)
     {
         if (invocation != invocation_type::Async) {
             blocklog("TweetReader must be Async, ignoring configuration", log_warning);
         }
         m_msg_sent = 0;
         m_msg_recv = 0;
         outgate_basename = "out_tweet";
         m_msg_type = type_to_id<Tweet>::id();
         register_variable("msg_sent",make_rd_var(no_mutex_t(), m_msg_sent));
         register_variable("msg_recv",make_rd_var(no_mutex_t(), m_msg_recv));
     }
Esempio n. 6
0
        /**
         * @brief Constructor
         * @param name         The name of the source block
         * @param invocation   Invocation type of the block (Indirect, Direct, Async)
         */
        PFQSource(const std::string &name, invocation_type invocation)
        : Block(name, invocation_type::Async)
        , m_gate_id(register_output_gate("source_out"))
#if defined(USE_SIMPLE_PACKET) || defined(USE_SLICED_PACKET)
        , m_allocator()
#else
        , m_mem_block(new MemoryBatch(4096*4))
#endif
        , m_pfq()
        , m_device()
        {
            if (invocation != invocation_type::Async) {
                blocklog("PFQSource must be Async, ignoring configuration", log_warning);
            }
        }
Esempio n. 7
0
        /**
         * @brief Configures the block: defines the capture interface, the possible hw-queues in use, etc.
         * @param n The configuration parameters 
         */
        virtual void _configure(const pugi::xml_node& n) 
        {
            std::cout << __PRETTY_FUNCTION__ << std::endl;

            int offset = 0;
            int slots  = 131072;
            int caplen = 1514;

            bool timestamp = false;

            pugi::xml_node queues = n.child("queues");
            if(!queues)
                throw std::runtime_error("PFQSource:: no queues node");
            
            m_device = std::string(queues.attribute("device").value());
            if(m_device.length()==0)
                throw std::runtime_error("PFQSource::no device attribute ");
            
            auto clattr  = queues.attribute("caplen");
            auto offattr = queues.attribute("offset");
            auto slotattr = queues.attribute("slots");

            auto tsattr = queues.attribute("tstamp");

            if (!clattr.empty())
                caplen = clattr.as_int();
           
            if (!offattr.empty())
                offset = offattr.as_int();

            if (!slotattr.empty())
                slots = slotattr.as_int();

            if (!tsattr.empty())
                timestamp = tsattr.as_bool();

            std::vector<unsigned int> vq;
            
            m_pfq.open(caplen, offset, slots);

            for (xml_node queue=queues.child("queue"); queue; queue=queue.next_sibling("queue"))
                vq.push_back(queue.attribute("number").as_uint());
            
            if(!vq.empty())
            {
                auto it = vq.begin();
                auto it_e = vq.end();
                for (;it!=it_e;++it)
                {
                    m_pfq.add_device(m_device.c_str(),*it);
                }
            }
            else
            {
                blocklog("PFQSource: no queues specified, sniffing on device ", log_info);
                m_pfq.add_device(m_device.c_str(), net::pfq::any_queue);
            } 
          
            std::cout << "PFQ: dev:" << m_device << " caplen:" << caplen << " tstamp:" << std::boolalpha << timestamp; 
            std::cout << " queues:";
            std::copy(vq.begin(), vq.end(), std::ostream_iterator<int>(std::cout, ","));
            std::cout << std::endl;

            {
                std::lock_guard<std::mutex> lock(m_mutex);
                m_max_caplen = std::max(m_max_caplen, caplen);
            }

            net::payload::size_of(m_max_caplen);

            // the slice_allocator must be created once the dynamic_buffer (or net::payload)
            // is set to a given size.
            //
#if defined(USE_SIMPLE_PACKET) || defined(USE_SLICED_PACKET)            
            m_allocator.reset(new allocator_type);
#endif           
            m_pfq.caplen(caplen);
            m_pfq.toggle_time_stamp(timestamp);
            m_pfq.enable();         
            
        }
Esempio n. 8
0
        /**
         * @brief Configures the block, opens all necessary contexts
         * @param n The configuration parameters 
         */
        void _configure(const pugi::xml_node& n) 
        {
			std::string command;
           pugi::xml_node source;
			int val;
			unsigned int tx_mask = 0;
			unsigned int rx_mask = 0;

			source = n.child("design");
            if(!source) 
                blocklog("missing parameter design, firwmare of acceleration card was untouched!", log_info);
            else
			{
				command = std::string("csboot -f0 ") + source.attribute("filename").value() + "; sleep 1;";
				val = system(command.c_str());

				command = std::string("Booting card with firwmare file ") + source.attribute("filename").value() + (val == 0 ? ": OK" : ": ERROR");
                blocklog(command , log_info);
			}

			source = n.child("interfaces");
            if(!source)
			{
                blocklog("missing parameter 'interfaces', assuming enable='1'", log_info);
				val = 1;
            }
            else
				val = source.attribute("enable").as_uint();
			if(val)
			{
				blocklog("Enabling input interfaces", log_info);
				command = "ibufctl -Ae1";
				val = system(command.c_str());
			}

			rx_mask = 0xFF;
            source = n.child("channels");
            if(!source) {
				blocklog("missing parameter channels, usign default value!", log_info);
            }
            else
                rx_mask = source.attribute("rx_mask").as_uint();

            /* initialize szedata2 */
            /* get sze device handle */
            sze = szedata_open(sze_dev);
            if (sze == NULL) {
                std::cerr << "szedata_open failed" << std::endl;
                exit(1);
            }

            /* set 5s timeout for szedata_read_next */
            SZE2_RX_POLL_TIMEOUT = 30;

            /* subscribe wanted interfaces and set poll byte conuts */
            val = szedata_subscribe3(sze, &rx_mask, &tx_mask);
            if (val) {
                throw std::runtime_error("subscription failed");
                exit(1);
            }

            /* start */
            val = szedata_start(sze);
            if (val) {
                throw std::runtime_error("start failed");
                exit(1);
            }
            /* szedata2 initialized */
        }