CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

packet_forward()

Assignment 2 - Spring 2025

The goal of packet_forward() is to simulate sending a packet from a source node to a destination node, following the routing table entries that were loaded using get_route_info().

The packet will be forwarded step-by-step using each node’s next hop, until it reaches the final destination. Along the way, we also keep track of how many packets and bytes have been forwarded.

For example:

Forwarding packet: nodeA;nodeC;928
Node nodeA sends to node nodeB (cost: 8)
Node nodeB sends to node nodeC (cost: 3)
Node nodeC is the destination. Done forwarding for the packet.
Current packet size: 928 bytes  


How do we do this?

To simulate packet forwarding, we need to:

  1. Parse the Packet String:

    • The input format is source;destination;size

    • Use sscanf() to extract all three values from the string.

  2. Start from the Source Node:

    • Use find_node() to get the node where the packet begins.

  3. Look for the Destination in the Source's Routing Table:

    • Go through the source node’s dest_list to find a route to the final destination.

  4. Forward the Packet Step-by-Step:

    • For each hop:

      • Print the step (src sends to nextHop)

      • Increment packets_sent and bytes_sent

      • Move to the next node (using find_node() again)

    • Repeat until you reach the destination.

  5. Print Completion Message

    • Confirm that the destination has been reached.

    • Show the final packet size.

Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 25 more lessons in Carleton University - SYSC 2006.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.