|
| 1 | +/** |
| 2 | + * \file |
| 3 | + * \brief Declaration of the DpdkMbuf class. |
| 4 | + * \author Pavel Siska <[email protected]> |
| 5 | + * \date 2023 |
| 6 | + */ |
| 7 | +/* |
| 8 | + * Copyright (C) 2023 CESNET |
| 9 | + * |
| 10 | + * LICENSE TERMS |
| 11 | + * |
| 12 | + * Redistribution and use in source and binary forms, with or without |
| 13 | + * modification, are permitted provided that the following conditions |
| 14 | + * are met: |
| 15 | + * 1. Redistributions of source code must retain the above copyright |
| 16 | + * notice, this list of conditions and the following disclaimer. |
| 17 | + * 2. Redistributions in binary form must reproduce the above copyright |
| 18 | + * notice, this list of conditions and the following disclaimer in |
| 19 | + * the documentation and/or other materials provided with the |
| 20 | + * distribution. |
| 21 | + * 3. Neither the name of the Company nor the names of its contributors |
| 22 | + * may be used to endorse or promote products derived from this |
| 23 | + * software without specific prior written permission. |
| 24 | + */ |
| 25 | + |
| 26 | +#pragma once |
| 27 | + |
| 28 | +#include <cstdint> |
| 29 | +#include <rte_mbuf.h> |
| 30 | +#include <vector> |
| 31 | + |
| 32 | +namespace ipxp { |
| 33 | + |
| 34 | +/** |
| 35 | + * @brief Wrapper class for DPDK mbuf objects. |
| 36 | + */ |
| 37 | +class DpdkMbuf { |
| 38 | +public: |
| 39 | + |
| 40 | + /** |
| 41 | + * @brief Constructs a DpdkMbuf object. |
| 42 | + * @param mBufsCount The initial size of the mbufs vector. |
| 43 | + */ |
| 44 | + DpdkMbuf(size_t mBufsCount = 0); |
| 45 | + |
| 46 | + /** |
| 47 | + * @brief Releases the allocated mbufs. |
| 48 | + */ |
| 49 | + ~DpdkMbuf(); |
| 50 | + |
| 51 | + /** |
| 52 | + * @brief Resizes the mbufs vector. |
| 53 | + * @param mBufsCount The new size of the mbufs vector. |
| 54 | + */ |
| 55 | + void resize(size_t mBufsCount); |
| 56 | + |
| 57 | + /** |
| 58 | + * @brief Sets the number of mbufs in use. |
| 59 | + * @param mBufsInUse The number of mbufs currently in use. |
| 60 | + */ |
| 61 | + void setMbufsInUse(size_t mBufsInUse) noexcept; |
| 62 | + |
| 63 | + /** |
| 64 | + * @brief Returns the maximum size (currently allocated) of the mbufs vector. |
| 65 | + * @return The maximum size of the mbufs vector. |
| 66 | + */ |
| 67 | + uint16_t maxSize() const noexcept; |
| 68 | + |
| 69 | + /** |
| 70 | + * @brief Returns the current size of the mbufs vector. (in use) |
| 71 | + * @return The current size of the mbufs vector. |
| 72 | + */ |
| 73 | + uint16_t size() const noexcept; |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief Returns a pointer to the underlying mbufs data. |
| 77 | + * @return A pointer to the underlying mbufs data. |
| 78 | + */ |
| 79 | + rte_mbuf** data(); |
| 80 | + |
| 81 | + /** |
| 82 | + * @brief Releases all the mbufs. |
| 83 | + * @note Function calls rte_pktmbuf_free() |
| 84 | + */ |
| 85 | + void releaseMbufs(); |
| 86 | + |
| 87 | + /** |
| 88 | + * @brief Overloaded subscript operator to access mbufs by index. |
| 89 | + * @param index The index of the mbuf to access. |
| 90 | + * @return The mbuf at the specified index. |
| 91 | + */ |
| 92 | + rte_mbuf* operator[](int index) { return m_mBufs[index]; } |
| 93 | + |
| 94 | +private: |
| 95 | + std::vector<rte_mbuf*> m_mBufs; |
| 96 | + uint16_t m_mBufsCount; |
| 97 | + uint16_t m_mBufsInUse; |
| 98 | +}; |
| 99 | + |
| 100 | +} // namespace ipxp |
0 commit comments