Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions include/core/Packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* used by routers for data transmission.
*/
class Packet {
int pageID; /**< ID of the page that the packet belongs to. */
int pagePosition; /**< Position of the packet in the page. */
int pageLength; /**< Length of the page. */
int routerPriority; /**< Priority of the packet in the router. The lower the value, the higher the priority. */
size_t pageID; /**< ID of the page that the packet belongs to. */
size_t pagePosition; /**< Position of the packet in the page. */
size_t pageLength; /**< Length of the page. */
size_t routerPriority; /**< Priority of the packet in the router. The lower the value, the higher the priority. */
IPAddress destinationIP; /**< Reference to the destination terminal IP. */
IPAddress originIP; /**< Reference to the origin terminal IP. */

Expand Down Expand Up @@ -73,25 +73,25 @@ class Packet {
* @brief Gets the page ID.
* @return Page ID.
*/
[[nodiscard]] int getPageID() const noexcept;
[[nodiscard]] size_t getPageID() const noexcept;

/**
* @brief Gets the position of this packet within its page.
* @return Page position (0-based).
*/
[[nodiscard]] int getPagePosition() const noexcept;
[[nodiscard]] size_t getPagePosition() const noexcept;

/**
* @brief Gets the total length of the page this packet belongs to.
* @return Page length.
*/
[[nodiscard]] int getPageLength() const noexcept;
[[nodiscard]] size_t getPageLength() const noexcept;

/**
* @brief Gets the router priority assigned to this packet.
* @return Router priority. The lower the value, the higher the priority.
*/
[[nodiscard]] int getRouterPriority() const noexcept;
[[nodiscard]] size_t getRouterPriority() const noexcept;

/**
* @brief Gets the destination IP address.
Expand Down Expand Up @@ -175,19 +175,19 @@ inline void Packet::setRouterPriority(int priority) noexcept {
}

// =============== Getters ===============
inline int Packet::getPageID() const noexcept {
inline size_t Packet::getPageID() const noexcept {
return pageID;
}

inline int Packet::getPagePosition() const noexcept {
inline size_t Packet::getPagePosition() const noexcept {
return pagePosition;
}

inline int Packet::getPageLength() const noexcept {
inline size_t Packet::getPageLength() const noexcept {
return pageLength;
}

inline int Packet::getRouterPriority() const noexcept {
inline size_t Packet::getRouterPriority() const noexcept {
return routerPriority;
}

Expand Down
26 changes: 23 additions & 3 deletions include/core/PacketBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class PacketBuffer {
};

private:
List<Packet> packets; /**< Internal packet storage */
Mode mode; /**< Operation mode */
size_t capacity; /**< Maximum capacity (0 = unlimited) */
List<Packet> packets; /**< Internal packet storage */
Mode mode; /**< Operation mode */
size_t capacity; /**< Maximum capacity (0 = unlimited) */
IPAddress destinationIP; /**< Associated router IP (for output buffers) */

public:
// =============== Constructors & Destructor ===============
Expand All @@ -40,6 +41,14 @@ class PacketBuffer {
*/
explicit PacketBuffer(Mode mode = Mode::FIFO, size_t capacity = 0);

/**
* @brief Constructor with associated router IP.
* @param ip Associated router IP address.
* @param mode Operation mode (FIFO or PRIORITY, default PRIORITY).
* @param capacity Maximum buffer capacity (0 = unlimited, default).
*/
explicit PacketBuffer(IPAddress ip, Mode mode = Mode::PRIORITY, size_t capacity = 0);

/**
* @brief Destructor
*/
Expand All @@ -66,6 +75,13 @@ class PacketBuffer {
PacketBuffer& operator=(PacketBuffer&&) noexcept = default;

// =============== Getters ===============
/**
* @brief Gets the associated destination IP.
* @return Destination IP address.
* @note A 0.0 IP indicates no specific association.
*/
[[nodiscard]] IPAddress getDestinationIP() const noexcept;

/**
* @brief Gets the maximum capacity.
* @return Capacity (0 = unlimited).
Expand Down Expand Up @@ -243,6 +259,10 @@ class PacketBuffer {
};

// =============== Getters ===============
[[nodiscard]] inline IPAddress PacketBuffer::getDestinationIP() const noexcept {
return destinationIP;
}

inline size_t PacketBuffer::getCapacity() const noexcept {
return capacity;
}
Expand Down
Loading