CMPS 144 Fall 2026
Prog. Assg. #5: Simplistic Router Simulation
Due: 11:59pm, Nov. 12

Note: The two background sections resulted from "conversations" between your instructor and Google's Gemini AI agent. End of note.

Background: Routers

A router acts as a traffic controller within a packet-switched network (or across interconnected networks, such as the Internet), moving each unit of data (which is called a packet) efficiently from its source to its destination. It accomplishes this role via two primary functions:

On the Internet as a whole, traffic distribution is bimodal, in the sense that packets generally fall into two very distinct size categories. Large packets (1300 to 1500 bytes) carry actual data payloads (e.g., data from a video stream, file download, or a webpage being loaded). Small packets (40 to 64 bytes) typically contain data useful for network housekeeping, such as TCP acknowledgements (in which a receiver says "I got the data you sent" to a sender). Some small packets contain tiny data bursts representing gaming inputs or voice-over-IP (VoIP) audio.

The step-by-step lifecycle of a packet, with respect to a router that it "encounters" on the way to its destination, goes something like this:

  1. Reception and Bit-to-Packet Assembly: The router's physical interface receives raw electrical signals, optical light pulses, or wireless radio waves and converts these signals back into a sequence of digital bits (0's and 1's), thereby "assembling" the packet. The time required to carry out this function is called reception delay.
  2. Input Queueing: The packet is placed into the router's input buffer (i.e., queue). If the input buffer is already full because traffic is arriving too fast, the incoming packet is "dropped" (i.e., ignored). (Such an event is called buffer overflow.) The time that a packet remains in this queue is called input queuing delay.
  3. Nodal Processing: The packet is taken from the input buffer and processed. Such processing includes verifying that the packet wasn't corrupted or altered during transmission.
  4. Routing Table Lookup (Path Determination): Based upon the packet's intended destination (which is described by an IP (Internet Protocol) address stored within the packet), the router uses its internal routing table to determine two crucial things:
    1. from which of the router's output interfaces the packet should exit and
    2. the IP address of the router to which the packet should go next (called the next-hop address).

    The time taken by this and the previous step together is called processing delay.

  5. Switching to the Output Interface: The packet is sent along the router's internal bus to its designated exit port. The time taken during this step is called switching delay.
  6. Output Queueing (The Waiting Line): The packet arrives at the exit port and enters the port's output buffer (containing packets that are waiting to be sent along their way from that port). The time a packet spends in this queue is called queueing delay.
  7. Transmission (Serialization): The packet is taken from the output queue, at which time its digital bits (0's and 1's) are translated into physical signals (electricity or light) and pushed onto the transmission medium bit-by-bit. The time it takes to complete this function is called transmission delay and is given by the formula Transmission Delay = L/R, where L is the length/size of the packet (measured in bits or bytes) and R is the transmission rate (or link bandwidth) (measured in bits (or bytes) per second (or per some other unit of time).

    In modern networking, the transmission rate is almost always limited by the physical bandwidth of the transmission medium (often called the "link") rather than the processing or switching speeds of the router itself.

Industry-standard terms for the total clock time a packet spends "living" inside a router are node residence time and single-hop delay (or per-hop latency).


Background: Discrete Event Simulation

A discrete event simulation (DES) is a modeling approach in which a system’s operation is represented as a chronological sequence of distinct events. Unlike continuous simulations where variables change smoothly and constantly over time (like fluid flowing through a pipe), a DES changes state only at specific, isolated points in time. Between these events, the system state remains completely unchanged.

There are two basic categories of such simulations, differing in how "time" advances:


Assignment

This assignment is to complete (one class within) a Java program that performs a simplistic tick-based discrete event simulation of the interactions between a network router and the packets that "pass through" it over time.

Recall from above the seven steps that a packet goes through during its interaction with each router on its journey from source to destination. Our simulation essentially collapses the first six steps into one so that, in effect, there are only two steps, the first of which places a newly-received packet into a queue and the second of which transmits the packet at the front of the queue.

Here are the relevant Java source code files, plus a file containing sample input:

The crucial method in the RouterSimulator class is the aforementioned advanceOneTick(), each execution of which simulates the actions that occur within the simulated router during a single tick. It also updates instance variables (and/or the objects to which they are bound) in such a way as to keep a record of those events, making available to the observer methods the data they need to return correct responses.

At a high level of abstraction, advanceOneTick() is to operate as follows:

  1. update the tick counter to advance the time
  2. Determine whether or not a new packet arrives during the current tick. If yes, create a new packet using the makePacket() method. (The IDs of the created packets should be 1, 2, 3, etc., etc.) If the created packet's size is such that placing it on the queue would cause an overflow (i.e., exceed the queue's capacity for # of bytes), the packet is dropped. Otherwise, the packet is placed at the rear of the queue.
  3. Next, transmit as many bytes as possible (up to the bandwidth) from any packets that are on the queue (in order starting at the front of the queue, of course). Depending upon the sizes of the packets towards the front of the queue, this could mean that just a fraction of one packet gets transmitted, or it could mean that several packets get transmitted in full and (possibly) a fraction of another one. Note that each instance of the Packet class includes a variable for the purpose of keeping track of how many of its bytes remain to be transmitted. For any packet all or some of whose bytes are transmitted during a given tick, that instance variable should be decreased by that number of bytes.

Notes:

  • The simulation does not literally transmit any bytes of any simulated packet! Indeed, the Packet class does not even include an instance variable for representing the contents of a packet! Simulating such a transmission simply means updating whatever variables are needed to record that such a (simulated) transmission has occurred.
  • When a packet is dropped, it should be inserted at the end of the droppedPackets list; similarly, when all of the bytes of a packet have been transmitted, that packet should be inserted at the end of the transmittedPackets list. The right way to do that is to use the add() method, as in droppedPackets.add(packet).
End of notes.


Sample Simulation

Using the inputs found in the sample input file, here is what a run of the program produces:

Welcome to RouterSimulationApp

Inputs:
  Seed for Random: 25
  Minimum packet size: 15
  Maximum packet size: 1500
  Arrival Probability: 0.4
  Queue Capacity: 5000
  Bandwidth: 240
  Ticks to simulate: 20

After 1 ticks:
  # packets to have arrived: 0
  # packets fully transmitted: 0
  # packets dropped: 0
  # packets in queue: 0

After 2 ticks:
  # packets to have arrived: 1
  # packets fully transmitted: 0
  # packets dropped: 0
  # packets in queue: 1

After 3 ticks:
  # packets to have arrived: 2
  # packets fully transmitted: 0
  # packets dropped: 0
  # packets in queue: 2

After 4 ticks:
  # packets to have arrived: 3
  # packets fully transmitted: 0
  # packets dropped: 0
  # packets in queue: 3

After 5 ticks:
  # packets to have arrived: 3
  # packets fully transmitted: 1
  # packets dropped: 0
  # packets in queue: 2

After 6 ticks:
  # packets to have arrived: 3
  # packets fully transmitted: 1
  # packets dropped: 0
  # packets in queue: 2

After 7 ticks:
  # packets to have arrived: 3
  # packets fully transmitted: 1
  # packets dropped: 0
  # packets in queue: 2

After 8 ticks:
  # packets to have arrived: 3
  # packets fully transmitted: 1
  # packets dropped: 0
  # packets in queue: 2

After 9 ticks:
  # packets to have arrived: 3
  # packets fully transmitted: 1
  # packets dropped: 0
  # packets in queue: 2

After 10 ticks:
  # packets to have arrived: 4
  # packets fully transmitted: 2
  # packets dropped: 0
  # packets in queue: 2

After 11 ticks:
  # packets to have arrived: 5
  # packets fully transmitted: 2
  # packets dropped: 0
  # packets in queue: 3

After 12 ticks:
  # packets to have arrived: 5
  # packets fully transmitted: 2
  # packets dropped: 0
  # packets in queue: 3

After 13 ticks:
  # packets to have arrived: 6
  # packets fully transmitted: 2
  # packets dropped: 0
  # packets in queue: 4

After 14 ticks:
  # packets to have arrived: 7
  # packets fully transmitted: 2
  # packets dropped: 1
  # packets in queue: 4

After 15 ticks:
  # packets to have arrived: 7
  # packets fully transmitted: 2
  # packets dropped: 1
  # packets in queue: 4

After 16 ticks:
  # packets to have arrived: 7
  # packets fully transmitted: 3
  # packets dropped: 1
  # packets in queue: 3

After 17 ticks:
  # packets to have arrived: 7
  # packets fully transmitted: 3
  # packets dropped: 1
  # packets in queue: 3

After 18 ticks:
  # packets to have arrived: 8
  # packets fully transmitted: 4
  # packets dropped: 2
  # packets in queue: 2

After 19 ticks:
  # packets to have arrived: 8
  # packets fully transmitted: 5
  # packets dropped: 2
  # packets in queue: 1

After 20 ticks:
  # packets to have arrived: 9
  # packets fully transmitted: 5
  # packets dropped: 3
  # packets in queue: 1


Average delay of fully transmitted packets: 7.600000

Fully transmitted packets:
ID:1; Size:840; Arrival Time:2; Departure Time:5
ID:2; Size:1252; Arrival Time:3; Departure Time:10
ID:3; Size:1407; Arrival Time:4; Departure Time:16
ID:4; Size:535; Arrival Time:10; Departure Time:18
ID:5; Size:51; Arrival Time:11; Departure Time:19

Dropped packets:
ID:7; Size:417; Arrival Time:14; bytes yet to be transmitted:417
ID:8; Size:575; Arrival Time:18; bytes yet to be transmitted:575
ID:9; Size:1134; Arrival Time:20; bytes yet to be transmitted:1134

Packets on the queue:
ID:6; Size:870; Arrival Time:13; bytes yet to be transmitted:395

Goodbye.


Program Submission

Submit the Java source code (meaning the .java file) of your completed RouterSimulator class, as usual, to the appropriate Brightspace drop box. Make sure to identify any agent (human or otherwise) with whom you collaborated, as well as any defects in your work, using comments near the beginning of the class.