Skip to content

feat PageReassembler #7

@David-A-T-M

Description

@David-A-T-M

Implement PageReassembler Service

Description

Implement the PageReassembler class. Unlike previous data models, this is a mutable stateful class responsible for collecting incoming Packet objects and reconstructing a full Page once all fragments are received.

Technical Specifications

  • Type: Standard Java class (not a record, as it requires mutable state).
  • Internal Storage: Use a fixed-size array Packet[] to store fragments at their respective pagePos. This allows $O(1)$ access and clear visibility of missing slots (null).
  • Fields:
    • long pageId: The ID of the page being reassembled.
    • IpAddress srcIp: Expected source address for validation.
    • int total: Total number of packets expected.
    • int count: Current number of packets received.
    • long timeout: Absolute simulation tick when this assembler should be discarded if incomplete.
  • Key Methods:
    • boolean addPacket(Packet p): Validates metadata (ID, IP, length) and places the packet in the array. Returns true if added, false if redundant or invalid.
    • boolean isComplete(): Returns true if count == total.
    • Page package(): Produces a final Page object if complete. Throws an exception if called prematurely.
    • double getCompletionRate(): Returns the percentage of received packets.

Validation logic

  • The constructor must initialize the Packet[] array with the size of total.
  • addPacket must ignore packets that don't match the pageId or srcIp of the reassembler.
  • Prevent duplicate packet insertion (check if packets[pos] != null).

Tasks

  • Create PageReassembler.java in the assembler (or service) package.
  • Implement state management logic.
  • Add unit tests in PageReassemblerTest.java:
    • Successful full reassembly.
    • Handling of out-of-order packets.
    • Prevention of inconsistent packet insertion.
    • Validation of completion logic.
  • Verify 100% branch coverage with JaCoCo.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions