Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java: Build a Defragment class with two public methods: addFrag and toString. The addFrag method will be called each time a new packet fragment arrives.

java:

Build a Defragment class with two public methods: addFrag and toString. The addFrag method will be called each time a new packet fragment arrives. Each fragment will come with four pieces of information:

Packet ID. Each fragment will have a packet ID number. This number will identify the original packet that the fragment came from. You can use the Packet ID to group fragments together as you reassemble them.

Fragment Offset. The Fragment Offset is the number of bytes this fragment is from the beginning of the original packet. A Fragment Offset of zero indicates the first fragment of a packet; a Fragment Offset of 65,535 would indicate a fragment that starts at the very last byte of a packet. On the real Internet, the Fragment Offset must always be a multiple of 8; for this assignment, you should not make that assumption.

Fragment Length. Each fragment will contain a positive number of bytes. On the real Internet, fragments lengths are frequently about 1500 bytes, but the length could be as small as 1 or as large as 65,536.

More Fragments Bit. Each fragment includes a bit (zero or one) indicating whether there are more fragments from the original packet. The very last fragment of a packet will always contain a More Fragments value of zero; all previous fragments will have a one.

Your declaration for the addFrag method will thus be:

public void addFrag(int id, int froff, int length, boolean morefrag);

Your implementation should make use of several instances of the List ADT from the textbook -- a list of fragments for a given packet that is currently being reassembled; you could be reassembling several packets at once, so you will need a list of such lists; and a list of packets that have been completely reassembled. Several of these lists could be sorted and/or indexed; it is up to you whether to use linked- or array-based implementations. Do not rely on the built-in Java collection class libraries, such as ArrayList, Vector, and their friends.

Example Run:

A 2000-byte packet with ID 1234, in three chunks. Input:

ID FrOff Len MF 1234 0 1000 1 1234 1000 500 1 1234 1500 500 0

Output:

Packet 1234, 2000 bytes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

1. Design an effective socialization program for employees.

Answered: 1 week ago