Blame src/vma/proto/L2_address.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 L2_ADDRESS_H
Packit Service aa3af4
#define L2_ADDRESS_H
Packit Service aa3af4
Packit Service aa3af4
#include <infiniband/verbs.h>
Packit Service aa3af4
#include <stdio.h>
Packit Service aa3af4
#include <string.h>
Packit Service aa3af4
Packit Service aa3af4
#include "vma/util/to_str.h"
Packit Service aa3af4
#include "vma/util/vtypes.h"
Packit Service aa3af4
Packit Service aa3af4
typedef size_t 		addrlen_t;
Packit Service aa3af4
typedef unsigned char* 	address_t;
Packit Service aa3af4
Packit Service aa3af4
// 20 Bytes will
Packit Service aa3af4
#define L2_ADDR_MAX	20
Packit Service aa3af4
Packit Service aa3af4
class L2_address : public tostr
Packit Service aa3af4
{
Packit Service aa3af4
public:
Packit Service aa3af4
	L2_address(address_t const address, addrlen_t const len);
Packit Service aa3af4
	L2_address() : m_len(0) {};
Packit Service aa3af4
	virtual ~L2_address() {};
Packit Service aa3af4
Packit Service aa3af4
	virtual L2_address* clone() const = 0;
Packit Service aa3af4
Packit Service aa3af4
	void		set(address_t const address, addrlen_t const len);
Packit Service aa3af4
Packit Service aa3af4
	addrlen_t	get_addrlen() const { return m_len; };
Packit Service aa3af4
	address_t	get_address() const { return (address_t)m_p_raw_address; };
Packit Service aa3af4
Packit Service aa3af4
	virtual bool 	compare(L2_address const& other) const;
Packit Service aa3af4
Packit Service aa3af4
protected:
Packit Service aa3af4
	addrlen_t	m_len;
Packit Service aa3af4
	unsigned char	m_p_raw_address[L2_ADDR_MAX];
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
class ETH_addr : public L2_address
Packit Service aa3af4
{
Packit Service aa3af4
public:
Packit Service aa3af4
	ETH_addr(address_t const address) : L2_address(address, 6) {};
Packit Service aa3af4
	~ETH_addr() {};
Packit Service aa3af4
	const std::string to_str() const;
Packit Service aa3af4
Packit Service aa3af4
	virtual L2_address* clone() const
Packit Service aa3af4
	{
Packit Service aa3af4
		return (new ETH_addr(get_address()));
Packit Service aa3af4
	}
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
class IPoIB_addr : public L2_address
Packit Service aa3af4
{
Packit Service aa3af4
public:
Packit Service aa3af4
Packit Service aa3af4
	IPoIB_addr(): L2_address(), m_qpn(0)
Packit Service aa3af4
	{
Packit Service aa3af4
Packit Service aa3af4
	}
Packit Service aa3af4
Packit Service aa3af4
	//This constructor is for UC
Packit Service aa3af4
	IPoIB_addr(address_t const address) : L2_address(address, 20), m_qpn(0)
Packit Service aa3af4
	{
Packit Service aa3af4
		extract_qpn();
Packit Service aa3af4
	};
Packit Service aa3af4
	//This constructor is for MC
Packit Service aa3af4
	IPoIB_addr(uint32_t qpn, address_t const address) : L2_address(address, 20), m_qpn(qpn) {};
Packit Service aa3af4
	~IPoIB_addr() {};
Packit Service aa3af4
Packit Service aa3af4
	virtual L2_address* clone() const
Packit Service aa3af4
	{
Packit Service aa3af4
		uint32_t qpn = ((IPoIB_addr*)this)->get_qpn();
Packit Service aa3af4
		return (new IPoIB_addr(qpn, get_address()));
Packit Service aa3af4
	}
Packit Service aa3af4
Packit Service aa3af4
	void 		set_qpn(uint32_t qpn) { m_qpn = qpn; };
Packit Service aa3af4
	uint32_t 	get_qpn() { return m_qpn; };
Packit Service aa3af4
Packit Service aa3af4
	const std::string to_str() const;
Packit Service aa3af4
Packit Service aa3af4
private:
Packit Service aa3af4
	uint32_t 	m_qpn;
Packit Service aa3af4
Packit Service aa3af4
	void		extract_qpn();
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
#endif /* L2_ADDRESS_H */