Пример #1
0
 void receive_hello(std::shared_ptr<tcp::socket> socket
         , std::shared_ptr<std::vector<std::uint8_t>> buffer
         , std::size_t const read_size = sizeof(ofp_header))
 {
     auto const read_head = buffer->size();
     buffer->resize(read_head + read_size);
     boost::asio::async_read(*socket
             , boost::asio::buffer(&(*buffer)[read_head], read_size)
             , boost::asio::transfer_exactly(read_size)
             , [=](boost::system::error_code const& ec, std::size_t const) {
         if (ec) {
             std::cout << "read error: " << ec.message() << std::endl;
             return;
         }
         auto const header = detail::read_ofp_header(boost::asio::buffer(*buffer));
         if (header.type != hello::message_type) {
             std::cout << "not hello message" << std::endl;
             return;
         }
         if (header.length != buffer->size()) {
             receive_hello(std::move(socket), std::move(buffer), header.length - buffer->size());
             return;
         }
         auto channel = std::make_shared<v10::secure_channel_impl<ControllerHandler>>(
                 std::move(*socket), controller_handler_, *thread_pool_);
         auto it = buffer->begin();
         channel->run(hello::decode(it, buffer->end()));
     });
 }
Пример #2
0
void pim_input()
{//接收,检查报文类型,交由相应的函数处理
	int length;
	u_int32 src,dst;
	struct ip *ip;
	struct pim *pim;
	int iphdrlen,pimlen;
	
	length=recvfrom(pimsocket,pim_receive_buf,64*1024,0,NULL,NULL);

	if(length<sizeof(struct ip))
	{
		log(LOG_INFO,"PIM packet too short,receive failed!");
	}

	ip=(struct ip *)pim_receive_buf;
	src=ip->ip_src.s_addr;
	dst=ip->ip_dst.s_addr;
	iphdrlen=ip->ip_hl<<2;

	pim=(struct pim *)(pim_receive_buf+iphdrlen);
	pimlen=length-iphdrlen;

	if (pimlen<sizeof(pim)) 
	{
		log(LOG_INFO,"PIM packet too short,receive failed!");
		return;
    }
    
    switch (pim->pim_type) 
	{
		case PIM_HELLO:
			receive_hello(src,dst,(char *)(pim),pimlen);
		return;
	
		case PIM_JOIN_PRUNE:
			receive_join_prune(src,dst,(char *)(pim),pimlen);
		return;
	
		case PIM_ASSERT:
			receive_assert(src,dst,(char *)(pim),pimlen);
		return;
		
		case PIM_GRAFT:
			receive_pim_graft(src,dst,(char *)(pim),pimlen);
		return;
		
		case PIM_GRAFT_ACK:
			receive_pim_graft_ack(src,dst,(char *)(pim),pimlen);
		return;

		default:
			log(LOG_INFO,"ignoring unused PIM packet from %s to %s",inet_fmt(src, s1), inet_fmt(dst, s2));
		return;
    }
}
Пример #3
0
 void send_hello(std::shared_ptr<tcp::socket> socket)
 {
     auto buffer = std::make_shared<std::vector<std::uint8_t>>();
     boost::asio::async_write(*socket, boost::asio::buffer(hello{v10::OFP_VERSION}.encode(*buffer))
             , [=](boost::system::error_code const& ec, std::size_t const) mutable {
         if (ec) {
             std::cout << "send error: " << ec.message() << std::endl;
             return;
         }
         buffer->clear();
         receive_hello(std::move(socket), std::move(buffer));
     });
 }