Blame src/vma/proto/dst_entry.h

Packit Service aa3af4
/*
Packit Service aa3af4
 * Copyright (c) 2001-2020 Mellanox Technologies, Ltd. All rights reserved.
Packit Service aa3af4
 *
Packit Service aa3af4
 * This software is available to you under a choice of one of two
Packit Service aa3af4
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit Service aa3af4
 * General Public License (GPL) Version 2, available from the file
Packit Service aa3af4
 * COPYING in the main directory of this source tree, or the
Packit Service aa3af4
 * BSD license below:
Packit Service aa3af4
 *
Packit Service aa3af4
 *     Redistribution and use in source and binary forms, with or
Packit Service aa3af4
 *     without modification, are permitted provided that the following
Packit Service aa3af4
 *     conditions are met:
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions of source code must retain the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer.
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions in binary form must reproduce the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer in the documentation and/or other materials
Packit Service aa3af4
 *        provided with the distribution.
Packit Service aa3af4
 *
Packit Service aa3af4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service aa3af4
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service aa3af4
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service aa3af4
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service aa3af4
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service aa3af4
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service aa3af4
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service aa3af4
 * SOFTWARE.
Packit Service aa3af4
 */
Packit Service aa3af4
Packit Service aa3af4
Packit Service aa3af4
#ifndef DST_ENTRY_H
Packit Service aa3af4
#define DST_ENTRY_H
Packit Service aa3af4
Packit Service aa3af4
#include <unistd.h>
Packit Service aa3af4
#include <sys/socket.h>
Packit Service aa3af4
#include "vma/util/if.h"
Packit Service aa3af4
#include <netinet/in.h>
Packit Service aa3af4
Packit Service aa3af4
#include "vlogger/vlogger.h"
Packit Service aa3af4
#include "utils/lock_wrapper.h"
Packit Service aa3af4
#include "vma/sock/socket_fd_api.h"
Packit Service aa3af4
#include "vma/proto/route_entry.h"
Packit Service aa3af4
#include "vma/proto/route_val.h"
Packit Service aa3af4
#include "vma/proto/neighbour_table_mgr.h"
Packit Service aa3af4
#include "vma/dev/net_device_val.h"
Packit Service aa3af4
#include "vma/dev/net_device_table_mgr.h"
Packit Service aa3af4
#include "vma/dev/wqe_send_handler.h"
Packit Service aa3af4
#include "vma/dev/wqe_send_ib_handler.h"
Packit Service aa3af4
#include "vma/dev/ring.h"
Packit Service aa3af4
#include "vma/dev/ring_allocation_logic.h"
Packit Service aa3af4
#include "vma/infra/sender.h"
Packit Service aa3af4
#include "header.h"
Packit Service aa3af4
#include "ip_address.h"
Packit Service aa3af4
Packit Service aa3af4
struct socket_data {
Packit Service aa3af4
	int	fd;
Packit Service aa3af4
	uint8_t ttl;
Packit Service aa3af4
	uint8_t	tos;
Packit Service aa3af4
	uint32_t pcp;
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
typedef struct {
Packit Service aa3af4
	vma_wr_tx_packet_attr flags;
Packit Service aa3af4
	uint16_t mss;
Packit Service aa3af4
} vma_send_attr;
Packit Service aa3af4
Packit Service aa3af4
class dst_entry : public cache_observer, public tostr, public neigh_observer
Packit Service aa3af4
{
Packit Service aa3af4
Packit Service aa3af4
public:
Packit Service aa3af4
	dst_entry(in_addr_t dst_ip, uint16_t dst_port, uint16_t src_port, socket_data &sock_data, resource_allocation_key &ring_alloc_logic);
Packit Service aa3af4
	virtual ~dst_entry();
Packit Service aa3af4
Packit Service aa3af4
	virtual void 	notify_cb();
Packit Service aa3af4
Packit Service aa3af4
	virtual bool 	prepare_to_send(struct vma_rate_limit_t &rate_limit, bool skip_rules=false, bool is_connect=false);
Packit Service aa3af4
#ifdef DEFINED_TSO
Packit Service aa3af4
        virtual ssize_t fast_send(const iovec* p_iov, const ssize_t sz_iov, vma_send_attr attr) = 0;
Packit Service aa3af4
	virtual ssize_t slow_send(const iovec* p_iov, const ssize_t sz_iov, vma_send_attr attr,
Packit Service aa3af4
			struct vma_rate_limit_t &rate_limit, int flags = 0,
Packit Service aa3af4
			socket_fd_api* sock = 0, tx_call_t call_type = TX_UNDEF) = 0;
Packit Service aa3af4
#else
Packit Service aa3af4
	virtual ssize_t slow_send(const iovec* p_iov, size_t sz_iov, bool is_dummy, struct vma_rate_limit_t &rate_limit, bool b_blocked = true, bool is_rexmit = false, int flags = 0, socket_fd_api* sock = 0, tx_call_t call_type = TX_UNDEF) = 0 ;
Packit Service aa3af4
	virtual ssize_t fast_send(const iovec* p_iov, const ssize_t sz_iov, bool is_dummy, bool b_blocked = true, bool is_rexmit = false) = 0;
Packit Service aa3af4
#endif /* DEFINED_TSO */
Packit Service aa3af4
Packit Service aa3af4
	bool		try_migrate_ring(lock_base& socket_lock);
Packit Service aa3af4
Packit Service aa3af4
	bool 		is_offloaded() { return m_b_is_offloaded; }
Packit Service aa3af4
	void		set_bound_addr(in_addr_t addr);
Packit Service aa3af4
	void		set_so_bindtodevice_addr(in_addr_t addr);
Packit Service aa3af4
	in_addr_t	get_dst_addr();
Packit Service aa3af4
	uint16_t	get_dst_port();
Packit Service aa3af4
	inline in_addr_t get_src_addr() const {
Packit Service aa3af4
		return m_pkt_src_ip;
Packit Service aa3af4
	}
Packit Service aa3af4
	int		modify_ratelimit(struct vma_rate_limit_t &rate_limit);
Packit Service aa3af4
	bool		update_ring_alloc_logic(int fd, lock_base & socket_lock, resource_allocation_key & ring_alloc_logic);
Packit Service aa3af4
Packit Service aa3af4
#if _BullseyeCoverage
Packit Service aa3af4
    #pragma BullseyeCoverage off
Packit Service aa3af4
#endif
Packit Service aa3af4
	net_device_val*	get_net_dev()
Packit Service aa3af4
	{
Packit Service aa3af4
		return m_p_net_dev_val;
Packit Service aa3af4
	}
Packit Service aa3af4
#if _BullseyeCoverage
Packit Service aa3af4
    #pragma BullseyeCoverage on
Packit Service aa3af4
#endif
Packit Service aa3af4
Packit Service aa3af4
	virtual transport_type_t get_obs_transport_type() const;
Packit Service aa3af4
	virtual flow_tuple get_flow_tuple() const;
Packit Service aa3af4
Packit Service aa3af4
	void		return_buffers_pool();
Packit Service aa3af4
	int		get_route_mtu();
Packit Service aa3af4
	inline void	set_ip_ttl(uint8_t ttl) { m_header.set_ip_ttl(ttl); }
Packit Service aa3af4
	inline void	set_ip_tos(uint8_t tos) { m_header.set_ip_tos(tos); }
Packit Service aa3af4
	inline bool	set_pcp(uint32_t pcp) {
Packit Service aa3af4
		return m_header.set_vlan_pcp(get_priority_by_tc_class(pcp)); }
Packit Service aa3af4
	inline header*	get_network_header() { return &m_header;}
Packit Service aa3af4
	inline ring*	get_ring() { return m_p_ring;}
Packit Service aa3af4
protected:
Packit Service aa3af4
	ip_address 		m_dst_ip;
Packit Service aa3af4
	uint16_t 		m_dst_port;
Packit Service aa3af4
	uint16_t 		m_src_port;
Packit Service aa3af4
Packit Service aa3af4
	in_addr_t		m_bound_ip;
Packit Service aa3af4
	in_addr_t		m_so_bindtodevice_ip;
Packit Service aa3af4
	in_addr_t		m_route_src_ip; // source IP used to register in route manager
Packit Service aa3af4
	in_addr_t		m_pkt_src_ip; // source IP address copied into IP header
Packit Service aa3af4
	lock_mutex_recursive 	m_slow_path_lock;
Packit Service aa3af4
	lock_mutex		m_tx_migration_lock;
Packit Service aa3af4
	vma_ibv_send_wr 	m_inline_send_wqe;
Packit Service aa3af4
	vma_ibv_send_wr 	m_not_inline_send_wqe;
Packit Service aa3af4
	vma_ibv_send_wr 	m_fragmented_send_wqe;
Packit Service aa3af4
	wqe_send_handler*	m_p_send_wqe_handler;
Packit Service aa3af4
	ibv_sge 		*m_sge;
Packit Service aa3af4
	route_entry*		m_p_rt_entry;
Packit Service aa3af4
	route_val*		m_p_rt_val;
Packit Service aa3af4
	net_device_entry*	m_p_net_dev_entry;
Packit Service aa3af4
	net_device_val*		m_p_net_dev_val;
Packit Service aa3af4
	neigh_entry*		m_p_neigh_entry;
Packit Service aa3af4
	neigh_val*		m_p_neigh_val;
Packit Service aa3af4
	bool 			m_b_is_offloaded;
Packit Service aa3af4
	bool 			m_b_force_os;
Packit Service aa3af4
	ring*			m_p_ring;
Packit Service aa3af4
	ring_allocation_logic_tx m_ring_alloc_logic;
Packit Service aa3af4
	mem_buf_desc_t* 	m_p_tx_mem_buf_desc_list;
Packit Service aa3af4
	int			m_b_tx_mem_buf_desc_list_pending;
Packit Service aa3af4
	header 			m_header;
Packit Service aa3af4
	header 			m_header_neigh;
Packit Service aa3af4
	uint8_t 		m_ttl;
Packit Service aa3af4
	uint8_t 		m_tos;
Packit Service aa3af4
	uint8_t 		m_pcp;
Packit Service aa3af4
	bool 			m_b_is_initialized;
Packit Service aa3af4
Packit Service aa3af4
	vma_ibv_send_wr* 	m_p_send_wqe;
Packit Service aa3af4
	uint32_t 		m_max_inline;
Packit Service aa3af4
	ring_user_id_t		m_id;
Packit Service aa3af4
	uint16_t		m_max_ip_payload_size;
Packit Service aa3af4
	uint16_t		m_max_udp_payload_size;
Packit Service aa3af4
Packit Service aa3af4
	virtual transport_t 	get_transport(sockaddr_in to) = 0;
Packit Service aa3af4
	virtual uint8_t 	get_protocol_type() const = 0;
Packit Service aa3af4
	virtual bool 		get_net_dev_val();
Packit Service aa3af4
	virtual uint32_t 	get_inline_sge_num() = 0;
Packit Service aa3af4
	virtual ibv_sge*	get_sge_lst_4_inline_send() = 0;
Packit Service aa3af4
	virtual ibv_sge*	get_sge_lst_4_not_inline_send() = 0;
Packit Service aa3af4
Packit Service aa3af4
	virtual bool 		offloaded_according_to_rules();
Packit Service aa3af4
	virtual void 		init_members();
Packit Service aa3af4
	virtual bool 		resolve_net_dev(bool is_connect=false);
Packit Service aa3af4
	virtual void		set_src_addr();
Packit Service aa3af4
	bool 				update_net_dev_val();
Packit Service aa3af4
	bool 				update_rt_val();
Packit Service aa3af4
	virtual bool 		resolve_neigh();
Packit Service aa3af4
	virtual bool 		resolve_ring();
Packit Service aa3af4
	virtual bool 		release_ring();
Packit Service aa3af4
	virtual ssize_t 	pass_buff_to_neigh(const iovec *p_iov, size_t sz_iov, uint16_t packet_id = 0);
Packit Service aa3af4
	virtual void 		configure_ip_header(header *h, uint16_t packet_id = 0);
Packit Service aa3af4
	virtual void 		configure_headers() { conf_hdrs_and_snd_wqe();};
Packit Service aa3af4
	bool 			conf_hdrs_and_snd_wqe();
Packit Service aa3af4
	virtual bool 		conf_l2_hdr_and_snd_wqe_eth();
Packit Service aa3af4
	virtual bool 		conf_l2_hdr_and_snd_wqe_ib();
Packit Service aa3af4
	virtual void 		init_sge() {};
Packit Service aa3af4
	bool 			alloc_transport_dep_res();
Packit Service aa3af4
	bool 			alloc_neigh_val(transport_type_t tranport);
Packit Service aa3af4
Packit Service aa3af4
	void			do_ring_migration(lock_base& socket_lock, resource_allocation_key &old_key);
Packit Service aa3af4
	inline void		set_tx_buff_list_pending(bool is_pending = true) {m_b_tx_mem_buf_desc_list_pending = is_pending;}
Packit Service aa3af4
	int			get_priority_by_tc_class(uint32_t tc_clas);
Packit Service aa3af4
	inline void		send_ring_buffer(ring_user_id_t id, vma_ibv_send_wr* p_send_wqe, vma_wr_tx_packet_attr attr)
Packit Service aa3af4
	{
Packit Service aa3af4
		if (unlikely(is_set(attr, VMA_TX_PACKET_DUMMY))) {
Packit Service aa3af4
			if (m_p_ring->get_hw_dummy_send_support(id, p_send_wqe)) {
Packit Service aa3af4
				vma_ibv_wr_opcode last_opcode = m_p_send_wqe_handler->set_opcode(*p_send_wqe, VMA_IBV_WR_NOP);
Packit Service aa3af4
				m_p_ring->send_ring_buffer(id, p_send_wqe, attr);
Packit Service aa3af4
				m_p_send_wqe_handler->set_opcode(*p_send_wqe, last_opcode);
Packit Service aa3af4
			} else {
Packit Service aa3af4
				/* free the buffer if dummy send is not supported */
Packit Service aa3af4
				mem_buf_desc_t* p_mem_buf_desc = (mem_buf_desc_t*)(p_send_wqe->wr_id);
Packit Service aa3af4
				m_p_ring->mem_buf_tx_release(p_mem_buf_desc, true);
Packit Service aa3af4
			}
Packit Service aa3af4
		} else {
Packit Service aa3af4
			m_p_ring->send_ring_buffer(id, p_send_wqe, attr);
Packit Service aa3af4
		}
Packit Service aa3af4
	}
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
Packit Service aa3af4
#endif /* DST_ENTRY_H */