< Back
Page 9 of 9
This chapter is from the book
1.9 Computer Simulation Project
Simulation of Networking Packets. Write a computer program in C or C++ to simulate a “packet.” Each packet must have two distinct parts: header and data. The data is fixed on 10 bytes consisting of all logic 1s. The header is 9 bytes long and consists of three fields only: priority (1 byte), source address (4 bytes), and destination address (4 bytes).
- For a Packet A, initialize the priority field to be 0, and source and destination addresses to be 10.0.0.1 and 192.0.1.0, respectively.
- For a Packet B, initialize the priority field to be 1, and source and destination addresses to be 11.1.0.1 and 192.0.1.0, respectively.
- For a Packet C, initialize the priority field to be 0, and source and destination addresses to be 11.1.0.1 and 192.0.1.0, respectively.
- Demonstrate that your program can create the packets defined in parts (a), (b), and (c).
- Extend your program such that a comparator looks at the priority fields and destination addresses of any combination of two packets. If the destination addresses are the same, it chooses the packet with the highest priority and leaves the packet with lower priority in a register with incremented priority. Otherwise, it chooses randomly one of the packets and leaves the other one in the register with incremented priority. Show that your program is capable of choosing Packet B.
< Back
Page 9 of 9